tools: runtime SSE/SSE2 detection

Change-Id: I29330061e2986ec2ae899c2f3a63d0eadd9cc194
This commit is contained in:
Tomaž Vajngerl
2015-11-13 12:24:35 +01:00
committed by Tomaž Vajngerl
parent d5c28d2616
commit 154bcd887d
3 changed files with 92 additions and 0 deletions

28
include/tools/cpuid.hxx Normal file
View File

@@ -0,0 +1,28 @@
/* -*- 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/.
*
*/
#ifndef INCLUDED_TOOLS_CPUID_HXX
#define INCLUDED_TOOLS_CPUID_HXX
#include <sal/config.h>
#include <tools/toolsdllapi.h>
namespace tools
{
namespace cpuid
{
TOOLS_DLLPUBLIC bool hasSSE();
TOOLS_DLLPUBLIC bool hasSSE2();
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -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 \

View File

@@ -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: */