This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[AARCH64][ACLE] Implement __ARM_FP_FENV_ROUNDING in aarch64 backend.


This patch implements the __ARM_FP_FENV_ROUNDING macro in the aarch64 backend.
AArch64 supports configurable rounding modes, which can be set using the
standard C fesetround() function. According to the ACLE 2.0 specification,
__ARM_FP_FENV_ROUNDING is defined to 1 only when fesetround() is provided.
Since newlib doesn't provide this function, and since armv8 aarch64 hardware
provides support for configurable rounding modes for scalar and simd, we only define the macro when we are building a compiler targeting glibc (i.e. target
aarch64-none-linux-gnu), which does provide fesetround().

Cross tested on aarch64-none-elf and aarch64-none-linux-gnu. Bootstrapped and
tested on aarch64-none-linux-gnu.

---

gcc/

2015-XX-XX  Bilyan Borisov  <bilyan.borisov@foss.arm.com>

	* config/aarch64/aarch64-c.c (aarch64_update_cpp_builtins): New macro
	definition.

gcc/testsuite/

2015-XX-XX  Bilyan Borisov  <bilyan.borisov@foss.arm.com>

	* gcc.target/aarch64/fesetround-checking-baremetal.c: New.
	* gcc.target/aarch64/fesetround-checking-linux.c: Likewise.
diff --git a/gcc/config/aarch64/aarch64-c.c b/gcc/config/aarch64/aarch64-c.c
index ad95c78b9895a33da3e5a0ec6328219b887ade37..0e07d74639340176f51587e37e5ea91b57fdeee1 100644
--- a/gcc/config/aarch64/aarch64-c.c
+++ b/gcc/config/aarch64/aarch64-c.c
@@ -97,8 +97,15 @@ aarch64_update_cpp_builtins (cpp_reader *pfile)
 
   aarch64_def_or_undef (TARGET_SIMD, "__ARM_FEATURE_NUMERIC_MAXMIN", pfile);
   aarch64_def_or_undef (TARGET_SIMD, "__ARM_NEON", pfile);
-
-
+  /* Since fesetround () is not present in newlib, but it's present in glibc, we
+     only define the __ARM_FP_FENV_ROUNDING macro to 1 when glibc is used
+     i.e. on aarch64-none-linux-gnu.  The OPTION_GLIBC macro is undefined on
+     aarch64-none-elf, and is defined on aarch64-none-linux-gnu to an expression
+     that evaluates to 1 when targetting glibc.  The musl, bionic, and uclibc
+     cases haven't been investigated, so don't do any action in that case.  */
+#ifdef OPTION_GLIBC
+    aarch64_def_or_undef (OPTION_GLIBC, "__ARM_FP_FENV_ROUNDING", pfile);
+#endif
   aarch64_def_or_undef (TARGET_CRC32, "__ARM_FEATURE_CRC32", pfile);
 
   cpp_undef (pfile, "__AARCH64_CMODEL_TINY__");
diff --git a/gcc/testsuite/gcc.target/aarch64/fesetround-checking-baremetal.c b/gcc/testsuite/gcc.target/aarch64/fesetround-checking-baremetal.c
new file mode 100644
index 0000000000000000000000000000000000000000..1202dfa2e81923f0d2c9b6be1eb71e3192d5d974
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fesetround-checking-baremetal.c
@@ -0,0 +1,18 @@
+/* { dg-do compile { target { aarch64*-*-elf* } } } */
+
+extern void abort ();
+
+int
+main ()
+{
+  /* According to ACLE 2.0, __ARM_FP_FENV_ROUNDING macro should be defined to 1
+     when fesetround () is supported.  Since aarch64-none-elf which uses newlib
+     doesn't support this, we error if the macro is defined to 1.
+   */
+#if defined (__ARM_FP_FENV_ROUNDING)
+#error "According to ACLE 2.0, __ARM_FP_FENV_ROUNDING macro should be defined \
+to 1 only when fesetround () is supported."
+#else
+  return 0;
+#endif
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/fesetround-checking-linux.c b/gcc/testsuite/gcc.target/aarch64/fesetround-checking-linux.c
new file mode 100644
index 0000000000000000000000000000000000000000..d79f384d672bf8d0847b41ab8cc2cc594a805dca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fesetround-checking-linux.c
@@ -0,0 +1,18 @@
+/* { dg-do compile { target { aarch64*-*-linux* } } } */
+
+extern void abort ();
+
+int
+main ()
+{
+  /* According to ACLE 2.0, __ARM_FP_FENV_ROUNDING macro should be defined to 1
+     when fesetround () is supported.  In our case, this is on
+     aarch64-none-linux-gnu.
+   */
+#if defined (__ARM_FP_FENV_ROUNDING) && (__ARM_FP_FENV_ROUNDING == 1)
+  return 0;
+#else
+#error "According to ACLE 2.0, __ARM_FP_FENV_ROUNDING macro should be defined \
+to 1 when fesetround () is supported."
+#endif
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]