This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Add comparison operators for vector types
- From: Chris Lattner <clattner at apple dot com>
- To: Joseph S. Myers <joseph at codesourcery dot com>
- Cc: Andrew Pinski <Andrew_Pinski at playstation dot sony dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Trevor_Smigiel <Trevor_Smigiel at playstation dot sony dot com>
- Date: Mon, 1 Jun 2009 14:10:45 -0700
- Subject: Re: [PATCH] Add comparison operators for vector types
- References: <firstname.lastname@example.org> <Pine.LNX.email@example.com>
On Jun 1, 2009, at 6:40 AM, Joseph S. Myers wrote:
On Fri, 29 May 2009, Andrew Pinski wrote:
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
the same as !(v == 0)) certainly seems strange, and leads to the
of whether it is v != 0 or !(v == 0) that determines the truthvalue
when used in a boolean context (do these language extensions allow
to be used in such a context?).
The general model used for the generic vector extensions is C++
which returns valarray<bool> for these operations. Since
comparisons in C
return int not bool, this might suggest valarray<int> for C; bearing
mind that vectors of the given number of bools or ints may not exist
hardware, the OpenCL approach of returning a vector of the same size
the inputs seems reasonable, even if the choice of -1 for true
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.