[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
New special form suggestion: LET-CONSTANT
If the expression to which the variable is
bound is constant and there are no SETQs to the variable, all
references to the variable may be legitimately replaced by the
It isn't an optimization in the Symbolics 3600, for most constants. The
same is true in any other machine that keeps variables in registers and
doesn't have an immediate addressing mode capable of accomodating all Lisp
constants, I believe.
Actually that's not quite true. On the 68k in Lucid lisp for instance compare
1. (let ((foo 'baz))
(setf (car x) foo))
2. (setf (car x) 'baz)
The symbol baz can't be represented as an immediate addressing mode. Instead
it is at some constant offset (inside any particular procedure)
from a closure pointer which is in a known register. There is a memory to memory
move on the 68k that can accomodate a source addressing mode that refers to
baz, and a destination mode that refers to (car x), assuming x is already in
a register. So case 2 takes one instruction, whereas case 1 under your description
would take two--one to move baz into the register used for foo, and one to move
that into (car x). Of course in this simple case a peephole optimizer should
be able to clean case 1 up, but if there is other intervening stuff around it
may not get it as easily as the source level transform.
So on some machines the optimization is more generally useful than your note implies.