From 154bcd887d3772addc8196944044fa57738d3cf2 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 13 Nov 2015 12:24:35 +0100 Subject: tools: runtime SSE/SSE2 detection Change-Id: I29330061e2986ec2ae899c2f3a63d0eadd9cc194 --- tools/Library_tl.mk | 1 + tools/source/misc/cpuid.cxx | 63 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tools/source/misc/cpuid.cxx (limited to 'tools') 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 +#include + +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 +static void getCpuId(uint32_t array[4]) +{ + __cpuid((int*)array, 1); +} +#else +#include +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: */ -- cgit v1.2.3