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