为了以后优化算法,还是硬着头皮学了一下汇编,也就是C\C++与汇编的混合编程,帖一个类的代码,非常简单的东西,觉得还可以优化。识别CPU的型号,使用了Intel的CPUID指令,还没有来得及看AMD的资料,以后有空了我也做一个类似于CPUID一样的小工具呵呵。
class CIntelCpuInfo{
private:
DWORD m_VersionInfo;
DWORD m_Features;
void GetFeatures();
void GetVersionInfo();
public:
CIntelCpuInfo() {};
~CIntelCpuInfo() {};
void Show();
};
void CIntelCpuInfo::Show()
{
this->GetVersionInfo();
this->GetFeatures();
};
void CIntelCpuInfo::GetVersionInfo()
{
DWORD VER;
DWORD BACKUP;
DWORD STEP,MODEL,FAMILY;
__asm{
MOV EAX,01H;
CPUID;
MOV VER,EAX;
MOV BACKUP,EAX;
AND EAX,0000000FH;
MOV STEP,EAX;
MOV EAX,BACKUP;
SHR EAX,4;
AND EAX,0000000FH;
MOV MODEL,EAX;
MOV EAX,BACKUP;
SHR EAX,8;
AND EAX,0000000FH;
MOV FAMILY,EAX;
};
cout<<"Family ID : "<<FAMILY<<" Stepping ID : "<<STEP<<" Model : "<<MODEL<<endl;
};
void CIntelCpuInfo::GetFeatures()
{
DWORD C,D;
DWORD SSE3Tag;
DWORD SSTEPTag;
DWORD SSE2Tag;
DWORD SSE1Tag;
DWORD MMXTag;
__asm{
MOV EAX,01H;
CPUID;
MOV C,ECX;
PUSH ECX;
AND ECX,01H;
MOV SSE3Tag,ECX;
POP ECX;
AND ECX,0080H;
MOV SSTEPTag,ECX;
SHR SSTEPTag,7;
MOV D,EDX;
SHR EDX,23;
PUSH EDX;
PUSH EDX;
AND EDX,01H;
MOV MMXTag,EDX;
POP EDX;
SHR EDX,2;
AND EDX,01H;
MOV SSE1Tag,EDX;
POP EDX;
SHR EDX,3;
AND EDX,01H;
MOV SSE2Tag,EDX;
};
cout<<"SSE3 Support ? "<<SSE3Tag<<endl;
cout<<"SSE2 Support ? "<<SSE2Tag<<endl;
cout<<"SSE1 Support ? "<<SSE1Tag<<endl;
cout<<"Enhanced SpeedStepping ? "<<SSTEPTag<<endl;
};
我的CPU是2002年下半年的,Intel Pentium 4 Northwood 1.8GA,嗬嗬,搞得多么先进一样。截图如下,
结果完全正确。有了一些经验,在以后的程序中,可以通过识别CPU类型进行额外的优化,以后好好的研究Intel的Manual。
posted on 2006-08-18 22:15
周波 阅读(980)
评论(1) 编辑 收藏 引用 所属分类:
无庸技术