FLOAT optimizer is now a bit more clever and returns a typed output with inlined forms

This commit is contained in:
Juan Jose Garcia Ripoll 2012-06-02 09:51:08 +02:00
parent be2136dca2
commit 22d8ff707c
2 changed files with 30 additions and 0 deletions

View file

@ -29,3 +29,9 @@
(error (c) failure))
failure))
(defun constant-value-p (form &optional env)
(if (constant-expression-p form)
(handler-case
(values t (cmp-eval form))
(error (c) (values nil form)))
(values nil form)))

View file

@ -316,3 +316,27 @@
(define-compiler-macro coerce (&whole form value type &environment env)
(expand-coerce form value type env))
(define-compiler-macro float (&whole form value &optional float &environment env)
(or
(and
float
(policy-inline-type-checks env)
(multiple-value-bind (constant-p float)
(constant-value-p float env)
(when (and constant-p (floatp float))
(let* ((aux (gentemp))
(float (type-of float))
(c-type (lisp-type->rep-type float)))
`(let ((value ,value))
(declare (:read-only value))
(compiler-typecase value
(,float value)
(t
(ffi:c-inline (value) (:object) ,c-type
,(ecase c-type
(:double "ecl_to_double(#0)")
(:float "ecl_to_float(#0)")
(:long-double "ecl_to_long_double(#0)"))
:one-liner t :side-effects nil))))))))
form))