public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: FX <fxcoudert@gmail.com>
Cc: gcc@gcc.gnu.org, "Joseph S. Myers" <joseph@codesourcery.com>,
	FX via Fortran <fortran@gcc.gnu.org>
Subject: Re: Floating-point comparisons in the middle-end
Date: Thu, 1 Sep 2022 11:23:36 +0200	[thread overview]
Message-ID: <YxB6GGjkTdUFY+iz@tucnak> (raw)
In-Reply-To: <3BD50DD7-5C9E-42CB-992C-A66584411A4F@gmail.com>

On Thu, Sep 01, 2022 at 11:04:03AM +0200, FX wrote:
> Hi Jakub,
> 
> >> 2.  All the functions are available as GCC type-generic built-ins (yeah!),
> >> except there is no __builtin_ iseqsig
> >> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77928).  Is there a
> >> fundamental problem with creating one, and could someone help there?
> > 
> > IMHO until that one is implemented you can just use
> > tx = x, ty = y, tx>=ty && tx<=ty
> > (in GENERIC just SAVE_EXPR<x> >= SAVE_EXPR<y> && SAVE_EXPR<x> <= SAVE_EXPR<y>
> 
> If it’s just that (optimization aside), I probably can create a C built-in. It would need to be:
> 
> 1. defined in builtins.def
> 2. lowered in builtins.cc
> 3. type-checked in c-family/c-common.cc
> 4. documented in doc/extend.texi
> 5. tested in fp-test.cc
> 6. covered in the testsuite
> 
> Is that right?

Dunno if we really need a builtin for this, especially if it is lowered
to that x >= y && x <= y early, will defer to Joseph.

Because if it is for better code generation only, IMNSHO we want to optimize
even when users write it that way by hand and so want to pattern recognize
that during instruction selection before expansion (isel pass) or during
expansion if target can do that.
E.g. x86 with AVX can do that:

where the 4 booleans are A>B, A<B, A=B, Unordered and Yes/No is whether
signal is raised when one or both of the operands are QNaN (it is raised
always if at least one is SNaN):
EQ_OQ (EQ) 0H Equal (ordered, non-signaling) False False True False No
LT_OS (LT) 1H Less-than (ordered, signaling) False True False False Yes
LE_OS (LE) 2H Less-than-or-equal (ordered, signaling) False True True False Yes
UNORD_Q (UNORD) 3H Unordered (non-signaling) False False False True No
NEQ_UQ (NEQ) 4H Not-equal (unordered, non-signaling) True True False True No
NLT_US (NLT) 5H Not-less-than (unordered, signaling) True False True True Yes
NLE_US (NLE) 6H Not-less-than-or-equal (unordered, signaling) True False False True Yes
ORD_Q (ORD) 7H Ordered (non-signaling) True True True False No
EQ_UQ 8H Equal (unordered, non-signaling) False False True True No
NGE_US (NGE) 9H Not-greater-than-or-equal (unordered, signaling) False True False True Yes
NGT_US (NGT) AH Not-greater-than (unordered, signaling) False True True True Yes
FALSE_OQ (FALSE) BH False (ordered, non-signaling) False False False False No
NEQ_OQ CH Not-equal (ordered, non-signaling) True True False False No
GE_OS (GE) DH Greater-than-or-equal (ordered, signaling) True False True False Yes
GT_OS (GT) EH Greater-than (ordered, signaling) True False False False Yes
TRUE_UQ (TRUE) FH True (unordered, non-signaling) True True True True No
EQ_OS 10H Equal (ordered, signaling) False False True False Yes
LT_OQ 11H Less-than (ordered, non-signaling) False True False False No
LE_OQ 12H Less-than-or-equal (ordered, non-signaling) False True True False No
UNORD_S 13H Unordered (signaling) False False False True Yes
NEQ_US 14H Not-equal (unordered, signaling) True True False True Yes
NLT_UQ 15H Not-less-than (unordered, non-signaling) True False True True No
NLE_UQ 16H Not-less-than-or-equal (unordered, non-signaling) True False False True No
ORD_S 17H Ordered (signaling) True True True False Yes
EQ_US 18H Equal (unordered, signaling) False False True True Yes
NGE_UQ 19H Not-greater-than-or-equal (unordered, non-signaling) False True False True No
NGT_UQ 1AH Not-greater-than (unordered, non-signaling) False True True True No
FALSE_OS 1BH False (ordered, signaling) False False False False Yes
NEQ_OS 1CH Not-equal (ordered, signaling) True True False False Yes
GE_OQ 1DH Greater-than-or-equal (ordered, non-signaling) True False True False No
GT_OQ 1EH Greater-than (ordered, non-signaling) True False False False No
TRUE_US 1FH True (unordered, signaling) True True True True Yes

So x >= y && x <= y can be handled using vcmpeq_ossd or similar instructions.

	Jakub


  reply	other threads:[~2022-09-01  9:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01  8:04 FX
2022-09-01  8:19 ` Jakub Jelinek
2022-09-01  9:04   ` FX
2022-09-01  9:23     ` Jakub Jelinek [this message]
2022-09-01 10:06       ` FX
2022-09-01 15:21         ` Joseph Myers
2022-09-01 15:57           ` Marc Glisse
2022-09-01 16:22             ` Joseph Myers
2022-09-01 16:24           ` FX
2022-09-01 16:44             ` Joseph Myers
2022-09-01 18:15               ` FX
2022-09-01 14:32   ` Segher Boessenkool
2022-09-01 15:19 ` Joseph Myers
2022-09-01 18:38   ` FX
2022-09-01 19:13     ` Joseph Myers
2022-09-01 18:47   ` FX
2022-09-01 19:16     ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxB6GGjkTdUFY+iz@tucnak \
    --to=jakub@redhat.com \
    --cc=fortran@gcc.gnu.org \
    --cc=fxcoudert@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).