mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-09 06:30:32 -07:00
FLOAT optimizer is now a bit more clever and returns a typed output with inlined forms
This commit is contained in:
parent
be2136dca2
commit
22d8ff707c
2 changed files with 30 additions and 0 deletions
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue