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,338 of 117,927   
   Krishna Myneni to Krishna Myneni   
   Re: D! and D@   
   23 Mar 24 14:13:34   
   
   From: krishna.myneni@ccreweb.org   
      
   On 3/22/24 08:59, Krishna Myneni wrote:   
   ...   
   > For little-endian Forth systems which place the high order cell of the   
   > double number on top of the stack, the definitions would be   
   >   
   > : D! ( d a -- ) >r swap r> 2! ;   
   > : D@ ( a -- d ) 2@ swap ;   
   >   
   ...   
   >   
   > More generally, the problem with the double number word set is that it   
   > attempts to use the same word set for two different types:   
   >   
   > 1) pairs of cell length numbers   
   > 2) double length integers   
   >   
   > It would be better to separate the words for these two types, the latter   
   > having prefix of "D" and the former having prefix "2".   
   >   
      
   On a possibly related note, standard Forth has D2* and D2/ but not   
   DLSHIFT and DRSHIFT. These are double number, non-arithmetic, left shift   
   and right shift words with a specified number of bits to shift.   
      
   D2* is the same as 1 DLSHIFT   
      
   but   
      
   D2/ is the same as 1 DRSHIFT only for positive double numbers   
      
   I had need for DLSHIFT and DRSHIFT recently, and this is what I came up   
   with.   
      
   \ u is the number of bits to shift   
   1 cells 8 * constant BITS_PER_CELL   
   0 value ubits   
      
   : DLSHIFT ( ud u -- ud2 ) BITS_PER_CELL min 0 ?DO D2* LOOP ;   
        dup 0= IF drop EXIT THEN   
        BITS_PER_CELL min to ubits   
        ubits lshift swap   
        dup >r ubits msbits or   
        r> ubits lshift swap ;   
      
   : DRSHIFT ( ud u -- ud2 )   
        dup 0= IF drop EXIT THEN   
        BITS_PER_CELL min to ubits   
        swap ubits rshift   
        swap dup >r ubits lsbits or   
        r> ubits rshift ;   
      
   With x86, it should be possible to write efficient versions of DLSHIFT   
   and DRSHIFT using SHLD and SHRD instructions.   
      
   --   
   Krishna Myneni   
      
   --- 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