This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Sorry about <=> on VECTOR_TYPE.


On Tue, Nov 12, 2019 at 10:19:49AM +0100, Richard Biener wrote:
> On Tue, Nov 12, 2019 at 10:02 AM Jakub Jelinek <jakub@redhat.com> wrote:
> >
> > On Tue, Nov 12, 2019 at 09:10:58AM +0100, Richard Biener wrote:
> > > On Tue, Nov 12, 2019 at 5:54 AM Jason Merrill <jason@redhat.com> wrote:
> > > >
> > > > I'm not sure what semantics we might eventually want for vector <=>, but let's
> > > > give a sorry for now.
> > >
> > > Given our vector extension does elementwise comparisons I don't think we can
> > > implement <=> in a reasonable manner.
> >
> > Why?  We indeed can't return a vector of std::strong_ordering or
> > std::partial_ordering classes, but we could return a vector of either the
> > underlying integral values (0/1/-1/-127), or vector of enums from which one
> > could construct those std::strong_ordering or std::partial_ordering classes.
> > We do not support vectors of pointers and so the only possibilities are
> > strong orderings for integral vectors and partial orderings for floating
> > point vectors.
> 
> But how to we actually emit (efficient) code for this?  A vector extension
> should produce (efficient) vector code.

For integers perhaps:
typedef int V __attribute__((vector_size(16)));

V
spaceship (V x, V y)
{
  return (x < y) | ((x > y) & (V) { 1, 1, 1, 1 });
}
or
	vpcmpgtd	%xmm1, %xmm0, %xmm2
	vpcmpgtd	%xmm0, %xmm1, %xmm0
	vpand	.LC0(%rip), %xmm2, %xmm2
	vpor	%xmm0, %xmm2, %xmm0
for -mavx?  Sure, for floating point it might be longer without -ffast-math,
though scalar floating <=> doesn't expand to something short either.
I believe it is something like
  x == y ? 0 : x < y ? -1 : x > y ? 1 : -127
so for float it could be something like (not sure about qNaNs and exceptions
for either scalar or vector)
vcmplt_oqps | (vcmpgt_oqps & {1,1,1,1}) \
| (vcmpunordps & {-127,-127,-127,-127})?

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]