home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 116,359 of 117,927   
   Ruvim to Krishna Myneni   
   Re: DLSHIFT and DRSHIFT   
   27 Mar 24 15:26:29   
   
   From: ruvim.pinka@gmail.com   
      
   On 2024-03-27 04:57, Krishna Myneni wrote:   
   > On 3/26/24 17:01, Krishna Myneni wrote:   
   >> Standard source definitions of DLSHIFT and DRSHIFT (double number left   
   >> shift and right shift), over full shift range, per discussion in prior   
   >> thread.   
   >>   
   >> Tests needed.   
   >   
   > Just tested DLSHIFT and found weird things going on. Traced the problem   
   > to LSHIFT.   
   >   
   >   
   > kforth64   
   >   
   > 1 64 LSHIFT .  \ expected to get zero   
   > 1              \ instead, got 1   
   >   
   > Then, I looked at the spec. for LSHIFT and, indeed, there is an   
   > ambiguous condition for u >= BITS_PER_CELL .   
   >   
   >   
   > 6.1.1805   
   > LSHIFT “l-shift”   
   > CORE   
   > ( x1 u – – x2 )   
   > Perform a logical left shift of u bit-places on x1, giving x2. Put   
   > zeroes into the least significant bits vacated by the shift. An   
   > ambiguous condition exists if u is greater than or equal to the number   
   > of bits in a cell.   
   >   
   [...]   
   > We shouldn't have an ambiguous condition here because of some   
   > idiosyncratic behavior of the SHL instruction!   
   >   
   > u 64 LSHIFT should be zero on all systems with cell sizes up to 64 bits.   
      
   Ideally — yes.   
      
   My rationale (see [1]) is that for any `x` and `u`, the result of a   
   single shift of `x` by `u` bits should always be equivalent to `u`   
   sequential shifts by 1 bit.   
      
   But neither the standard nor implementations follow this idea.   
      
   And I agree, this is rarely needed. So if a program requires this   
   behavior, it can test the behavior of "shift" operations in this regard   
   and redefine them in its own word list as:   
      
      : lshift ( x u -- x )   
        dup bits_per_cell u< if lshift exit then   
        2drop 0   
      ;   
      
      
   [1] An ambiguous condition in LSHIFT (2024-02-05)   
      
      
   --   
   Ruvim   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca