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

MCL optimizing

On Norvig p 279 he shows a rather contrived example that demonstrates the
capabilities of an unspecified compiler's optimization scheme:

(defun f1 (n l)
  (let ((l1 (first l))
         (l2 (second l)))
    (expt (* 1 (+ n 0))
          (- 4 (length (list l1 l2))))))

The disassembly he showed came out the same as if the body were just (* n n),
going so far as to ignore the "l" argument since all refs to it got optimized
away. ie, The compiler figured out the length had to be two, so expt would be
squaring, so etc.

I disassembled that under MCL and came out with quite a bit more. I *did* try
(declare (optimize (speed 3)(safety 0))) and a fixnum on "n", but did not see
much effect.

1) Is there some way I am missing to get MCL to optimize all the nonsense?

If not:

2) Does it matter? Is optimizing away deliberate nonsense just a neat parlor
trick? Assuming I am cagey enough not to code (expt (wawa 2)), that is. :)

Ken Tilton
Missing Link Software