Changeset 395 for trunk


Ignore:
Timestamp:
May 10, 2010, 7:15:51 AM (9 years ago)
Author:
cameron
Message:

Add compile-time detection of x86 and x86-64 compilation targets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/x86_CPU_detect.h

    r394 r395  
    66This file defines the following functions which perform
    77runtime tests to see if particular SIMD or other acceleration
    8 features are supported.   The functions return 0 if
    9 a feature is not supported, a nonzero value, otherwise.
     8features are supported on x86 and x86-64 architectures.
     9The functions return 0 if a feature is not supported, a nonzero value,
     10otherwise.
    1011
    1112CPU_has_MMX()
     
    2829#define X86_CPU_DETECT_H
    2930
     31/*  These routines are for the Intel/AMD x86 (32-bit) and x86-64 (64-bit)
     32    architectures.  Ensure that we are compiling for one of these
     33    architectures.  Define common macros x86_32 and x86_64 based on
     34    known compiler-specific macros for these architectures.
     35    See http://predef.sourceforge.net/prearch.html
     36*/
     37
     38#if defined(__x86_64__) || defined(_M_X86_64)
     39#define x86_64 1
     40#elif (defined(__i386__) || defined(_M_IX86) || defined(__i386) || defined(__THW_INTEL__)
     41#define x86_32 1
     42#endif
     43
     44#if defined(x86_32) || defined(x86_64)
     45
    3046enum CPUid_reg {
    3147  reg_eax = 0,
     
    3450  reg_edx = 3
    3551};
     52
     53#ifdef _MSC_VER
     54#include <intrin.h>
     55static inline int check_CPUid1_feature(CPUid_reg reg, int CPUid_bit) {
     56  int CPUinfo[4];
     57  __cpuid(CPUinfo, 1);
     58  return CPUInfo[reg] & CPUid_bit;
     59}
     60#endif
     61
     62#ifdef __GNUC__
     63#include <cpuid.h>
     64static inline int check_CPUid1_feature(CPUid_reg reg, int CPUid_bit) {
     65  int CPUinfo[4];
     66  if __get_cpuid(1, &CPUinfo[reg_eax], &CPUinfo[reg_ebx], &CPUinfo[reg_ecx], &CPUinfo[reg_edx]) {
     67    return CPUInfo[reg] & CPUid_bit;
     68  else return 0;
     69}
     70#endif
    3671
    3772
     
    6398#define POPCOUNT_CPUid_feature_bit (1 << 23)
    6499
    65 
    66 #ifdef _MSC_VER
    67 #include <intrin.h>
    68 static inline int check_CPUid1_feature(CPUid_reg reg, int CPUid_bit) {
    69   int CPUinfo[4];
    70   __cpuid(CPUinfo, 1);
    71   return CPUInfo[reg] & CPUid_bit;
    72 }
    73 #ifdef _M_X64
    74 #define x86_64 1
    75 #endif
    76 #endif
    77 
    78 #ifdef __GNUC__
    79 #include <cpuid.h>
    80 static inline int check_CPUid1_feature(CPUid_reg reg, int CPUid_bit) {
    81   int CPUinfo[4];
    82   if __get_cpuid(1, &CPUinfo[reg_eax], &CPUinfo[reg_ebx], &CPUinfo[reg_ecx], &CPUinfo[reg_edx]) {
    83     return CPUInfo[reg] & CPUid_bit;
    84   else return 0;
    85 }
    86 #ifdef __x86_64__
    87 #define x86_64 1
    88 #endif
    89 #endif
    90100
    91101static inline int CPU_has_MMX() {
     
    136146
    137147#endif
    138 
     148#endif
Note: See TracChangeset for help on using the changeset viewer.