Message ID | alpine.DEB.2.10.1308210237510.3628@laptop-mg.saclay.inria.fr |
---|---|
State | New |
Headers | show |
Ping http://gcc.gnu.org/ml/gcc-patches/2013-08/msg01381.html On Fri, 23 Aug 2013, Marc Glisse wrote: > On Sun, 4 Aug 2013, Gerald Pfeifer wrote: > >> On Sat, 13 Jul 2013, Marc Glisse wrote: >>> 2013-07-14 Marc Glisse <marc.glisse@inria.fr> >>> >>> gcc/cp/ >>> * call.c (build_conditional_expr_1): Handle the case with 1 vector >>> and 2 scalars. Call save_expr before building a vector. >>> * typeck.c (cp_build_binary_op): Check complain before complaining. >> >> Shouldn't this be documented somewhere (gcc/doc/*.texi and our web based >> release notes)? > > Yes, it should. I had posted this some time ago: > http://gcc.gnu.org/ml/gcc-patches/2013-02/msg00664.html > > Here is an updated version that also mentions the new scalar case: > > 2013-08-23 Marc Glisse <marc.glisse@inria.fr> > > * doc/extend.texi (Vector Extensions): Document ?: in C++.
Ping. On Fri, 13 Sep 2013, Marc Glisse wrote: > Ping > http://gcc.gnu.org/ml/gcc-patches/2013-08/msg01381.html > > On Fri, 23 Aug 2013, Marc Glisse wrote: > >> On Sun, 4 Aug 2013, Gerald Pfeifer wrote: >> >>> On Sat, 13 Jul 2013, Marc Glisse wrote: >>>> 2013-07-14 Marc Glisse <marc.glisse@inria.fr> >>>> >>>> gcc/cp/ >>>> * call.c (build_conditional_expr_1): Handle the case with 1 vector >>>> and 2 scalars. Call save_expr before building a vector. >>>> * typeck.c (cp_build_binary_op): Check complain before complaining. >>> >>> Shouldn't this be documented somewhere (gcc/doc/*.texi and our web based >>> release notes)? >> >> Yes, it should. I had posted this some time ago: >> http://gcc.gnu.org/ml/gcc-patches/2013-02/msg00664.html >> >> Here is an updated version that also mentions the new scalar case: >> >> 2013-08-23 Marc Glisse <marc.glisse@inria.fr> >> >> * doc/extend.texi (Vector Extensions): Document ?: in C++.
Sorry, I was waiting for Jason to review (since he's the subject matter expert), and I guess he was waiting for me? Jason, can you please have a look and approve? Only one comment from my side: Index: doc/extend.texi =================================================================== +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} Why "same size and number of elements" in the above? What is the difference between these two? Gerald
On Mon, 2 Dec 2013, Gerald Pfeifer wrote: > Only one comment from my side: > > Index: doc/extend.texi > =================================================================== > +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} > > Why "same size and number of elements" in the above? What is the > difference between these two? (on x86_64) A vector of 4 int and a vector of 4 long have the same number of elements but not the same size. A vector of 8 int and a vector of 4 long have the same size but not the same number of elements. For semantics, we want the same number of elements. To match the hardware, we want the same size.
On Mon, 2 Dec 2013, Marc Glisse wrote: >> Index: doc/extend.texi >> =================================================================== >> +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} >> >> Why "same size and number of elements" in the above? What is the >> difference between these two? > (on x86_64) > A vector of 4 int and a vector of 4 long have the same number of elements but > not the same size. > A vector of 8 int and a vector of 4 long have the same size but not the same > number of elements. > > For semantics, we want the same number of elements. To match the > hardware, we want the same size. Ah, so it was good I asked. :-) Thanks for your explanation. It seems the way this is intended is integer vector of the (same size and number of elements) as whereas I parsed it as (integer vector of the same size) and (number of elements) as hence wondering what the difference between the size of the vector and the number of elements was. Rephrasing this as "the same number and size of elements as" or better "the same number of elements of the same size as" may help avoid this. Gerald
The rest of the change is OK once you've clarified this. Jason
On Mon, 2 Dec 2013, Gerald Pfeifer wrote: > On Mon, 2 Dec 2013, Marc Glisse wrote: >>> Index: doc/extend.texi >>> =================================================================== >>> +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} >>> >>> Why "same size and number of elements" in the above? What is the >>> difference between these two? >> (on x86_64) >> A vector of 4 int and a vector of 4 long have the same number of elements but >> not the same size. >> A vector of 8 int and a vector of 4 long have the same size but not the same >> number of elements. >> >> For semantics, we want the same number of elements. To match the >> hardware, we want the same size. > > Ah, so it was good I asked. :-) Thanks for your explanation. > > It seems the way this is intended is > integer vector of the (same size and number of elements) as > whereas I parsed it as > (integer vector of the same size) and (number of elements) as > hence wondering what the difference between the size of the vector and > the number of elements was. 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. > Rephrasing this as "the same number and size of elements as" or better > "the same number of elements of the same size as" may help avoid this. 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}. +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)
Gerald, are you ok with this version? Jason's approval is conditional to your opinion ;-) On Tue, 31 Dec 2013, Marc Glisse wrote: > On Mon, 2 Dec 2013, Gerald Pfeifer wrote: > >> On Mon, 2 Dec 2013, Marc Glisse wrote: >>>> Index: doc/extend.texi >>>> =================================================================== >>>> +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} >>>> >>>> Why "same size and number of elements" in the above? What is the >>>> difference between these two? >>> (on x86_64) >>> A vector of 4 int and a vector of 4 long have the same number of elements >>> but >>> not the same size. >>> A vector of 8 int and a vector of 4 long have the same size but not the >>> same >>> number of elements. >>> >>> For semantics, we want the same number of elements. To match the >>> hardware, we want the same size. >> >> Ah, so it was good I asked. :-) Thanks for your explanation. >> >> It seems the way this is intended is >> integer vector of the (same size and number of elements) as >> whereas I parsed it as >> (integer vector of the same size) and (number of elements) as >> hence wondering what the difference between the size of the vector and >> the number of elements was. > > 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. > >> Rephrasing this as "the same number and size of elements as" or better >> "the same number of elements of the same size as" may help avoid this. > > 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}. > +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)
On Sat, 25 Jan 2014, Marc Glisse wrote:
> Good luck, catching up always seems to take forever...
Thanks!
And thanks for your explanations. With those, I am fine. (Might it make
sense to add some of the background you shared to the documentation to
describe the limitations? "No" or "Yes, but I don't have the time now"
both are valid answers and should not block you applying your patch.)
Gerald
On Thu, 30 Jan 2014, Gerald Pfeifer wrote: > And thanks for your explanations. With those, I am fine. Thanks, I'll commit shortly. > Might it make sense to add some of the background you shared to the > documentation to describe the limitations? I guess so. I'll mark it somewhere, but no promise as to when I might get to it.
Index: doc/extend.texi =================================================================== --- doc/extend.texi (revision 201948) +++ doc/extend.texi (working copy) @@ -7023,20 +7023,33 @@ 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. 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}. + 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