This is the mail archive of the
mailing list for the GCC project.
Re: Logic operators ! && || for vectors
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org, jason at gcc dot gnu dot org
- Date: Fri, 12 Apr 2013 12:06:07 +0200 (CEST)
- Subject: Re: Logic operators ! && || for vectors
- References: <alpine dot DEB dot 2 dot 02 dot 1304121028200 dot 4034 at stedding dot saclay dot inria dot fr> <CAFiYyc3uL2i-FVs43rLYqbGBzL9BCO0__Y3BsEAV5WYKPjmSzA at mail dot gmail dot com>
On Fri, 12 Apr 2013, Richard Biener wrote:
On Fri, Apr 12, 2013 at 11:03 AM, Marc Glisse <email@example.com> wrote:
this adds support for vector !, && and ||. In the long run, I think it would
be good to be able to use TRUTH_*_EXPR with vectors, but that's probably a
lot of work.
It currently restricts && and || to vector-vector operations. I'd like to
also support mixed scalar-vector later, but it is a bit more complicated.
With vectors, && evaluates both sides.
Exactly for this reason I think supporting logical operations is ill-defined
First, as a remark, in C++, && and || can be overloaded by the user, and
in that case they are not short-circuit, so doing this for vectors
wouldn't really be anything new. OpenCL also defines && and || for
The way we define "boolean" vectors allows to simply
use bit operations here - so what issue do you want to address? The
automatic X-to-bool decay? Thus, avoid the need to write v1 != 0 | v2 != 0?
My goal would be for people to share the code between the scalar and
vector versions, that code written for scalars would start just working
with vectors. Since people use !, && and || for scalars and not ~, & and
|, that means supporting those.
(there would still always be traps, like the fact that the equivalent of
"true" for vectors is -1, or that && is not short-circuit, but most code
would be fine)