Added unboxed letrec bindings.
This commit is contained in:
parent
c7926001ef
commit
8dc23d43eb
|
@ -0,0 +1,7 @@
|
|||
#lang typed/scheme #:optimize
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(let ((x (+ 1.0+2.0i 2.0+3.0i)))
|
||||
(let ((x (+ x 2.0+3.0i)))
|
||||
(+ x 3.0+6.0i)))
|
|
@ -0,0 +1,8 @@
|
|||
#lang typed/scheme #:optimize
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(letrec ((#{f : (Any -> Any)} (lambda: ((x : Any)) (f x)))
|
||||
(#{x : Inexact-Complex} 1.0+2.0i)
|
||||
(#{y : Inexact-Complex} (+ 2.0+4.0i 3.0+6.0i)))
|
||||
(+ x y))
|
|
@ -0,0 +1,23 @@
|
|||
#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+3.0i)
|
||||
(unboxed-gensym-5 (unsafe-flreal-part unboxed-gensym-4))
|
||||
(unboxed-gensym-6 (unsafe-flimag-part unboxed-gensym-4))
|
||||
(unboxed-gensym-7 (unsafe-fl+ unboxed-gensym-2 unboxed-gensym-5))
|
||||
(unboxed-gensym-8 (unsafe-fl+ unboxed-gensym-3 unboxed-gensym-6)))
|
||||
(let* ((unboxed-gensym-1 2.0+3.0i)
|
||||
(unboxed-gensym-2 (unsafe-flreal-part unboxed-gensym-1))
|
||||
(unboxed-gensym-3 (unsafe-flimag-part unboxed-gensym-1))
|
||||
(unboxed-gensym-4 (unsafe-fl+ unboxed-gensym-7 unboxed-gensym-2))
|
||||
(unboxed-gensym-5 (unsafe-fl+ unboxed-gensym-8 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+ unboxed-gensym-4 unboxed-gensym-7))
|
||||
(unboxed-gensym-10 (unsafe-fl+ unboxed-gensym-5 unboxed-gensym-8)))
|
||||
(unsafe-make-flrectangular unboxed-gensym-9 unboxed-gensym-10)))
|
|
@ -0,0 +1,20 @@
|
|||
#lang racket
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(letrec ((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+6.0i)
|
||||
(unboxed-gensym-8 (unsafe-flreal-part unboxed-gensym-7))
|
||||
(unboxed-gensym-9 (unsafe-flimag-part unboxed-gensym-7))
|
||||
(unboxed-gensym-10 (unsafe-fl+ unboxed-gensym-5 unboxed-gensym-8))
|
||||
(unboxed-gensym-11 (unsafe-fl+ unboxed-gensym-6 unboxed-gensym-9))
|
||||
(f (lambda (x) (f x))))
|
||||
(let* ((unboxed-gensym-12 (unsafe-fl+ unboxed-gensym-2 unboxed-gensym-10))
|
||||
(unboxed-gensym-13 (unsafe-fl+ unboxed-gensym-3 unboxed-gensym-11)))
|
||||
(unsafe-make-flrectangular unboxed-gensym-12 unboxed-gensym-13)))
|
||||
(void)
|
|
@ -0,0 +1,7 @@
|
|||
#lang typed/scheme
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(let ((x (+ 1.0+2.0i 2.0+3.0i)))
|
||||
(let ((x (+ x 2.0+3.0i)))
|
||||
(+ x 3.0+6.0i)))
|
|
@ -0,0 +1,8 @@
|
|||
#lang typed/scheme
|
||||
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(letrec ((#{f : (Any -> Any)} (lambda: ((x : Any)) (f x)))
|
||||
(#{x : Inexact-Complex} 1.0+2.0i)
|
||||
(#{y : Inexact-Complex} (+ 2.0+4.0i 3.0+6.0i)))
|
||||
(+ x y))
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
(define-syntax-class unboxed-let-opt-expr
|
||||
#:literal-sets (kernel-literals)
|
||||
(pattern (~and exp (let-values (clause:expr ...) body:expr ...))
|
||||
(pattern (~and exp ((~and op (~or (~literal let-values) (~literal letrec-values)))
|
||||
(clause:expr ...) body:expr ...))
|
||||
;; we look for bindings of complexes that are not mutated and only
|
||||
;; used in positions where we would unbox them
|
||||
;; these are candidates for unboxing
|
||||
|
@ -40,7 +41,8 @@
|
|||
(r (in-list (syntax->list #'(opt-candidates.real-binding ...))))
|
||||
(i (in-list (syntax->list #'(opt-candidates.imag-binding ...)))))
|
||||
(dict-set! unboxed-vars-table v (list r i)))
|
||||
#`(let* (opt-candidates.bindings ... ... opt-others.res ...)
|
||||
#`(#,(if (free-identifier=? #'op #'let-values) #'let* #'letrec)
|
||||
(opt-candidates.bindings ... ... opt-others.res ...)
|
||||
#,@(map (optimize) (syntax->list #'(body ...)))))))
|
||||
|
||||
;; if a variable is only used in complex arithmetic operations, it's safe
|
||||
|
|
Loading…
Reference in New Issue
Block a user