diff --git a/collects/tests/typed-scheme/optimizer/generic/inexact-complex-conjugate.rkt b/collects/tests/typed-scheme/optimizer/generic/inexact-complex-conjugate.rkt new file mode 100644 index 0000000000..9c647f6ab6 --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/generic/inexact-complex-conjugate.rkt @@ -0,0 +1,3 @@ +#lang typed/scheme #:optimize +(require racket/unsafe/ops) +(+ (conjugate 1.0+2.0i) (conjugate 2.0+4.0i)) diff --git a/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-conjugate.rkt b/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-conjugate.rkt new file mode 100644 index 0000000000..e5bc9583bc --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-conjugate.rkt @@ -0,0 +1,13 @@ +#lang typed/scheme #:optimize +(require racket/unsafe/ops) +(let* ((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 (unsafe-fl- 0.0 unboxed-gensym-3)) + (unboxed-gensym-5 2.0+4.0i) + (unboxed-gensym-6 (unsafe-flreal-part unboxed-gensym-5)) + (unboxed-gensym-7 (unsafe-flimag-part unboxed-gensym-5)) + (unboxed-gensym-8 (unsafe-fl- 0.0 unboxed-gensym-7)) + (unboxed-gensym-9 (unsafe-fl+ unboxed-gensym-2 unboxed-gensym-6)) + (unboxed-gensym-10 (unsafe-fl+ unboxed-gensym-4 unboxed-gensym-8))) + (unsafe-make-flrectangular unboxed-gensym-9 unboxed-gensym-10)) diff --git a/collects/typed-scheme/optimizer/inexact-complex.rkt b/collects/typed-scheme/optimizer/inexact-complex.rkt index bdaaadc32e..a386545082 100644 --- a/collects/typed-scheme/optimizer/inexact-complex.rkt +++ b/collects/typed-scheme/optimizer/inexact-complex.rkt @@ -2,7 +2,7 @@ (require syntax/parse "../utils/utils.rkt" - (for-template scheme/base scheme/flonum scheme/unsafe/ops) + (for-template scheme/base scheme/math scheme/flonum scheme/unsafe/ops) (types abbrev type-table utils subtype) (optimizer utils float)) @@ -104,6 +104,13 @@ (unsafe-fl* #,o2 #,(car e2))) #,(car d))) res))))))) + (pattern (#%plain-app (~and op (~literal conjugate)) c:unboxed-inexact-complex-opt-expr) + #:with real-part #'c.real-part + #:with imag-part (unboxed-gensym) + #:with (bindings ...) + (begin (log-optimization "unboxed unary inexact complex" #'op) + #`(#,@(append (syntax->list #'(c.bindings ...)) + (list #'(imag-part (unsafe-fl- 0.0 c.imag-part))))))) (pattern e:expr ;; can't work on inexact reals, which are a subtype of inexact ;; complexes, so this has to be equality