Optimize byte-reverse macro in alien.endian -- it was shifting each byte to the 0th bit place, bitand-ing it with HEX: ff, then shifting it to its final destination -- now we immediately shift to the proper location and bitand with the proper bitmask.

db4
Doug Coleman 2011-10-11 19:36:22 -07:00
parent 250e528209
commit 757889167a
1 changed files with 9 additions and 1 deletions

View File

@ -18,13 +18,21 @@ ERROR: invalid-signed-conversion n ;
[ invalid-signed-conversion ]
} case ; inline
<PRIVATE
: byte-mask ( #bits-shift -- mask )
[ HEX: ff ] dip shift ; foldable
PRIVATE>
MACRO: byte-reverse ( n signed? -- quot )
[
drop
[
dup iota [
[ 1 + - -8 * ] [ nip 8 * ] 2bi
'[ _ shift HEX: ff bitand _ shift ]
[ + ] [ nip byte-mask ] 2bi
'[ _ shift _ bitand ]
] with map
] [ 1 - [ bitor ] n*quot ] bi
] [