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