root/opal/mca/hwloc/hwloc201/hwloc/include/private/cpuid-x86.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. hwloc_have_x86_cpuid
  2. hwloc_have_x86_cpuid
  3. hwloc_x86_cpuid

   1 /*
   2  * Copyright © 2010-2012, 2014 Université Bordeaux
   3  * Copyright © 2010 Cisco Systems, Inc.  All rights reserved.
   4  * Copyright © 2014 Inria.  All rights reserved.
   5  *
   6  * See COPYING in top-level directory.
   7  */
   8 
   9 /* Internals for x86's cpuid.  */
  10 
  11 #ifndef HWLOC_PRIVATE_CPUID_X86_H
  12 #define HWLOC_PRIVATE_CPUID_X86_H
  13 
  14 #if (defined HWLOC_X86_32_ARCH) && (!defined HWLOC_HAVE_MSVC_CPUIDEX)
  15 static __hwloc_inline int hwloc_have_x86_cpuid(void)
  16 {
  17   int ret;
  18   unsigned tmp, tmp2;
  19   __asm__(
  20       "mov $0,%0\n\t"   /* Not supported a priori */
  21 
  22       "pushfl   \n\t"   /* Save flags */
  23 
  24       "pushfl   \n\t"                                           \
  25       "pop %1   \n\t"   /* Get flags */                         \
  26 
  27 #define TRY_TOGGLE                                              \
  28       "xor $0x00200000,%1\n\t"        /* Try to toggle ID */    \
  29       "mov %1,%2\n\t"   /* Save expected value */               \
  30       "push %1  \n\t"                                           \
  31       "popfl    \n\t"   /* Try to toggle */                     \
  32       "pushfl   \n\t"                                           \
  33       "pop %1   \n\t"                                           \
  34       "cmp %1,%2\n\t"   /* Compare with expected value */       \
  35       "jnz 0f\n\t"   /* Unexpected, failure */               \
  36 
  37       TRY_TOGGLE        /* Try to set/clear */
  38       TRY_TOGGLE        /* Try to clear/set */
  39 
  40       "mov $1,%0\n\t"   /* Passed the test! */
  41 
  42       "0: \n\t"
  43       "popfl    \n\t"   /* Restore flags */
  44 
  45       : "=r" (ret), "=&r" (tmp), "=&r" (tmp2));
  46   return ret;
  47 }
  48 #endif /* !defined HWLOC_X86_32_ARCH && !defined HWLOC_HAVE_MSVC_CPUIDEX*/
  49 #if (defined HWLOC_X86_64_ARCH) || (defined HWLOC_HAVE_MSVC_CPUIDEX)
  50 static __hwloc_inline int hwloc_have_x86_cpuid(void) { return 1; }
  51 #endif /* HWLOC_X86_64_ARCH */
  52 
  53 static __hwloc_inline void hwloc_x86_cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
  54 {
  55 #ifdef HWLOC_HAVE_MSVC_CPUIDEX
  56   int regs[4];
  57   __cpuidex(regs, *eax, *ecx);
  58   *eax = regs[0];
  59   *ebx = regs[1];
  60   *ecx = regs[2];
  61   *edx = regs[3];
  62 #else /* HWLOC_HAVE_MSVC_CPUIDEX */
  63   /* Note: gcc might want to use bx or the stack for %1 addressing, so we can't
  64    * use them :/ */
  65 #ifdef HWLOC_X86_64_ARCH
  66   hwloc_uint64_t sav_rbx;
  67   __asm__(
  68   "mov %%rbx,%2\n\t"
  69   "cpuid\n\t"
  70   "xchg %2,%%rbx\n\t"
  71   "movl %k2,%1\n\t"
  72   : "+a" (*eax), "=m" (*ebx), "=&r"(sav_rbx),
  73     "+c" (*ecx), "=&d" (*edx));
  74 #elif defined(HWLOC_X86_32_ARCH)
  75   __asm__(
  76   "mov %%ebx,%1\n\t"
  77   "cpuid\n\t"
  78   "xchg %%ebx,%1\n\t"
  79   : "+a" (*eax), "=&SD" (*ebx), "+c" (*ecx), "=&d" (*edx));
  80 #else
  81 #error unknown architecture
  82 #endif
  83 #endif /* HWLOC_HAVE_MSVC_CPUIDEX */
  84 }
  85 
  86 #endif /* HWLOC_PRIVATE_X86_CPUID_H */

/* [<][>][^][v][top][bottom][index][help] */