From: Raymond Toy Date: Sun, 19 Aug 2012 14:58:06 +0000 (-0700) Subject: Floating-point micro-optimizations X-Git-Tag: snapshot-2012-09~8 X-Git-Url: http://common-lisp.net/gitweb?p=projects%2Fcmucl%2Fcmucl.git;a=commitdiff_plain;h=5293d44e876c4d08a1a1f19b037a8afd54961eb8 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. --- diff --git a/src/compiler/float-tran.lisp b/src/compiler/float-tran.lisp index 7a82135..d0a3703 100644 --- a/src/compiler/float-tran.lisp +++ b/src/compiler/float-tran.lisp @@ -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) + (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: