summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/fenv/m68k
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/m68k
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/m68k')
-rw-r--r--libc-top-half/musl/src/fenv/m68k/fenv.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/fenv/m68k/fenv.c b/libc-top-half/musl/src/fenv/m68k/fenv.c
new file mode 100644
index 0000000..d0658e6
--- /dev/null
+++ b/libc-top-half/musl/src/fenv/m68k/fenv.c
@@ -0,0 +1,85 @@
+#include <fenv.h>
+#include <features.h>
+
+#if __HAVE_68881__ || __mcffpu__
+
+static unsigned getsr()
+{
+ unsigned v;
+ __asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v));
+ return v;
+}
+
+static void setsr(unsigned v)
+{
+ __asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v));
+}
+
+static unsigned getcr()
+{
+ unsigned v;
+ __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v));
+ return v;
+}
+
+static void setcr(unsigned v)
+{
+ __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v));
+}
+
+int feclearexcept(int mask)
+{
+ if (mask & ~FE_ALL_EXCEPT) return -1;
+ setsr(getsr() & ~mask);
+ return 0;
+}
+
+int feraiseexcept(int mask)
+{
+ if (mask & ~FE_ALL_EXCEPT) return -1;
+ setsr(getsr() | mask);
+ return 0;
+}
+
+int fetestexcept(int mask)
+{
+ return getsr() & mask;
+}
+
+int fegetround(void)
+{
+ return getcr() & FE_UPWARD;
+}
+
+hidden int __fesetround(int r)
+{
+ setcr((getcr() & ~FE_UPWARD) | r);
+ return 0;
+}
+
+int fegetenv(fenv_t *envp)
+{
+ envp->__control_register = getcr();
+ envp->__status_register = getsr();
+ __asm__ __volatile__ ("fmove.l %%fpiar,%0"
+ : "=dm"(envp->__instruction_address));
+ return 0;
+}
+
+int fesetenv(const fenv_t *envp)
+{
+ static const fenv_t default_env = { 0 };
+ if (envp == FE_DFL_ENV)
+ envp = &default_env;
+ setcr(envp->__control_register);
+ setsr(envp->__status_register);
+ __asm__ __volatile__ ("fmove.l %0,%%fpiar"
+ : : "dm"(envp->__instruction_address));
+ return 0;
+}
+
+#else
+
+#include "../fenv.c"
+
+#endif