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/107748] New: [13 Regression] Isn't _mm_cvtsbh_ss incorrect?
Date: Fri, 18 Nov 2022 10:10:58 +0000	[thread overview]
Message-ID: <bug-107748-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107748
           Summary: [13 Regression] Isn't _mm_cvtsbh_ss incorrect?
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

The implementation:

/* Convert One BF16 Data to One Single Float Data.  */
extern __inline float
__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
_mm_cvtsbh_ss (__bf16 __A)
{
  union{ float a; unsigned int b;} __tmp;
  __tmp.b = ((unsigned int)(__A)) << 16;
  return __tmp.a;
}

except for the __bfloat16 -> __bf16 change used to be correct in GCC 12,
if one can ignore sNaN (and I presume the builtin is ok with that), then when
__A argument was actually unsigned or signed short, the above did the right
thing.
But now it certainly doesn't, because it converts the floating point BFmode
__A to integer, then shifts the integer 16 bits up and then VIEW_CONVERT_EXPRs
it into float.  So, instead of -ffinite-math-only BF -> SF conversion it
actually
does BF -> SF -> USI conversions, then multiplies by 65536 and then VCE to SF.
So, either it can just do return __A; but that will emit a library call unless
-ffinite-math-only/-ffast-math, or it could be e.g.
  unsigned short int __b;
  unsigned int __c;
  float __ret;
  __builtin_memcpy (&__b, &__A, sizeof (__b));
  __c = __b << 16;
  __builtin_memcpy (&__ret, &__c, sizeof (__ret));
  return __ret;
Note, the a and b identifiers in the union look bad as well, a and b aren't
reserved identifiers...

             reply	other threads:[~2022-11-18 10:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 10:10 jakub at gcc dot gnu.org [this message]
2022-11-18 10:11 ` [Bug target/107748] " jakub at gcc dot gnu.org
2022-11-18 10:14 ` jakub at gcc dot gnu.org
2022-11-18 11:31 ` crazylht at gmail dot com
2022-11-18 11:46 ` jakub at gcc dot gnu.org
2022-11-18 12:04 ` jakub at gcc dot gnu.org
2022-11-21  9:30 ` cvs-commit at gcc dot gnu.org
2022-11-21  9:33 ` cvs-commit at gcc dot gnu.org
2022-11-21  9:35 ` cvs-commit at gcc dot gnu.org
2022-11-21  9:36 ` jakub at gcc dot gnu.org
2022-11-22  5:16 ` crazylht at gmail dot com
2022-11-28  1:03 ` cvs-commit at gcc dot gnu.org
2022-11-28  1:03 ` crazylht at gmail dot com
2022-11-29 14:41 ` jakub at gcc dot gnu.org
2023-05-03 15:19 ` cvs-commit 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-107748-4@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).