math.vectors: change vlshift and vrshift to mask the shift count by HEX: ff, to make them behave consistently with their SIMD counterparts

db4
Slava Pestov 2009-09-25 18:50:44 -05:00
parent c0abb9ce95
commit ed37950a33
2 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,7 @@
IN: math.vectors.tests
USING: math.vectors tools.test kernel ;
USING: math.vectors tools.test kernel specialized-arrays compiler
kernel.private ;
SPECIALIZED-ARRAY: int
[ { 1 2 3 } ] [ 1/2 { 2 4 6 } n*v ] unit-test
[ { 1 2 3 } ] [ { 2 4 6 } 1/2 v*n ] unit-test
@ -21,4 +23,12 @@ USING: math.vectors tools.test kernel ;
[ { 0 3 2 5 4 } ] [ { 1 2 3 4 5 } { 1 1 1 1 1 } v+- ] unit-test
[ 1 ] [ { C{ 0 1 } } dup v. ] unit-test
[ 1 ] [ { C{ 0 1 } } dup v. ] unit-test
! Make sure vector shifts behave the same as hardware SIMD vector shifts
[ int-array{ 0 0 0 0 } ] [ int-array{ 10 20 30 40 } -1 vlshift ] unit-test
[ int-array{ 0 0 0 0 } ] [
int-array{ 10 20 30 40 }
[ { int-array } declare -1 vlshift ] compile-call
] unit-test

View File

@ -61,8 +61,8 @@ PRIVATE>
: vbitor ( u v -- w ) over '[ _ [ bitor ] fp-bitwise-op ] 2map ;
: vbitxor ( u v -- w ) over '[ _ [ bitxor ] fp-bitwise-op ] 2map ;
: vlshift ( u n -- w ) '[ _ shift ] map ;
: vrshift ( u n -- w ) neg '[ _ shift ] map ;
: vlshift ( u n -- w ) HEX: ff bitand '[ _ shift ] map ;
: vrshift ( u n -- w ) HEX: ff bitand neg '[ _ shift ] map ;
: vfloor ( u -- v ) [ floor ] map ;
: vceiling ( u -- v ) [ ceiling ] map ;