]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libatomic: Provide FPU exception defines for __hppa__
authorJohn David Anglin <danglin@gcc.gnu.org>
Sat, 3 Feb 2024 15:43:00 +0000 (15:43 +0000)
committerJohn David Anglin <danglin@gcc.gnu.org>
Sat, 3 Feb 2024 15:44:29 +0000 (15:44 +0000)
The exception defines in <fenv.h> do not match the exception bits
in the FPU status register on hppa-linux and hppa64-hpux11.11.  On
linux, they match the trap enable bits.  On 64-bit hpux, they match
the exception bits for IA64.  The IA64 bits are in a different
order and location than HPPA.  HP uses table look ups to reorder
the bits in code to test and raise exceptions.

All the architectures that I looked at just pass the FPU status
register to __atomic_feraiseexcept().  The simplest approach for
hppa is to define FE_INEXACT, etc, to match the status register
and not include <fenv.h>..

2024-02-03  John David Anglin  <danglin@gcc.gnu.org>

libatomic/ChangeLog:

PR target/59778
* configure.tgt (hppa*): Set ARCH.
* config/pa/fenv.c: New file.

libatomic/config/pa/fenv.c [new file with mode: 0644]
libatomic/configure.tgt

diff --git a/libatomic/config/pa/fenv.c b/libatomic/config/pa/fenv.c
new file mode 100644 (file)
index 0000000..232e841
--- /dev/null
@@ -0,0 +1,74 @@
+/* Copyright (C) 2012-2024 Free Software Foundation, Inc.
+
+   This file is part of the GNU Atomic Library (libatomic).
+
+   Libatomic is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "libatomic_i.h"
+
+#define FE_INEXACT     (1<<27)
+#define FE_UNDERFLOW   (1<<28)
+#define FE_OVERFLOW    (1<<29)
+#define FE_DIVBYZERO   (1<<30)
+#define FE_INVALID     (1<<31)
+
+/* Raise the supported floating-point exceptions from EXCEPTS.  Other
+   bits in EXCEPTS are ignored.  */
+
+void
+__atomic_feraiseexcept (int excepts __attribute__ ((unused)))
+{
+  volatile float r __attribute__ ((unused));
+#ifdef FE_INVALID
+  if (excepts & FE_INVALID)
+  {
+    volatile float zero = 0.0f;
+    r = zero / zero;
+  }
+#endif
+#ifdef FE_DIVBYZERO
+  if (excepts & FE_DIVBYZERO)
+    {
+      volatile float zero = 0.0f;
+      r = 1.0f / zero;
+    }
+#endif
+#ifdef FE_OVERFLOW
+  if (excepts & FE_OVERFLOW)
+    {
+      volatile float max = __FLT_MAX__;
+      r = max * max;
+    }
+#endif
+#ifdef FE_UNDERFLOW
+  if (excepts & FE_UNDERFLOW)
+    {
+      volatile float min = __FLT_MIN__;
+      r = min * min;
+    }
+#endif
+#ifdef FE_INEXACT
+  if (excepts & FE_INEXACT)
+    {
+      volatile float three = 3.0f;
+      r = 1.0f / three;
+    }
+#endif
+}
index 67a5f2dff80f2640c377c70e2f5f9a2d4d408bf9..4237f283fe4054d3bc66630259793c200369b236 100644 (file)
@@ -36,6 +36,7 @@ case "${target_cpu}" in
        XCFLAGS="${XCFLAGS} -mfp-trap-mode=sui"
        ARCH=alpha
        ;;
+  hppa*)               ARCH=pa ;;
   rs6000 | powerpc*)   ARCH=powerpc ;;
   riscv*)              ARCH=riscv ;;
   sh*)                 ARCH=sh ;;