fenv.s 1.4 KB
Newer Older
R
rofl0r 已提交
1 2 3 4 5 6 7 8 9 10
.global feclearexcept
.type feclearexcept,@function
feclearexcept:
		# maintain exceptions in the sse mxcsr, clear x87 exceptions
	mov %edi,%ecx
	and $0x3f,%ecx
	fnstsw %ax
	test %eax,%ecx
	jz 1f
	fnclex
R
rofl0r 已提交
11
1:	stmxcsr -8(%esp)
R
rofl0r 已提交
12
	and $0x3f,%eax
R
rofl0r 已提交
13 14
	or %eax,-8(%esp)
	test %ecx,-8(%esp)
R
rofl0r 已提交
15 16
	jz 1f
	not %ecx
R
rofl0r 已提交
17 18
	and %ecx,-8(%esp)
	ldmxcsr -8(%esp)
R
rofl0r 已提交
19 20 21 22 23 24 25
1:	xor %eax,%eax
	ret

.global feraiseexcept
.type feraiseexcept,@function
feraiseexcept:
	and $0x3f,%edi
R
rofl0r 已提交
26 27 28
	stmxcsr -8(%esp)
	or %edi,-8(%esp)
	ldmxcsr -8(%esp)
R
rofl0r 已提交
29 30 31 32 33 34 35 36 37
	xor %eax,%eax
	ret

.global __fesetround
.type __fesetround,@function
__fesetround:
	push %rax
	xor %eax,%eax
	mov %edi,%ecx
R
rofl0r 已提交
38 39 40 41 42
	fnstcw (%esp)
	andb $0xf3,1(%esp)
	or %ch,1(%esp)
	fldcw (%esp)
	stmxcsr (%esp)
R
rofl0r 已提交
43
	shl $3,%ch
R
rofl0r 已提交
44 45 46
	andb $0x9f,1(%esp)
	or %ch,1(%esp)
	ldmxcsr (%esp)
R
rofl0r 已提交
47 48 49 50 51 52 53
	pop %rcx
	ret

.global fegetround
.type fegetround,@function
fegetround:
	push %rax
R
rofl0r 已提交
54
	stmxcsr (%esp)
R
rofl0r 已提交
55 56 57 58 59 60 61 62 63
	pop %rax
	shr $3,%eax
	and $0xc00,%eax
	ret

.global fegetenv
.type fegetenv,@function
fegetenv:
	xor %eax,%eax
R
rofl0r 已提交
64 65
	fnstenv (%edi)
	stmxcsr 28(%edi)
R
rofl0r 已提交
66 67 68 69 70 71
	ret

.global fesetenv
.type fesetenv,@function
fesetenv:
	xor %eax,%eax
R
rofl0r 已提交
72
	inc %edi
R
rofl0r 已提交
73
	jz 1f
R
rofl0r 已提交
74 75
	fldenv -1(%edi)
	ldmxcsr 27(%edi)
R
rofl0r 已提交
76 77 78 79 80
	ret
1:	push %rax
	push %rax
	pushq $0xffff
	pushq $0x37f
R
rofl0r 已提交
81
	fldenv (%esp)
R
rofl0r 已提交
82
	pushq $0x1f80
R
rofl0r 已提交
83 84
	ldmxcsr (%esp)
	add $40,%esp
R
rofl0r 已提交
85 86 87 88 89 90 91
	ret

.global fetestexcept
.type fetestexcept,@function
fetestexcept:
	and $0x3f,%edi
	push %rax
R
rofl0r 已提交
92
	stmxcsr (%esp)
R
rofl0r 已提交
93 94 95 96 97
	pop %rsi
	fnstsw %ax
	or %esi,%eax
	and %edi,%eax
	ret