Subject: bug#69770: closed (Re: bug#69770: [PATCH] build: strengthen 16 bit float support checks)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 13 Mar 2024 12:39:02 +0000

Your bug report

#69770: [PATCH] build: strengthen 16 bit float support checks

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
69770: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69770
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#69770: [PATCH] build: strengthen 16 bit float support checks
From: Pádraig Brady <[email-masked]>
To: Grisha Levit <[email-masked]>, [email-masked]
Date: Wed, 13 Mar 2024 12:36:51 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

On 13/03/2024 02:24, Grisha Levit wrote:
> 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.

Looks good!

I'll follow up with another patch to all these involved checks to be cached / bypassed,
by wrapping them in AC_CACHE_VAL().

Marking this as done.

thanks!
Pádraig

Subject: [PATCH] build: strengthen 16 bit float support checks
From: Grisha Levit <[email-masked]>
To: [email-masked]
Cc: Grisha Levit <[email-masked]>
Date: Tue, 12 Mar 2024 22:24:34 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

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