Optimize add1 and sub1 on floats and fixnums.

This commit is contained in:
Vincent St-Amour 2011-03-15 16:42:01 -04:00
parent d06bf0de91
commit 3ebe9e78f9
3 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,17 @@
#;
(
add1.rkt line 14 col 6 - add1 - fixnum add1
add1.rkt line 15 col 6 - sub1 - fixnum sub1
add1.rkt line 16 col 6 - add1 - float add1
add1.rkt line 17 col 6 - sub1 - float sub1
6
2
3.3
1.25
)
#lang typed/racket #:optimize
(ann (add1 5) Fixnum)
(ann (sub1 3) Fixnum)
(ann (add1 2.3) Float)
(ann (sub1 2.25) Float)

View File

@ -150,4 +150,15 @@
#:when (subtypeof? #'n -NonNegFixnum) ; (abs min-fixnum) is not a fixnum
#:with opt
(begin (log-optimization "fixnum fxabs" #'op)
#'(unsafe-fxabs n.opt))))
#'(unsafe-fxabs n.opt)))
(pattern (#%plain-app (~and op (~literal add1)) n:fixnum-expr)
#:when (subtypeof? this-syntax -Fixnum)
#:with opt
(begin (log-optimization "fixnum add1" #'op)
#'(unsafe-fx+ n.opt 1)))
(pattern (#%plain-app (~and op (~literal sub1)) n:fixnum-expr)
#:when (subtypeof? this-syntax -Fixnum)
#:with opt
(begin (log-optimization "fixnum sub1" #'op)
#'(unsafe-fx- n.opt 1))))

View File

@ -124,4 +124,13 @@
(pattern (#%plain-app (~and op (~literal zero?)) f:float-expr)
#:with opt
(begin (log-optimization "float zero?" #'op)
#'(unsafe-fl= f.opt 0.0))))
#'(unsafe-fl= f.opt 0.0)))
(pattern (#%plain-app (~and op (~literal add1)) n:float-expr)
#:with opt
(begin (log-optimization "float add1" #'op)
#'(unsafe-fl+ n.opt 1.0)))
(pattern (#%plain-app (~and op (~literal sub1)) n:float-expr)
#:with opt
(begin (log-optimization "float sub1" #'op)
#'(unsafe-fl- n.opt 1.0))))