Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -634,6 +634,28 @@ ...@@ -634,6 +634,28 @@
(frob >) (frob >)
(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)
(give-up))
(let ((val (continuation-value y)))
(multiple-value-bind (frac exp sign)
(decode-float val)
(unless (= frac 0.5)
(give-up))
`(* x (float (/ ,val) x)))))
;; Convert 2*x to x+x.
(deftransform * ((x y) (float real) * :when :both)
(unless (constant-continuation-p y)
(give-up))
(let ((val (continuation-value y)))
(unless (= val 2)
(give-up))
'(+ x x)))
;;;; Irrational transforms: ;;;; Irrational transforms:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment