public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/99497] _mm_min_ss/_mm_max_ss incorrect results when values known at compile time
Date: Tue, 09 Mar 2021 23:12:34 +0000	[thread overview]
Message-ID: <bug-99497-4-eJJhdERO4S@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99497-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Simplified:
#include <x86intrin.h>

void
print128 (__m128 var)
{
  float val[4];
  __builtin_memcpy (val, &var, sizeof(val));
  __builtin_printf ("%f %f %f %f \n", val[0], val[1], val[2], val[3]);
}

int
main ()
{
  __m128 a = _mm_set_ss (__builtin_nanf (""));
  __m128 b = _mm_set_ss (2.0f);
  __m128 c = _mm_max_ss (a, b);
  __m128 d = _mm_max_ss (b, a);
  print128 (c);
  print128 (d);
  return 0;
}

The RTL SMAX etc. ops are defined as:
/* Minimum and maximum values of two operands.  We need both signed and
   unsigned forms.  (We cannot use MIN for SMIN because it conflicts
   with a macro of the same name.)   The signed variants should be used
   with floating point.  Further, if both operands are zeros, or if either
   operand is NaN, then it is unspecified which of the two operands is
   returned as the result.  */

DEF_RTL_EXPR(SMIN, "smin", "ee", RTX_COMM_ARITH)
DEF_RTL_EXPR(SMAX, "smax", "ee", RTX_COMM_ARITH)
DEF_RTL_EXPR(UMIN, "umin", "ee", RTX_COMM_ARITH)
DEF_RTL_EXPR(UMAX, "umax", "ee", RTX_COMM_ARITH)

So, if _mm*_{min,max}_ss has the same requirement on what exactly should be
returned when both operands are zero or if either operand is NaN, then we
probably need to use an UNSPEC unless -ffast-math tells us NaNs won't appear or
sign of zero doesn't matter.

  reply	other threads:[~2021-03-09 23:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 22:43 [Bug c++/99497] New: " scott_sas_smith at hotmail dot com
2021-03-09 23:12 ` jakub at gcc dot gnu.org [this message]
2021-03-09 23:14 ` [Bug target/99497] " jakub at gcc dot gnu.org
2021-03-10  8:15 ` rguenth at gcc dot gnu.org
2021-03-10  8:35 ` jakub at gcc dot gnu.org

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-99497-4-eJJhdERO4S@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).