I am trying to write some OO code that will use the cpuid instruction to determine the SIMD support of a processor.
I have some code what works fine when in a traditional C style but when I put in into a C++ class, I get stack corruption.
Here is the relevant code:
Cpuid.h
Code: Select all
#ifndef _CPUID_H_
#define _CPUID_H_
class CpuInfo
{
public:
CpuInfo();
~CpuInfo();
bool Scan();
const char* Vendor();
protected:
private:
union{
struct { unsigned long b,d,c; } regs;
char str[13];
} vendor;
};
#endif
Code: Select all
#include "cpuid.h"
#include "string.h"
CpuInfo::CpuInfo()
{
memset(this,0,sizeof(CpuInfo));
}
CpuInfo::~CpuInfo()
{
}
bool CpuInfo::Scan()
{
_asm
{
pusha
xor eax,eax
cpuid
mov [this]CpuInfo.vendor.regs.b,ebx
mov [this]CpuInfo.vendor.regs.c,ecx
mov [this]CpuInfo.vendor.regs.d,edx
popa
}
return true;
}
const char * CpuInfo::Vendor()
{
return vendor.str;
}
Thanks,
Andrew