fix return value of ungetc when argument is outside unsigned char range
[musl.git] / src / fenv / m68k / fenv.c
blobd0658e6784777e3aee5bb10c5f40ff18aaba926f
1 #include <fenv.h>
2 #include <features.h>
4 #if __HAVE_68881__ || __mcffpu__
6 static unsigned getsr()
8 unsigned v;
9 __asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v));
10 return v;
13 static void setsr(unsigned v)
15 __asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v));
18 static unsigned getcr()
20 unsigned v;
21 __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v));
22 return v;
25 static void setcr(unsigned v)
27 __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v));
30 int feclearexcept(int mask)
32 if (mask & ~FE_ALL_EXCEPT) return -1;
33 setsr(getsr() & ~mask);
34 return 0;
37 int feraiseexcept(int mask)
39 if (mask & ~FE_ALL_EXCEPT) return -1;
40 setsr(getsr() | mask);
41 return 0;
44 int fetestexcept(int mask)
46 return getsr() & mask;
49 int fegetround(void)
51 return getcr() & FE_UPWARD;
54 hidden int __fesetround(int r)
56 setcr((getcr() & ~FE_UPWARD) | r);
57 return 0;
60 int fegetenv(fenv_t *envp)
62 envp->__control_register = getcr();
63 envp->__status_register = getsr();
64 __asm__ __volatile__ ("fmove.l %%fpiar,%0"
65 : "=dm"(envp->__instruction_address));
66 return 0;
69 int fesetenv(const fenv_t *envp)
71 static const fenv_t default_env = { 0 };
72 if (envp == FE_DFL_ENV)
73 envp = &default_env;
74 setcr(envp->__control_register);
75 setsr(envp->__status_register);
76 __asm__ __volatile__ ("fmove.l %0,%%fpiar"
77 : : "dm"(envp->__instruction_address));
78 return 0;
81 #else
83 #include "../fenv.c"
85 #endif