On Sat, 25 Jan 2014, Gerald Pfeifer wrote:

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.

Good luck, catching up always seems to take forever...

+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?

No.

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?

Yes. The idea (in OpenCL) is that we have a vector unit where everything has the same size (booleans are represented as -1 or 0 in an integer type of suitable size), you never mix things of different size. This is not so far from what SSE/AVX/Neon/Altivec provide.

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)?

Something like b<c returns a vector of long, and that's what we use as a condition for ?:. And we are only allowing a small set of possibilities to be sure there is no ambiguity about what the user wanted. IIRC, in an earlier patch (that was rejected) I was allowing (long vector) ? int : short and that was giving a vector of long, but your example was rejected because the user could want either a vector of bool (narrow the longs to bool) or a vector of long (a completely new size of vector).


Having a special vector type for bool vectors is an alternative that would make sense. It would be closer to Sparc's VIS instructions, or where Intel seems to be going with AVX512. But that's not what we have implemented, it would likely require a different attribute, defining a different type. It would be quite a bit of work introducing that in gcc.

--
Marc Glisse

Reply via email to