forked from Chuyu-Team/VC-LTL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftol2_downlevel.cpp
More file actions
130 lines (108 loc) · 2.1 KB
/
Copy pathftol2_downlevel.cpp
File metadata and controls
130 lines (108 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#if defined _ATL_XP_TARGETING && defined _M_IX86
extern "C" extern int __isa_available;
extern "C" __declspec(naked) int __cdecl _ftol2(double x)
{
__asm
{
push ebp
mov ebp, esp
sub esp, 20h
and esp, 0FFFFFFF0h
fld st
fst dword ptr[esp + 18h]
fistp qword ptr[esp + 10h]
fild qword ptr[esp + 10h]
mov edx, [esp + 18h]
mov eax, [esp + 10h]
test eax, eax
jz short integer_QnaN_or_zero
arg_is_not_integer_QnaN :
fsubp st(1), st
test edx, edx
jns short positive
fstp dword ptr[esp]
mov ecx, [esp]
xor ecx, 80000000h
add ecx, 7FFFFFFFh
adc eax, 0
mov edx, [esp + 14h]
adc edx, 0
jmp short localexit
positive :
fstp dword ptr[esp]
mov ecx, [esp]
add ecx, 7FFFFFFFh
sbb eax, 0
mov edx, [esp + 14h]
sbb edx, 0
jmp short localexit
integer_QnaN_or_zero :
mov edx, [esp + 14h]
test edx, 7FFFFFFFh
jnz short arg_is_not_integer_QnaN
fstp dword ptr[esp + 18h]
fstp dword ptr[esp + 18h]
localexit :
leave
retn
}
}
extern "C" __declspec(naked) int __cdecl _ftol2_pentium4(double x)
{
__asm
{
push ebp
mov ebp, esp
sub esp, 8
and esp, 0FFFFFFF8h
fstp qword ptr[esp]
cvttsd2si eax, qword ptr[esp]
leave
retn
}
}
extern "C" __declspec(naked) int __cdecl _ftol2_sse(double x)
{
/*if (__isa_available == 0)
{
return _ftol2_downlevel(x);
}
else
{
return _ftol2_pentium4_downlevel(x);
}*/
//使用内联汇编提高性能
__asm
{
cmp __isa_available, 0
jz short _ftol2
jmp _ftol2_pentium4
}
}
extern "C" __declspec(naked) int __cdecl _ftol2_sse_excpt(double x)
{
/*if (__isa_available)
{
short currentState;
__asm { fstcw currentState }
if ((currentState & 0x7F) == 0x7F)
{
return _ftol2_pentium4_downlevel(x);
}
}
return _ftol2_downlevel(x);*/
//使用内联汇编提高性能
__asm
{
cmp __isa_available, 0
jz _ftol2
sub esp, 4
fnstcw[esp]
pop eax
and ax, 7Fh
cmp ax, 7Fh
jz _ftol2_pentium4
jmp _ftol2
}
}
#endif