Added optimization for make-polar

This commit is contained in:
Vincent St-Amour 2010-08-03 15:31:38 -04:00
parent dbdbaed506
commit fb31a6556e
7 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,3 @@
#lang typed/scheme #:optimize
(make-polar 0 0)

View File

@ -0,0 +1,9 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
;; top level
(make-polar 1.0 1.0)
;; nested
(+ 1.0+2.0i (make-polar 2.0 4.0))

View File

@ -0,0 +1,4 @@
#lang racket
(make-polar 0 0)
(void)

View File

@ -0,0 +1,28 @@
#lang racket
(require racket/unsafe/ops)
;; top level
(let*-values (((unboxed-gensym-1) 1.0)
((unboxed-gensym-2) 1.0)
((unboxed-gensym-3) (unsafe-fl* unboxed-gensym-1
(unsafe-flcos unboxed-gensym-2)))
((unboxed-gensym-4) (unsafe-fl* unboxed-gensym-1
(unsafe-flsin unboxed-gensym-2))))
(unsafe-make-flrectangular unboxed-gensym-3 unboxed-gensym-4))
;; nested
(let*-values (((unboxed-gensym-1) 1.0+2.0i)
((unboxed-gensym-2) (unsafe-flreal-part unboxed-gensym-1))
((unboxed-gensym-3) (unsafe-flimag-part unboxed-gensym-1))
((unboxed-gensym-4) 2.0)
((unboxed-gensym-5) 4.0)
((unboxed-gensym-6) (unsafe-fl* unboxed-gensym-4
(unsafe-flcos unboxed-gensym-5)))
((unboxed-gensym-7) (unsafe-fl* unboxed-gensym-4
(unsafe-flsin unboxed-gensym-5)))
((unboxed-gensym-8) (unsafe-fl+ unboxed-gensym-2 unboxed-gensym-6))
((unboxed-gensym-9) (unsafe-fl+ unboxed-gensym-3 unboxed-gensym-7)))
(unsafe-make-flrectangular unboxed-gensym-8 unboxed-gensym-9))
(void)

View File

@ -0,0 +1,3 @@
#lang typed/scheme
(make-polar 0 0)

View File

@ -0,0 +1,9 @@
#lang typed/scheme
(require racket/unsafe/ops)
;; top level
(make-polar 1.0 1.0)
;; nested
(+ 1.0+2.0i (make-polar 2.0 4.0))

View File

@ -232,8 +232,20 @@
#:with imag-binding (unboxed-gensym)
#:with (bindings ...)
(begin (log-optimization "make-rectangular elimination" #'op)
#`(((real-binding) real.opt)
#'(((real-binding) real.opt)
((imag-binding) imag.opt))))
(pattern (#%plain-app (~and op (~literal make-polar))
r:float-coerce-expr theta:float-coerce-expr)
#:with magnitude (unboxed-gensym)
#:with angle (unboxed-gensym)
#:with real-binding (unboxed-gensym)
#:with imag-binding (unboxed-gensym)
#:with (bindings ...)
(begin (log-optimization "make-rectangular elimination" #'op)
#'(((magnitude) r.opt)
((angle) theta.opt)
((real-binding) (unsafe-fl* magnitude (unsafe-flcos angle)))
((imag-binding) (unsafe-fl* magnitude (unsafe-flsin angle))))))
;; if we see a variable that's already unboxed, use the unboxed bindings
(pattern v:id
@ -308,6 +320,16 @@
(begin (log-optimization "unary inexact complex" #'op)
#'(op.unsafe n.opt)))
(pattern (~and exp (#%plain-app (~and op (~literal make-polar)) r theta))
#:when (isoftype? #'exp -InexactComplex)
#:with exp*:unboxed-inexact-complex-opt-expr #'exp
#:with opt
(begin (log-optimization "make-polar" #'op)
(reset-unboxed-gensym)
#'(let*-values (exp*.bindings ...)
(unsafe-make-flrectangular exp*.real-binding
exp*.imag-binding))))
(pattern (~and e (#%plain-app op:id args:expr ...))
#:with unboxed-info (dict-ref unboxed-funs-table #'op #f)
#:when (syntax->datum #'unboxed-info)