diff --git a/scheme/last-revision b/scheme/last-revision index 785c0c1..ddbefde 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1167 +1168 diff --git a/scheme/pass-specify-rep-primops.ss b/scheme/pass-specify-rep-primops.ss index c6366df..d0ef288 100644 --- a/scheme/pass-specify-rep-primops.ss +++ b/scheme/pass-specify-rep-primops.ss @@ -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