[PATCH] Aarch32/64: Support __FLT_EVAL_METHOD__ values other than 0, 1, 2
Andrea Corallo
andrea.corallo@arm.com
Mon Apr 4 08:39:25 GMT 2022
Hi all,
when _Float16 in native precision is supported GCC defines
__FLT_EVAL_METHOD__ to 16 as per ISO/IEC TS 18661-3.
Ex:
$ ./arm-none-eabi-gcc -mthumb -march=armv8.1-m.main+fp -mfloat-abi=softfp -xc /dev/null -E -dM | grep FLT_EVAL
#define __FLT_EVAL_METHOD__ 16
#define __FLT_EVAL_METHOD_TS_18661_3__ 16
Unfortunately libc/include/math.h understands only values 0, 1 and 2
leading to have newlib non compilable for those configurations.
I think in newlib we should either:
1- Handle __FLT_EVAL_METHOD__ == 16
2- Build in a C mode which does not enable _Float16 (ex -std=c11)
3- Build without the _FloatN extensions -fpermitted-flt-eval-methods=c11
I think 1 should be the favorite approach.
ISO/IEC 9899:201x [1] suggests that for other values of FLT_EVAL_METHOD
other than 0, 1, 2 the definition of float_t and double_t is
implementation-defined.
The suggested patch implements that for arm and Aarch64.
Note, some previous discussion on this topic can be found here [2] as
follow-up to a patch addressing the same issue (only for the
case__FLT_EVAL_METHOD__ == 16 case).
Best Regards
Andrea
[1] <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf>
[2] <https://sourceware.org/legacy-ml/newlib/2019/msg00597.html>
-------------- next part --------------
>From d4c38a902e7bd5a2686d4d758c5cd563069c5bb2 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <andrea.corallo@arm.com>
Date: Wed, 30 Mar 2022 15:40:59 +0200
Subject: [PATCH] Aarch32/64: Support __FLT_EVAL_METHOD__ values other
than 0, 1, 2
2022-03-30 Andrea Corallo <andrea.corallo@arm.com>
* libc/include/machine/ieeefp.h (__FLOAT_TYPE, __DOUBLE_TYPE): New
macros.
* libc/include/math.h: Uses __DOUBLE_TYPE __FLOAT_TYPE to define
double_t float_t if possible.
---
newlib/libc/include/machine/ieeefp.h | 4 ++++
newlib/libc/include/math.h | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index 4dc13828c..c65c67769 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -90,6 +90,8 @@
#ifndef __SOFTFP__
# define _SUPPORTS_ERREXCEPT
#endif
+#define __DOUBLE_TYPE double
+#define __FLOAT_TYPE float
#endif
#if defined (__aarch64__)
@@ -102,6 +104,8 @@
#ifdef __ARM_FP
# define _SUPPORTS_ERREXCEPT
#endif
+#define __DOUBLE_TYPE double
+#define __FLOAT_TYPE float
#endif
#ifdef __epiphany__
diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index ba1a8a17e..da056b5b6 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -158,6 +158,15 @@ extern int isnan (double);
#else
/* Implementation-defined. Assume float_t and double_t have been
* defined previously for this configuration (e.g. config.h). */
+
+ /* If __DOUBLE_TYPE is defined (__FLOAT_TYPE is then supposed to be
+ defined as well) float_t and double_t definition is suggested by
+ an arch specific header. */
+ #ifdef __DOUBLE_TYPE
+ typedef __DOUBLE_TYPE double_t
+ typedef __FLOAT_TYPE float_t
+ #endif
+ /* Assume config.h has provided these types. */
#endif
#else
/* Assume basic definitions. */
--
2.25.1
More information about the Newlib
mailing list