> (defun test1 (xmin) > (declare (single-float xmin) > (optimize (safety 0) (speed 3))) > (let ((x-ht (make-hash-table))) > (declare (hash-table x-ht)) > (flet ((get-x-index (x) > (declare (single-float x)) > (let ((index (gethash x x-ht nil))) > (unless index > (setf index > (setf (gethash x x-ht) > (the fixnum (truncate (- x xmin)))))) > index))) > (loop for i of-type Fixnum from 0 to 10 > for x of-type Single-Float = (random 100.0) > do (print (list (get-x-index x))))))) [,,,] > Compiling TEST1 generates 1 efficiency note: > * (compile 'test1) > ; In: LAMBDA (XMIN) > > ; (LOOP FOR I OF-TYPE FIXNUM ...) > ; --> BLOCK LET LET ANSI-LOOP::LOOP-BODY TAGBODY ANSI-LOOP::LOOP-REALLY-DESETQ > ; ==> > ; (SETQ X (RANDOM 100.0)) > ; Note: Doing float to pointer coercion (cost 13) to X. > ; > ; Compiling Top-Level Form: > > ; Compilation unit finished. > ; 1 note > > As I understand from reading Sections 5.11.10 and 5.13.3 of the CMUCL > user's manual, GET-X-INDEX is local call and this "float to pointer coercion" > efficiency note probably should not be issued. Could anybody show me how > to make the compiler not to make this float-to-pointer coercion?
GET-X-INDEX is a local function, but GETHASH is not; so the compiler needs to box the value of X. This was what I suspected but I'm not sure it's true or not. If it were true, I should get a similar note for test0 as TRUNCATE in TEST0 isn't a local function, either. Best, -cph
