summaryrefslogtreecommitdiff
path: root/src/fenv/sh/fenv.S
blob: cd47b5bc21eb2db33cc942d60743b32352c42e86 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#if __SH_FPU_ANY__ || __SH4__

.global fegetround
.type   fegetround, @function
fegetround:
	sts fpscr, r0
	rts
	 and #3, r0

.global __fesetround
.type   __fesetround, @function
__fesetround:
	sts fpscr, r0
	or  r4, r0
	lds r0, fpscr
	rts
	 mov #0, r0

.global fetestexcept
.type   fetestexcept, @function
fetestexcept:
	sts fpscr, r0
	and r4, r0
	rts
	 and #0x7c, r0

.global feclearexcept
.type   feclearexcept, @function
feclearexcept:
	mov r4, r0
	and #0x7c, r0
	not r0, r4
	sts fpscr, r0
	and r4, r0
	lds r0, fpscr
	rts
	 mov #0, r0

.global feraiseexcept
.type   feraiseexcept, @function
feraiseexcept:
	mov r4, r0
	and #0x7c, r0
	sts fpscr, r4
	or  r4, r0
	lds r0, fpscr
	rts
	 mov #0, r0

.global fegetenv
.type   fegetenv, @function
fegetenv:
	sts fpscr, r0
	mov.l r0, @r4
	rts
	 mov #0, r0

.global fesetenv
.type   fesetenv, @function
fesetenv:
	mov r4, r0
	cmp/eq #-1, r0
	bf 1f

	! the default environment is complicated by the fact that we need to
	! preserve the current precision bit, which we do not know a priori
	sts fpscr, r0
	mov #8, r1
	swap.w r1, r1
	bra 2f
	 and r1, r0

1:	mov.l @r4, r0      ! non-default environment
2:	lds r0, fpscr
	rts
	 mov #0, r0

#endif