bug-coreutils@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Grisha Levit <grishalevit@gmail.com>
To: 69770@debbugs.gnu.org
Cc: Grisha Levit <grishalevit@gmail.com>
Subject: bug#69770: [PATCH] build: strengthen 16 bit float support checks
Date: Tue, 12 Mar 2024 22:24:34 -0400	[thread overview]
Message-ID: <20240313022545.13117-1-grishalevit@gmail.com> (raw)

Recent clang provides __bf16 on aarch64 but it is broken.

If built with -O0, the conversion is wrong:

    $ printf '\x3F\x80' | od --end=big -An -tfB | tr -d ' '
    1.875

If built with -O1 or higher, compilation fails:

    fatal error: error in backend: Cannot select: 0xb400007a58d29780: f32 = fp_extend 0xb400007a58d31720
      0xb400007a58d31720: bf16,ch = CopyFromReg 0xb400007b78c53720, Register:bf16 %13
        0xb400007a58d29470: bf16 = Register %13
    In function: print_bfloat

The latter issue does not cause the existing configure test to fail
because the promotion is optimized out.

* configure.ac: Ensure 16 bit float promotion code does not get
optimized out, and produces an expected result.
---
 configure.ac | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 248e30ca2..21bee28d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -569,13 +569,14 @@ ac_c_werror_flag=$cu_save_c_werror_flag
 
 # Test compiler support for half precision floating point types (for od)
 AC_MSG_CHECKING([IEEE 16 bit floating point])
- AC_COMPILE_IFELSE(
+ AC_RUN_IFELSE(
    [AC_LANG_SOURCE([[
      int
      main (void)
      {
-        _Float16 hf;
+        volatile _Float16 hf = 1;
         float f = hf;  /* Ensure compiler can promote to float.  */
+        return !(f == 1.0f);
      }
   ]])
   ],[
@@ -589,13 +590,14 @@ if test $ieee_16_bit_supported = yes; then
 fi
 
 AC_MSG_CHECKING([Brain 16 bit floating point])
- AC_COMPILE_IFELSE(
+ AC_RUN_IFELSE(
    [AC_LANG_SOURCE([[
      int
      main (void)
      {
-        __bf16 hf;
+        volatile __bf16 hf = 1;
         float f = hf;  /* Ensure compiler can promote to float.  */
+        return !(f == 1.0f);
      }
   ]])
   ],[
-- 
2.44.0





             reply	other threads:[~2024-03-13  2:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13  2:24 Grisha Levit [this message]
2024-03-13 12:36 ` bug#69770: [PATCH] build: strengthen 16 bit float support checks Pádraig Brady
2024-03-14  5:59 ` Paul Eggert
2024-03-14 13:03   ` Pádraig Brady
2024-03-14 13:35     ` Collin Funk
2024-03-14 14:48       ` Pádraig Brady
2024-03-14 15:51         ` Collin Funk
2024-03-15  5:21     ` Paul Eggert
2024-03-15 11:49       ` Pádraig Brady

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-coreutils

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

  git send-email \
    --in-reply-to=20240313022545.13117-1-grishalevit@gmail.com \
    --to=grishalevit@gmail.com \
    --cc=69770@debbugs.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).