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
|
;
;
; assembler routines to detect CPU-features
;
; MMX / 3DNow! / SSE / SSE2
;
; for the LAME project
; Frank Klemm, Robert Hegemann 2000-10-12
;
%include "nasm.h"
globaldef has_MMX_nasm
globaldef has_3DNow_nasm
globaldef has_SSE_nasm
globaldef has_SSE2_nasm
segment_code
testCPUID:
pushfd
pop eax
mov ecx,eax
xor eax,0x200000
push eax
popfd
pushfd
pop eax
cmp eax,ecx
ret
;---------------------------------------
; int has_MMX_nasm (void)
;---------------------------------------
has_MMX_nasm:
pushad
call testCPUID
jz return0 ; no CPUID command, so no MMX
mov eax,0x1
CPUID
test edx,0x800000
jz return0 ; no MMX support
jmp return1 ; MMX support
;---------------------------------------
; int has_SSE_nasm (void)
;---------------------------------------
has_SSE_nasm:
pushad
call testCPUID
jz return0 ; no CPUID command, so no SSE
mov eax,0x1
CPUID
test edx,0x02000000
jz return0 ; no SSE support
jmp return1 ; SSE support
;---------------------------------------
; int has_SSE2_nasm (void)
;---------------------------------------
has_SSE2_nasm:
pushad
call testCPUID
jz return0 ; no CPUID command, so no SSE2
mov eax,0x1
CPUID
test edx,0x04000000
jz return0 ; no SSE2 support
jmp return1 ; SSE2 support
;---------------------------------------
; int has_3DNow_nasm (void)
;---------------------------------------
has_3DNow_nasm:
pushad
call testCPUID
jz return0 ; no CPUID command, so no 3DNow!
mov eax,0x80000000
CPUID
cmp eax,0x80000000
jbe return0 ; no extended MSR(1), so no 3DNow!
mov eax,0x80000001
CPUID
test edx,0x80000000
jz return0 ; no 3DNow! support
; 3DNow! support
return1:
popad
xor eax,eax
inc eax
ret
return0:
popad
xor eax,eax
ret
end
|