[PATCH] Add comparison operators for vector types

Chris Lattner clattner@apple.com
Mon Jun 1 21:10:00 GMT 2009


On Jun 1, 2009, at 6:40 AM, Joseph S. Myers wrote:

> On Fri, 29 May 2009, Andrew Pinski wrote:
>
>> Hi,
>>  The C/C++ Language extension for the Cell defines the comparison
>> operators for vectors.  The result of these operators is a single
>> boolean value representing the bitwise AND of all pairwise
>> comparisons.  This patch adds support for these operators and a
>> testcase to test them for both C and C++.
>
> Defining both == and != in this way (so that (v != 0) is not  
> necessarily
> the same as !(v == 0)) certainly seems strange, and leads to the  
> question
> of whether it is v != 0 or !(v == 0) that determines the truthvalue  
> of v
> when used in a boolean context (do these language extensions allow  
> vectors
> to be used in such a context?).
>
> The general model used for the generic vector extensions is C++  
> valarray,
> which returns valarray<bool> for these operations.  Since  
> comparisons in C
> return int not bool, this might suggest valarray<int> for C; bearing  
> in
> mind that vectors of the given number of bools or ints may not exist  
> in
> hardware, the OpenCL approach of returning a vector of the same size  
> as
> the inputs seems reasonable, even if the choice of -1 for true  
> elements
> seems odd in language design terms.

-1 is definitely different, but it is also somewhat consistent: it is  
just a sign extended bool.  This matches many existing popular vector  
ISAs quite well.

-Chris



More information about the Gcc-patches mailing list