summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-01-02 18:52:54 +0000
committerrubidium <rubidium@openttd.org>2014-01-02 18:52:54 +0000
commitb1001258668ee3fd2cdb579ddbc9aa3bd5ac0c2c (patch)
tree7d2d197e68e21b05e940fe308e73d9f0d2715ab0 /src
parent7247ecf172e85ed47b13ccb9aa1ffcc2050b0114 (diff)
downloadopenttd-b1001258668ee3fd2cdb579ddbc9aa3bd5ac0c2c.tar.xz
(svn r26207) -Codechange: move the CPUID flag detection into cpu.cpp
Diffstat (limited to 'src')
-rw-r--r--src/cpu.cpp14
-rw-r--r--src/cpu.h9
-rw-r--r--src/viewport_sprite_sorter_sse4.cpp8
3 files changed, 23 insertions, 8 deletions
diff --git a/src/cpu.cpp b/src/cpu.cpp
index efa070bcb..45b7faab4 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -7,9 +7,10 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
-/** @file cpu.cpp OS/CPU/compiler dependant real time tick sampling. */
+/** @file cpu.cpp OS/CPU/compiler dependant CPU specific calls. */
#include "stdafx.h"
+#include "core/bitmath_func.hpp"
#undef RDTSC_AVAILABLE
@@ -107,3 +108,14 @@ void ottd_cpuid(int info[4], int type)
info[0] = info[1] = info[2] = info[3] = 0;
}
#endif
+
+bool HasCPUIDFlag(uint type, uint index, uint bit)
+{
+ int cpu_info[4] = {-1};
+ ottd_cpuid(cpu_info, 0);
+ uint max_info_type = cpu_info[0];
+ if (max_info_type < type) return false;
+
+ ottd_cpuid(cpu_info, type);
+ return HasBit(cpu_info[index], bit);
+}
diff --git a/src/cpu.h b/src/cpu.h
index 8ea95f5bb..08495dfc1 100644
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -25,4 +25,13 @@ uint64 ottd_rdtsc();
*/
void ottd_cpuid(int info[4], int type);
+/**
+ * Check whether the current CPU has the given flag.
+ * @param type The type to be passing to cpuid (usually 1).
+ * @param index The index in the returned info array.
+ * @param bit The bit index that needs to be set.
+ * @return The value of the bit, or false when there is no CPUID or the type is not available.
+ */
+bool HasCPUIDFlag(uint type, uint index, uint bit);
+
#endif /* CPU_H */
diff --git a/src/viewport_sprite_sorter_sse4.cpp b/src/viewport_sprite_sorter_sse4.cpp
index 40bbca87d..7cd48e7d9 100644
--- a/src/viewport_sprite_sorter_sse4.cpp
+++ b/src/viewport_sprite_sorter_sse4.cpp
@@ -97,13 +97,7 @@ void ViewportSortParentSpritesSSE41(ParentSpriteToSortVector *psdv)
*/
bool ViewportSortParentSpritesSSE41Checker()
{
- int cpu_info[4] = {-1};
- ottd_cpuid(cpu_info, 0);
- unsigned int max_info_type = cpu_info[0];
- if (max_info_type < 1) return false;
-
- ottd_cpuid(cpu_info, 1);
- return (cpu_info[2] & (1 << 19)) != 0;
+ return HasCPUIDFlag(1, 2, 19);
}
#endif /* WITH_SSE */