add s390x port
[musl] / src / fenv / s390x / fenv.c
1 #include <fenv.h>
2
3 static inline unsigned get_fpc(void)
4 {
5         unsigned fpc;
6         __asm__ __volatile__("efpc %0" : "=r"(fpc));
7         return fpc;
8 }
9
10 static inline void set_fpc(unsigned fpc)
11 {
12         __asm__ __volatile__("sfpc %0" :: "r"(fpc));
13 }
14
15 int feclearexcept(int mask)
16 {
17         mask &= FE_ALL_EXCEPT;
18         set_fpc(get_fpc() & ~mask);
19         return 0;
20 }
21
22 int feraiseexcept(int mask)
23 {
24         mask &= FE_ALL_EXCEPT;
25         set_fpc(get_fpc() | mask);
26         return 0;
27 }
28
29 int fetestexcept(int mask)
30 {
31         return get_fpc() & mask & FE_ALL_EXCEPT;
32 }
33
34 int fegetround(void)
35 {
36         return get_fpc() & 3;
37 }
38
39 int __fesetround(int r)
40 {
41         set_fpc(get_fpc() & ~3L | r);
42         return 0;
43 }
44
45 int fegetenv(fenv_t *envp)
46 {
47         *envp = get_fpc();
48         return 0;
49 }
50
51 int fesetenv(const fenv_t *envp)
52 {
53         set_fpc(envp != FE_DFL_ENV ? *envp : 0);
54         return 0;
55 }