public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "crazylht at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/98612] _mm_comieq_sd has wrong semantics
Date: Mon, 11 Jan 2021 06:05:07 +0000	[thread overview]
Message-ID: <bug-98612-4-w9cOkoKYVL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98612-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98612

--- Comment #2 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Guillaume Piolat from comment #0)
> Created attachment 49926 [details]
> Behaviour with 3 compilers
> 
> _mm_comieq_sd has different NaN semantics for different people.
> 
> # The Unordered team
> - GCC will return 1 for a comparison that involved NaN.
> - this maps to the underlying instruction
> 
> # The Ordered team
> - Intel intrinsics guide says: 
> 
>      RETURN ( a[63:0] == b[63:0] ) ? 1 : 0
> 
>   which indicates an ordered comparison.

ICC take _mm_{u,}comi{eq,lt,le,gt,ge}_s{s,d} as ordered comparison, and
_mm_{u,}comineq_s{s,d} as unordered comparison, GCC didn't take {Q,}NAN operand
into consideration.

The codes has been in gcc for more than 15 years, and I'm not sure if some
applications are taking advantage of this "bug" in gcc, so do we really need to
"fix" it?

Technically, we can just "refine" as.

modified   gcc/config/i386/emmintrin.h
@@ -515,7 +515,7 @@ _mm_cmpunord_sd (__m128d __A, __m128d __B)
 extern __inline int __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
 _mm_comieq_sd (__m128d __A, __m128d __B)
 {
-  return __builtin_ia32_comisdeq ((__v2df)__A, (__v2df)__B);
+  return __A[0] == __B[0];
 }

  parent reply	other threads:[~2021-01-11  6:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-09 14:46 [Bug libstdc++/98612] New: " guillaume.piolat at gmail dot com
2021-01-09 14:47 ` [Bug libstdc++/98612] " guillaume.piolat at gmail dot com
2021-01-11  6:05 ` crazylht at gmail dot com [this message]
2021-01-11  6:45 ` [Bug target/98612] " crazylht at gmail dot com
2021-01-11  8:36 ` rguenth at gcc dot gnu.org
2021-01-11 12:54 ` guillaume.piolat at gmail dot com
2021-01-12  3:18 ` cvs-commit at gcc dot gnu.org
2021-01-19  3:15 ` crazylht at gmail dot com
2021-01-19  7:28 ` ubizjak at gmail dot com
2023-03-24 11:20 ` andysem at mail dot ru

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=bug-98612-4-w9cOkoKYVL@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).