1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #pragma once
12 
13 #include <sal/config.h>
14 #include <tools/toolsdllapi.h>
15 #include <o3tl/typed_flags_set.hxx>
16 #include <rtl/ustring.hxx>
17 
18 namespace cpuid {
19 
20 enum class InstructionSetFlags
21 {
22     NONE  = 0x00,
23     HYPER = 0x01,
24     SSE2  = 0x02,
25     SSSE3 = 0x04,
26     SSE41 = 0x08,
27     SSE42 = 0x10,
28     AVX   = 0x20,
29     AVX2  = 0x40
30 };
31 
32 } // end cpuid
33 
34 namespace o3tl {
35     template<> struct typed_flags<cpuid::InstructionSetFlags> : is_typed_flags<cpuid::InstructionSetFlags, 0x07f> {};
36 }
37 
38 namespace cpuid {
39 
40 /** Get supported instruction set flags determined at runtime by probing the CPU.
41  */
42 TOOLS_DLLPUBLIC InstructionSetFlags getCpuInstructionSetFlags();
43 
44 /** Check if a certain instruction set is supported by the CPU at runtime.
45  */
46 TOOLS_DLLPUBLIC bool isCpuInstructionSetSupported(InstructionSetFlags eInstructions);
47 
48 /** Returns a string of supported instructions.
49  */
50 TOOLS_DLLPUBLIC OUString instructionSetSupportedString();
51 
52 /** Check if SSE2 is supported by the CPU
53  */
hasSSE2()54 inline bool hasSSE2()
55 {
56     return isCpuInstructionSetSupported(InstructionSetFlags::SSE2);
57 }
58 
59 /** Check if SSSE3 is supported by the CPU
60  */
hasSSSE3()61 inline bool hasSSSE3()
62 {
63     return isCpuInstructionSetSupported(InstructionSetFlags::SSSE3);
64 }
65 
66 /** Check if AVX2 is supported by the CPU
67  */
hasAVX2()68 inline bool hasAVX2()
69 {
70     return isCpuInstructionSetSupported(InstructionSetFlags::AVX2);
71 }
72 
73 /** Check if Hyper Threading is supported
74  */
hasHyperThreading()75 inline bool hasHyperThreading()
76 {
77     return isCpuInstructionSetSupported(InstructionSetFlags::HYPER);
78 }
79 
80 } // end cpuid
81 
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
83