自动检测 128 位四路 SSE2
原始发布页
打开来源页面查看 1 个交叉存档
SVN rev 150 中加入了一些代码,试图自动检测是否使用四路 SSE2。我们需要这样做,是因为它只在某些具有 128 位 SSE2 的较新 CPU 上更快,而在具有 64 位 SSE2 的 CPU 上并非如此。
它使用 CPUID 指令获取 CPU 品牌、家族、型号编号和步进。那是容易的部分。难的是知道该如何处理型号编号。我没能找到任何 CPU 家族、型号和步进编号的表格。我只能依据看到的各种零散报告来判断。
我最终得出了以下代码:
代码:
// We need Intel Nehalem or AMD K10 or better for 128bit SSE2
// Nehalem = i3/i5/i7 and some Xeon
// K10 = Opterons with 4 or more cores, Phenom, Phenom II, Athlon II
// Intel Core i5 family 6, model 26 or 30
// Intel Core i7 family 6, model 26 or 30
// Intel Core i3 family 6, model 37
// AMD Phenom family 16, model 10
bool fUseSSE2 = ((fIntel && nFamily \* 10000 + nModel >= 60026) ||
(fAMD && nFamily \* 10000 + nModel >= 160010));我看到 AMD CPU 有一些零星且不一致的型号编号,所以不确定这能否涵盖所有具备该能力的 AMD CPU。
如果判断有误,你仍可以用 -4way 或 -4way=0 覆盖它。
它会把检测结果打印到 debug.log 中。搜索 CPUID 即可。
这只在使用 GCC 构建时启用。
英文原文
展开英文原文
SVN rev 150 has some code to try to auto-detect whether to use 4-way SSE2. We need this because it's only faster on certain newer CPUs that have 128-bit SSE2 and not ones with 64-bit SSE2.
It uses the CPUID instruction to get the CPU brand, family, model number and stepping. That's the easy part. Knowing what to do with the model number is the hard part. I was not able to find any table of family, model and stepping numbers for CPUs. I had to go by various random reports I saw.
Here's what I ended up with:
Code:
// We need Intel Nehalem or AMD K10 or better for 128bit SSE2 // Nehalem = i3/i5/i7 and some Xeon // K10 = Opterons with 4 or more cores, Phenom, Phenom II, Athlon II // Intel Core i5 family 6, model 26 or 30 // Intel Core i7 family 6, model 26 or 30 // Intel Core i3 family 6, model 37 // AMD Phenom family 16, model 10 bool fUseSSE2 = ((fIntel && nFamily * 10000 + nModel >= 60026) || (fAMD && nFamily * 10000 + nModel >= 160010));
I saw some sporadic inconsistent model numbers for AMD CPUs, so I'm not sure if this will catch all capable AMDs.
If it's wrong, you can still override it with -4way or -4way=0.
It prints what it finds in debug.log. Search on CPUID.
This is only enabled if built with GCC.