Botan
1.10.17
src
utils
cpuid.h
Go to the documentation of this file.
1
/*
2
* Runtime CPU detection
3
* (C) 2009-2010 Jack Lloyd
4
*
5
* Distributed under the terms of the Botan license
6
*/
7
8
#ifndef BOTAN_CPUID_H__
9
#define BOTAN_CPUID_H__
10
11
#include <botan/types.h>
12
13
namespace
Botan
{
14
15
/**
16
* A class handling runtime CPU feature detection
17
*/
18
class
BOTAN_DLL
CPUID
19
{
20
public
:
21
/**
22
* Probe the CPU and see what extensions are supported
23
*/
24
static
void
initialize
();
25
26
/**
27
* Return a best guess of the cache line size
28
*/
29
static
size_t
cache_line_size
() {
return
cache_line; }
30
31
/**
32
* Check if the processor supports RDTSC
33
*/
34
static
bool
has_rdtsc
()
35
{
return
x86_processor_flags_has(CPUID_RDTSC_BIT); }
36
37
/**
38
* Check if the processor supports SSE2
39
*/
40
static
bool
has_sse2
()
41
{
return
x86_processor_flags_has(CPUID_SSE2_BIT); }
42
43
/**
44
* Check if the processor supports SSSE3
45
*/
46
static
bool
has_ssse3
()
47
{
return
x86_processor_flags_has(CPUID_SSSE3_BIT); }
48
49
/**
50
* Check if the processor supports SSE4.1
51
*/
52
static
bool
has_sse41
()
53
{
return
x86_processor_flags_has(CPUID_SSE41_BIT); }
54
55
/**
56
* Check if the processor supports SSE4.2
57
*/
58
static
bool
has_sse42
()
59
{
return
x86_processor_flags_has(CPUID_SSE42_BIT); }
60
61
/**
62
* Check if the processor supports extended AVX vector instructions
63
*/
64
static
bool
has_avx
()
65
{
return
x86_processor_flags_has(CPUID_AVX_BIT); }
66
67
/**
68
* Check if the processor supports AES-NI
69
*/
70
static
bool
has_aes_ni
()
71
{
return
x86_processor_flags_has(CPUID_AESNI_BIT); }
72
73
/**
74
* Check if the processor supports PCMULUDQ
75
*/
76
static
bool
has_pcmuludq
()
77
{
return
x86_processor_flags_has(CPUID_PCMUL_BIT); }
78
79
/**
80
* Check if the processor supports MOVBE
81
*/
82
static
bool
has_movbe
()
83
{
return
x86_processor_flags_has(CPUID_MOVBE_BIT); }
84
85
/**
86
* Check if the processor supports RDRAND
87
*/
88
static
bool
has_rdrand
()
89
{
return
x86_processor_flags_has(CPUID_RDRAND_BIT); }
90
91
/**
92
* Check if the processor supports AltiVec/VMX
93
*/
94
static
bool
has_altivec
() {
return
altivec_capable; }
95
private
:
96
enum
CPUID_bits {
97
CPUID_RDTSC_BIT = 4,
98
CPUID_SSE2_BIT = 26,
99
CPUID_PCMUL_BIT = 33,
100
CPUID_SSSE3_BIT = 41,
101
CPUID_SSE41_BIT = 51,
102
CPUID_SSE42_BIT = 52,
103
CPUID_MOVBE_BIT = 54,
104
CPUID_AESNI_BIT = 57,
105
CPUID_AVX_BIT = 60,
106
CPUID_RDRAND_BIT = 62
107
};
108
109
static
bool
x86_processor_flags_has(u64bit bit)
110
{
111
return
((x86_processor_flags >> bit) & 1);
112
}
113
114
static
u64bit
x86_processor_flags;
115
static
size_t
cache_line;
116
static
bool
altivec_capable;
117
};
118
119
}
120
121
#endif
Botan::CPUID
Definition
cpuid.h:19
Botan::CPUID::has_aes_ni
static bool has_aes_ni()
Definition
cpuid.h:70
Botan::CPUID::has_ssse3
static bool has_ssse3()
Definition
cpuid.h:46
Botan::CPUID::has_sse2
static bool has_sse2()
Definition
cpuid.h:40
Botan::CPUID::has_avx
static bool has_avx()
Definition
cpuid.h:64
Botan::CPUID::has_sse42
static bool has_sse42()
Definition
cpuid.h:58
Botan::CPUID::cache_line_size
static size_t cache_line_size()
Definition
cpuid.h:29
Botan::CPUID::has_rdtsc
static bool has_rdtsc()
Definition
cpuid.h:34
Botan::CPUID::has_movbe
static bool has_movbe()
Definition
cpuid.h:82
Botan::CPUID::initialize
static void initialize()
Definition
cpuid.cpp:196
Botan::CPUID::has_rdrand
static bool has_rdrand()
Definition
cpuid.h:88
Botan::CPUID::has_sse41
static bool has_sse41()
Definition
cpuid.h:52
Botan::CPUID::has_pcmuludq
static bool has_pcmuludq()
Definition
cpuid.h:76
Botan::CPUID::has_altivec
static bool has_altivec()
Definition
cpuid.h:94
Botan
Definition
algo_base.h:14
Botan::u64bit
unsigned long long u64bit
Definition
types.h:49
Generated by
1.18.0