[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



I wanted to square the value of an expression "efficiently".  I tried
(^$ x 2) and found that the compiler generated a call to ^$ instead of
doing it inline.  This is the first lossage I found.  Then I tried
using ((lambda (y) (*$ y y)) x) and found that it generated the right
thing (basically a single floating multiply instruction) as long as
the symbol x was not declared.  If x was declared to be flonum then
it generated a lot of random pushing and poping.  E.g.

(declare (flonum (square flonum)))
(defun square (x) ((lambda (y) (*$ y y)) x))

caused it to generate code to pick up its arg, move it onto some pdl,
get the address of it on the pdl, get it via the address, do the
multiply, and finally clean up the pdl.  Whew!  Maybe i should stop
declaring my functions!

I did manage to win by adding (declare (flonum y)) to the file, but
thats not a very good solution because it forces me to make sure every
y I use is a flonum.  Can the compiler be made smarter about this
situation?  I'd be curious to know what mechanism is causing it to
generate this code so even if you decide not to fix it could you
explain it to me?

P.S.  I noticed the compiler was generating a PUSH P,[FLOAT1] at the
start of all my functions and doing a POPJ at the end.  Why not
have it just do JRST FLOAT1 at the end instead?