comparison src/cpuinfo/SDL_cpuinfo.c @ 881:9eb85a211abd

Date: Tue, 30 Mar 2004 18:18:13 -0600 From: Tyler Montbriand Subject: [SDL] Detecting Opteron CPU features I can now get SDL_cpuinfo.c to detect the AMD Opteron's RDTSC, MMX, MMXEXT, 3DNOW, 3DNOWEXT, SSE, and SSE2 instruction set extensions under Linux. It took one #ifdef'ed block of new asm code to account for the 64-bit flags register, but the other two blocks worked fine without modification, just needed to modify the #ifdef's a bit.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 11 Apr 2004 19:49:34 +0000
parents b2fda076b02e
children b4b64bb88f2f
comparison
equal deleted inserted replaced
880:9ef41050100c 881:9eb85a211abd
79 "1: \n" 79 "1: \n"
80 : "=m" (has_CPUID) 80 : "=m" (has_CPUID)
81 : 81 :
82 : "%eax", "%ecx" 82 : "%eax", "%ecx"
83 ); 83 );
84 #elif defined(__GNUC__) && defined(__x86_64__)
85 /* Technically, if this is being compiled under __x86_64__ then it has
86 CPUid by definition. But it's nice to be able to prove it. :) */
87 __asm__ (
88 " pushfq # Get original EFLAGS \n"
89 " popq %%rax \n"
90 " movq %%rax,%%rcx \n"
91 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
92 " pushq %%rax # Save new EFLAGS value on stack \n"
93 " popfq # Replace current EFLAGS value \n"
94 " pushfq # Get new EFLAGS \n"
95 " popq %%rax # Store new EFLAGS in EAX \n"
96 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
97 " jz 1f # Processor=80486 \n"
98 " movl $1,%0 # We have CPUID support \n"
99 "1: \n"
100 : "=m" (has_CPUID)
101 :
102 : "%rax", "%rcx"
103 );
84 #elif defined(_MSC_VER) 104 #elif defined(_MSC_VER)
85 __asm { 105 __asm {
86 pushfd ; Get original EFLAGS 106 pushfd ; Get original EFLAGS
87 pop eax 107 pop eax
88 mov ecx, eax 108 mov ecx, eax
101 } 121 }
102 122
103 static __inline__ int CPU_getCPUIDFeatures() 123 static __inline__ int CPU_getCPUIDFeatures()
104 { 124 {
105 int features = 0; 125 int features = 0;
106 #if defined(__GNUC__) && defined(i386) 126 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
107 __asm__ ( 127 __asm__ (
108 " movl %%ebx,%%edi\n" 128 " movl %%ebx,%%edi\n"
109 " xorl %%eax,%%eax # Set up for CPUID instruction \n" 129 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
110 " cpuid # Get and save vendor ID \n" 130 " cpuid # Get and save vendor ID \n"
111 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 131 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
137 } 157 }
138 158
139 static __inline__ int CPU_getCPUIDFeaturesExt() 159 static __inline__ int CPU_getCPUIDFeaturesExt()
140 { 160 {
141 int features = 0; 161 int features = 0;
142 #if defined(__GNUC__) && defined(i386) 162 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
143 __asm__ ( 163 __asm__ (
144 " movl %%ebx,%%edi\n" 164 " movl %%ebx,%%edi\n"
145 " movl $0x80000000,%%eax # Query for extended functions \n" 165 " movl $0x80000000,%%eax # Query for extended functions \n"
146 " cpuid # Get extended function limit \n" 166 " cpuid # Get extended function limit \n"
147 " cmpl $0x80000001,%%eax \n" 167 " cmpl $0x80000001,%%eax \n"