about summary refs log tree commit diff
path: root/src/fenv/s390x/fenv.c
blob: 9a3488d7e3185dc775f90ad5077f7b5e8df3023a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <fenv.h>

static inline unsigned get_fpc(void)
{
	unsigned fpc;
	__asm__ __volatile__("efpc %0" : "=r"(fpc));
	return fpc;
}

static inline void set_fpc(unsigned fpc)
{
	__asm__ __volatile__("sfpc %0" :: "r"(fpc));
}

int feclearexcept(int mask)
{
	mask &= FE_ALL_EXCEPT;
	set_fpc(get_fpc() & ~mask);
	return 0;
}

int feraiseexcept(int mask)
{
	mask &= FE_ALL_EXCEPT;
	set_fpc(get_fpc() | mask);
	return 0;
}

int fetestexcept(int mask)
{
	return get_fpc() & mask & FE_ALL_EXCEPT;
}

int fegetround(void)
{
	return get_fpc() & 3;
}

int __fesetround(int r)
{
	set_fpc(get_fpc() & ~3L | r);
	return 0;
}

int fegetenv(fenv_t *envp)
{
	*envp = get_fpc();
	return 0;
}

int fesetenv(const fenv_t *envp)
{
	set_fpc(envp != FE_DFL_ENV ? *envp : 0);
	return 0;
}