
if (cpuid().ECX[28] == True)
MsgBox % "支持高级矢量扩展"
if (cpuid().edx[26] == True)
MsgBox % "支持SSE2指令"
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=103994
CPUID() {
static cpuid := 0
if not cpuid {
; C source code - https://godbolt.org/z/1YPd6jz61
code := (A_PtrSize == 4)
? "VYnlV4t9EFaLdQhTiw+LBg+iiQaLRQyJGItFFIkPiRBbXl9dww=="
: "U4sBSYnKSYnTQYsID6JBiQJBiRtBiQhBiRFbww=="
size := StrLen(RTrim(code, "=")) * 3 // 4
bin := DllCall("GlobalAlloc", "uint", 0, "uptr", size, "ptr")
DllCall("VirtualProtect", "ptr", bin, "ptr", size, "uint", 0x40, "uint*", old:=0)
DllCall("crypt32\CryptStringToBinary", "str", code, "uint", 0, "uint", 0x1, "ptr", bin, "uint*", size, "ptr", 0, "ptr", 0)
; Set eax flag to 1 to retrieve supported CPU features.
; See this for CPU features: https://wiki.osdev.org/CPUID
; Also see: Appendix D.2 - CPUID Feature Flags Related to Instruction Support
; On page 1861 - https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/40332.pdf
DllCall(bin, "uint*", a := 1, "uint*", b := 0, "uint*", c := 0, "uint*", d := 0)
; Free memory.
DllCall("GlobalFree", "ptr", bin)
; To check for SSE2 use the following code example:
; if cpuid().edx[26] == True
eax := {0: a & 1}
ebx := {0: b & 1}
ecx := {0: c & 1}
edx := {0: d & 1}
loop 31 {
eax[A_Index] := !!(1 << A_Index & a)
ebx[A_Index] := !!(1 << A_Index & b)
ecx[A_Index] := !!(1 << A_Index & c)
edx[A_Index] := !!(1 << A_Index & d)
}
cpuid := {eax: eax, ebx: ebx, ecx: ecx, edx: edx}
}
return cpuid
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)