]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.tree.propagation: convert /i of a positive integer by a power of two into...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 12 Sep 2009 02:03:11 +0000 (21:03 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 12 Sep 2009 02:03:11 +0000 (21:03 -0500)
basis/compiler/tree/propagation/propagation-tests.factor
basis/compiler/tree/propagation/transforms/transforms.factor

index 4c6e8f55d74d06fff41cd3ff4597d375a21ed047..1b24bc0c8f68d707b6a92f57cac21e3f84d06557 100644 (file)
@@ -819,3 +819,8 @@ M: tuple-with-read-only-slot clone
 
 ! Don't crash if bad literal inputs are passed to unsafe words
 [ f ] [ [ { } 1 fixnum+fast ] final-info first literal?>> ] unit-test
+
+! Converting /i to shift
+[ t ] [ [ >fixnum dup 0 >= [ 16 /i ] when ] { /i fixnum/i fixnum/i-fast } inlined? ] unit-test
+[ f ] [ [ >fixnum dup 0 >= [ 16 /i ] when ] { fixnum-shift-fast } inlined? ] unit-test
+[ f ] [ [ >float dup 0 >= [ 16 /i ] when ] { /i float/f } inlined? ] unit-test
index 9d0e5c89990398c24c275f734ff82896a6e496e2..e08a21d4b99fd721d7ab21f252e2d2643bdf93b0 100644 (file)
@@ -80,6 +80,17 @@ IN: compiler.tree.propagation.transforms
     ] [ f ] if
 ] "custom-inlining" set-word-prop
 
+{ /i fixnum/i fixnum/i-fast bignum/i } [
+    [
+        in-d>> first2 [ value-info ] bi@ {
+            [ drop class>> integer class<= ]
+            [ drop interval>> 0 [a,a] interval>= ]
+            [ nip literal>> integer? ]
+            [ nip literal>> power-of-2? ]
+        } 2&& [ [ log2 neg shift ] ] [ f ] if
+    ] "custom-inlining" set-word-prop
+] each
+
 ! Integrate this with generic arithmetic optimization instead?
 : both-inputs? ( #call class -- ? )
     [ in-d>> first2 ] dip '[ value-info class>> _ class<= ] both? ;