Optimizations on one-argument cases of arithmetic operations.
original commit: 0ee0886cab6989843a9bef1eb3797657e0f1d0c2
This commit is contained in:
parent
6c0c6b3f65
commit
9bef097987
|
@ -0,0 +1,20 @@
|
|||
#lang typed/scheme #:optimize
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(- 12)
|
||||
(- 12.0)
|
||||
(/ 4.2)
|
||||
|
||||
(+ 1)
|
||||
(+ 1.0)
|
||||
(+ (expt 2 100))
|
||||
(* 1)
|
||||
(* 1.0)
|
||||
(* (expt 2 100))
|
||||
(min 1)
|
||||
(min 1.0)
|
||||
(min (expt 2 100))
|
||||
(max 1)
|
||||
(max 1.0)
|
||||
(max (expt 2 100))
|
|
@ -71,6 +71,12 @@
|
|||
#:with opt
|
||||
(begin (log-optimization "binary nonzero fixnum" #'op)
|
||||
#'(op.unsafe n1.opt n2.opt)))
|
||||
|
||||
(pattern (#%plain-app (~and op (~literal -)) f:fixnum-expr)
|
||||
#:with opt
|
||||
(begin (log-optimization "unary fixnum" #'op)
|
||||
#'(unsafe-fx- 0 f.opt)))
|
||||
|
||||
(pattern (#%plain-app (~and op (~literal exact->inexact)) n:fixnum-expr)
|
||||
#:with opt
|
||||
(begin (log-optimization "fixnum to float" #'op)
|
||||
|
|
|
@ -68,13 +68,22 @@
|
|||
#:with opt
|
||||
(begin (log-optimization "binary float" #'op)
|
||||
(n-ary->binary #'op.unsafe #'f1.opt #'f2.opt #'(fs.opt ...))))
|
||||
(pattern (~and res (#%plain-app (~var op (float-op binary-float-comps))
|
||||
f1:float-expr
|
||||
f2:float-expr
|
||||
fs:float-expr ...))
|
||||
(pattern (#%plain-app (~var op (float-op binary-float-comps))
|
||||
f1:float-expr
|
||||
f2:float-expr
|
||||
fs:float-expr ...)
|
||||
#:with opt
|
||||
(begin (log-optimization "binary float comp" #'op)
|
||||
(n-ary->binary #'op.unsafe #'f1.opt #'f2.opt #'(fs.opt ...))))
|
||||
|
||||
(pattern (#%plain-app (~and op (~literal -)) f:float-expr)
|
||||
#:with opt
|
||||
(begin (log-optimization "unary float" #'op)
|
||||
#'(unsafe-fl- 0.0 f.opt)))
|
||||
(pattern (#%plain-app (~and op (~literal /)) f:float-expr)
|
||||
#:with opt
|
||||
(begin (log-optimization "unary float" #'op)
|
||||
#'(unsafe-fl/ 1.0 f.opt)))
|
||||
|
||||
;; 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)
|
||||
|
|
16
collects/typed-scheme/optimizer/number.rkt
Normal file
16
collects/typed-scheme/optimizer/number.rkt
Normal file
|
@ -0,0 +1,16 @@
|
|||
#lang scheme/base
|
||||
|
||||
(require syntax/parse
|
||||
(for-template scheme/base scheme/flonum scheme/unsafe/ops)
|
||||
"../utils/utils.rkt"
|
||||
(optimizer utils))
|
||||
|
||||
(provide number-opt-expr)
|
||||
|
||||
(define-syntax-class number-opt-expr
|
||||
;; these cases are all identity
|
||||
(pattern (#%plain-app (~and op (~or (~literal +) (~literal *) (~literal min) (~literal max)))
|
||||
f:expr)
|
||||
#:with opt
|
||||
(begin (log-optimization "unary number" #'op)
|
||||
((optimize) #'f))))
|
|
@ -7,7 +7,7 @@
|
|||
racket/private/for)
|
||||
"../utils/utils.rkt"
|
||||
(types abbrev type-table utils subtype)
|
||||
(optimizer utils fixnum float inexact-complex vector string
|
||||
(optimizer utils number fixnum float inexact-complex vector string
|
||||
pair sequence box struct dead-code))
|
||||
|
||||
(provide optimize-top)
|
||||
|
@ -21,6 +21,7 @@
|
|||
#:literal-sets (kernel-literals)
|
||||
|
||||
;; interesting cases, where something is optimized
|
||||
(pattern e:number-opt-expr #:with opt #'e.opt)
|
||||
(pattern e:fixnum-opt-expr #:with opt #'e.opt)
|
||||
(pattern e:float-opt-expr #:with opt #'e.opt)
|
||||
(pattern e:inexact-complex-opt-expr #:with opt #'e.opt)
|
||||
|
|
Loading…
Reference in New Issue
Block a user