]> gitweb.factorcode.org Git - factor.git/commitdiff
write v? and vmask in terms of bitwise ops
authorJoe Groff <arcata@gmail.com>
Thu, 1 Oct 2009 05:09:25 +0000 (00:09 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 1 Oct 2009 05:09:25 +0000 (00:09 -0500)
basis/math/vectors/vectors-docs.factor
basis/math/vectors/vectors.factor
extra/math/matrices/simd/simd.factor

index 1d323822bd05b33642605e8007e373fa7e172a6b..9b6f0a04f196e5c050fcad6eb7a3eabfb8993e64 100644 (file)
@@ -343,8 +343,8 @@ HELP: vmask
 { $description "Returns a copy of " { $snippet "u" } " with the elements for which the corresponding element of " { $snippet "?" } " is false replaced by zero." } ;
 
 HELP: v?
-{ $values { "?" "a sequence of booleans" } { "true" "a sequence of numbers" } { "false" "a sequence of numbers" } { "w" "a sequence of numbers" } }
-{ $description "Creates a new sequence by selecting elements from the " { $snippet "true" } " and " { $snippet "false" } " sequences based on whether the corresponding element of the " { $snippet "?" } " sequence is true or false." } ;
+{ $values { "mask" "a sequence of booleans" } { "true" "a sequence of numbers" } { "false" "a sequence of numbers" } { "w" "a sequence of numbers" } }
+{ $description "Creates a new sequence by selecting elements from the " { $snippet "true" } " and " { $snippet "false" } " sequences based on whether the corresponding bits of the " { $snippet "mask" } " sequence are set or not." } ;
 
 { 2map v+ v- v* v/ } related-words
 
index a3d51752bdbcfd4d6d14a763fb21239e46975ba4..ffb761c54357150af85243476a380fe0db64b974 100644 (file)
@@ -99,9 +99,10 @@ PRIVATE>
 : vunordered? ( u v -- w ) [ unordered? ] { } 2map-as ;
 : v=  ( u v -- w ) [ =   ] { } 2map-as ;
 
-: v?   ( ? true false -- w ) [ ? ] pick 3map-as ;
+: v? ( mask true false -- w )
+    [ vbitand ] [ vbitandn ] bi-curry* bi vbitor ; inline
 
-: vmask ( u ? -- u' ) swap dup dup vbitxor v? ;
+: vmask ( u ? -- u' ) vbitand ; inline
 
 : vfloor    ( u -- v ) [ floor ] map ;
 : vceiling  ( u -- v ) [ ceiling ] map ;
index 0c4c3e1866a3b3fd0932d8f17050a7ebab055e03..bc213fec3a279e78e00ad7f983cbc7a711f774da 100644 (file)
@@ -121,7 +121,7 @@ TYPED:: m4^n ( m: matrix4 n: fixnum -- m^n: matrix4 )
 TYPED:: scale-matrix4 ( factors: float-4 -- matrix: matrix4 )
     matrix4 (struct) :> c
 
-    factors { t t t f } vmask :> factors'
+    factors float-4{ t t t f } vmask :> factors'
 
     factors' { 0 3 3 3 } vshuffle
     factors' { 3 1 3 3 } vshuffle
@@ -137,11 +137,11 @@ TYPED:: translation-matrix4 ( offset: float-4 -- matrix: matrix4 )
     matrix4 (struct) :> c
 
     float-4{ 0.0 0.0 0.0 1.0 } :> c4
-    { t t t f } offset c4 v? :> offset'
+    float-4{ t t t f } offset c4 v? :> offset'
 
-    offset' { 3 3 3 0 } vshuffle { t f f t } vmask
-    offset' { 3 3 3 1 } vshuffle { f t f t } vmask
-    offset' { 3 3 3 2 } vshuffle { f f t t } vmask
+    offset' { 3 3 3 0 } vshuffle float-4{ t f f t } vmask
+    offset' { 3 3 3 1 } vshuffle float-4{ f t f t } vmask
+    offset' { 3 3 3 2 } vshuffle float-4{ f f t t } vmask
     c4
 
     c set-rows ;
@@ -166,7 +166,7 @@ TYPED:: rotation-matrix4 ( axis: float-4 theta: float -- matrix: matrix4 )
     axis2 cc ones axis2 v- v* v+ :> diagonal
 
     axis { 0 0 1 3 } vshuffle axis { 1 2 2 3 } vshuffle v* 1-c v*
-    { t t t f } vmask :> triangle-a
+    float-4{ t t t f } vmask :> triangle-a
     ss { 2 1 0 3 } vshuffle triangle-sign v* :> triangle-b
     triangle-a triangle-b v+ :> triangle-lo
     triangle-a triangle-b v- :> triangle-hi
@@ -186,12 +186,12 @@ TYPED:: frustum-matrix4 ( xy: float-4 near: float far: float -- matrix: matrix4
     matrix4 (struct) :> c
 
     near near near far + 2 near far * * float-4-boa :> num
-    { t t f f } xy near far - float-4-with v? :> denom
+    float-4{ t t f f } xy near far - float-4-with v? :> denom
     num denom v/ :> fov
 
-    fov { 0 0 0 0 } vshuffle { t f f f } vmask
-    fov { 1 1 1 1 } vshuffle { f t f f } vmask
-    fov { 2 2 2 3 } vshuffle { f f t t } vmask
+    fov { 0 0 0 0 } vshuffle float-4{ t f f f } vmask
+    fov { 1 1 1 1 } vshuffle float-4{ f t f f } vmask
+    fov { 2 2 2 3 } vshuffle float-4{ f f t t } vmask
     float-4{ 0.0 0.0 -1.0 0.0 }
 
     c set-rows ;