add sse fenv support on i386 through hwcap
[musl] / src / fenv / x86_64 / fenv.s
1 .global feclearexcept
2 .type feclearexcept,@function
3 feclearexcept:
4         mov %edi,%ecx
5         not %ecx
6         stmxcsr -8(%rsp)
7         and %ecx,-8(%rsp)
8         ldmxcsr -8(%rsp)
9         test $0x3f,%ecx
10         jnz 2f
11 1:      fnclex
12         xor %eax,%eax
13         ret
14 2:      fnstsw %ax
15         and %ecx,%eax
16         jz 1b
17         sub $32,%rsp
18         fnstenv (%rsp)
19         mov %al,4(%rsp)
20         fldenv (%rsp)
21         add $32,%rsp
22         xor %eax,%eax
23         ret
24
25 .global feraiseexcept
26 .type feraiseexcept,@function
27 feraiseexcept:  
28         stmxcsr -8(%rsp)
29         or %edi,-8(%rsp)
30         ldmxcsr -8(%rsp)
31         xor %eax,%eax
32         ret
33
34 .global fesetround
35 .type fesetround,@function
36 fesetround:
37         push %rax
38         xor %eax,%eax
39         mov %edi,%ecx
40         fnstcw (%rsp)
41         andb $0xf3,1(%rsp)
42         or %ch,1(%rsp)
43         fldcw (%rsp)
44         stmxcsr (%rsp)
45         shl $3,%ch
46         andb $0x9f,1(%rsp)
47         or %ch,1(%rsp)
48         ldmxcsr (%rsp)
49         pop %rcx
50         ret
51
52 .global fegetround
53 .type fegetround,@function
54 fegetround:
55         push %rax
56         stmxcsr (%rsp)
57         pop %rax
58         shr $3,%eax
59         and $0xc00,%eax
60         ret
61
62 .global fegetenv
63 .type fegetenv,@function
64 fegetenv:
65         xor %eax,%eax
66         fnstenv (%rdi)
67         stmxcsr 28(%rdi)
68         ret
69
70 .global fesetenv
71 .type fesetenv,@function
72 fesetenv:
73         xor %eax,%eax
74         inc %rdi
75         jz 1f
76         fldenv -1(%rdi)
77         ldmxcsr 27(%rdi)
78         ret
79 1:      push %rax
80         push %rax
81         push %rax
82         pushq $0x37f
83         fldenv (%rsp)
84         pushq $0x1f80
85         ldmxcsr (%rsp)
86         add $40,%rsp
87         ret
88
89 .global fetestexcept
90 .type fetestexcept,@function
91 fetestexcept:
92         push %rax
93         stmxcsr (%rsp)
94         pop %rsi
95         fnstsw %ax
96         or %esi,%eax
97         and %edi,%eax
98         ret