Fix bindings of unboxed complex float functions.
Closes PR 12475. Closes PR 14284.
This commit is contained in:
parent
cb885b3b55
commit
c60b31f0d1
|
@ -267,19 +267,28 @@
|
||||||
#:with (bindings ...)
|
#:with (bindings ...)
|
||||||
;; add unboxed parameters to the unboxed vars table
|
;; add unboxed parameters to the unboxed vars table
|
||||||
(let ((to-unbox (syntax->datum #'(fun.unboxed ...))))
|
(let ((to-unbox (syntax->datum #'(fun.unboxed ...))))
|
||||||
(for ([index (in-list to-unbox)]
|
(define/with-syntax (unboxed ...)
|
||||||
[real-part (in-syntax #'(real-params ...))]
|
(for/list ([param (in-syntax #'params)]
|
||||||
[imag-part (in-syntax #'(imag-params ...))])
|
[i (in-naturals)]
|
||||||
(add-unboxed-var! (list-ref (syntax->list #'params) index) real-part imag-part))
|
#:when (memq i to-unbox))
|
||||||
(define boxed
|
param))
|
||||||
|
(define/with-syntax (boxed ...)
|
||||||
(for/list ([param (in-syntax #'params)]
|
(for/list ([param (in-syntax #'params)]
|
||||||
[i (in-naturals)]
|
[i (in-naturals)]
|
||||||
#:unless (memq i to-unbox))
|
#:unless (memq i to-unbox))
|
||||||
param))
|
param))
|
||||||
|
(for ([orig-param (in-syntax #'(unboxed ...))]
|
||||||
|
[real-part (in-syntax #'(real-params ...))]
|
||||||
|
[imag-part (in-syntax #'(imag-params ...))])
|
||||||
|
(add-unboxed-var! orig-param real-part imag-part))
|
||||||
|
|
||||||
;; real parts of unboxed parameters go first, then all
|
;; real parts of unboxed parameters go first, then all
|
||||||
;; imag parts, then boxed occurrences of unboxed
|
;; imag parts, then boxed occurrences of unboxed
|
||||||
;; parameters will be inserted when optimizing the body
|
;; parameters will be inserted when optimizing the body
|
||||||
|
;; We add the original bindings so that dead code in the body,
|
||||||
|
;; (which will not be optimized), will have correct bindings
|
||||||
#`(((fun) (#%plain-lambda
|
#`(((fun) (#%plain-lambda
|
||||||
(real-params ... imag-params ... #,@(reverse boxed))
|
(real-params ... imag-params ... boxed ...)
|
||||||
body.opt ...))))))
|
(let ([unboxed 'check-syntax-binding] ...)
|
||||||
|
body.opt ...)))))))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#;#;
|
||||||
|
#<<END
|
||||||
|
TR opt: pr12475.rkt 18:2 ((letrec-values (((for-loop) (lambda (so-far-init) (if (quote #t) (* so-far-init (quote 1.0)) so-far-init)))) for-loop) (quote 0.0+0.0i)) -- unboxed call site
|
||||||
|
TR opt: pr12475.rkt 18:21 for-loop -- fun -> unboxed fun
|
||||||
|
TR opt: pr12475.rkt 19:29 so-far-init -- unboxed var -> table
|
||||||
|
TR opt: pr12475.rkt 21:26 (* so-far-init (quote 1.0)) -- unboxed binary float complex
|
||||||
|
TR opt: pr12475.rkt 21:29 so-far-init -- leave var unboxed
|
||||||
|
TR opt: pr12475.rkt 21:41 (quote 1.0) -- float-arg-expr in complex ops
|
||||||
|
TR opt: pr12475.rkt 22:26 so-far-init -- dead else branch
|
||||||
|
TR opt: pr12475.rkt 23:5 for-loop -- unboxed let loop
|
||||||
|
TR opt: pr12475.rkt 24:3 (quote 0.0+0.0i) -- unboxed literal
|
||||||
|
END
|
||||||
|
""
|
||||||
|
#lang typed/racket
|
||||||
|
|
||||||
|
(: coefficients->poly (-> Float-Complex))
|
||||||
|
(define (coefficients->poly)
|
||||||
|
((letrec-values (((for-loop)
|
||||||
|
(lambda (so-far-init)
|
||||||
|
(if '#t
|
||||||
|
(* so-far-init '1.0)
|
||||||
|
so-far-init))))
|
||||||
|
for-loop)
|
||||||
|
'0.0+0.0i))
|
|
@ -0,0 +1,28 @@
|
||||||
|
#;#;
|
||||||
|
#<<END
|
||||||
|
TR info: pr14284.rkt 26:26 displayln -- hidden parameter
|
||||||
|
TR opt: pr14284.rkt 24:13 0.0+2.0i -- unboxed literal
|
||||||
|
TR opt: pr14284.rkt 24:6 (+ 1.0 0.0+2.0i) -- unboxed binary float complex
|
||||||
|
TR opt: pr14284.rkt 24:9 1.0 -- float-arg-expr in complex ops
|
||||||
|
TR opt: pr14284.rkt 25:27 x -- unboxed var -> table
|
||||||
|
TR opt: pr14284.rkt 25:4 optimizable -- fun -> unboxed fun
|
||||||
|
TR opt: pr14284.rkt 27:25 (+ x y) -- unboxed binary float complex
|
||||||
|
TR opt: pr14284.rkt 27:28 x -- leave var unboxed
|
||||||
|
TR opt: pr14284.rkt 27:30 y -- unbox float-complex
|
||||||
|
TR opt: pr14284.rkt 28:15 3.0+3.0i -- unboxed literal
|
||||||
|
TR opt: pr14284.rkt 28:2 (optimizable 3.0+3.0i "a" "b") -- call to fun with unboxed args
|
||||||
|
TR opt: pr14284.rkt 28:2 (optimizable 3.0+3.0i "a" "b") -- unboxed call site
|
||||||
|
END
|
||||||
|
#<<END
|
||||||
|
a
|
||||||
|
4.0+5.0i
|
||||||
|
|
||||||
|
END
|
||||||
|
#lang typed/racket
|
||||||
|
|
||||||
|
(letrec:
|
||||||
|
([y (+ 1.0 0.0+2.0i)]
|
||||||
|
[optimizable (lambda: ([x : Float-Complex] [a : String] [b : String])
|
||||||
|
(displayln a)
|
||||||
|
(+ x y))])
|
||||||
|
(optimizable 3.0+3.0i "a" "b"))
|
Loading…
Reference in New Issue
Block a user