en:pfw:dlshift_drshift
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
en:pfw:dlshift_drshift [2024-04-03 23:09] – [Coded with D2* and D2/] albert | en:pfw:dlshift_drshift [2024-04-09 14:40] – [Test code] 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 ===== | ||
< | < | ||
- | 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 | + | tuck lshift >r \ hi' |
- | | + | 2dup 32 - |
- | lshift | + | 2dup |
- | 2r> r> or or ; | + | |
- | + | lshift | |
- | decimal | + | 2r> r> or or ; |
- | tuck 2dup rshift >r | + | |
- | | + | : DRSHIFT ( lo hi n -- lo' hi' ) \ n in [0,32*2] |
- | | + | tuck 2dup rshift >r |
- | rshift 2r> or or \ build lo' | + | 32 - |
- | r> ; \ hi' | + | 2dup |
+ | | ||
+ | rshift 2r> or or \ compose | ||
+ | r> ; \ hi' | ||
</ | </ | ||
- | ===== Take care ===== | + | ===== Possibly a problem |
We assume for single cell LSHIFT and RSHIFT: | We assume for single cell LSHIFT and RSHIFT: | ||
- | < | + | - x n shift --> x, for n=0 |
- | 1) x n shift --> x | + | |
- | 2) x n shift --> 0 | + | Test your forth. If 2. does not hold: |
- | To be precise: | + | : LSHIFT ( x n -- x' ) dup 32 u< if lshift exit then 2drop 0 ; |
- | </code> | + | |
===== Test code ===== | ===== Test code ===== | ||
< | < | ||
decimal | decimal | ||
- | : DUHEX. ( ud -- ) <# 32 2/ 0 do # loop #> type space ; | + | : DU.HEX ( ud -- ) base @ >r hex |
- | : (TEST) ( ud ud -- ) 2over 2over duhex. duhex. | + | |
+ | : (TEST) ( ud ud -- ) 2over 2over du.hex du.hex | ||
cr ." #shifts dlshift--------- drshift---------" | cr ." #shifts dlshift--------- drshift---------" | ||
- | 32 2* 3 + -2 | + | 32 2* 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 | + | 2over 2over i dlshift |
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) ; |
</ | </ | ||
===== Test results (noForth t) ===== | ===== Test results (noForth t) ===== | ||
< | < | ||
- | @)hex OK.0 | ||
@)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF | @)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF | ||
#shifts dlshift--------- drshift--------- | #shifts dlshift--------- drshift--------- | ||
Line 137: | Line 140: | ||
</ | </ | ||
< | < | ||
- | @)hex OK.0 | + | |
@)test2 0000000000000001 8000000000000000 | @)test2 0000000000000001 8000000000000000 | ||
#shifts dlshift--------- drshift--------- | #shifts dlshift--------- drshift--------- | ||
Line 244: | Line 247: | ||
then 2drop drop 0. ; | then 2drop drop 0. ; | ||
</ | </ | ||
- | Remember that D2/ is in fact an arithmic | + | Remember that D2/ is in fact an arithmetic |
en/pfw/dlshift_drshift.txt · Last modified: 2024-04-09 14:41 by albert