User Tools

Site Tools


en:pfw:dlshift_drshift

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:dlshift_drshift [2024-04-03 23:09] – [Coded with D2* and D2/] alberten:pfw:dlshift_drshift [2024-04-09 14:41] (current) – [Test results (noForth t)] albert
Line 1: Line 1:
-===== Shifting doubles =====+===== Shifting doubles: DLSHIFT and DRSHIFT =====
 an.02apr2024 an.02apr2024
  
Line 9: Line 9:
 ===== Coded with LSHIFT and RSHIFT ===== ===== Coded with LSHIFT and RSHIFT =====
 <code> <code>
-decimal : DLSHIFT ( lo hi n -- lo' hi' )    \ n in [0,32*2] +decimal  
-    tuck lshift >r              \ hi' +: DLSHIFT ( lo hi n -- lo' hi' )    \ n in [0,32*2] 
-    2dup 32 - negate rshift >r  upper lo to lower hi +    tuck lshift >r          \ hi' 
-    2dup 32 - lshift >r         lower lo to upper hi +    2dup 32 -  
-    lshift                      \ lo' +    2dup   lshift >r        lower lo to upper hi 
-    2r> r> or or   ;            build hi' +    negate rshift >r        upper lo to lower hi 
- +    lshift                  \ lo' 
-decimal : DRSHIFT ( lo hi n -- lo' hi' )    \ n in [0,32*2] +    2r> r> or or   ;        compose hi' 
-    tuck 2dup rshift >r         \ hi' +     
-    2dup 32 - negate lshift >r  lower hi to upper lo +: DRSHIFT ( lo hi n -- lo' hi' )    \ n in [0,32*2] 
-    32 - rshift >r              upper hi to lower lo +    tuck 2dup rshift >r     \ hi' 
-    rshift 2r> or or            build lo' +    32 - 
-    r> ;                        \ hi'+    2dup   rshift >r        upper hi to lower lo 
 +    negate lshift >r        lower hi to upper lo 
 +    rshift 2r> or or        compose lo' 
 +    r> ;                    \ hi'
 </code> </code>
-===== Take care =====+===== Possibly a problem =====
 We assume for single cell LSHIFT and RSHIFT: We assume for single cell LSHIFT and RSHIFT:
-<code> +  - x n shift --> x,   for n=0 
-1) x n shift --> x     for n=0 +  x n shift --> 0,   for n not in [0,32-1]. More precise: for n in [-32,-1] or in [32,32*2] 
-2) x n shift --> 0     for n not in [0,32-1]  (test your forth) +Test your forth. If 2. does not hold: 
-   To be precise: result zero for n in [-32,-1] or in [32,32*2] +  : LSHIFT ( x n -- x' ) dup 32 uif lshift exit then 2drop 0 ; 
-</code>+
 ===== Test code ===== ===== Test code =====
 <code> <code>
 decimal decimal
-DUHEX. ( ud -- ) <# 32 2/ 0 do # loop #> type space ; +DU.HEX ( ud -- ) base @ >r hex 
-: (TEST) ( ud ud -- ) 2over 2over duhexduhex.+    <# 32 2/ 0 do # loop #>   type space r> base ! 
 +: (TEST) ( ud ud -- ) 2over 2over du.hex du.hex
     cr ." #shifts dlshift--------- drshift---------"     cr ." #shifts dlshift--------- drshift---------"
-    32 2* +   -2+    32 2* +   -2
     do cr i 3 and 0= if cr then i 7 .r space     do cr i 3 and 0= if cr then i 7 .r space
-        2over 2over i dlshift duhex. i drshift duhex.+        2over 2over i dlshift du.hex i drshift du.hex
     loop 2drop 2drop ;     loop 2drop 2drop ;
  
-: TEST1 -1. 2dup  (test) ; +: TEST1 ( -- ) -1. 2dup  (test) ; 
-: TEST2 0 -1 dup 1 rshift xor 1. (test) ;+: TEST2 ( -- ) 0 -1 dup 1 rshift xor 1. (test) ;
 </code> </code>
 ===== Test results (noForth t) ===== ===== Test results (noForth t) =====
 <code> <code>
-@)hex  OK.0 
 @)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF @)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
 #shifts dlshift--------- drshift--------- #shifts dlshift--------- drshift---------
Line 133: Line 136:
  
      40 0000000000000000 0000000000000000      40 0000000000000000 0000000000000000
-     41 0000000000000000 0000000000000000 +     41 0000000000000000 0000000000000000 OK.0
-     42 0000000000000000 0000000000000000  OK.0+
 </code> </code>
 <code> <code>
-@)hex  OK.0 
 @)test2 0000000000000001 8000000000000000 @)test2 0000000000000001 8000000000000000
 #shifts dlshift--------- drshift--------- #shifts dlshift--------- drshift---------
Line 224: Line 225:
  
      40 0000000000000000 0000000000000000      40 0000000000000000 0000000000000000
-     41 0000000000000000 0000000000000000 +     41 0000000000000000 0000000000000000  OK.0
-     42 0000000000000000 0000000000000000  OK.0+
 </code> </code>
 ===== Contributions ===== ===== Contributions =====
Line 244: Line 244:
     then 2drop drop 0. ;     then 2drop drop 0. ;
 </code> </code>
-Remember that D2/ is in fact an arithmic shift.+Remember that D2/ is in fact an arithmetic shift.
en/pfw/dlshift_drshift.1712178576.txt.gz · Last modified: 2024-04-03 23:09 by albert