From: krishna.myneni@ccreweb.org   
      
   On 3/29/24 11:55, Anton Ertl wrote:   
   > Krishna Myneni writes:   
   >> On 3/28/24 03:49, Anton Ertl wrote:   
   >>> Here's some data about the occurences in the Gforth image:   
   >>>   
   >>> Non-constant shift amount:   
   >>> 2 lshift   
   >>> 1 rshift   
   >>> 0 arshift   
   >>>   
   >>> Constant shift amount:   
   >>> 18 lit lshift   
   >>> 41 lit rshift   
   >>> 0 lit arshift   
   >>>   
   >> ...   
   >>   
   >> Checking the Forth code base which I use, I find ~ 100:1 ratio between   
   >> uses of constant shift amount to non-constant shifts. The existing   
   >> instances of non-constant shifts are comparable to yours: two in number   
   >> theory programs e.g., finding an exact fraction for a floating point   
   >> number, and one use in the assembler.   
   >>   
   >> I don't know what to conclude from this other than the kind of   
   >> application development I have been doing favors one over the other.   
   >   
   > It shows that Forth systems that support special code generation for   
   > operations with constants (probably all native-code systems, as well   
   > as Gforth) would be able to generate the same code in the vast   
   > majority of cases even with the change you propose. Only in the few   
   > non-constant cases a few extra instructions would be needed.   
   >   
      
   Ah, so optimizing Forth compilers can do a compile-time check for   
   literal shifts and not have to insert instructions for compare and   
   branch e.g., my new implementation of LSHIFT in kforth64   
      
   (from vm64-common.s)   
      
   .equ MAX_SHIFT_COUNT, WSIZE*8-1   
      
   L_lshift:   
    LDSP   
    DROP   
    mov (%rbx), %rcx   
    cmp $MAX_SHIFT_COUNT, %rcx   
    jbe lshift1   
    movq $0, WSIZE(%rbx)   
    NEXT   
   lshift1:   
    shlq %cl, WSIZE(%rbx)   
    NEXT   
      
      
   The older version was:   
      
   L_lshift:   
    LDSP   
    DROP   
    mov (%rbx), %rcx   
    shlq %cl, WSIZE(%rbx)   
    NEXT   
      
   Similarly for RSHIFT.   
      
   --   
   KM   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|