More float conversion optimizations.

original commit: 149d8535eb2988fab0bed739d375874f172db7c8
This commit is contained in:
Vincent St-Amour 2012-10-13 17:49:48 -04:00
parent 22cc8bc458
commit cc1dd45568
2 changed files with 40 additions and 3 deletions

View File

@ -1,10 +1,29 @@
#;
(
TR opt: exact-inexact.rkt 10:0 (exact->inexact (expt 10 100)) -- int to float
TR opt: exact-inexact.rkt 22:0 (exact->inexact (expt 10 100)) -- int to float
TR opt: exact-inexact.rkt 23:7 (exact->inexact (expt 2.3 3.2)) -- float to float
TR opt: exact-inexact.rkt 23:0 (round (exact->inexact (expt 2.3 3.2))) -- unary float
TR opt: exact-inexact.rkt 24:0 (real->double-flonum (expt 10 100)) -- int to float
TR opt: exact-inexact.rkt 25:7 (real->double-flonum (expt 2.3 3.2)) -- float to float
TR opt: exact-inexact.rkt 25:0 (round (real->double-flonum (expt 2.3 3.2))) -- unary float
TR opt: exact-inexact.rkt 28:0 (exact->inexact (expt 1.0f0 2.0f0)) -- single-float to single-float
TR opt: exact-inexact.rkt 29:0 (real->single-flonum (expt 1.0f0 2.0f0)) -- single-float to single-float
1e+100
14.0
1e+100
14.0
1.0f0
1.0f0
)
#lang typed/scheme
#:optimize
(exact->inexact (expt 10 100)) ; must not be a fixnum
(round (exact->inexact (expt 2.3 3.2))) ; already a float
(real->double-flonum (expt 10 100)) ; must not be a fixnum
(round (real->double-flonum (expt 2.3 3.2))) ; already a float
;; single floats
(exact->inexact (expt 1.0f0 2.0f0))
(real->single-flonum (expt 1.0f0 2.0f0))

View File

@ -40,6 +40,11 @@
(pattern e:expr
#:when (subtypeof? #'e -Flonum)
#:with opt ((optimize) #'e)))
(define-syntax-class single-float-expr
#:commit
(pattern e:expr
#:when (subtypeof? #'e -SingleFlonum)
#:with opt ((optimize) #'e)))
(define-syntax-class int-expr
#:commit
(pattern e:expr
@ -188,17 +193,30 @@
#'(let ([tmp f.opt]) (unsafe-fl* tmp tmp))))
;; we can optimize exact->inexact if we know we're giving it an Integer
(pattern (#%plain-app (~and op (~literal exact->inexact)) n:int-expr)
(pattern (#%plain-app (~and op (~or (~literal exact->inexact)
(~literal real->double-flonum)))
n:int-expr)
#:with opt
(begin (log-optimization "int to float" float-opt-msg this-syntax)
(add-disappeared-use #'op)
#'(->fl n.opt)))
;; we can get rid of it altogether if we're giving it a float
(pattern (#%plain-app (~and op (~literal exact->inexact)) f:float-expr)
(pattern (#%plain-app (~and op (~or (~literal exact->inexact)
(~literal real->double-flonum)))
f:float-expr)
#:with opt
(begin (log-optimization "float to float" float-opt-msg this-syntax)
(add-disappeared-use #'op)
#'f.opt))
;; same for single-flonums
(pattern (#%plain-app (~and op (~or (~literal exact->inexact)
(~literal real->single-flonum)))
f:single-float-expr)
#:with opt
(begin (log-optimization "single-float to single-float"
float-opt-msg this-syntax)
(add-disappeared-use #'op)
#'f.opt))
(pattern (#%plain-app (~and op (~literal zero?)) f:float-expr)
#:with opt