Convert multiplication by power of 2 into a shift

db4
Slava Pestov 2008-07-13 15:51:20 -05:00
parent 92fb077a94
commit 9df1363d5b
2 changed files with 17 additions and 3 deletions

View File

@ -151,8 +151,9 @@ M: byte-array byte-length length ;
swap dup length memcpy ; swap dup length memcpy ;
: (define-nth) ( word type quot -- ) : (define-nth) ( word type quot -- )
>r heap-size [ rot * >fixnum ] swap prefix [
r> append define-inline ; \ swap , [ heap-size , [ * >fixnum ] % ] [ % ] bi*
] [ ] make define-inline ;
: nth-word ( name vocab -- word ) : nth-word ( name vocab -- word )
>r "-nth" append r> create ; >r "-nth" append r> create ;

View File

@ -406,7 +406,7 @@ most-negative-fixnum most-positive-fixnum [a,b]
: convert-mod-to-and ( #call -- node ) : convert-mod-to-and ( #call -- node )
dup dup
dup node-in-d second node-literal 1- dup in-d>> second node-literal 1-
[ nip bitand ] curry f splice-quot ; [ nip bitand ] curry f splice-quot ;
\ mod [ \ mod [
@ -438,6 +438,19 @@ most-negative-fixnum most-positive-fixnum [a,b]
} }
} define-optimizers } define-optimizers
: convert-*-to-shift? ( #call -- ? )
dup in-d>> second node-literal
dup integer? [ power-of-2? ] [ drop f ] if ;
: convert-*-to-shift ( #call -- ? )
dup dup in-d>> second node-literal log2
[ nip fixnum-shift-fast ] curry
f splice-quot ;
\ fixnum*fast {
{ [ dup convert-*-to-shift? ] [ convert-*-to-shift ] }
} define-optimizers
{ + - * / } { + - * / }
[ { number number } "input-classes" set-word-prop ] each [ { number number } "input-classes" set-word-prop ] each