From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- include/tools/cpuid.hxx | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 include/tools/cpuid.hxx (limited to 'include/tools/cpuid.hxx') diff --git a/include/tools/cpuid.hxx b/include/tools/cpuid.hxx new file mode 100644 index 000000000..4f309ff11 --- /dev/null +++ b/include/tools/cpuid.hxx @@ -0,0 +1,109 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include +#include +#include +#include + +/* + +Do NOT include this header in source files compiled with CPU-specific code. +TODO: For the header to be safe that way, it should be free of any templates +or inline functions, otherwise their possibly emitted copies compiled +with the CPU-specific instructions might be chosen by the linker as the copy +to keep. + +Also see the note at the top of simdsupport.hxx . + +*/ + +namespace cpuid { + +enum class InstructionSetFlags +{ + NONE = 0x00, + HYPER = 0x01, + SSE2 = 0x02, + SSSE3 = 0x04, + SSE41 = 0x08, + SSE42 = 0x10, + AVX = 0x20, + AVX2 = 0x40, + AVX512F = 0x80 +}; + +} // end cpuid + +namespace o3tl { + template<> struct typed_flags : is_typed_flags {}; +} + +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() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::SSE2); +} + +/** Check if SSSE3 is supported by the CPU + */ +inline bool hasSSSE3() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::SSSE3); +} + +/** Check if AVX is supported by the CPU + */ +inline bool hasAVX() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::AVX); +} + +/** Check if AVX2 is supported by the CPU + */ +inline bool hasAVX2() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::AVX2); +} + +/** Check if AVX512F is supported by the CPU + */ +inline bool hasAVX512F() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::AVX512F); +} + +/** Check if Hyper Threading is supported + */ +inline bool hasHyperThreading() +{ + return isCpuInstructionSetSupported(InstructionSetFlags::HYPER); +} + +} // end cpuid + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3