Note from jkriegshauser: This code sample does not work as expected
on Multi-core processors (i.e. Core2 Duo/Quad, etc). The reason is
because the newer multi-core processors define the HTT flag as
"hardware multithreading" and the logical processor count will include
the cores even though Core2 Duo processors do not have HTT. See the
following Intel publications:
Intel Processor Identification and the CPUID Instruction: http://www.intel.com/assets/pdf/appnote/241618.pdf
Intel 64 and IA-32 Architectures Software Developer's Manual Vol 3A
(section 7.10.2):
http://www.intel.com/design/processor/manuals/253668.pdf
The following code returns non-zero when Hyper-Threading is enabled.
__inline BOOL hyperThreadingOn()
{
DWORD rEbx, rEdx;
__asm {
push eax // save registers used
push ebx
push ecx
push edx
xor eax,eax // cpuid(1)
add al, 0x01
_emit 0x0F
_emit 0xA2
mov rEdx, edx // Features Flags, bit 28 indicates if HTT (Hyper-Thread Technology) is
// available, but not if it is on; if on, Count of logical processors > 1.
mov rEbx, ebx // Bits 23-16: Count of logical processors.
// Valid only if Hyper-Threading Technology flag is set.
pop edx // restore registers used
pop ecx
pop ebx
pop eax
}
return (rEdx & (1<<28)) && (((rEbx & 0x00FF0000) >> 16) > 1);
}