home .. forth .. colorforth mail list archive ..

RE: [colorforth] FS/Forth for DOS: crude performance test


Sorry for the late answer, unexpected holidays.

> -----Message d'origine-----
> De : Lonnie Reed [mailto:lonnie@xxxxxxxxxxxxxxxxxxxxx]
> Envoyé : ven. 27 juin 2003 20:47
> À : colorforth@xxxxxxxxxxxxxxxxxx
> Objet : RE: [colorforth] FS/Forth for DOS: crude performance test
> 
> 
> >
> >> Just curious why all this XCHGing is required.
> >
> >It's because the x86 only has one stack pointer, but Forth 
> requires two stacks.
> > So to manipulate the data stack with PUSH and POP 
> instructions, the data stack
> >pointer must appear in the SP register.  But when invoking 
> colon definitions,
> >the return stack pointer must be in SP.
> >
> 
> Ahh, it makes sense now. I was using BP as my PSP 
> (data/parameter stack 
> pointer), and the primitives explicitly move the pointer:
> 
> Top of stack cached in AX.
> 
> : AND   AND AX,[BP]  INC BP  INC BP ;
> 
> : DUP   DEC BP  DEC BP  MOV [BP],AX  ;
> 
> : DROP   MOV AX,[BP]  INC BP  INC BP ;
> 
> etc. 
> 

I use BX as TOS and AX as data stack pointer:
:CODE AND  ax sp xchg  cx pop  bx cx and  ax sp xchg  ret CODE.
( that is xchg ax,sp  pop cx  and bx cx xchg ax sp ret )
6 bytes, 23 cycles ( or 20 and don't rememeber if pop is 15 or 12 ) without
ret
:CODE DROP ax sp xchg  bx pop  ax sp xchg  ret CODE.
With inlining + optimization one or both XCHG may disappear. Without
optimization, it takes 3 bytes whereas your formula takes 5.

One problem with BP is that in the instruction encoding a nul displacment is
mandatory in all cases whereas it is not with [DI] and [SI]. OTOH you can
sometimes take advantage of the fact that you can index down your data
stack:
: SWAP XCHG AX,[BP+2] ;
But I guess you know that.

> Not the most efficient way, I guess, but it seemed 
> straightforward and easy
> to understand, which was the goal. Optimization will come 
> later... I'm still
> calling the primitives rather than inlining to keep the 
> compiler simple.
> 

Take care of R> and THEN ( before ; ) when you'll implement tail recursion. 

> It sounds interesting to use PUSH/POP on both stacks, I'll 
> have to look into 
> that.
> 
> Thanks for the explanation.
> 
> -Lonnie  
> 
>  

 Amicalement,
  Frederic


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com