Fixes bug 191659: add1 and sub1 are slow
This commit is contained in:
parent
66b9f6968e
commit
f6b35c4506
Binary file not shown.
|
@ -26,7 +26,7 @@
|
||||||
fixnum->string
|
fixnum->string
|
||||||
fxarithmetic-shift-left fxarithmetic-shift-right fxarithmetic-shift
|
fxarithmetic-shift-left fxarithmetic-shift-right fxarithmetic-shift
|
||||||
fxmin fxmax
|
fxmin fxmax
|
||||||
error@fx+ error@fx* error@fx-)
|
error@fx+ error@fx* error@fx- error@fxadd1 error@fxsub1)
|
||||||
(import
|
(import
|
||||||
(ikarus system $fx)
|
(ikarus system $fx)
|
||||||
(ikarus system $chars)
|
(ikarus system $chars)
|
||||||
|
@ -52,17 +52,6 @@
|
||||||
[(fixnum? x) #f]
|
[(fixnum? x) #f]
|
||||||
[else (die 'fxzero? "not a fixnum" x)])))
|
[else (die 'fxzero? "not a fixnum" x)])))
|
||||||
|
|
||||||
(define fxadd1
|
|
||||||
(lambda (n)
|
|
||||||
(if (fixnum? n)
|
|
||||||
($fxadd1 n)
|
|
||||||
(die 'fxadd1 "not a fixnum" n))))
|
|
||||||
|
|
||||||
(define fxsub1
|
|
||||||
(lambda (n)
|
|
||||||
(if (fixnum? n)
|
|
||||||
($fxsub1 n)
|
|
||||||
(die 'fxsub1 "not a fixnum" n))))
|
|
||||||
|
|
||||||
(define fxlognot
|
(define fxlognot
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
@ -107,6 +96,22 @@
|
||||||
[(x y) (sys:fx- x y)]
|
[(x y) (sys:fx- x y)]
|
||||||
[(x) (sys:fx- x)]))
|
[(x) (sys:fx- x)]))
|
||||||
|
|
||||||
|
(define error@fxadd1
|
||||||
|
(make-fx-error 'fxadd1 "overflow during addition"))
|
||||||
|
|
||||||
|
(define error@fxsub1
|
||||||
|
(make-fx-error 'fxsub1 "overflow during subtraction"))
|
||||||
|
|
||||||
|
(define fxadd1
|
||||||
|
(lambda (n)
|
||||||
|
(import (ikarus))
|
||||||
|
(fxadd1 n)))
|
||||||
|
|
||||||
|
(define fxsub1
|
||||||
|
(lambda (n)
|
||||||
|
(import (ikarus))
|
||||||
|
(fxsub1 n)))
|
||||||
|
|
||||||
(define false-loop
|
(define false-loop
|
||||||
(lambda (who ls)
|
(lambda (who ls)
|
||||||
(if (pair? ls)
|
(if (pair? ls)
|
||||||
|
|
|
@ -406,7 +406,8 @@
|
||||||
exact->inexact inexact floor ceiling round log fl=? fl<? fl<=? fl>?
|
exact->inexact inexact floor ceiling round log fl=? fl<? fl<=? fl>?
|
||||||
fl>=? fl+ fl- fl* fl/ flsqrt flmin flzero? flnegative?
|
fl>=? fl+ fl- fl* fl/ flsqrt flmin flzero? flnegative?
|
||||||
sin cos tan asin acos atan sqrt exp
|
sin cos tan asin acos atan sqrt exp
|
||||||
flmax random)
|
flmax random
|
||||||
|
error@add1 error@sub1)
|
||||||
(import
|
(import
|
||||||
(ikarus system $fx)
|
(ikarus system $fx)
|
||||||
(ikarus system $flonums)
|
(ikarus system $flonums)
|
||||||
|
@ -1720,23 +1721,31 @@
|
||||||
(mk< >= $fx>= fxbn> bnfx> bnbn>= fxfl>= flfx>= bnfl>= flbn>= flfl>=
|
(mk< >= $fx>= fxbn> bnfx> bnbn>= fxfl>= flfx>= bnfl>= flbn>= flfl>=
|
||||||
exrt> rtex> exrt> rtex> flrt>= rtfl>= rtrt>=))
|
exrt> rtex> exrt> rtex> flrt>= rtfl>= rtrt>=))
|
||||||
|
|
||||||
|
(define error@add1
|
||||||
|
(lambda (x)
|
||||||
|
(import (ikarus))
|
||||||
|
(cond
|
||||||
|
[(fixnum? x) (+ (greatest-fixnum) 1)]
|
||||||
|
[(number? x) (+ x 1)]
|
||||||
|
[else (die 'add1 "not a number" x)])))
|
||||||
|
|
||||||
(define add1
|
(define add1
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
(import (ikarus))
|
||||||
|
(add1 x)))
|
||||||
|
|
||||||
|
(define error@sub1
|
||||||
|
(lambda (x)
|
||||||
|
(import (ikarus))
|
||||||
(cond
|
(cond
|
||||||
[(fixnum? x)
|
[(fixnum? x) (- (least-fixnum) 1)]
|
||||||
(foreign-call "ikrt_fxfxplus" x 1)]
|
[(number? x) (- x 1)]
|
||||||
[(bignum? x)
|
[else (die 'sub1 "not a number" x)])))
|
||||||
(foreign-call "ikrt_fxbnplus" 1 x)]
|
|
||||||
[else (die 'add1 "not a number" x)])))
|
|
||||||
|
|
||||||
(define sub1
|
(define sub1
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(cond
|
(import (ikarus))
|
||||||
[(fixnum? x)
|
(sub1 x)))
|
||||||
(foreign-call "ikrt_fxfxplus" x -1)]
|
|
||||||
[(bignum? x)
|
|
||||||
(foreign-call "ikrt_fxbnplus" -1 x)]
|
|
||||||
[else (die 'sub1 "not a number" x)])))
|
|
||||||
|
|
||||||
(define zero?
|
(define zero?
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1382
|
1383
|
||||||
|
|
|
@ -567,6 +567,10 @@
|
||||||
[error@fx+ ]
|
[error@fx+ ]
|
||||||
[error@fx* ]
|
[error@fx* ]
|
||||||
[error@fx- ]
|
[error@fx- ]
|
||||||
|
[error@add1 ]
|
||||||
|
[error@sub1 ]
|
||||||
|
[error@fxadd1 ]
|
||||||
|
[error@fxsub1 ]
|
||||||
[fasl-write i]
|
[fasl-write i]
|
||||||
[lambda i r ba se ne]
|
[lambda i r ba se ne]
|
||||||
[and i r ba se ne]
|
[and i r ba se ne]
|
||||||
|
|
|
@ -1199,6 +1199,17 @@
|
||||||
[(E) (nop)]
|
[(E) (nop)]
|
||||||
[(E a . a*) (assert-fixnums a a*)])
|
[(E a . a*) (assert-fixnums a a*)])
|
||||||
|
|
||||||
|
(define-primop add1 safe
|
||||||
|
[(V x) (cogen-value-+ x (K 1))])
|
||||||
|
(define-primop sub1 safe
|
||||||
|
[(V x) (cogen-value-+ x (K -1))])
|
||||||
|
|
||||||
|
(define-primop fxadd1 safe
|
||||||
|
[(V x) (cogen-value-+ x (K 1))])
|
||||||
|
(define-primop fxsub1 safe
|
||||||
|
[(V x) (cogen-value-+ x (K -1))])
|
||||||
|
|
||||||
|
|
||||||
(define-primop * safe
|
(define-primop * safe
|
||||||
[(V) (K (fxsll 1 fx-shift))]
|
[(V) (K (fxsll 1 fx-shift))]
|
||||||
[(V a b)
|
[(V a b)
|
||||||
|
|
|
@ -58,6 +58,10 @@
|
||||||
[(fx+) 'error@fx+]
|
[(fx+) 'error@fx+]
|
||||||
[(fx-) 'error@fx-]
|
[(fx-) 'error@fx-]
|
||||||
[(fx*) 'error@fx*]
|
[(fx*) 'error@fx*]
|
||||||
|
[(add1) 'error@add1]
|
||||||
|
[(sub1) 'error@sub1]
|
||||||
|
[(fxadd1) 'error@fxadd1]
|
||||||
|
[(fxsub1) 'error@fxsub1]
|
||||||
[else x]))
|
[else x]))
|
||||||
(define (make-interrupt-call op args)
|
(define (make-interrupt-call op args)
|
||||||
(make-funcall
|
(make-funcall
|
||||||
|
|
Loading…
Reference in New Issue