This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpattern_generator.h
More file actions
123 lines (105 loc) · 4.57 KB
/
Copy pathpattern_generator.h
File metadata and controls
123 lines (105 loc) · 4.57 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_CPU_CHECK_PATTERN_GENERATOR_H_
#define THIRD_PARTY_CPU_CHECK_PATTERN_GENERATOR_H_
#include <memory>
#include <string>
#include "malign_buffer.h"
namespace cpu_check {
class PatternGenerators;
struct FloatingPointResults {
bool operator==(const FloatingPointResults& other) const {
return f == other.f && d == other.d && ld == other.ld;
}
bool operator!=(const FloatingPointResults& other) const {
return f != other.f || d != other.d || ld != other.ld;
}
float f = 0.0;
double d = 0.0;
long double ld = 0.0;
};
class PatternGenerator {
public:
virtual ~PatternGenerator() {}
virtual std::string Name() const = 0;
virtual FloatingPointResults Generate(uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos,
bool exercise_floating_point,
MalignBuffer*) const = 0;
};
// Fills buffer with a systematic pattern.
// Returns iterate of chaotic floating point function of 'seed', with some
// reciprocal torture.
class FillBufferSystematic : public PatternGenerator {
public:
std::string Name() const override { return "Systematic"; }
FloatingPointResults Generate(uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos, bool exercise_floating_point,
MalignBuffer*) const override;
};
// Fills buffer with a random pattern.
// Returns iterate of chaotic floating point function of 'seed', with some
// reciprocal torture.
class FillBufferRandom : public PatternGenerator {
public:
std::string Name() const override { return "Random"; }
FloatingPointResults Generate(uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos, bool exercise_floating_point,
MalignBuffer*) const override;
};
// Fills buffer with a compressible pattern.
// Returns iterate of chaotic floating point function of 'seed', with some
// reciprocal torture.
class FillBufferText : public PatternGenerator {
public:
FillBufferText(const std::vector<std::string>& words) : words_(words) {}
std::string Name() const override { return "Text"; }
FloatingPointResults Generate(uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos, bool exercise_floating_point,
MalignBuffer*) const override;
private:
const std::vector<std::string>& words_;
};
// memset (conventional or rep;stos) randomly aligned, random width, randomly
// overlapped stretches of buffer. Constants aim to hit multiple times in
// cache lines and buffers. Untuned and based on nothing but hunches.
class FillBufferGrilledCheese : public PatternGenerator {
public:
std::string Name() const override { return "Cheese"; }
FloatingPointResults Generate(uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos, bool exercise_floating_point,
MalignBuffer*) const override;
};
class PatternGenerators {
public:
PatternGenerators();
const PatternGenerator& RandomGenerator(uint64_t round) const;
FloatingPointResults Generate(const PatternGenerator& generator,
const MalignBuffer::PunchedHole& hole,
uint64_t round,
MalignBuffer::CopyMethod copy_method,
bool use_repstos, bool exercise_floating_point,
MalignBuffer* b) const;
const std::vector<std::string>& words() const { return words_; }
private:
const std::vector<std::string> words_;
std::vector<std::unique_ptr<PatternGenerator>> generators_;
};
} // namespace cpu_check
#endif // THIRD_PARTY_CPU_CHECK_PATTERN_GENERATOR_H_