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

John Thompson john.thompson.jtsoftware at gmail.com
Wed Aug 25 18:13:39 PDT 2010


Thanks, Eli.  I finally got back to addressing this.  How's the enclosed?

-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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100825/e0a01a35/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vecreturn3.patch
Type: application/octet-stream
Size: 2583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100825/e0a01a35/attachment.obj>


More information about the cfe-commits mailing list