diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-05-08 10:47:04 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-07-09 02:46:43 +0200 |
commit | f43f9b99603736a4d54f550052509eb5f4d04b45 (patch) | |
tree | 96f8e17bc271471d54571d6ffce7146b6bcdb626 /include/tools/cpuid.hxx | |
parent | f65905dd0ff464774f338db44d69925f98e1766c (diff) |
CPU intrinsics detection (SSE, AVX)
Adds CPU intrinsics detection in configure pass for compile time
detection and "cpuid" runtime detection of which CPU instruction
sets are available on the user device.
Change-Id: I0ee4d0b22a7c51f72796d43e7383a31d03b437ad
Reviewed-on: https://gerrit.libreoffice.org/75175
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/tools/cpuid.hxx')
-rw-r--r-- | include/tools/cpuid.hxx | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/include/tools/cpuid.hxx b/include/tools/cpuid.hxx index 419d05714ae4..27e9987398e4 100644 --- a/include/tools/cpuid.hxx +++ b/include/tools/cpuid.hxx @@ -13,22 +13,73 @@ #include <sal/config.h> #include <tools/toolsdllapi.h> +#include <o3tl/typed_flags_set.hxx> +#include <rtl/ustring.hxx> -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && defined(__SSE2__) -#define LO_SSE2_AVAILABLE 1 -#elif defined(_MSC_VER) -#define LO_SSE2_AVAILABLE 1 -#endif +namespace cpuid { -namespace tools +enum class InstructionSetFlags { -namespace cpuid + NONE = 0x00, + HYPER = 0x01, + SSE2 = 0x02, + SSSE3 = 0x04, + SSE41 = 0x08, + SSE42 = 0x10, + AVX = 0x20, + AVX2 = 0x40 +}; + +} // end cpuid + +namespace o3tl { + template<> struct typed_flags<cpuid::InstructionSetFlags> : is_typed_flags<cpuid::InstructionSetFlags, 0x07f> {}; +} + +namespace cpuid { + +/** Get supported instruction set flags determined at runtime by probing the CPU. + */ +TOOLS_DLLPUBLIC InstructionSetFlags getCpuInstructionSetFlags(); + +/** Check if a certain instruction set is supported by the CPU at runtime. + */ +TOOLS_DLLPUBLIC bool isCpuInstructionSetSupported(InstructionSetFlags eInstructions); + +/** Returns a string of supported instructions. + */ +TOOLS_DLLPUBLIC OUString instructionSetSupportedString(); + +/** Check if SSE2 is supported by the CPU + */ +inline bool hasSSE2() { - TOOLS_DLLPUBLIC bool hasSSE2(); - TOOLS_DLLPUBLIC bool hasHyperThreading(); + return isCpuInstructionSetSupported(InstructionSetFlags::SSE2); } + +/** Check if SSSE3 is supported by the CPU + */ +inline bool hasSSSE3() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::SSSE3); +} + +/** Check if AVX2 is supported by the CPU + */ +inline bool hasAVX2() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::AVX2); +} + +/** Check if Hyper Threading is supported + */ +inline bool hasHyperThreading() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::HYPER); } -#endif +} // end cpuid + +#endif // INCLUDED_TOOLS_CPUID_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |