1 .hidden __hwcap
2 
3 .global feclearexcept
4 .type feclearexcept,@function
5 feclearexcept:
6 	mov 4(%esp),%ecx
7 	and $0x3f,%ecx
8 	fnstsw %ax
9 		# consider sse fenv as well if the cpu has XMM capability
10 	call 1f
11 1:	addl $__hwcap-1b,(%esp)
12 	pop %edx
13 	testl $0x02000000,(%edx)
14 	jz 2f
15 		# maintain exceptions in the sse mxcsr, clear x87 exceptions
16 	test %eax,%ecx
17 	jz 1f
18 	fnclex
19 1:	push %edx
20 	stmxcsr (%esp)
21 	pop %edx
22 	and $0x3f,%eax
23 	or %eax,%edx
24 	test %edx,%ecx
25 	jz 1f
26 	not %ecx
27 	and %ecx,%edx
28 	push %edx
29 	ldmxcsr (%esp)
30 	pop %edx
31 1:	xor %eax,%eax
32 	ret
33 		# only do the expensive x87 fenv load/store when needed
34 2:	test %eax,%ecx
35 	jz 1b
36 	not %ecx
37 	and %ecx,%eax
38 	test $0x3f,%eax
39 	jz 1f
40 	fnclex
41 	jmp 1b
42 1:	sub $32,%esp
43 	fnstenv (%esp)
44 	mov %al,4(%esp)
45 	fldenv (%esp)
46 	add $32,%esp
47 	xor %eax,%eax
48 	ret
49 
50 .global feraiseexcept
51 .type feraiseexcept,@function
52 feraiseexcept:
53 	mov 4(%esp),%eax
54 	and $0x3f,%eax
55 	sub $32,%esp
56 	fnstenv (%esp)
57 	or %al,4(%esp)
58 	fldenv (%esp)
59 	add $32,%esp
60 	xor %eax,%eax
61 	ret
62 
63 .global __fesetround
64 .hidden __fesetround
65 .type __fesetround,@function
66 __fesetround:
67 	mov 4(%esp),%ecx
68 	push %eax
69 	xor %eax,%eax
70 	fnstcw (%esp)
71 	andb $0xf3,1(%esp)
72 	or %ch,1(%esp)
73 	fldcw (%esp)
74 		# consider sse fenv as well if the cpu has XMM capability
75 	call 1f
76 1:	addl $__hwcap-1b,(%esp)
77 	pop %edx
78 	testl $0x02000000,(%edx)
79 	jz 1f
80 	stmxcsr (%esp)
81 	shl $3,%ch
82 	andb $0x9f,1(%esp)
83 	or %ch,1(%esp)
84 	ldmxcsr (%esp)
85 1:	pop %ecx
86 	ret
87 
88 .global fegetround
89 .type fegetround,@function
90 fegetround:
91 	push %eax
92 	fnstcw (%esp)
93 	pop %eax
94 	and $0xc00,%eax
95 	ret
96 
97 .global fegetenv
98 .type fegetenv,@function
99 fegetenv:
100 	mov 4(%esp),%ecx
101 	xor %eax,%eax
102 	fnstenv (%ecx)
103 		# consider sse fenv as well if the cpu has XMM capability
104 	call 1f
105 1:	addl $__hwcap-1b,(%esp)
106 	pop %edx
107 	testl $0x02000000,(%edx)
108 	jz 1f
109 	push %eax
110 	stmxcsr (%esp)
111 	pop %edx
112 	and $0x3f,%edx
113 	or %edx,4(%ecx)
114 1:	ret
115 
116 .global fesetenv
117 .type fesetenv,@function
118 fesetenv:
119 	mov 4(%esp),%ecx
120 	xor %eax,%eax
121 	inc %ecx
122 	jz 1f
123 	fldenv -1(%ecx)
124 	movl -1(%ecx),%ecx
125 	jmp 2f
126 1:	push %eax
127 	push %eax
128 	push %eax
129 	push %eax
130 	pushl $0xffff
131 	push %eax
132 	pushl $0x37f
133 	fldenv (%esp)
134 	add $28,%esp
135 		# consider sse fenv as well if the cpu has XMM capability
136 2:	call 1f
137 1:	addl $__hwcap-1b,(%esp)
138 	pop %edx
139 	testl $0x02000000,(%edx)
140 	jz 1f
141 		# mxcsr := same rounding mode, cleared exceptions, default mask
142 	and $0xc00,%ecx
143 	shl $3,%ecx
144 	or $0x1f80,%ecx
145 	mov %ecx,4(%esp)
146 	ldmxcsr 4(%esp)
147 1:	ret
148 
149 .global fetestexcept
150 .type fetestexcept,@function
151 fetestexcept:
152 	mov 4(%esp),%ecx
153 	and $0x3f,%ecx
154 	fnstsw %ax
155 		# consider sse fenv as well if the cpu has XMM capability
156 	call 1f
157 1:	addl $__hwcap-1b,(%esp)
158 	pop %edx
159 	testl $0x02000000,(%edx)
160 	jz 1f
161 	stmxcsr 4(%esp)
162 	or 4(%esp),%eax
163 1:	and %ecx,%eax
164 	ret
165