]> gitweb.factorcode.org Git - factor.git/commitdiff
Another identity in value numbering for bitfields
authorDaniel Ehrenberg <littledan@pool-224-36.res.carleton.edu>
Thu, 8 Oct 2009 20:20:42 +0000 (15:20 -0500)
committerDaniel Ehrenberg <littledan@pool-224-36.res.carleton.edu>
Thu, 8 Oct 2009 20:20:42 +0000 (15:20 -0500)
basis/classes/struct/bit-accessors/bit-accessors.factor
basis/compiler/tree/propagation/propagation-tests.factor
basis/compiler/tree/propagation/transforms/transforms.factor

index 7a2fdb0cac660be0181d134f5066da1b2725d394..c535e52c0a2cce1cf19354efb39cd91e0288efba 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel sequences math fry locals math.order alien.accessors ;
 IN: classes.struct.bit-accessors
 
 ! Bitfield accessors are little-endian on all platforms
-! Why not? It's platform-dependent in C
+! Why not? It's unspecified in C
 
 : ones-between ( start end -- n )
     [ 2^ 1 - ] bi@ swap bitnot bitand ;
index c1b66915421e18fed766ae04c5e692b83e6e4e61..0a8cb61a9f8d63c9ec895ceddb74ec10e8172a12 100644 (file)
@@ -902,3 +902,7 @@ M: tuple-with-read-only-slot clone
 
 [ t ] [ [ alien-unsigned-1 255 bitand ] { bitand fixnum-bitand } inlined? ] unit-test
 [ t ] [ [ alien-unsigned-1 255 swap bitand ] { bitand fixnum-bitand } inlined? ] unit-test
+
+[ t ] [ [ { fixnum } declare 256 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test
+[ t ] [ [ { fixnum } declare 250 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test
+[ f ] [ [ { fixnum } declare 257 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test
index 08ac30624851b2fc8db2d1cdb673e789a375c4e5..b8ff96f8331d593e3a95996da10fbca945440b81 100644 (file)
@@ -45,13 +45,26 @@ IN: compiler.tree.propagation.transforms
 : simplify-bitand? ( value -- ? )
     value-info literal>> positive-fixnum? ;
 
+: all-ones? ( int -- ? )
+    dup 1 + bitand zero? ; inline
+
 : redundant-bitand? ( var 111... -- ? )
-    [ value-info ] bi@ { [
-        nip literal>>
-        { [ positive-fixnum? ] [ dup 1 + bitand zero? ] } 1&&
-    ] [
-        [ interval>> ] [ literal>> ] bi* 0 swap [a,b] interval-subset?
-    ] } 2&& ;
+    [ value-info ] bi@ [ interval>> ] [ literal>> ] bi* {
+        [ nip integer? ]
+        [ nip all-ones? ]
+        [ 0 swap [a,b] interval-subset? ]
+    } 2&& ;
+
+: (zero-bitand?) ( value-info value-info' -- ? )
+    [ interval>> ] [ literal>> ] bi* {
+        [ nip integer? ]
+        [ nip bitnot all-ones? ]
+        [ 0 swap bitnot [a,b] interval-subset? ]
+    } 2&& ;
+
+: zero-bitand? ( var1 var2 -- ? )
+    [ value-info ] bi@
+    { [ (zero-bitand?) ] [ swap (zero-bitand?) ] } 2|| ;
 
 {
     bitand-integer-integer
@@ -61,6 +74,10 @@ IN: compiler.tree.propagation.transforms
 } [
     [
         {
+            {
+                [ dup in-d>> first2 zero-bitand? ]
+                [ drop [ 2drop 0 ] ]
+            }
             {
                 [ dup in-d>> first2 redundant-bitand? ]
                 [ drop [ drop ] ]