I understand why

(defun square (x)
  (* x x))

is slow, because the arithmetic has to be generic.  But why is

(defun square-df-int (x)
  (declare (double-float x))
  (* x x))

almost as slow as square, whereas 

(defun square-df (x)
  (declare (double-float x))
  (prog ((var 0.0d0))
     (setq var (* x x))
     var))

is about ten times faster?  This is all being compiled with speed 3
and safety 0.  The compiler is saying (about square-df-int) that it
has to do float to pointer coercion on the result --- by searching on
this term I found the CMUCL manual on the web, which led me to an
example which led me to make square-df, but I still don't really
understand what's going on.  It seems that float to pointer coercion
means converting the result from a non-descriptor representation (the
double-float bits) to a descriptor (a lisp object), but why does it
have to do this and how/why is square-df getting around it?

Can anyone help me?  I'm in the early stages of optimizing a program;
the lisp version was much easier to write and debug than the C
version, but it's unforunately about 50 times slower right now.

Cheers,

rif


Reply via email to