Re: [PATCH] libgcc: Rename __trunchfbf2 to __extendhfbf2

2024-05-01 Thread Jakub Jelinek
On Wed, May 01, 2024 at 12:55:25PM -0700, H.J. Lu wrote:
> Since bfloat16 has the same range as float32, _Float16 to bfloat16
> conversion is an extension, not a truncation.  Rename trunchfbf2.c
> to extendhfbf2.c to provide __extendhfbf2, instead of __trunchfbf2.
> 
> Since _Float16 to bfloat16 conversion never worked from the day one,
> the same libgcc version of __trunchfbf2 is used with __extendhfbf2 so
> that this can be backported to release branches all the way where
> __trunchfbf2 was added.

This is wrong.
First of all, it is ABI incompatible change, we can't do that.
And second, neither _Float16 is a subset of __bf16 nor the other way,
so both extend and trunc names are equally wrong.

Jakub



[PATCH] libgcc: Rename __trunchfbf2 to __extendhfbf2

2024-05-01 Thread H.J. Lu
Since bfloat16 has the same range as float32, _Float16 to bfloat16
conversion is an extension, not a truncation.  Rename trunchfbf2.c
to extendhfbf2.c to provide __extendhfbf2, instead of __trunchfbf2.

Since _Float16 to bfloat16 conversion never worked from the day one,
the same libgcc version of __trunchfbf2 is used with __extendhfbf2 so
that this can be backported to release branches all the way where
__trunchfbf2 was added.

gcc/testsuite/

PR libgcc/114907
* gcc.dg/pr114907-1.c: New test.
* gcc.dg/pr114907-2.c: Likewise.

libgcc/

PR libgcc/114907
* config/aarch64/libgcc-softfp.ver (__trunchfbf2): Renamed to ...
(__extendhfbf2): This.
* config/aarch64/t-softfp (softfp_extensions): Add hfbf.
(softfp_truncations): Remove hfbf.
* config/i386/libgcc-darwin.ver (__trunchfbf2): Renamed to ...
(__extendhfbf2): This.
* config/i386/libgcc-glibc.ver (__trunchfbf2): Renamed to ...
(__extendhfbf2): This.
* config/i386/libgcc-sol2.ver (__trunchfbf2): Renamed to ...
(__extendhfbf2): This.
* config/i386/t-softfp (softfp_extensions): Add hfbf.
(softfp_truncations): Remove hfbf.
(CFLAGS-trunchfbf2.c): Renamed to ...
(CFLAGS-extendhfbf2.c): This.
* soft-fp/trunchfbf2.c: Renamed to ...
* soft-fp/extendhfbf2.c: This.
(__trunchfbf2): Renamed to ...
(__extendhfbf2): This.
---
 gcc/testsuite/gcc.dg/pr114907-1.c | 21 +++
 gcc/testsuite/gcc.dg/pr114907-2.c | 17 +++
 libgcc/config/aarch64/libgcc-softfp.ver   |  2 +-
 libgcc/config/aarch64/t-softfp|  4 ++--
 libgcc/config/i386/libgcc-darwin.ver  |  2 +-
 libgcc/config/i386/libgcc-glibc.ver   |  2 +-
 libgcc/config/i386/libgcc-sol2.ver|  2 +-
 libgcc/config/i386/t-softfp   |  6 +++---
 .../soft-fp/{trunchfbf2.c => extendhfbf2.c}   |  6 +++---
 9 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr114907-1.c
 create mode 100644 gcc/testsuite/gcc.dg/pr114907-2.c
 rename libgcc/soft-fp/{trunchfbf2.c => extendhfbf2.c} (94%)

diff --git a/gcc/testsuite/gcc.dg/pr114907-1.c 
b/gcc/testsuite/gcc.dg/pr114907-1.c
new file mode 100644
index 000..9f6219d5e88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114907-1.c
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+/* { dg-options "-O0" } */
+/* { dg-add-options bfloat16 } */
+/* { dg-require-effective-target bfloat16_runtime } */
+
+__bf16 bfa, bfb, bfc, bfd, bfe, bff;
+_Float16 f16a, f16b;
+float f32a, f32b;
+double da, db;
+
+int
+main (void)
+{
+  bfa = f16a;
+  f16b = bfb;
+  bfc = f32a;
+  f32b = bfd;
+  bfe = da;
+  db = bff;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pr114907-2.c 
b/gcc/testsuite/gcc.dg/pr114907-2.c
new file mode 100644
index 000..41cc88f0652
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114907-2.c
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-options "-O0" } */
+/* { dg-add-options bfloat16 } */
+/* { dg-add-options __float128 } */
+/* { dg-require-effective-target bfloat16_runtime } */
+/* { dg-require-effective-target __float128 } */
+
+__bf16 bfa, bfb;
+__float128 fa, fb;
+
+int
+main (void)
+{
+  bfa = fa;
+  fb = bfb;
+  return 0;
+}
diff --git a/libgcc/config/aarch64/libgcc-softfp.ver 
b/libgcc/config/aarch64/libgcc-softfp.ver
index 9ba857036ab..d6e427cbf7e 100644
--- a/libgcc/config/aarch64/libgcc-softfp.ver
+++ b/libgcc/config/aarch64/libgcc-softfp.ver
@@ -30,6 +30,7 @@ GCC_11.0 {
 %inherit GCC_13.0.0 GCC_11.0.0
 GCC_13.0.0 {
   __extendbfsf2
+  __extendhfbf2
   __floatdibf
   __floattibf
   __floatundibf
@@ -37,7 +38,6 @@ GCC_13.0.0 {
   __truncdfbf2
   __truncsfbf2
   __trunctfbf2
-  __trunchfbf2
 }
 
 %inherit GCC_14.0.0 GCC_13.0.0
diff --git a/libgcc/config/aarch64/t-softfp b/libgcc/config/aarch64/t-softfp
index 80e7e77a545..5c7e6dbc5b5 100644
--- a/libgcc/config/aarch64/t-softfp
+++ b/libgcc/config/aarch64/t-softfp
@@ -1,7 +1,7 @@
 softfp_float_modes := tf
 softfp_int_modes := si di ti
-softfp_extensions := sftf dftf hftf bfsf
-softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf hfbf
+softfp_extensions := sftf dftf hftf bfsf hfbf
+softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf
 softfp_exclude_libgcc2 := n
 softfp_extras += fixhfti fixunshfti floattihf floatuntihf \
 floatdibf floatundibf floattibf floatuntibf \
diff --git a/libgcc/config/i386/libgcc-darwin.ver 
b/libgcc/config/i386/libgcc-darwin.ver
index 06560d6b47f..1e7efb828ed 100644
--- a/libgcc/config/i386/libgcc-darwin.ver
+++ b/libgcc/config/i386/libgcc-darwin.ver
@@ -29,13 +29,13 @@ GCC_12.0.0 {
 GCC_14.0.0 {
   # Added to GCC_13.0.0 in i386/libgcc-glibc.ver.
   __extendbfsf2
+  __extendhfbf2
   __floattibf
   __floatuntibf
   __truncdfbf2
   __truncsfbf2
   __trunctfbf2
   __truncxfbf2
-  __trunchfbf2
   # Added to GCC_14.0.0 in i386/libgcc-glibc.ver.
   __fixxfbitint
   __fixtfbitint
diff