Optimize coercion of integer literals.

This commit is contained in:
Vincent St-Amour 2010-08-03 16:55:03 -04:00
parent 1fb68707fc
commit bdf84f371d
10 changed files with 31 additions and 7 deletions

View File

@ -1,4 +1,4 @@
(module float-promotion typed/scheme #:optimize
(require racket/unsafe/ops racket/flonum)
(+ 1 2.0)
(+ (quotient 1 1) 2.0)
(+ (expt 100 100) 2.0))

View File

@ -1,3 +1,3 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(+ 2 1.0+2.0i 3.0+6.0i)
(+ (quotient 2 1) 1.0+2.0i 3.0+6.0i)

View File

@ -0,0 +1,6 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(+ 1 2.0)
1

View File

@ -1,4 +1,4 @@
(module float-promotion typed/scheme #:optimize
(require racket/unsafe/ops racket/flonum)
(unsafe-fl+ (unsafe-fx->fl 1) 2.0)
(unsafe-fl+ (unsafe-fx->fl (quotient 1 1)) 2.0)
(unsafe-fl+ (->fl (expt 100 100)) 2.0))

View File

@ -1,6 +1,6 @@
#lang typed/scheme
(require racket/unsafe/ops)
(let* ((unboxed-gensym-1 (unsafe-fx->fl 2))
(let* ((unboxed-gensym-1 (unsafe-fx->fl (unsafe-fxquotient 2 1)))
(unboxed-gensym-2 1.0+2.0i)
(unboxed-gensym-3 (unsafe-flreal-part unboxed-gensym-2))
(unboxed-gensym-4 (unsafe-flimag-part unboxed-gensym-2))

View File

@ -0,0 +1,7 @@
#lang racket
(require racket/unsafe/ops)
(unsafe-fl+ 1.0 2.0)
1
(void)

View File

@ -1,4 +1,4 @@
(module float-promotion typed/scheme
(require racket/unsafe/ops racket/flonum)
(+ 1 2.0)
(+ (quotient 1 1) 2.0)
(+ (expt 100 100) 2.0))

View File

@ -1,3 +1,3 @@
#lang typed/scheme
(require racket/unsafe/ops)
(+ 2 1.0+2.0i 3.0+6.0i)
(+ (quotient 2 1) 1.0+2.0i 3.0+6.0i)

View File

@ -0,0 +1,6 @@
#lang typed/scheme
(require racket/unsafe/ops)
(+ 1 2.0)
1

View File

@ -1,7 +1,7 @@
#lang scheme/base
(require syntax/parse
syntax/id-table racket/dict
syntax/id-table racket/dict scheme/flonum
(for-template scheme/base scheme/flonum scheme/unsafe/ops)
"../utils/utils.rkt"
(types abbrev type-table utils subtype)
@ -59,6 +59,11 @@
;; note: none of the unary operations have types where non-float arguments
;; can result in float (as opposed to real) results
(define-syntax-class float-arg-expr
;; we can convert literals right away
(pattern (quote n)
#:when (exact-integer? (syntax->datum #'n))
#:with opt
(datum->syntax #'here (->fl (syntax->datum #'n))))
(pattern e:fixnum-expr
#:with opt #'(unsafe-fx->fl e.opt))
(pattern e:int-expr