[Ecls-list] INCF/1+ and LOOP differences at same OPTIMIZE/SAFETY levels

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Fri Dec 24 10:54:44 UTC 2010


Thanks for reporting.

The cause of the problem was not related to safety levels but rather how
variables are incremented. LOOP uses a SETF statement with a THE around the
new value. Your examples were using a bare SETF form (or INCF, which
translates into something similar).

That would have no further consequences, but it turns out that ECL's
macroexpander was not optimizing the SETF form. Instead,

(SETF I (1+ I)) -> (LET ((X (1+ I))) (SETQ I X)

as you see in the macroexpanded version there is no direct enforcement of X
to be fixnum and thus no possible optimization.

I have fixed SETF to at least recognize the simple case in which there are
only variables involved and not multiple temporary values. Now the behavior
should be as you expected

> (disassemble '(lambda (x) (declare (optimize (safety 0))) (let ((i x))
(declare (fixnum i)) (incf i) (if (> i 3) (print 2)))))

;;; Compiling (DEFUN C::GAZONK ...).
;;; Emitting code for C::GAZONK.
/*    function definition for GAZONK                                */
/*    optimize speed 3, debug 0, space 0, safety 0                  */
static cl_object L1c__gazonk(cl_object V1)
{ VT2 VLEX2 CLSR2 STCK2
    const cl_env_ptr cl_env_copy = ecl_process_env();
    cl_object value0;
TTL:
    {cl_fixnum V2;                            /*  I               */
    V2= fix(V1);
    V2= (V2)+(1);
   [...]

Best

Juanjo

-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20101224/45c99ab9/attachment.html>


More information about the ecl-devel mailing list