This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++,doc] vector conditional expression
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 25 Jan 2014 22:49:19 +0100 (CET)
- Subject: Re: [C++,doc] vector conditional expression
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1307071343320 dot 31289 at stedding dot saclay dot inria dot fr> <51DAE2FE dot 1040707 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1307081810170 dot 17629 at stedding dot saclay dot inria dot fr> <51DB7FA0 dot 8090601 at redhat dot com> <alpine dot DEB dot 2 dot 02 dot 1307132114160 dot 18427 at stedding dot saclay dot inria dot fr> <alpine dot LNX dot 2 dot 00 dot 1308041851180 dot 9767 at trevally dot site> <alpine dot DEB dot 2 dot 10 dot 1308210237510 dot 3628 at laptop-mg dot saclay dot inria dot fr> <alpine dot DEB dot 2 dot 10 dot 1309131006310 dot 3557 at laptop-mg dot saclay dot inria dot fr> <alpine dot DEB dot 2 dot 10 dot 1312021416050 dot 11672 at stedding dot saclay dot inria dot fr> <alpine dot LNX dot 2 dot 00 dot 1312021450510 dot 2185 at tuna dot site> <alpine dot DEB dot 2 dot 10 dot 1312021504020 dot 11672 at stedding dot saclay dot inria dot fr> <alpine dot LNX dot 2 dot 00 dot 1312021805000 dot 2185 at tuna dot site> <alpine dot DEB dot 2 dot 10 dot 1312311335460 dot 3608 at laptop-mg dot saclay dot inria dot fr> <alpine dot DEB dot 2 dot 10 dot 1401221501120 dot 25546 at stedding dot saclay dot inria dot fr>
Hi Mark,
On Wed, 22 Jan 2014, Marc Glisse wrote:
> Gerald, are you ok with this version? Jason's approval is conditional
> to your opinion ;-)
sorry for the delay. I "killed" my notebook on the first day of
vaction in December by means of a few drops of water, and am still
catching up from weeks without connectivity more or less.
>> I think you had parsed it ok. In code terms:
>> size: sizeof(vec)
>> number of elements: sizeof(vec)/sizeof(vec[0])
>>
>> Now when the number of elements is fixed, saying that vectors have
>> the same (total) size or that they have elements of the same size is
>> equivalent, so any interpretation is fine.
Got it.
>> Ok. Like this then?
>>
>> +In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
>> +@code{b} and @code{c} are vectors of the same type and @code{a} is an
>> +integer vector with the same number of elements of the same size as @code{b}
>> +and @code{c}, computes all three arguments and creates a vector
>> +@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in
>> +OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
In the above, would "with the same number of elements" be sufficient?
Or do the elements of @code{a} really need to be the same size as those
of @code{b} and @code{c} as "...of the same size..." seems to imply?
I _think_ I now understand everything, the above just makes me wonder
whether that is a false sense of security. ;-)
>> +As in the case of binary operations, this syntax is also accepted when
>> +one of @code{b} or @code{c} is a scalar that is then transformed into a
>> +vector. If both @code{b} and @code{c} are scalars and the type of
>> +@code{true?b:c} has the same size as the element type of @code{a}, then
>> +@code{b} and @code{c} are converted to a vector type whose elements have
>> +this type and with the same number of elements as @code{a}.
>>
>> (though arguably one could parse this to mean that the elements of a
>> have the same size as the whole vector b, but I am fine with ignoring
>> this)
Yeah, I'm not worried about that.
What puzzles me a bit is the part about the size of the type of
@code{true?b:c} being the same as the element type of @code{a}.
I would have expected that @code{a} could be a vector of bool, @code{b}
a long integer constant and @code{c} another long integer constant, but
apparently this is not covered (sizeof bool != size long)?
Gerald