summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/fenv/powerpc64
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/fenv/powerpc64
parentInitial commit. (diff)
downloadwasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz
wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/fenv/powerpc64')
-rw-r--r--libc-top-half/musl/src/fenv/powerpc64/fenv.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/fenv/powerpc64/fenv.c b/libc-top-half/musl/src/fenv/powerpc64/fenv.c
new file mode 100644
index 0000000..90dabdc
--- /dev/null
+++ b/libc-top-half/musl/src/fenv/powerpc64/fenv.c
@@ -0,0 +1,69 @@
+#define _GNU_SOURCE
+#include <fenv.h>
+#include <features.h>
+
+static inline double get_fpscr_f(void)
+{
+ double d;
+ __asm__ __volatile__("mffs %0" : "=d"(d));
+ return d;
+}
+
+static inline long get_fpscr(void)
+{
+ return (union {double f; long i;}) {get_fpscr_f()}.i;
+}
+
+static inline void set_fpscr_f(double fpscr)
+{
+ __asm__ __volatile__("mtfsf 255, %0" : : "d"(fpscr));
+}
+
+static void set_fpscr(long fpscr)
+{
+ set_fpscr_f((union {long i; double f;}) {fpscr}.f);
+}
+
+int feclearexcept(int mask)
+{
+ mask &= FE_ALL_EXCEPT;
+ if (mask & FE_INVALID) mask |= FE_ALL_INVALID;
+ set_fpscr(get_fpscr() & ~mask);
+ return 0;
+}
+
+int feraiseexcept(int mask)
+{
+ mask &= FE_ALL_EXCEPT;
+ if (mask & FE_INVALID) mask |= FE_INVALID_SOFTWARE;
+ set_fpscr(get_fpscr() | mask);
+ return 0;
+}
+
+int fetestexcept(int mask)
+{
+ return get_fpscr() & mask & FE_ALL_EXCEPT;
+}
+
+int fegetround(void)
+{
+ return get_fpscr() & 3;
+}
+
+hidden int __fesetround(int r)
+{
+ set_fpscr(get_fpscr() & ~3L | r);
+ return 0;
+}
+
+int fegetenv(fenv_t *envp)
+{
+ *envp = get_fpscr_f();
+ return 0;
+}
+
+int fesetenv(const fenv_t *envp)
+{
+ set_fpscr_f(envp != FE_DFL_ENV ? *envp : 0);
+ return 0;
+}