The GetCurrentProcessorNumber example shows code that implements this function using the CPUID instruction. I tried this myself and can confirm that it works on Mac OS X.
Here is my version that I used on Mac OS X
uint32_t CPUInfo[4]; \
CPUID(CPUInfo, 1, 0); \
/* CPUInfo[1] is EBX, bits 24-31 are APIC ID */ \
if ( (CPUInfo[3] & (1 << 9)) == 0) { \
CPU = -1; /* no APIC on chip */ \
} \
else { \
CPU = (unsigned)CPUInfo[1] >> 24; \
} \
if (CPU < 0) CPU = 0; \
}
source
share