File 1144-erts-Improve-Float16-type-checking.patch of Package erlang
From c4e95057d269d7e10bfedb51f0c1cb46006a34b4 Mon Sep 17 00:00:00 2001
From: "Matwey V. Kornilov" <matwey.kornilov@gmail.com>
Date: Sat, 16 Nov 2024 20:07:08 +0300
Subject: [PATCH] erts: Improve Float16 type checking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
At least gcc 14.2 at x86 platform correctly returns sizeof(_Float16)
value, but then the compilation is failed as the following:
beam/erl_bits.c: In function ‘erts_bs_get_float_2’:
beam/erl_bits.c:485:9: error: invalid conversion from type ‘_Float16’ without option ‘-msse2’
485 | f.fd = FP16_TO_FP64(f16);
| ^
Add the new check in order to fix build at x86 platform. Please note,
that the patch correctly check the compiler behaviour when
CFLAGS="-msse2" ./configure
is run.
---
erts/configure.ac | 12 ++++++++++++
erts/emulator/beam/erl_bits.c | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/erts/configure.in b/erts/configure.in
index e79def7c42..466cc07176 100644
--- a/erts/configure.in
+++ b/erts/configure.in
@@ -1903,6 +1903,18 @@ AC_CHECK_SIZEOF(time_t)
AC_CHECK_SIZEOF(suseconds_t)
AC_CHECK_SIZEOF(_Float16)
+dnl Check that _Float16 is not only exists but also is usable. The check is
+dnl mainly for x86 platform which requires -msse2 flag.
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[_Float16 x = 0.0;]],[[]])],
+ [AC_MSG_CHECKING([for _Float16 convertible])
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([FLOAT16_IS_CONVERTIBLE],[1],
+ [Define to 1 if _Float16 can be converted from/to double.])
+ ],
+ [AC_MSG_CHECKING([for _Float16 convertible])
+ AC_MSG_RESULT([no])
+ ])
+
BITS64=
if test $ac_cv_sizeof_void_p = 8; then
diff --git a/erts/emulator/beam/erl_bits.c b/erts/emulator/beam/erl_bits.c
index a385884128..25177097e2 100644
--- a/erts/emulator/beam/erl_bits.c
+++ b/erts/emulator/beam/erl_bits.c
@@ -40,7 +40,7 @@
#define BIT_IS_MACHINE_ENDIAN(x) (((x)&BSF_LITTLE) == BIT_ENDIAN_MACHINE)
-#if (SIZEOF__FLOAT16 == 2)
+#if (SIZEOF__FLOAT16 == 2) && defined(FLOAT16_IS_CONVERTIBLE)
typedef _Float16 erlfp16;
#define FP16_FROM_FP64(x) ((_Float16) x)
#define FP16_TO_FP64(x) ((double) x)
--
2.43.0