Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 27 Oct 2012 11:44:47 -0500 From: Chris Hinsley Newsgroups: comp.lang.forth Date: Sat, 27 Oct 2012 17:44:47 +0100 Message-ID: <2012102717444755036-chrishinsley@gmailcom> References: <2012102715594849117-chrishinsley@gmailcom> <201210271603106615-chrishinsley@gmailcom> <1315f2d4-5da9-42dc-af23-d7d7a9f9018b@l12g2000vbj.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: well formed flag ? User-Agent: Unison/2.1.9 Lines: 94 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-nGZzRke/Dl8Znx4iRtwHbiDWBKzSTFFGwdPgiD0ePkeTp+RJs6FHBuS2h6/kdykhlnCseX2/iKTcfuf!5CWJHLUjAkzj7fzU3jjZktLyEHtlSUTrLkEEDX6zT03I6llKTtQFdLRS+yvLnhcTnpHsIQk= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4461 Xref: csiph.com comp.lang.forth:16771 On 2012-10-27 16:06:07 +0000, Alex McDonald said: > On Oct 27, 4:33 pm, Alex McDonald wrote: >> On Oct 27, 4:03 pm, Chris Hinsley 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...