Thanks for all the replies. I do have a few more questions I'd like to
have clarified though.
Alexey Dejneka wrote:
>Jonathan J Simpson <[EMAIL PROTECTED]> writes:
>
>
>
>>(declaim (optimize (speed 3) (safety 0)))
>>
>>(defstruct vec4
>> (x 0d0 :type double-float)
>> (y 0d0 :type double-float)
>> (z 0d0 :type double-float)
>> (w 0d0 :type double-float))
>>
>>Produces four compiler notes:
>>
>> In: DEFSTRUCT VEC4
>>
>>; (DEFSTRUCT VEC4
>>; (X 0.0d0 :TYPE DOUBLE-FLOAT)
>>; (Y 0.0d0 :TYPE DOUBLE-FLOAT)
>>; (Z 0.0d0 :TYPE DOUBLE-FLOAT)
>>; ...)
>>; Note: Doing float to pointer coercion (cost 13) to "<return value>".
>>
>>
>>I thought that in cmucl, structs could have unboxed slots.
>>
>>
>
>They have. But global functions, returning floats, must box them. The
>notes are produced for VEC4-X, -Y, -Z, -W. Is the code using these
>accessors they are inline expanded and do not need to box the return
>values. E.g. in
>
>
> (defun foo (v)
> (declare (type vec4 v))
> (+ (vec4-x v) (vec4-y v) (vec4-z v)))
>
>arguments of + (which is open-coded) are not boxed, but the result,
>which is returned from FOO, is. See the discussion of local calls and
>inline expansion in "CMU Common Lisp User's Manual".
>
>
>
OK, I understand the part about global functions boxing their return
values. Sometimes, though, I can't seem to get the accessors to inline
and I thought that there might be a root cause related to structure slots.
For instance:
(defun foobar (v)
(declare (type vec4 v))
(make-vec4
:x (vec4-x v)
:y (vec4-y v)
:z (vec4-z v)
:w (vec4-w v)))
gives 4 coercion notes, one for each arg to make-vec4. However, your
foo function compiles without any notes(except for the final return
value for foo). Why? I can't seem to find a way to convince make-vec4
that I'm passing double-floats and that it doesn't need to box the
arguments.
If I pass constants, then I have no problems:
(defun foobar2 (v)
(declare (type vec4 v))
(make-vec4
:x 0d0
:y 0d0
:z 0d0
:w 0d0))
Thanks,
Jonathan Simpson