- ! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg.
+ ! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
- USING: kernel sequences words fry generic accessors
+ USING: alien.c-types kernel sequences words fry generic accessors
classes.tuple classes classes.algebra definitions
- stack-checker.state quotations classes.tuple.private math
+ stack-checker.dependencies quotations classes.tuple.private math
math.partial-dispatch math.private math.intervals sets.private
math.floats.private math.integers.private layouts math.order
vectors hashtables combinators effects generalizations assocs
- sets combinators.short-circuit sequences.private locals
+ sets combinators.short-circuit sequences.private locals growable
stack-checker namespaces compiler.tree.propagation.info ;
+ FROM: math => float ;
IN: compiler.tree.propagation.transforms
\ equal? [
] "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? ;
-
- \ min [
- {
- { [ dup fixnum both-inputs? ] [ [ fixnum-min ] ] }
- { [ dup float both-inputs? ] [ [ float-min ] ] }
- [ f ]
- } cond nip
- ] "custom-inlining" set-word-prop
-
- \ max [
- {
- { [ dup fixnum both-inputs? ] [ [ fixnum-max ] ] }
- { [ dup float both-inputs? ] [ [ float-max ] ] }
- [ f ]
- } cond nip
- ] "custom-inlining" set-word-prop
-
! Generate more efficient code for common idiom
\ clone [
in-d>> first value-info literal>> {
\ index [
dup sequence? [
dup length 4 >= [
- dup length zip >hashtable '[ _ at ]
+ dup length iota zip >hashtable '[ _ at ]
] [ drop f ] if
] [ drop f ] if
] 1 define-partial-eval
} 1&& ;
: lookup-table-seq ( assoc -- table )
- [ keys supremum 1 + ] keep '[ _ at ] { } map-as ;
+ [ keys supremum 1 + iota ] keep '[ _ at ] { } map-as ;
: lookup-table-quot ( seq -- newquot )
lookup-table-seq
\ intersect [ intersect-quot ] 1 define-partial-eval
+: fixnum-bits ( -- n )
+ cell-bits tag-bits get - ;
+
+: bit-quot ( #call -- quot/f )
+ in-d>> second value-info interval>> 0 fixnum-bits [a,b] interval-subset?
+ [ [ >fixnum ] dip fixnum-bit? ] f ? ;
+
+\ bit? [ bit-quot ] "custom-inlining" set-word-prop
++
+ ! Speeds up sum-file, sort and reverse-complement benchmarks by
+ ! compiling decoder-readln better
+ \ push [
+ in-d>> second value-info class>> growable class<=
+ [ \ push def>> ] [ f ] if
+ ] "custom-inlining" set-word-prop
+
+ ! We want to constant-fold calls to heap-size, and recompile those
+ ! calls when a C type is redefined
+ \ heap-size [
+ dup word? [
+ [ inlined-dependency depends-on ] [ heap-size '[ _ ] ] bi
+ ] [ drop f ] if
+ ] 1 define-partial-eval
- ! Copyright (C) 2004, 2009 Slava Pestov.
+ ! Copyright (C) 2004, 2010 Slava Pestov.
! Copyright (C) 2008, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
- USING: kernel kernel.private sequences
- sequences.private math math.private combinators ;
+ USING: kernel kernel.private sequences sequences.private math
+ math.private math.order combinators ;
IN: math.integers.private
: fixnum-min ( x y -- z ) [ fixnum< ] most ; foldable
M: fixnum u> fixnum> ; inline
M: fixnum u>= fixnum>= ; inline
+ M: fixnum min over fixnum? [ fixnum-min ] [ call-next-method ] if ; inline
+ M: fixnum max over fixnum? [ fixnum-max ] [ call-next-method ] if ; inline
+
M: fixnum + fixnum+ ; inline
M: fixnum - fixnum- ; inline
M: fixnum * fixnum* ; inline
M: fixnum bitnot fixnum-bitnot ; inline
-M: fixnum bit? neg shift 1 bitand 0 > ; inline
+: fixnum-bit? ( n m -- b )
+ neg shift 1 bitand 0 > ;
+
+M: fixnum bit? fixnum-bit? ; inline
: fixnum-log2 ( x -- n )
0 swap [ dup 1 eq? ] [ [ 1 + ] [ 2/ ] bi* ] until drop ;