Chisheng Huang <[EMAIL PROTECTED]> writes:

> (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.

-- 
Regards,
Alexey Dejneka

"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer

Reply via email to