en:pfw:dlshift_drshift
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:pfw:dlshift_drshift [2024-04-04 22:45] – [Test results (noForth t)] albert | en:pfw:dlshift_drshift [2024-04-09 14:41] (current) – [Test results (noForth t)] albert | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Shifting doubles, DLSHIFT and DRSHIFT ===== | + | ===== 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 ===== | ||
< | < | ||
Line 37: | Line 40: | ||
: (TEST) ( ud ud -- ) 2over 2over du.hex du.hex | : (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 du.hex i drshift du.hex | 2over 2over i dlshift du.hex i drshift du.hex | ||
Line 47: | Line 50: | ||
===== Test results (noForth t) ===== | ===== Test results (noForth t) ===== | ||
< | < | ||
- | :)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF | + | @)test1 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF |
#shifts dlshift--------- drshift--------- | #shifts dlshift--------- drshift--------- | ||
-2 0000000000000000 0000000000000000 | -2 0000000000000000 0000000000000000 | ||
Line 133: | Line 136: | ||
40 0000000000000000 0000000000000000 | 40 0000000000000000 0000000000000000 | ||
- | 41 0000000000000000 0000000000000000 | + | 41 0000000000000000 0000000000000000 OK.0 |
- | 42 0000000000000000 0000000000000000 | + | |
</ | </ | ||
< | < | ||
- | @)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 |
- | | + | |
</ | </ | ||
===== Contributions ===== | ===== Contributions ===== |
en/pfw/dlshift_drshift.1712263515.txt.gz · Last modified: 2024-04-04 22:45 by albert