diff mbox series

libgcc: Rename __trunchfbf2 to __extendhfbf2

Message ID 20240501195525.599855-1-hjl.tools@gmail.com
State New
Headers show
Series libgcc: Rename __trunchfbf2 to __extendhfbf2 | expand

Commit Message

H.J. Lu May 1, 2024, 7:55 p.m. UTC
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%)

Comments

Jakub Jelinek May 1, 2024, 8 p.m. UTC | #1
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
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/pr114907-1.c b/gcc/testsuite/gcc.dg/pr114907-1.c
new file mode 100644
index 00000000000..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 00000000000..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 --git a/libgcc/config/i386/libgcc-glibc.ver b/libgcc/config/i386/libgcc-glibc.ver
index 5b360ac1249..451f1b1c57f 100644
--- a/libgcc/config/i386/libgcc-glibc.ver
+++ b/libgcc/config/i386/libgcc-glibc.ver
@@ -218,13 +218,13 @@  GCC_12.0.0 {
 %inherit GCC_13.0.0 GCC_12.0.0
 GCC_13.0.0 {
   __extendbfsf2
+  __extendhfbf2
   __floattibf
   __floatuntibf
   __truncdfbf2
   __truncsfbf2
   __trunctfbf2
   __truncxfbf2
-  __trunchfbf2
 }
 
 %inherit GCC_14.0.0 GCC_13.0.0
diff --git a/libgcc/config/i386/libgcc-sol2.ver b/libgcc/config/i386/libgcc-sol2.ver
index 77570b634a3..59dcfeca674 100644
--- a/libgcc/config/i386/libgcc-sol2.ver
+++ b/libgcc/config/i386/libgcc-sol2.ver
@@ -136,13 +136,13 @@  GCC_14.0.0 {
   __truncxfhf2
   # 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 --git a/libgcc/config/i386/t-softfp b/libgcc/config/i386/t-softfp
index 222698d9efd..07d9bb0aeca 100644
--- a/libgcc/config/i386/t-softfp
+++ b/libgcc/config/i386/t-softfp
@@ -6,9 +6,9 @@  LIB2FUNCS_EXCLUDE += $(libgcc2-hf-functions)
 libgcc2-hf-extras = $(addsuffix .c, $(libgcc2-hf-functions))
 LIB2ADD += $(addprefix $(srcdir)/config/i386/, $(libgcc2-hf-extras))
 
-softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf bfsf
+softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf bfsf hfbf
 softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf \
-		      tfbf xfbf dfbf sfbf hfbf
+		      tfbf xfbf dfbf sfbf
 
 softfp_extras += eqhf2 fixxfbitint $(foreach m,hf bf xf,floatbitint$(m))
 
@@ -17,6 +17,7 @@  CFLAGS-extendhfdf2.c += -msse2
 CFLAGS-extendhftf2.c += -msse2
 CFLAGS-extendhfxf2.c += -msse2
 CFLAGS-extendbfsf2.c += -msse2
+CFLAGS-extendhfbf2.c += -msse2
 
 CFLAGS-truncsfhf2.c += -msse2
 CFLAGS-truncdfhf2.c += -msse2
@@ -26,7 +27,6 @@  CFLAGS-truncsfbf2.c += -msse2
 CFLAGS-truncdfbf2.c += -msse2
 CFLAGS-truncxfbf2.c += -msse2
 CFLAGS-trunctfbf2.c += -msse2
-CFLAGS-trunchfbf2.c += -msse2
 
 CFLAGS-floatbitintbf.c += -msse2
 CFLAGS-floatbitinthf.c += -msse2
diff --git a/libgcc/soft-fp/trunchfbf2.c b/libgcc/soft-fp/extendhfbf2.c
similarity index 94%
rename from libgcc/soft-fp/trunchfbf2.c
rename to libgcc/soft-fp/extendhfbf2.c
index f3d650123ef..3443948da3f 100644
--- a/libgcc/soft-fp/trunchfbf2.c
+++ b/libgcc/soft-fp/extendhfbf2.c
@@ -1,6 +1,6 @@ 
 /* Software floating-point emulation.
-   Truncate IEEE half into bfloat16.
-   Copyright (C) 2022 Free Software Foundation, Inc.
+   Extend IEEE half into bfloat16.
+   Copyright (C) 2022-2024 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -36,7 +36,7 @@ 
    truncate to BFtype.  */
 
 BFtype
-__trunchfbf2 (HFtype a)
+__extendhfbf2 (HFtype a)
 {
   FP_DECL_EX;
   FP_DECL_H (A);