compiler.tree.propagation: convert /i of a positive integer by a power of two into a shift

db4
Slava Pestov 2009-09-11 21:03:11 -05:00
parent 86a848bae6
commit dd661edf46
2 changed files with 16 additions and 0 deletions

View 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

View 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? ;