try fixing/optimizing x86_64 fenv exception code
[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         fnstenv -32(%rsp)
32         or %edi,-28(%rsp)
33         fldenv -32(%rsp)
34         xor %eax,%eax
35         ret
36
37 .global fesetround
38 .type fesetround,@function
39 fesetround:
40         push %rax
41         xor %eax,%eax
42         mov %edi,%ecx
43         fnstcw (%rsp)
44         andb $0xf3,1(%rsp)
45         or %ch,1(%rsp)
46         fldcw (%rsp)
47         stmxcsr (%rsp)
48         shl $3,%ch
49         andb $0x9f,1(%rsp)
50         or %ch,1(%rsp)
51         ldmxcsr (%rsp)
52         pop %rcx
53         ret
54
55 .global fegetround
56 .type fegetround,@function
57 fegetround:
58         push %rax
59         stmxcsr (%rsp)
60         pop %rax
61         shr $3,%eax
62         and $0xc00,%eax
63         ret
64
65 .global fegetenv
66 .type fegetenv,@function
67 fegetenv:
68         xor %eax,%eax
69         fnstenv (%rdi)
70         stmxcsr 28(%rdi)
71         ret
72
73 .global fesetenv
74 .type fesetenv,@function
75 fesetenv:
76         xor %eax,%eax
77         inc %rdi
78         jz 1f
79         fldenv -1(%rdi)
80         ldmxcsr 27(%rdi)
81         ret
82 1:      push %rax
83         push %rax
84         push %rax
85         pushq $0x37f
86         fldenv (%rsp)
87         pushq $0x1f80
88         ldmxcsr (%rsp)
89         add $40,%rsp
90         ret
91
92 .global fetestexcept
93 .type fetestexcept,@function
94 fetestexcept:
95         push %rax
96         stmxcsr (%rsp)
97         pop %rsi
98         fnstsw %ax
99         or %esi,%eax
100         and %edi,%eax
101         ret