Basic optimizations for extflonums.

original commit: 171d874757ffd111aa3bd5c4d17ca01251144c68
This commit is contained in:
Vincent St-Amour 2014-04-22 18:09:44 -04:00
parent ff31fe4e07
commit ebf87fd795
3 changed files with 53 additions and 4 deletions

View File

@ -0,0 +1,48 @@
#lang racket/base
(require syntax/parse racket/extflonum
syntax/parse/experimental/specialize
(for-template racket/base racket/extflonum racket/unsafe/ops)
"../utils/utils.rkt"
(optimizer utils numeric-utils logging float))
(provide extflonum-opt-expr)
(define (mk-extflonum-tbl generic) ; all operations are prefixed
(mk-unsafe-tbl generic "~a" "unsafe-~a"))
(define binary-extflonum-ops
;; comparisons are good too, because we don't have to do n-ary->binary
;; (all ops are binary only)
(mk-extflonum-tbl (list #'extfl+ #'extfl- #'extfl* #'extfl/
#'extfl= #'extfl< #'extfl> #'extfl<= #'extfl>=
#'extflmin #'extflmax #'extflexpt)))
(define unary-extflonum-ops
(mk-extflonum-tbl (list #'extflabs #'extflround #'extflfloor #'extflceiling #'extfltruncate
#'extflsin #'extflcos #'extfltan #'extflasin #'extflacos #'extflatan
#'extfllog #'extflexp #'extflsqrt)))
(define-syntax-class/specialize unary-extflonum-op (float-op unary-extflonum-ops))
(define-syntax-class/specialize binary-extflonum-op (float-op binary-extflonum-ops))
;; TODO do conversions (unsafe-fx->extfl, unsafe-extfl->fx)
;; TODO do extflvector ops
(define-syntax-rule (log-extfl-opt opt-label)
(log-opt opt-label "Extflonum arithmetic specialization."))
;; Those are easy. Because extflonums are disjoint from the rest of the numeric
;; tower, if the operations type check at all, they have the right types for
;; optimization. Ops are all fixed arity, too.
(define-syntax-class extflonum-opt-expr
#:commit
#:literal-sets (kernel-literals)
(pattern (#%plain-app op:unary-extflonum-op t:opt-expr)
#:do [(log-extfl-opt "unary extflonum")]
#:with opt #'(op.unsafe t.opt))
(pattern (#%plain-app op:binary-extflonum-op t1:opt-expr t2:opt-expr)
#:do [(log-extfl-opt "binary extflonum")]
#:with opt #'(op.unsafe t1.opt t2.opt)))

View File

@ -8,7 +8,7 @@
(types numeric-tower union abbrev)
(optimizer utils numeric-utils logging fixnum))
(provide float-opt-expr float-arg-expr int-expr)
(provide float-opt-expr float-arg-expr int-expr float-op)
(define (mk-float-tbl generic)

View File

@ -5,8 +5,9 @@
(private syntax-properties)
(types type-table)
(optimizer utils
number fixnum float float-complex vector string list pair
sequence box struct dead-code apply unboxed-let
number fixnum float extflonum float-complex
vector string list pair sequence
box struct dead-code apply unboxed-let
hidden-costs))
@ -38,7 +39,7 @@
(pattern :number-opt-expr)
(pattern :fixnum-opt-expr)
(pattern :float-opt-expr)
;; TODO add optimizations for extflonums. should be easy (like structs), if it typechecks, it's the right type
(pattern :extflonum-opt-expr)
(pattern :float-complex-opt-expr)
(pattern :vector-opt-expr)
(pattern :string-opt-expr)