18 if (buffer.empty())
return 0;
19 uint8_t
ret = buffer.front();
20 buffer = buffer.subspan(1);
34 using Sim = std::bitset<S::Size()>;
36 std::vector<S> real(2);
38 std::vector<Sim> sim(2);
41 auto compare_fn = [&](
unsigned idx) {
43 auto it = real[idx].begin();
44 unsigned first = S::Size();
45 unsigned last = S::Size();
46 for (
unsigned i = 0; i < S::Size(); ++i) {
47 bool match = (it != real[idx].end()) && *it == i;
48 assert(sim[idx][i] == real[idx][i]);
49 assert(match == real[idx][i]);
50 assert((it == real[idx].end()) != (it != real[idx].end()));
53 if (first == S::Size()) first = i;
57 assert(it == real[idx].end());
58 assert(!(it != real[idx].end()));
60 assert(sim[idx].any() == real[idx].Any());
64 assert(first == real[idx].First());
65 assert(last == real[idx].Last());
73 int command = ReadByte(buffer) % 64;
75 unsigned args = ReadByte(buffer);
76 unsigned dest = ((
args & 7) * sim.size()) >> 3;
77 unsigned src = (((
args >> 3) & 7) * sim.size()) >> 3;
78 unsigned aux = (((
args >> 6) & 3) * sim.size()) >> 2;
80 assert((sim.empty() && dest == 0 && src == 0 && aux == 0) ||
81 (!sim.empty() && dest < sim.size() && src < sim.size() && aux < sim.size()));
87 if (dest < sim.size() &&
command-- == 0) {
89 unsigned val = ReadByte(buffer) % S::Size();
90 assert(sim[dest][val] == real[dest][val]);
94 }
else if (dest < sim.size() &&
command-- == 0) {
96 unsigned val = ReadByte(buffer) % S::Size();
97 assert(sim[dest][val] == real[dest][val]);
99 real[dest].Reset(val);
101 }
else if (dest < sim.size() &&
command-- == 0) {
103 unsigned val = ReadByte(buffer) % S::Size();
104 assert(sim[dest][val] == real[dest][val]);
105 sim[dest].set(val,
args >> 7);
106 real[dest].Set(val,
args >> 7);
108 }
else if (sim.size() < 4 &&
command-- == 0) {
110 sim.resize(sim.size() + 1);
111 real.resize(real.size() + 1);
113 }
else if (sim.size() < 4 &&
command-- == 0) {
115 unsigned val = ReadByte(buffer) % S::Size();
116 std::bitset<S::Size()> newset;
118 sim.push_back(newset);
119 real.push_back(S::Singleton(val));
121 }
else if (dest < sim.size() &&
command-- == 0) {
126 for (
unsigned i = 0; i < S::Size(); ++i) {
127 if (rng.randbool()) {
133 }
else if (dest < sim.size() &&
command-- == 0) {
135 unsigned r1 = rng.randrange(S::Size());
136 unsigned r2 = rng.randrange(S::Size());
137 unsigned r3 = rng.randrange(S::Size());
140 real[dest] = {r1, r2, r3};
145 }
else if (!sim.empty() &&
command-- == 0) {
147 compare_fn(sim.size() - 1);
151 }
else if (sim.size() < 4 && src < sim.size() &&
command-- == 0) {
153 sim.emplace_back(sim[src]);
154 real.emplace_back(real[src]);
156 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
159 sim[dest] = sim[src];
160 real[dest] = real[src];
162 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
164 swap(sim[dest], sim[src]);
165 swap(real[dest], real[src]);
167 }
else if (sim.size() < 4 &&
command-- == 0) {
169 unsigned r1 = rng.randrange(S::Size());
170 unsigned r2 = rng.randrange(S::Size());
174 real.push_back(
S{r1, r2});
176 }
else if (dest < sim.size() &&
command-- == 0) {
178 unsigned len = ReadByte(buffer) % S::Size();
181 for (
unsigned i = 0; i < len; ++i) sim[dest][i] =
true;
182 real[dest] = S::Fill(len);
184 }
else if (src < sim.size() &&
command-- == 0) {
186 unsigned val = ReadByte(buffer) % S::Size();
188 auto it = real[src].begin(), it_copy = it;
189 for (
unsigned i = 0; i < S::Size(); ++i) {
190 if (i == val) it_copy = it;
191 bool match = (it != real[src].end()) && *it == i;
192 assert(match == sim[src][i]);
195 assert(it == real[src].end());
197 for (
unsigned i = val; i < S::Size(); ++i) {
198 bool match = (it_copy != real[src].end()) && *it_copy == i;
199 assert(match == sim[src][i]);
200 if (match) ++it_copy;
202 assert(it_copy == real[src].end());
204 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
207 sim[dest] |= sim[src];
208 real[dest] |= real[src];
210 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
213 sim[dest] &= sim[src];
214 real[dest] &= real[src];
216 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
219 sim[dest] &= ~sim[src];
220 real[dest] -= real[src];
222 }
else if (src < sim.size() && dest < sim.size() &&
command-- == 0) {
225 sim[dest] ^= sim[src];
226 real[dest] ^= real[src];
228 }
else if (src < sim.size() && dest < sim.size() && aux < sim.size() &&
command-- == 0) {
231 sim[dest] = sim[src] | sim[aux];
232 real[dest] = real[src] | real[aux];
234 }
else if (src < sim.size() && dest < sim.size() && aux < sim.size() &&
command-- == 0) {
237 sim[dest] = sim[src] & sim[aux];
238 real[dest] = real[src] & real[aux];
240 }
else if (src < sim.size() && dest < sim.size() && aux < sim.size() &&
command-- == 0) {
243 sim[dest] = sim[src] & ~sim[aux];
244 real[dest] = real[src] - real[aux];
246 }
else if (src < sim.size() && dest < sim.size() && aux < sim.size() &&
command-- == 0) {
249 sim[dest] = sim[src] ^ sim[aux];
250 real[dest] = real[src] ^ real[aux];
252 }
else if (src < sim.size() && aux < sim.size() &&
command-- == 0) {
254 bool is_superset = (sim[aux] & ~sim[src]).none();
255 bool is_subset = (sim[src] & ~sim[aux]).none();
256 assert(real[src].IsSupersetOf(real[aux]) == is_superset);
257 assert(real[src].IsSubsetOf(real[aux]) == is_subset);
258 assert(real[aux].IsSupersetOf(real[src]) == is_subset);
259 assert(real[aux].IsSubsetOf(real[src]) == is_superset);
261 }
else if (src < sim.size() && aux < sim.size() &&
command-- == 0) {
263 assert((sim[src] == sim[aux]) == (real[src] == real[aux]));
264 assert((sim[src] != sim[aux]) == (real[src] != real[aux]));
266 }
else if (src < sim.size() && aux < sim.size() &&
command-- == 0) {
268 assert((sim[src] & sim[aux]).any() == real[src].Overlaps(real[aux]));
269 assert((sim[src] & sim[aux]).any() == real[aux].Overlaps(real[src]));
275 for (
unsigned i = 0; i < sim.size(); ++i) {
284 unsigned typdat = ReadByte(buffer) % 8;
287 TestType<bitset_detail::IntBitSet<uint16_t>>(buffer);
288 TestType<bitset_detail::MultiIntBitSet<uint16_t, 1>>(buffer);
289 }
else if (typdat == 1) {
291 TestType<bitset_detail::MultiIntBitSet<uint16_t, 2>>(buffer);
292 TestType<bitset_detail::IntBitSet<uint32_t>>(buffer);
293 }
else if (typdat == 2) {
295 TestType<bitset_detail::MultiIntBitSet<uint16_t, 3>>(buffer);
296 }
else if (typdat == 3) {
298 TestType<bitset_detail::IntBitSet<uint64_t>>(buffer);
299 TestType<bitset_detail::MultiIntBitSet<uint64_t, 1>>(buffer);
300 TestType<bitset_detail::MultiIntBitSet<uint32_t, 2>>(buffer);
301 TestType<bitset_detail::MultiIntBitSet<uint16_t, 4>>(buffer);
302 }
else if (typdat == 4) {
304 TestType<bitset_detail::MultiIntBitSet<uint32_t, 3>>(buffer);
305 }
else if (typdat == 5) {
307 TestType<bitset_detail::MultiIntBitSet<uint64_t, 2>>(buffer);
308 TestType<bitset_detail::MultiIntBitSet<uint32_t, 4>>(buffer);
309 }
else if (typdat == 6) {
311 TestType<bitset_detail::MultiIntBitSet<uint64_t, 3>>(buffer);
312 }
else if (typdat == 7) {
314 TestType<bitset_detail::MultiIntBitSet<uint64_t, 4>>(buffer);
std::span< const uint8_t > FuzzBufferType
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
#define S(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)