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,380 of 117,927   
   Krishna Myneni to Krishna Myneni   
   Re: DLSHIFT and DRSHIFT   
   29 Mar 24 09:41:08   
   
   From: krishna.myneni@ccreweb.org   
      
   On 3/26/24 19: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.   
   >   
   > Gforth does the same thing   
   >   
   > 1 64 LSHIFT .  1   
   > 1 65 LSHIFT .  2   
   > etc.   
   >   
   >   
   > 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.   
   >   
      
   I have revised LSHIFT and RSHIFT in kForth-32 and kForth-64 to give   
   expected results for shift count >= BITS_PER_CELL (still have to update   
   kForth-Win32). Some test code to check that these words behave as expected:   
      
   1 CELLS 8 * constant BITS_PER_CELL   
      
   : test-lshift ( -- )   
        BITS_PER_CELL 6 + 0 DO   
          I 2 .R 2 SPACES   
          1 I LSHIFT   
          BINARY BITS_PER_CELL U.R CR DECIMAL   
        LOOP ;   
      
   : test-rshift ( -- )   
        1 BITS_PER_CELL 1- LSHIFT   
        BITS_PER_CELL 6 + 0 DO   
          I 2 .R 2 SPACES   
          DUP I RSHIFT   
          BINARY BITS_PER_CELL U.R CR DECIMAL   
        LOOP  DROP ;   
      
   TEST-LSHIFT ( on 32-bit system )   
     0                                 1   
     1                                10   
     2                               100   
     3                              1000   
     4                             10000   
     5                            100000   
     6                           1000000   
     7                          10000000   
     8                         100000000   
     9                        1000000000   
   10                       10000000000   
   11                      100000000000   
   12                     1000000000000   
   13                    10000000000000   
   14                   100000000000000   
   15                  1000000000000000   
   16                 10000000000000000   
   17                100000000000000000   
   18               1000000000000000000   
   19              10000000000000000000   
   20             100000000000000000000   
   21            1000000000000000000000   
   22           10000000000000000000000   
   23          100000000000000000000000   
   24         1000000000000000000000000   
   25        10000000000000000000000000   
   26       100000000000000000000000000   
   27      1000000000000000000000000000   
   28     10000000000000000000000000000   
   29    100000000000000000000000000000   
   30   1000000000000000000000000000000   
   31  10000000000000000000000000000000   
   32                                 0   
   33                                 0   
   34                                 0   
   35                                 0   
   36                                 0   
   37                                 0   
     ok   
   TEST-RSHIFT ( on 32-bit system )   
     0  10000000000000000000000000000000   
     1   1000000000000000000000000000000   
     2    100000000000000000000000000000   
     3     10000000000000000000000000000   
     4      1000000000000000000000000000   
     5       100000000000000000000000000   
     6        10000000000000000000000000   
     7         1000000000000000000000000   
     8          100000000000000000000000   
     9           10000000000000000000000   
   10            1000000000000000000000   
   11             100000000000000000000   
   12              10000000000000000000   
   13               1000000000000000000   
   14                100000000000000000   
   15                 10000000000000000   
   16                  1000000000000000   
   17                   100000000000000   
   18                    10000000000000   
   19                     1000000000000   
   20                      100000000000   
   21                       10000000000   
   22                        1000000000   
   23                         100000000   
   24                          10000000   
   25                           1000000   
   26                            100000   
   27                             10000   
   28                              1000   
   29                               100   
   30                                10   
   31                                 1   
   32                                 0   
   33                                 0   
   34                                 0   
   35                                 0   
   36                                 0   
   37                                 0   
     ok   
      
   Similar displays for 64-bit systems.   
      
   --   
   KM   
      
   --- 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