diff --git a/collects/tests/typed-scheme/optimizer/generic/inexact-complex-float.rkt b/collects/tests/typed-scheme/optimizer/generic/inexact-complex-float.rkt new file mode 100644 index 0000000000..bb13749a32 --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/generic/inexact-complex-float.rkt @@ -0,0 +1,6 @@ +#lang typed/scheme #:optimize +(require racket/unsafe/ops) +(+ 1.0+2.0i 2.0 3.0+6.0i) +(- 1.0 2.0+4.0i 3.0+6.0i) +(- 1.0+2.0i 2.0 3.0+6.0i) +(- 1.0+2.0i 2.0+4.0i 3.0) diff --git a/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-float.rkt b/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-float.rkt new file mode 100644 index 0000000000..00f73a0a2f --- /dev/null +++ b/collects/tests/typed-scheme/optimizer/hand-optimized/inexact-complex-float.rkt @@ -0,0 +1,62 @@ +#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 2.0) + (unboxed-gensym-5 0.0) + (unboxed-gensym-6 3.0+6.0i) + (unboxed-gensym-7 (unsafe-flreal-part unboxed-gensym-6)) + (unboxed-gensym-8 (unsafe-flimag-part unboxed-gensym-6)) + (unboxed-gensym-9 (unsafe-fl+ (unsafe-fl+ unboxed-gensym-2 + unboxed-gensym-4) + unboxed-gensym-7)) + (unboxed-gensym-10 (unsafe-fl+ (unsafe-fl+ unboxed-gensym-3 + unboxed-gensym-5) + unboxed-gensym-8))) + (unsafe-make-flrectangular unboxed-gensym-9 unboxed-gensym-10)) +(let* ((unboxed-gensym-1 1.0) + (unboxed-gensym-2 0.0) + (unboxed-gensym-3 2.0+4.0i) + (unboxed-gensym-4 (unsafe-flreal-part unboxed-gensym-3)) + (unboxed-gensym-5 (unsafe-flimag-part unboxed-gensym-3)) + (unboxed-gensym-6 3.0+6.0i) + (unboxed-gensym-7 (unsafe-flreal-part unboxed-gensym-6)) + (unboxed-gensym-8 (unsafe-flimag-part unboxed-gensym-6)) + (unboxed-gensym-9 (unsafe-fl- (unsafe-fl- unboxed-gensym-1 + unboxed-gensym-4) + unboxed-gensym-7)) + (unboxed-gensym-10 (unsafe-fl- (unsafe-fl- unboxed-gensym-2 + unboxed-gensym-5) + unboxed-gensym-8))) + (unsafe-make-flrectangular unboxed-gensym-9 unboxed-gensym-10)) +(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 2.0) + (unboxed-gensym-5 0.0) + (unboxed-gensym-6 3.0+6.0i) + (unboxed-gensym-7 (unsafe-flreal-part unboxed-gensym-6)) + (unboxed-gensym-8 (unsafe-flimag-part unboxed-gensym-6)) + (unboxed-gensym-9 (unsafe-fl- (unsafe-fl- unboxed-gensym-2 + unboxed-gensym-4) + unboxed-gensym-7)) + (unboxed-gensym-10 (unsafe-fl- (unsafe-fl- unboxed-gensym-3 + unboxed-gensym-5) + unboxed-gensym-8))) + (unsafe-make-flrectangular unboxed-gensym-9 unboxed-gensym-10)) +(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 2.0+4.0i) + (unboxed-gensym-5 (unsafe-flreal-part unboxed-gensym-4)) + (unboxed-gensym-6 (unsafe-flimag-part unboxed-gensym-4)) + (unboxed-gensym-7 3.0) + (unboxed-gensym-8 0.0) + (unboxed-gensym-9 (unsafe-fl- (unsafe-fl- unboxed-gensym-2 + unboxed-gensym-5) + unboxed-gensym-7)) + (unboxed-gensym-10 (unsafe-fl- (unsafe-fl- unboxed-gensym-3 + unboxed-gensym-6) + 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 8c47f7ee88..3d65c7d823 100644 --- a/collects/typed-scheme/optimizer/inexact-complex.rkt +++ b/collects/typed-scheme/optimizer/inexact-complex.rkt @@ -111,6 +111,14 @@ (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 + ;; special handling of inexact reals + #:when (subtypeof? #'e -Flonum) + #:with real-part (unboxed-gensym) + #:with imag-part (unboxed-gensym) + #:with (bindings ...) + #`((real-part #,((optimize) #'e)) + (imag-part 0.0))) (pattern e:expr ;; can't work on inexact reals, which are a subtype of inexact ;; complexes, so this has to be equality @@ -131,7 +139,7 @@ (define-syntax-class inexact-complex-expr (pattern e:expr - #:when (isoftype? #'e -InexactComplex) + #:when (subtypeof? #'e -InexactComplex) #:with opt ((optimize) #'e))) (define-syntax-class inexact-complex-opt-expr @@ -142,9 +150,10 @@ (pattern (~and exp (#%plain-app (~or (~var op (float-op binary-inexact-complex-ops)) (~and op (~literal conjugate))) e:inexact-complex-expr ...)) + #:when (isoftype? #'exp -InexactComplex) #:with exp*:unboxed-inexact-complex-opt-expr #'exp #:with opt (begin (log-optimization "unboxed inexact complex" #'exp) - (begin (reset-unboxed-gensym) - #'(let* (exp*.bindings ...) - (unsafe-make-flrectangular exp*.real-part exp*.imag-part)))))) + (reset-unboxed-gensym) + #'(let* (exp*.bindings ...) + (unsafe-make-flrectangular exp*.real-part exp*.imag-part)))))