Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Identify Pentium 4 Processor is supporting HT

yaumeileng
Beginner
505 Views
Hi,

I have come accross on the training material online regarding on how to determine is the processor is supporting on HT. I have copied the sample code given and run it on RedHat 9.0 on a Pentium 4 PC. here is the sample code;

===================================================
#define HT_BIT 0x10000000 // EDX[28] - Bit 28 set indicates
// Hyper-Threading Technology is supported
// in hardware.
#define FAMILY_ID 0x0f00 // EAX[11:8] - Bit 11 thru 8 contains family
// processor id
#define EXT_FAMILY_ID 0x0f00000 // EAX[23:20] - Bit 23 thru 20 contains
// extended family processor id
#define PENTIUM4_ID 0x0f00 // Pentium 4 family processor id
// Returns non-zero if Hyper-Threading Technology is supported on
// the processors and zero if not. This does not mean that
// Hyper-Threading Technology is necessarily enabled.


unsigned int HTSupported(void)
{
unsigned int reg_eax = 0;
unsigned int reg_edx = 0;
unsigned int vendor_id[3] = {0, 0, 0};
__try { // verify cpuid instruction is supported
__asm {
xor eax, eax // call cpuid with eax = 0
cpuid // get vendor id string
mov vendor_id, ebx
mov vendor_id + 4, edx
mov vendor_id + 8, ecx
mov eax, 1 // call cpuid with eax = 1
cpuid
mov reg_eax, eax // eax contains cpu family type info
mov reg_edx, edx // edx has info whether Hyper-Threading
// Technology is available
}
}
__except (EXCEPTION_EXECUTE_HANDLER ) {
return 0; // CPUID is not supported and so Hyper-Threading Technology
// is not supported
}

// Check to see if this is a Pentium 4 or later processor
if (((reg_eax & FAMILY_ID) == PENTIUM4_ID) || (reg_eax & EXT_FAMILY_ID))
if (vendor_id[0] == 'uneG')
if (vendor_id[1] == 'Ieni')
if (vendor_id[2] == 'letn')
return (reg_edx & HT_BIT); // Genuine Intel Processor with
// Hyper-Threading Technology
return 0; // This is not a genuine Intel processor.
}
===================================================

but some how when i compile the source code using gcc, here are the following errors return:

***********************************************
[root@intel-1 HT_test]# gcc Ht.c
Ht.c: In function `HTSupported':
Ht.c:20: `__try' undeclared (first use in this function)
Ht.c:20: (Each undeclared identifier is reported only once
Ht.c:20: for each function it appears in.)
Ht.c:20: parse error before '{' token
Ht.c:41:27: warning: multi-character character constant
Ht.c:42:29: warning: multi-character character constant
Ht.c:43:31: warning: multi-character character constant
***********************************************

Why is such happening? I tried to include but somehow this library isn't available.

Is gcc no more supporting on Win32 API? if so, how can I change the above sample code to accomodate on RedHat 9.0 platform?

Please guide!

-yau-
0 Kudos
4 Replies
ClayB
New Contributor I
505 Views
Yau -
There seems to be several things that are missing from the code example that you posted. Could you attach the source file or give a pointer to the source of the code? Have you been able to compile the code on a Windows system or a different version of Linux?
My first guess is that this was meant to be compiled with the Intel compiler. I've never used inline assembly code, so I'm not sure if gcc supports that feature (I expect it does, so there might be some other problem).
--clay
0 Kudos
Henry_G_Intel
Employee
505 Views
Hello Yau,
I can compile the example codeon Win32 using the Intel C++ compiler. I have to include excpt.h to avoid undefined references. The compile command is simply: icl ht_id.cpp -c.
Icannot compile the example code on Linux, however.
Best regards,
Henry

Message Edited by hagabb on 03-22-2005 01:21 PM

0 Kudos
yaumeileng
Beginner
505 Views
hi,

I have attached the sample source code. Well I did include the header excpt.h but somehow is not working on Linux platform.

Is there a way that i do not need the Intel Compiler C++ to compile on Linux?

I need to write a code on detecting the HT support in my project which is running on Linux.

Please help!

Thank you

-yau-
0 Kudos
TimP
Honored Contributor III
505 Views
On linux, you need something closer to C++. The code you show is specific to Microsoft compilers, which don't exist on linux. Cygwin has headers which implement Microsoft __try and __except, so you could attempt it by copying in those headers. You would still have to deal with the __asm syntax, which differs from the default syntax for IA 32-bit linux. Why don't you use something saner like strncmp() for your string comparison?

g++ and Intel icc for linux are close enough in the extensions they handle that it should not make much difference which one you use.
0 Kudos
Reply