src/cpuinfo/SDL_cpuinfo.c
changeset 881 9eb85a211abd
parent 804 b2fda076b02e
child 887 b4b64bb88f2f
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"