Added coercions for floats with unboxed complex operations.
However, this generates superfluous operations involving their imaginary part of 0.
This commit is contained in:
parent
fff71e6a1d
commit
025af5b815
|
@ -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)
|
|
@ -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))
|
|
@ -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)))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user