__cpuid Rückgabe Interpretieren



  • Hi

    Ich versuche gerade per c++ Herauszufinden ob eine CPU VT-x oder AMD-V unterstüzt. Dabei bin ich über __cpuid gestolpert.

    Laut MSDN relativ einfach zu verwenden:
    http://msdn.microsoft.com/en-us/library/hskdteyh(VS.80).aspx

    Doch mit der Interpretation der Rückgabewerte komme ich leider nicht klar.

    #include <iostream>
    #include <windows.h>
    #include <direct.h>
    #include <string>
    #include <io.h>
    
    // cpu info
    #include <intrin.h>
    
    int main (int argc, char *argv[])
    {
    	int cpuinfo[4];
    	__cpuid (cpuinfo, 0);
    
    	printf ("Info0: %d\n", cpuinfo[0]);
    	printf ("Info1: %d\n", cpuinfo[1]);
    	printf ("Info2: %d\n", cpuinfo[2]);
    	printf ("Info3: %d\n", cpuinfo[3]);
    
    	printf ("\n");
    	for (int i = 0; i < 4; i++)
    	{
    		printf ("Info%d: ", i);
    		for (int j = 31; j >= 0; j--)
    		{
    			printf ("%d", (cpuinfo[i] >> j) & 1);
    			if ((j % 4) == 0)
    			{
    				printf (" ");
    			}
    		}
    		printf ("\n");
    	}
    
    	return 0;
    }
    

    Ausgabe:

    Info0: 10
    Info1: 1970169159
    Info2: 1818588270
    Info3: 1231384169
    
    Info0: 0000 0000 0000 0000 0000 0000 0000 1010
    Info1: 0111 0101 0110 1110 0110 0101 0100 0111
    Info2: 0110 1100 0110 0101 0111 0100 0110 1110
    Info3: 0100 1001 0110 0101 0110 1110 0110 1001
    

    Meine CPU:
    Intel Core 2 Duo 2,4GHz

    Info0 müsste folgendes beinhalten:
    Stepping ID
    Model
    Family
    Processor Type
    ...

    Wenn ich das ganze aber mit dem Intel pdf vergleiche finde ich dort nichts was zu meinem Prozessor passen würde, aber warscheinlich lese ich dort nur etwas falsch ^^.
    http://www.intel.com/assets/pdf/appnote/241618.pdf

    Vielleicht kann mir von euch wer weiterhelfen 🙂

    Falls wer einen einfacheren Weg kennt um herauszufinden ob VT-x oder AMD-V unterstützt wird nehm ich den auch gern 😉

    Hier ist das zugehörige AMD pdf falls wer nen AMD hat und den code testen will:
    http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf

    yogg





  • Habs rausgefunden 🙂

    __cpuid (cpuinfo, 0);
    __cpuid (cpuinfo, 1);
    __cpuid (cpuinfo, 0x80000000);

    Die Werte dahinter bestimmen welche Infos zurückkommen. Die Infos die ich wollte fand ich bei "__cpuid (cpuinfo, 1);" Arrayindex 2 Bit 5 bei Intel CPUs. Und "__cpuid (cpuinfo, 0x80000001);" Arrayindex 2 Bit 2 bei AMD.

    __cpuid (cpuinfo, 0); Liefert übrigends den 12 Stelligen Vendor String (ohne Nullterminierung!) des CPU Herstellers.

    __cpuid (cpuinfo, 0);
    char cpustring[13];
    memset(cpustring, 0, sizeof(cpustring));
    *((int*)cpustring) = cpuinfo[1];
    *((int*)(cpustring+4)) = cpuinfo[3];
    *((int*)(cpustring+8)) = cpuinfo[2];
    
    printf ("Vendorstring: %s\n", cpustring);
    
    Vendorstring: GenuineIntel
    Vendorstring: AuthenticAMD
    

    yogg


Anmelden zum Antworten