summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-13 12:24:35 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-11-13 14:10:10 +0100
commit154bcd887d3772addc8196944044fa57738d3cf2 (patch)
tree92b153c854ddc2cf49c20f1702766c906d3231d0 /tools
parentd5c28d2616f4fad5f490387efa27d651c7b9243f (diff)
tools: runtime SSE/SSE2 detection
Change-Id: I29330061e2986ec2ae899c2f3a63d0eadd9cc194
Diffstat (limited to 'tools')
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/misc/cpuid.cxx63
2 files changed, 64 insertions, 0 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index 2d105cdabf97..65ba17c63303 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -69,6 +69,7 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
tools/source/memtools/multisel \
tools/source/memtools/unqidx \
tools/source/misc/appendunixshellword \
+ tools/source/misc/cpuid \
tools/source/misc/extendapplicationenvironment \
tools/source/misc/getprocessworkingdir \
tools/source/misc/solarmutex \
diff --git a/tools/source/misc/cpuid.cxx b/tools/source/misc/cpuid.cxx
new file mode 100644
index 000000000000..1d0518c2442e
--- /dev/null
+++ b/tools/source/misc/cpuid.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <tools/cpuid.hxx>
+#include <cstdint>
+
+namespace tools
+{
+namespace cpuid
+{
+
+// First minimize to MSVC / GCC compat. compiler and x86 / x64 architecture
+#if (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
+
+namespace
+{
+#if defined(_MSC_VER)
+#include <intrin.h>
+static void getCpuId(uint32_t array[4])
+{
+ __cpuid((int*)array, 1);
+}
+#else
+#include <cpuid.h>
+static void getCpuId(uint32_t array[4])
+{
+ __get_cpuid(1, array + 0, array + 1, array + 2, array + 3);
+}
+#endif
+}
+
+bool hasSSE()
+{
+ uint32_t cpuInfoArray[] = {0, 0, 0, 0};
+ getCpuId(cpuInfoArray);
+ return (cpuInfoArray[3] & (1 << 25)) != 0;
+}
+bool hasSSE2()
+{
+ uint32_t cpuInfoArray[] = {0, 0, 0, 0};
+ getCpuId(cpuInfoArray);
+ return (cpuInfoArray[3] & (1 << 26)) != 0;
+}
+
+#else
+
+bool hasSSE() { return false; }
+bool hasSSE2() { return false; }
+
+#endif
+
+}
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */