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