forked from travisdowns/uarch-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isa-support.cpp
64 lines (51 loc) · 1.29 KB
/
isa-support.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* isa-support.cpp
*/
#include "isa-support.hpp"
#include "cpu/cpu.h"
#include <assert.h>
struct Entry {
x86Feature feature;
PSnipCPUFeature psnip_feature;
const char *name;
bool supported() const {
return psnip_cpu_feature_check(psnip_feature);
}
};
#define MAKE_ENTRY(x) Entry{x, PSNIP_CPU_FEATURE_X86_ ## x, #x},
const Entry FEATURES_ARRAY[] = {
FEATURES_X(MAKE_ENTRY)
};
const size_t FEATURES_COUNT = sizeof(FEATURES_ARRAY)/sizeof(FEATURES_ARRAY[0]);
const Entry& lookup(x86Feature feature) {
assert(feature >= 0);
assert(feature < FEATURES_COUNT);
return FEATURES_ARRAY[feature];
}
const char* to_name(x86Feature feature) {
return lookup(feature).name;
}
bool supports(std::vector<x86Feature> features) {
for (auto& f : features) {
if (!lookup(f).supported()) {
return false;
}
}
return true;
}
std::string to_string(x86Feature f) {
return lookup(f).name;
}
std::string support_string() {
std::string result;
for (const Entry& e : FEATURES_ARRAY) {
if (e.supported()) {
result += result.empty() ? e.name : std::string(" ") + e.name;
}
}
return result;
}
std::ostream& operator<<(std::ostream& os, const x86Feature& f) {
os << to_string(f);
return os;
}