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,339 of 117,927   
   Krishna Myneni to Krishna Myneni   
   Re: D! and D@   
   23 Mar 24 20:47:07   
   
   From: krishna.myneni@ccreweb.org   
      
   On 3/23/24 14:16, Krishna Myneni wrote:   
   > On 3/23/24 14:13, Krishna Myneni wrote:   
   > ...   
   >> 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.   
   >>   
   >   
   > I left out the definitions of MSBITS and LSBITS (shown below):   
   >   
   >   Return the u least significant bits of cell value u1   
   > \ as the most significant bits of u2   
   > : lsbits ( u1 u -- u2 )   
   >      BITS_PER_CELL min   
   >      BITS_PER_CELL - negate   
   >      lshift ;   
   >   
   > \ Return the u most significant bits of cell value u1   
   > \ as the least significant bits of u2   
   > : msbits ( u1 u -- u2 )   
   >      BITS_PER_CELL min   
   >      BITS_PER_CELL - negate   
   >      rshift ;   
   >   
      
   Just realized that these versions of DRSHIFT and DLSHIFT are limited to   
   shift of 0 bits -- 1 cell width in bits, rather than the general shift   
   count of 0 bits -- 2 cells width in bits. They have to be modified for   
   general use on double length numbers. Of course one can write the   
   general shifts in terms of these by applying them twice if needed.   
      
   --   
   Krishna   
      
   --- 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