Debian Codegraph @

libmp3lame/i386/cpu_feat.nas

raw
1 ;
2 ;
3 ; assembler routines to detect CPU-features
4 ;
5 ; MMX / 3DNow! / SSE / SSE2
6 ;
7 ; for the LAME project
8 ; Frank Klemm, Robert Hegemann 2000-10-12
9 ;
10
11 %include "nasm.h"
12
13 globaldef has_MMX_nasm
14 globaldef has_3DNow_nasm
15 globaldef has_SSE_nasm
16 globaldef has_SSE2_nasm
17
18 segment_code
19
20 testCPUID:
21 pushfd
22 pop eax
23 mov ecx,eax
24 xor eax,0x200000
25 push eax
26 popfd
27 pushfd
28 pop eax
29 cmp eax,ecx
30 ret
31
32 ;---------------------------------------
33 ; int has_MMX_nasm (void)
34 ;---------------------------------------
35
36 has_MMX_nasm:
37 pushad
38 call testCPUID
39 jz return0 ; no CPUID command, so no MMX
40
41 mov eax,0x1
42 CPUID
43 test edx,0x800000
44 jz return0 ; no MMX support
45 jmp return1 ; MMX support
46
47 ;---------------------------------------
48 ; int has_SSE_nasm (void)
49 ;---------------------------------------
50
51 has_SSE_nasm:
52 pushad
53 call testCPUID
54 jz return0 ; no CPUID command, so no SSE
55
56 mov eax,0x1
57 CPUID
58 test edx,0x02000000
59 jz return0 ; no SSE support
60 jmp return1 ; SSE support
61
62 ;---------------------------------------
63 ; int has_SSE2_nasm (void)
64 ;---------------------------------------
65
66 has_SSE2_nasm:
67 pushad
68 call testCPUID
69 jz return0 ; no CPUID command, so no SSE2
70
71 mov eax,0x1
72 CPUID
73 test edx,0x04000000
74 jz return0 ; no SSE2 support
75 jmp return1 ; SSE2 support
76
77 ;---------------------------------------
78 ; int has_3DNow_nasm (void)
79 ;---------------------------------------
80
81 has_3DNow_nasm:
82 pushad
83 call testCPUID
84 jz return0 ; no CPUID command, so no 3DNow!
85
86 mov eax,0x80000000
87 CPUID
88 cmp eax,0x80000000
89 jbe return0 ; no extended MSR(1), so no 3DNow!
90
91 mov eax,0x80000001
92 CPUID
93 test edx,0x80000000
94 jz return0 ; no 3DNow! support
95 ; 3DNow! support
96 return1:
97 popad
98 xor eax,eax
99 inc eax
100 ret
101
102 return0:
103 popad
104 xor eax,eax
105 ret
106
107 end