Casting scalars to vectors

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Casting scalars to vectors

John Thompson

According to the AltiVec standard (section 2.4.6 in http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf), casting a scalar to a vector is illegal, yet gcc seems to support it, as seen in many of those little files in the PS3 SDK in target\ppu\include\bits, which have statements like:

vec_uint4 mask = (vec_uint4)(vec_int4)(-1);

where vec_uint4 and vec_int4 are typedefs for vector types, i.e.:
 
typedef vector int vec_int4;

What does this actually do? I'm guessing it's supposed to fill the vector components with -1.

How should this be handled in Clang?

I filed a Bugzilla bug 6846 on this.
 
If Clang should support it
, I might be able to take a crack at it, with a little guidance.

--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

John Thompson
My colleague pointed out that it's not a cast, but a literal, which Clang should support.
 
-John

On Mon, Apr 19, 2010 at 11:45 AM, John Thompson <[hidden email]> wrote:

According to the AltiVec standard (section 2.4.6 in http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf), casting a scalar to a vector is illegal, yet gcc seems to support it, as seen in many of those little files in the PS3 SDK in target\ppu\include\bits, which have statements like:

vec_uint4 mask = (vec_uint4)(vec_int4)(-1);

where vec_uint4 and vec_int4 are typedefs for vector types, i.e.:
 
typedef vector int vec_int4;

What does this actually do? I'm guessing it's supposed to fill the vector components with -1.

How should this be handled in Clang?

I filed a Bugzilla bug 6846 on this.
 
If Clang should support it
, I might be able to take a crack at it, with a little guidance.

--
John Thompson
[hidden email]




--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

Eli Friedman
On Mon, Apr 19, 2010 at 3:00 PM, John Thompson
<[hidden email]> wrote:
> My colleague pointed out that it's not a cast, but a literal, which Clang
> should support.

I'm pretty sure that's already implemented... are you passing
-faltivec to clang?

-Eli

> -John
>
> On Mon, Apr 19, 2010 at 11:45 AM, John Thompson
> <[hidden email]> wrote:
>>
>> According to the AltiVec standard (section 2.4.6 in
>> http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf), casting
>> a scalar to a vector is illegal, yet gcc seems to support it, as seen in
>> many of those little files in the PS3 SDK in target\ppu\include\bits, which
>> have statements like:
>>
>> vec_uint4 mask = (vec_uint4)(vec_int4)(-1);
>>
>> where vec_uint4 and vec_int4 are typedefs for vector types, i.e.:
>>
>> typedef vector int vec_int4;
>>
>> What does this actually do? I'm guessing it's supposed to fill the vector
>> components with -1.
>>
>> How should this be handled in Clang?
>>
>> I filed a Bugzilla bug 6846 on this.
>>
>> If Clang should support it
>> , I might be able to take a crack at it, with a little guidance.
>>
>> --
>> John Thompson
>> [hidden email]
>>
>
>
>
> --
> John Thompson
> [hidden email]
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

John Thompson
>I'm pretty sure that's already implemented... are you passing
>-faltivec to clang?
Yes.
 
This stops the error, but is it enough?:
 
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp (revision 101528)
+++ lib/Sema/SemaInit.cpp (working copy)
@@ -886,7 +886,7 @@
 
     // OpenCL & AltiVec require all elements to be initialized.
     if (numEltsInit != maxElements)
-      if (SemaRef.getLangOptions().OpenCL || SemaRef.getLangOptions().AltiVec)
+      if (SemaRef.getLangOptions().OpenCL)
         SemaRef.Diag(IList->getSourceRange().getBegin(),
                      diag::err_vector_incorrect_num_initializers)
           << (numEltsInit < maxElements) << maxElements << numEltsInit;

On Mon, Apr 19, 2010 at 4:07 PM, Eli Friedman <[hidden email]> wrote:
On Mon, Apr 19, 2010 at 3:00 PM, John Thompson
> My colleague pointed out that it's not a cast, but a literal, which Clang
> should support.

I'm pretty sure that's already implemented... are you passing
-faltivec to clang?

-Eli

> -John
>
> On Mon, Apr 19, 2010 at 11:45 AM, John Thompson
> <[hidden email]> wrote:
>>
>> According to the AltiVec standard (section 2.4.6 in
>> http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf), casting
>> a scalar to a vector is illegal, yet gcc seems to support it, as seen in
>> many of those little files in the PS3 SDK in target\ppu\include\bits, which
>> have statements like:
>>
>> vec_uint4 mask = (vec_uint4)(vec_int4)(-1);
>>
>> where vec_uint4 and vec_int4 are typedefs for vector types, i.e.:
>>
>> typedef vector int vec_int4;
>>
>> What does this actually do? I'm guessing it's supposed to fill the vector
>> components with -1.
>>
>> How should this be handled in Clang?
>>
>> I filed a Bugzilla bug 6846 on this.
>>
>> If Clang should support it
>> , I might be able to take a crack at it, with a little guidance.
>>
>> --
>> John Thompson
>> [hidden email]
>>
>
>
>
> --
> John Thompson
> [hidden email]
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>



--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

Chris Lattner

On Apr 19, 2010, at 6:02 PM, John Thompson wrote:

>I'm pretty sure that's already implemented... are you passing
>-faltivec to clang?
Yes.
 
This stops the error, but is it enough?:

That should be enough, if you like that patch go ahead and commit it (with a testcase).

