Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #16771

Re: well formed flag ?

From Chris Hinsley <chris.hinsley@gmail.com>
Newsgroups comp.lang.forth
Date 2012-10-27 17:44 +0100
Message-ID <2012102717444755036-chrishinsley@gmailcom> (permalink)
References <2012102715594849117-chrishinsley@gmailcom> <201210271603106615-chrishinsley@gmailcom> <dd0589f1-d982-4279-a3d3-b4cb7b5aea8d@s14g2000vba.googlegroups.com> <1315f2d4-5da9-42dc-af23-d7d7a9f9018b@l12g2000vbj.googlegroups.com>
Subject Re: well formed flag ?

Show all headers | View raw


On 2012-10-27 16:06:07 +0000, Alex McDonald said:

> On Oct 27, 4:33 pm, Alex McDonald <b...@rivadpm.com> wrote:
>> On Oct 27, 4:03 pm, Chris Hinsley <chris.hins...@gmail.com> wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On 2012-10-27 14:59:48 +0000, Chris Hinsley said:
>> 
>>>> Folks, I'm doing some tweaking to my hobby Forth compiler and just been
>>>> doing some inlineing work.
>> 
>>>> I'm not very happy about the size of the x86 code for comparision words
>>>> (I know I could reduce the code size if I had a full optimizing code
>>>> generator, but I don't yet…) this is my code for "<"
>> 
>>>>    defword ">", 0, WORD_GT, WORD_INLINE_COMMA
>>>>    POPDSP eax
>>>>    cmp eax, ebx
>>>>    setg bl
>>>>    movzx ebx, bl
>>>>    neg ebx
>>>>    ret
>>>>    defword_end
>> 
>>>> I followed the 'well formed flag' comments in Ms Rathers book for this,
>>>> but the IF and TRUE, FALSE words only talk about 0 for false or not
>>>> zero for true. Is it definately the case that Forth needs -1 to come
>>>> from the comparason words ?
>> 
>>>> Are you allowed to write code that _needs_ the -1 from the ">" ? ie if
>>>> it produce just a 1, would that be incorrect ?
>> 
>>>> Chris
>> 
>>> I might also add that my 0BRANCH word is:
>> 
>>>         defword "0BRANCH", 0, WORD_ZBRANCH, WORD_INLINE_COMMA
>>>         mov eax, ebx
>>>         POPDSP ebx
>>>         test eax, eax
>>>         jz strict near i_jmp
>>>         ret
>>>         defword_end
>> 
>>> Regards
>> 
>>> Chris
>> 
>> : < ( 2 -- 1 )
>> \ ' nseopt compiles; code=$4014DF len=16 type=1
>> \ defined in src\kernel\gkernel32.f at line 564
>> ( $0 )    mov     edx eax                           \ 8BD0
>> ( $2 )    or      ecx $-1                           \ 83C9FF
>> ( $5 )    xor     eax eax                           \ 33C0
>> ( $7 )    cmp     dword { $0 ebp } edx              \ 395500
>> ( $A )    cmovl   eax ecx                           \ 0F4CC1
>> ( $D )    add     ebp $4                            \ 83C504
>> ( $10 )   ret                                       \ C3 ( end ) ok
>> 
>> EAX is top of stack, EBP is the stack pointer and { EBP } is next to
>> top.
>> 
>> I'd definitely stick to well formed flags since this;
>> 
>> variable var 0 var !
>> : foo 10 < negate var +! ;
>> 
>> is well-formed Forth.
> 
> There's also
> 
> : >= ( 2 -- 1 )
> ( $0 )    sub     eax dword { $0 ebp }              \ 2B4500
> ( $3 )    cdq                                       \ 99
> ( $4 )    mov     eax edx                           \ 8BC2
> ( $6 )    add     ebp $4                            \ 83C504
> ( $9 )    ret                                       \ C3 ( end ) ok
> 
> and correspondingly < is   neg eax

One thing I just noticed is that NASM isn't encodeing small constant 
adds as a single byte, it's useing the full 4 byte encodeing ! I don't 
recall there being an option to tell NASM to optimise constants, I 
thought there was only -O flags to say optimize branches ?

Need to double check the NASM manual...

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 15:59 +0100
  Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 16:03 +0100
    Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 08:33 -0700
      Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 09:06 -0700
        Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 09:26 -0700
          Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:33 +0100
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:38 +0100
            Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 12:52 -0700
              Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 21:01 +0100
                Re: well formed flag ? Coos Haak <chforth@hccnet.nl> - 2012-10-27 22:18 +0200
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-28 04:19 -0400
        Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 17:44 +0100
          Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-27 14:52 -0400
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:06 +0100
        Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 19:25 +0100
          Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 19:33 +0100
          Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 15:08 -0700
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-28 00:53 +0100
  Re: well formed flag ? Mark Wills <forthfreak@gmail.com> - 2012-10-27 09:31 -0700
    Re: well formed flag ? "A. K." <akk@nospam.org> - 2012-10-27 19:21 +0200
      Re: well formed flag ? Mark Wills <forthfreak@gmail.com> - 2012-10-27 10:33 -0700
        Re: well formed flag ? Coos Haak <chforth@hccnet.nl> - 2012-10-27 22:21 +0200
        Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-28 12:33 +1100
          Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-27 15:46 -1000
  Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-27 08:54 -1000
    Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:11 +0100
  Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-28 11:05 +1100
    Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-28 11:53 +0000
      Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-28 14:17 +0100
        Re: well formed flag ? mhx@iae.nl (Marcel Hendrix) - 2012-10-28 16:59 +0200
          Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-28 18:37 +0100
        Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-29 23:46 +1100
          Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-29 08:33 -0500
            Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-29 08:25 -0700
              Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-29 12:27 -0500
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 08:18 -0700
                Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-30 10:33 -0500
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 08:48 -0700
                Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-30 11:45 -0500
                Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-30 20:10 +0100
                Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-30 15:10 -0700
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 18:28 -0700
                Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-11-02 05:28 -0700
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-11-02 08:13 -0700
                Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-30 12:50 -1000
                Re: well formed flag ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 14:57 +0000
                Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-31 17:58 +0100
                Re: well formed flag ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 17:39 +0000
                Re: well formed flag ? David Thompson <dave.thompson2@verizon.net> - 2012-11-16 23:21 -0500
                Aliasing (was: well formed flag ?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 14:03 +0000
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-31 12:06 -0400
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-31 09:31 -0700
                Aliases (was: well formed flag ?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 17:02 +0000
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-31 20:06 -0400
      Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-29 23:47 +1100
        Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-30 18:02 +0000
          Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-31 11:44 +1100
            Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-31 09:25 +0000

csiph-web