diff mbox

Document ?: for vectors

Message ID alpine.DEB.2.02.1302132358340.23435@stedding.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse Feb. 13, 2013, 11:09 p.m. UTC
Hello,

today I found this patch that I had written a couple months ago, and I am 
wondering whether we want it for 4.8. I am tempted to keep ?: undocumented 
as long as the C front-end doesn't have it. The fact that very few 
optimizations are done on it (and some might still be broken) is another 
argument in this direction. On the other hand, it is there, we might as 
well document it.

2013-02-13  Marc Glisse  <marc.glisse@inria.fr>

 	* doc/extend.texi (Vector Extensions): Document ?: in C++.
diff mbox

Patch

Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi	(revision 196034)
+++ gcc/doc/extend.texi	(working copy)
@@ -6990,20 +6990,30 @@  otherwise. Consider the following exampl
 typedef int v4si __attribute__ ((vector_size (16)));
 
 v4si a = @{1,2,3,4@};
 v4si b = @{3,2,1,4@};
 v4si c;
 
 c = a >  b;     /* The result would be @{0, 0,-1, 0@}  */
 c = a == b;     /* The result would be @{0,-1, 0,-1@}  */
 @end smallexample
 
+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 of the same size and number of elements 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}.
+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.
+
 Vector shuffling is available using functions
 @code{__builtin_shuffle (vec, mask)} and
 @code{__builtin_shuffle (vec0, vec1, mask)}.
 Both functions construct a permutation of elements from one or two
 vectors and return a vector of the same type as the input vector(s).
 The @var{mask} is an integral vector with the same width (@var{W})
 and element count (@var{N}) as the output vector.
 
 The elements of the input vectors are numbered in memory ordering of
 @var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}.  The