Hello everybody.
We are currently using CMUCL for coding a small 3d library as a
University project.
We tend to declare types of variables since we do not want to waste time
in real-time-type-checking.
Reading the cmu/cl documentation, I think that the single-float type
(the one we need) is represented with a descriptor. This means that it
uses a pointer to represent any single-float variable, which value must
be allocated on the heap, then causing expensive consing.
Ways to force cmu/cl (python?) to use non-descriptors representations
are briefly described: in a general way, you are invited to declare
types of any variable to ensure that each one will receive values from
only one type.
Unfortunately, some cases are described where this is not enough (these
examples are all said to generate the "Note: Doing float to pointer
coercion (cost 13)..." note at compilation, and I can't figure out why.
No tricks to solve them are provided in the present documentation...
I would like you to help me solve this sample problem, and to provide me
further explanations to widen my understanding on typing.
(declaim (optimize (speed 3)
(compilation-speed 0)
(safety 0)
(debug 0)))
(defun cf (x y)
(declare (type single-float x y))
(the single-float (+ 1s0 y)))
(compile 'cf)
>>Note: Doing float to pointer coercion (cost 13) to "<return value>".
Thank you very much for your help.
--
----------------------------------------------
Jonathan BAILLEUL (········@emi.u-bordeaux.fr)
Maitrise Informatique, Universite Bordeaux I
>>>>> "Jonathan" == Jonathan BAILLEUL <········@emi.u-bordeaux.fr> writes:
Jonathan> Unfortunately, some cases are described where this is not enough (these
Jonathan> examples are all said to generate the "Note: Doing float to pointer
Jonathan> coercion (cost 13)..." note at compilation, and I can't figure out why.
Jonathan> No tricks to solve them are provided in the present documentation...
Jonathan> I would like you to help me solve this sample problem, and to provide me
Jonathan> further explanations to widen my understanding on typing.
Jonathan> (declaim (optimize (speed 3)
Jonathan> (compilation-speed 0)
Jonathan> (safety 0)
Jonathan> (debug 0)))
Jonathan> (defun cf (x y)
Jonathan> (declare (type single-float x y))
Jonathan> (the single-float (+ 1s0 y)))
(Typo: 1s0 is a short-float, not single-float. You really want 1f0.
For CMUCL it doesn't matter since they're the same.)
Jonathan> (compile 'cf)
>>> Note: Doing float to pointer coercion (cost 13) to "<return value>".
CMUCL has to box up the result of adding 1 to Y because it doesn't
know how cf is being used. In general, there's no way around
it---CMUCL has to box up the result.
If this is really a major problem for you, there some alternatives:
1. If the function is small enough, declare it inline. This can get
rid of the boxing since it's inline.
2. Place the offending functions in an flet/label's. Then CMUCL can
deduce exactly how cf is being used and there get rid of the boxing.
3. Look up block compilation in the user's manual. This is like
using labels, but on a file basis.
If these don't help, I think you'll have to live with the consing.
Ray