Commit 5293d44e authored by Raymond Toy's avatar Raymond Toy
Browse files

Floating-point micro-optimizations

o Convert x/n to x*(1/n) when n is a power of two since 1/n has an
  exact representation.
o Convert 2*x to x+x.
parent 441a76a6
......@@ -634,6 +634,28 @@
(frob >)
(frob =))
;; Convert (/ x n) to (* x (/ n)) when x is a float and n is a power
;; of two, because (/ n) can be reprsented exactly.
(deftransform / ((x y) (float float) * :when :both)
(unless (constant-continuation-p y)
(let ((val (continuation-value y)))
(multiple-value-bind (frac exp sign)
(decode-float val)
(unless (= frac 0.5)
`(* x (float (/ ,val) x)))))
;; Convert 2*x to x+x.
(deftransform * ((x y) (float real) * :when :both)
(unless (constant-continuation-p y)
(let ((val (continuation-value y)))
(unless (= val 2)
'(+ x x)))
;;;; Irrational transforms:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment