[cfe-commits] [QUESTION] vecreturn attribute question 1

Eli Friedman eli.friedman at gmail.com
Wed Aug 25 18:36:05 PDT 2010


On Wed, Aug 25, 2010 at 6:13 PM, John Thompson
<john.thompson.jtsoftware at gmail.com> wrote:
> Thanks, Eli.  I finally got back to addressing this.  How's the enclosed?

Looks fine.

In a subsequent patch, it would be nice to address the following:
1. Would some check that the vector is small enough to be returned in
a single register be appropriate?

2. Is it valid to attach vecreturn to a struct with no members?

-Eli

> -John
>
> On Tue, Aug 10, 2010 at 8:28 PM, Eli Friedman <eli.friedman at gmail.com>
> wrote:
>>
>> On Tue, Aug 10, 2010 at 1:08 PM, John Thompson
>> <john.thompson.jtsoftware at gmail.com> wrote:
>> > Since this is what I believe is a custom attribute, to make sure we are
>> > on
>> > the same page, the vecreturn attribute is described as follows in our
>> > gcc
>> > doc:
>> >
>> > ***
>> > Returning a Vector Class in Registers
>> >
>> > According to the PPU ABI specifications, a class with a single member of
>> > vector type is returned in
>> > memory when used as the return value of a function. This results in
>> > inefficient code when implementing
>> > vector classes. To return the value in a single vector register, add the
>> > vecreturn attribute to the class
>> > definition. This attribute is also applicable to struct types.
>> >
>> > Example:
>> >
>> > struct Vector
>> > {
>> >   __vector float xyzw;
>> > } __attribute__((vecreturn));
>> >
>> > Vector Add(Vector lhs, Vector rhs)
>> > {
>> >   Vector result;
>> >   result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
>> >   return result; // This will be returned in a register
>> > }
>> > ***
>> >
>> > I believe I should be doing a little more checking to make sure the
>> > structure/class to which the vecreturn attribute is attached is of the
>> > proper kind, i.e. only has one data member, and the member is a vector.
>> >
>> > Is the enclosed patch the right way to do this checking, using the field
>> > iterator?
>> >
>> > If so, may I check it in?  Otherwise, please let me know the right way
>> > to do
>> > it.
>>
>> It's the right approach.
>>
>> +  CXXRecordDecl *record = static_cast<CXXRecordDecl*>(d);
>>
>> The following is preferred:
>> CXXRecordDecl *record = cast<CXXRecordDecl>(d);
>>
>> You probably want to check isPOD().
>>
>> Would some check that the vector is small enough to be returned in a
>> single register be appropriate?
>>
>> Is there some reason why vecreturn is only valid for C++?  If not, you
>> should check for a RecordDecl instead of a CXXRecordDecl.
>>
>> -Eli
>
>
>
> --
> John Thompson
> John.Thompson.JTSoftware at gmail.com
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>




More information about the cfe-commits mailing list