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