-Chris

 
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp (revision 101528)
+++ lib/Sema/SemaInit.cpp (working copy)
@@ -886,7 +886,7 @@
 
     // OpenCL & AltiVec require all elements to be initialized.
     if (numEltsInit != maxElements)
-      if (SemaRef.getLangOptions().OpenCL || SemaRef.getLangOptions().AltiVec)
+      if (SemaRef.getLangOptions().OpenCL)
         SemaRef.Diag(IList->getSourceRange().getBegin(),
                      diag::err_vector_incorrect_num_initializers)
           << (numEltsInit < maxElements) << maxElements << numEltsInit;

On Mon, Apr 19, 2010 at 4:07 PM, Eli Friedman <[hidden email]> wrote:
On Mon, Apr 19, 2010 at 3:00 PM, John Thompson
> My colleague pointed out that it's not a cast, but a literal, which Clang
> should support.

I'm pretty sure that's already implemented... are you passing
-faltivec to clang?

-Eli

> -John
>
> On Mon, Apr 19, 2010 at 11:45 AM, John Thompson
> <[hidden email]> wrote:
>>
>> According to the AltiVec standard (section 2.4.6 in
>> http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf), casting
>> a scalar to a vector is illegal, yet gcc seems to support it, as seen in
>> many of those little files in the PS3 SDK in target\ppu\include\bits, which
>> have statements like:
>>
>> vec_uint4 mask = (vec_uint4)(vec_int4)(-1);
>>
>> where vec_uint4 and vec_int4 are typedefs for vector types, i.e.:
>>
>> typedef vector int vec_int4;
>>
>> What does this actually do? I'm guessing it's supposed to fill the vector
>> components with -1.
>>
>> How should this be handled in Clang?
>>
>> I filed a Bugzilla bug 6846 on this.
>>
>> If Clang should support it
>> , I might be able to take a crack at it, with a little guidance.
>>
>> --
>> John Thompson
>> [hidden email]
>>
>
>
>
> --
> John Thompson
> [hidden email]
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>



--
John Thompson
[hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

Anton Lokhmotov
In reply to this post by John Thompson
> This stops the error, but is it enough?

Sorry, I couldn't understand from the thread what was the error?

> -      if (SemaRef.getLangOptions().OpenCL ||
SemaRef.getLangOptions().AltiVec)
> +      if (SemaRef.getLangOptions().OpenCL)

In other words, it's something that's not required for AltiVec but is
required for OpenCL?

Cheers,
Anton.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

John Thompson
In reply to this post by John Thompson
Anton,
 
Clang was generating an error on vector initializers, when all the vector slots are not provided, i.e.:
 
vector unsigned int v = (vector unsigned int)(vector int)(-1); 
 
Instead of:
 
vector unsigned int v = (vector unsigned int)(vector int)(-1, -1, -1, -1); 
 
I'm seeing these kinds of statements in some headers in the PS3 sdk, which gcc allows.
 
I've checked in a fix and revised the altivec tests.  (Sorry I missed a test last night, and broke the build.)

I have a question, though (for Anton or anyone).  What will the initializers be for the unspecified slots?  Will they be 0?  What does gcc do?
 
-John
On Tue, Apr 20, 2010 at 2:34 AM, Anton Lokhmotov <[hidden email]> wrote:
> This stops the error, but is it enough?

Sorry, I couldn't understand from the thread what was the error?

> -      if (SemaRef.getLangOptions().OpenCL ||
SemaRef.getLangOptions().AltiVec)
> +      if (SemaRef.getLangOptions().OpenCL)

In other words, it's something that's not required for AltiVec but is
required for OpenCL?

Cheers,
Anton.





--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Casting scalars to vectors

John Thompson
I've run into a problem with vector literal/casting confusion:
 
vector float v = (vector float)((vector unsigned int)(0x49800000));
vecinit1.cpp:1:33: error: cannot initialize a vector element of type 'float' with an lvalue of type '__vector unsigned int'
vector float v = (vector float)((vector unsigned int)(0x49800000));
It appears to be treating the outer paren expression as a vector literal instead of a cast.
 
I'm looking into to it, but if someone knows a quick fix already...
-John
 
On Tue, Apr 20, 2010 at 12:45 PM, John Thompson <[hidden email]> wrote:
Anton,
 
Clang was generating an error on vector initializers, when all the vector slots are not provided, i.e.:
 
vector unsigned int v = (vector unsigned int)(vector int)(-1); 
 
Instead of:
 
vector unsigned int v = (vector unsigned int)(vector int)(-1, -1, -1, -1); 
 
I'm seeing these kinds of statements in some headers in the PS3 sdk, which gcc allows.
 
I've checked in a fix and revised the altivec tests.  (Sorry I missed a test last night, and broke the build.)

I have a question, though (for Anton or anyone).  What will the initializers be for the unspecified slots?  Will they be 0?  What does gcc do?
 
-John
On Tue, Apr 20, 2010 at 2:34 AM, Anton Lokhmotov <[hidden email]> wrote:
> This stops the error, but is it enough?

Sorry, I couldn't understand from the thread what was the error?

> -      if (SemaRef.getLangOptions().OpenCL ||
SemaRef.getLangOptions().AltiVec)
> +      if (SemaRef.getLangOptions().OpenCL)

In other words, it's something that's not required for AltiVec but is
required for OpenCL?

Cheers,
Anton.





--
John Thompson
[hidden email]




--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev