(gelöst)[x86] CPU Brand String ASCII oder ANSI?
Verfasst: 09.03.2011, 03:40
Hi,
Ist der CPU Brand String – also das, was CPUID für 0x80000002 bis 0x80000004 zurückgibt – ASCII oder ANSI? Ich finde überall widersprüchliche Angaben :/
Gruß, Ky
Nachtrag: Ich halte mich einfach mal an Intels Spezifikation, und die sagt: ASCII. Wer mal den CPU-Namen herausfinden muss (Achtung, Visual C++-exklusiv):
Ist der CPU Brand String – also das, was CPUID für 0x80000002 bis 0x80000004 zurückgibt – ASCII oder ANSI? Ich finde überall widersprüchliche Angaben :/
Gruß, Ky
Nachtrag: Ich halte mich einfach mal an Intels Spezifikation, und die sagt: ASCII. Wer mal den CPU-Namen herausfinden muss (Achtung, Visual C++-exklusiv):
Code: Alles auswählen
#include <intrin.h> // '__cpuid' intrinsic
typedef int CSignedInteger4Bytes;
typedef unsigned int CUnsignedInteger4Bytes;
typedef char CASCIICharacter;
#include <string>
typedef ::std::string CASCIIString;
//--------------------------------------------------------------------------------------------------------------------------
// Returns the current CPU's brand string (e.g. "Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz").
// If the CPU doesn't support this feature (< Pentium IV), "unknown" is returned.
//--------------------------------------------------------------------------------------------------------------------------
CASCIIString CPUBrand() {
// This function uses the 'CPUID' instruction via intrinsic to retrieve the CPU's built-in brand string.
// For the '__cpuid' intrinsic and an explanation of its parameters, see http://msdn.microsoft.com/library/hskdteyh.
// First, it is determined whether the CPU supports extended CPUID functions by checking if 0x80000000 returns a higher
// value in EAX. If it does, the values 0x80000002 through 0x80000004 can be used to retrieve the brand string[1].
CSignedInteger4Bytes eaxEbxEcxEdx[4];
__cpuid(eaxEbxEcxEdx, 0x80000000);
// consider: '__cpuid' expects signed 4-byte values, but 0x80000000 is unsigned
if(0x80000000u < CUnsignedInteger4Bytes(eaxEbxEcxEdx[0])) {
// The brand string itself is an ASCII string with a maximum length of 47 characters; with 4 characters stored in
// EAX, EBX, ECX and EDX each, for three CPUID calls[2].
union {
CASCIICharacter characters[48];
CSignedInteger4Bytes registers[4 * 3];
} processorBrandString;
__cpuid(processorBrandString.registers , 0x80000002);
__cpuid(processorBrandString.registers + 4, 0x80000003);
__cpuid(processorBrandString.registers + 8, 0x80000004);
return CASCIIString(processorBrandString.characters);
} else
return CASCIIString("unknown");
// [1] "Intel® Processor Identification and the CPUID Instruction", May 2002, Order Number: 241618-021, pg. 21:
// "To determine if the brand string is supported on a processor, software must follow the step below:
// 1. Execute the CPUID instruction with EAX=80000000h
// 2. If ((returned value in EAX) > 80000000h) then the processor supports the extended CPUID functions and EAX
// contains the largest extended function supported.
// 3. The processor brand string feature is supported if EAX > 80000000"
// [2] "Intel® Processor Identification and the CPUID Instruction", May 2002, Order Number: 241618-021, pg. 21:
// "The brand/frequency string is defined to be 48 characters long, 47 bytes will contain characters and the 48th
// byte is defined to be NULL (0). A processor may return less than the 47 ASCII characters as long as the string
// is null terminated and the processor returns valid data when CPUID is executed with EAX = 80000002h, 80000003h
// and 80000004h."
}