Added special case for (div x [positive-fixnum-power-of-2])

This commit is contained in:
Abdulaziz Ghuloum 2007-12-02 04:30:59 -05:00
parent ebb1f7c055
commit bc2e88e4e7
2 changed files with 26 additions and 1 deletions

View File

@ -1 +1 @@
1167
1168

View File

@ -708,6 +708,7 @@
[(P a b) (K #t)]
[(E a b) (nop)])
(define-primop $fxmodulo unsafe
[(V a b)
(with-tmp ([b (T b)]) ;;; FIXME: why is modulo called quotient?
@ -1160,6 +1161,30 @@
(cogen-pred-$fxzero? x))]
[(E x) (interrupt-unless (cogen-pred-fixnum? x))])
(define (log2 n)
(let f ([n n] [i 0])
(cond
[(zero? (fxand n 1))
(f (fxsra n 1) (+ i 1))]
[(= n 1) i]
[else #f])))
(define-primop div safe
[(V x n)
(struct-case n
[(constant i)
(cond
[(and (fixnum? i) (> i 0) (log2 i)) =>
(lambda (bits)
(seq*
(interrupt-unless (cogen-pred-fixnum? x))
(prm 'sll
(prm 'sra (T x) (K (+ bits fx-shift)))
(K fx-shift))))]
[else
(interrupt)])]
[else (interrupt)])])
(define-primop quotient safe
[(V x n)
(struct-case n