-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_t81.cpp
More file actions
668 lines (605 loc) · 26.7 KB
/
bench_t81.cpp
File metadata and controls
668 lines (605 loc) · 26.7 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
// bench/bench_t81.cpp — Benchmark exercising the core bigint paths.
#include <algorithm>
#include <array>
#include <cstdint>
#include <random>
#include <string>
#include <benchmark/benchmark.h>
#include <t81/core/detail/base_digits.hpp>
#include <t81/io/fast_decimal.hpp>
#include <t81/t81lib.hpp>
#include <t81/util/random.hpp>
#include <stdexcept>
#include <utility>
#include <vector>
namespace {
enum class ArithmeticOp : std::uint64_t {
Add,
Subtract,
Multiply,
Divide,
Modulo,
};
enum class CompareOp : std::uint64_t {
Equal,
NotEqual,
Less,
LessEqual,
Greater,
GreaterEqual,
};
constexpr std::uint64_t seed_offset(ArithmeticOp op, bool bigint) noexcept {
return 0x1b1b1b1bULL + (static_cast<std::uint64_t>(op) << 4) + (bigint ? 0x100U : 0U);
}
constexpr std::uint64_t seed_offset(CompareOp op, bool bigint) noexcept {
return 0x3c3c3c3cULL + (static_cast<std::uint64_t>(op) << 4) + (bigint ? 0x200U : 0U);
}
constexpr bool requires_nonzero_rhs(ArithmeticOp op) noexcept {
return op == ArithmeticOp::Divide || op == ArithmeticOp::Modulo;
}
template <typename Int> Int random_value(std::mt19937_64 &rng, std::size_t limbs);
template <> t81::core::limb random_value<t81::core::limb>(std::mt19937_64 &rng, std::size_t) {
return t81::util::random_limb(rng);
}
template <>
t81::core::bigint random_value<t81::core::bigint>(std::mt19937_64 &rng, std::size_t limbs) {
return t81::util::random_bigint(rng, limbs, true);
}
template <typename Int> Int random_nonzero_value(std::mt19937_64 &rng, std::size_t limbs) {
Int value;
do {
value = random_value<Int>(rng, limbs);
} while (value.is_zero());
return value;
}
constexpr std::size_t kCacheSize = 64;
template <typename Int>
std::vector<Int>
create_random_cache(std::mt19937_64 &rng, std::size_t limbs, std::size_t count, bool nonzero) {
std::vector<Int> cache;
cache.reserve(count);
while (cache.size() < count) {
Int value = random_value<Int>(rng, limbs);
if (nonzero && value.is_zero()) {
continue;
}
cache.push_back(std::move(value));
}
return cache;
}
template <typename Int>
Int next_cache_value(const std::vector<Int> &cache, std::size_t &index) {
const Int value = cache[index];
index = (index + 1) % cache.size();
return value;
}
std::string decimal_string(std::size_t digits) {
std::string result;
result.reserve(digits);
for (std::size_t index = 0; index < digits; ++index) {
result.push_back(static_cast<char>('1' + (index % 9)));
}
return result;
}
std::string base81_string(std::size_t digits) {
std::string result;
result.reserve(digits);
const auto &alphabet = t81::core::detail::BASE81_DIGITS;
for (std::size_t index = 0; index < digits; ++index) {
result.push_back(alphabet[index % alphabet.size()]);
}
return result;
}
t81::core::bigint build_large_bigint(std::size_t limbs) {
t81::core::bigint result = t81::core::bigint::zero();
for (std::size_t index = 0; index < limbs; ++index) {
result = result.shift_limbs(1);
result += t81::core::bigint(t81::core::limb::max());
}
return result;
}
t81::core::bigint bigint_pow(t81::core::bigint base, std::uint64_t exponent) {
t81::core::bigint result = t81::core::bigint::one();
while (exponent != 0) {
if ((exponent & 1) != 0) {
result *= base;
}
base *= base;
exponent >>= 1;
}
return result;
}
t81::core::bigint bigint_gcd(t81::core::bigint a, t81::core::bigint b) {
if (a.is_zero()) {
return b.abs();
}
if (b.is_zero()) {
return a.abs();
}
while (!b.is_zero()) {
const auto remainder = t81::core::bigint::div_mod(a, b).second;
a = b;
b = remainder;
}
return a.abs();
}
std::vector<std::uint8_t> serialize_bigint(const t81::core::bigint &value) {
std::vector<std::uint8_t> output;
output.reserve(value.limb_count() * t81::core::limb::BYTES);
for (std::size_t index = 0; index < value.limb_count(); ++index) {
const auto chunk = value.limb_at(index).to_bytes();
output.insert(output.end(), chunk.begin(), chunk.end());
}
return output;
}
t81::core::bigint deserialize_bigint(const std::vector<std::uint8_t> &data) {
t81::core::bigint result = t81::core::bigint::zero();
const auto chunk_size = t81::core::limb::BYTES;
const std::size_t chunks = data.size() / chunk_size;
for (std::size_t index = chunks; index-- > 0;) {
std::array<std::uint8_t, t81::core::limb::BYTES> chunk{};
std::copy_n(data.data() + index * chunk_size, chunk_size, chunk.data());
result = result.shift_limbs(1);
result += t81::core::bigint(t81::core::limb::from_bytes(chunk));
}
return result;
}
template <typename Int> Int apply_operation(const Int &lhs, const Int &rhs, ArithmeticOp op);
template <>
t81::core::limb apply_operation<t81::core::limb>(const t81::core::limb &lhs,
const t81::core::limb &rhs,
ArithmeticOp op) {
switch (op) {
case ArithmeticOp::Add:
return lhs + rhs;
case ArithmeticOp::Subtract:
return lhs - rhs;
case ArithmeticOp::Multiply:
return lhs * rhs;
case ArithmeticOp::Divide:
return lhs / rhs;
case ArithmeticOp::Modulo:
return lhs % rhs;
}
return lhs;
}
template <>
t81::core::bigint apply_operation<t81::core::bigint>(const t81::core::bigint &lhs,
const t81::core::bigint &rhs,
ArithmeticOp op) {
switch (op) {
case ArithmeticOp::Add:
return lhs + rhs;
case ArithmeticOp::Subtract:
return lhs - rhs;
case ArithmeticOp::Multiply:
return lhs * rhs;
case ArithmeticOp::Divide:
return lhs / rhs;
case ArithmeticOp::Modulo:
return lhs % rhs;
}
return lhs;
}
template <typename Int>
void bench_negation(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<Int>(rng, limbs, kCacheSize, false);
std::size_t cache_index = 0;
while (state.KeepRunning()) {
auto value = next_cache_value(cache, cache_index);
try {
auto result = -value;
benchmark::DoNotOptimize(std::move(result));
} catch (const std::overflow_error &) {
continue;
}
}
}
template <typename Int> bool apply_compare(const Int &lhs, const Int &rhs, CompareOp op);
template <>
bool apply_compare<t81::core::limb>(const t81::core::limb &lhs,
const t81::core::limb &rhs,
CompareOp op) {
switch (op) {
case CompareOp::Equal:
return lhs == rhs;
case CompareOp::NotEqual:
return lhs != rhs;
case CompareOp::Less:
return lhs < rhs;
case CompareOp::LessEqual:
return lhs <= rhs;
case CompareOp::Greater:
return lhs > rhs;
case CompareOp::GreaterEqual:
return lhs >= rhs;
}
return false;
}
template <>
bool apply_compare<t81::core::bigint>(const t81::core::bigint &lhs,
const t81::core::bigint &rhs,
CompareOp op) {
switch (op) {
case CompareOp::Equal:
return lhs == rhs;
case CompareOp::NotEqual:
return lhs != rhs;
case CompareOp::Less:
return lhs < rhs;
case CompareOp::LessEqual:
return lhs <= rhs;
case CompareOp::Greater:
return lhs > rhs;
case CompareOp::GreaterEqual:
return lhs >= rhs;
}
return false;
}
template <typename Int>
void
bench_compare(benchmark::State &state, CompareOp op, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto lhs_cache = create_random_cache<Int>(rng, limbs, kCacheSize, false);
const auto rhs_cache = create_random_cache<Int>(rng, limbs, kCacheSize, false);
std::size_t lhs_index = 0;
std::size_t rhs_index = 0;
while (state.KeepRunning()) {
const auto lhs = next_cache_value(lhs_cache, lhs_index);
const auto rhs = next_cache_value(rhs_cache, rhs_index);
const auto result = apply_compare<Int>(lhs, rhs, op);
benchmark::DoNotOptimize(static_cast<int>(result));
}
}
template <typename Int>
void bench_arithmetic(benchmark::State &state,
ArithmeticOp op,
std::uint64_t seed,
std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto lhs_cache = create_random_cache<Int>(rng, limbs, kCacheSize, false);
const auto rhs_cache =
create_random_cache<Int>(rng, limbs, kCacheSize, requires_nonzero_rhs(op));
std::size_t lhs_index = 0;
std::size_t rhs_index = 0;
while (state.KeepRunning()) {
const auto lhs = next_cache_value(lhs_cache, lhs_index);
const auto rhs = next_cache_value(rhs_cache, rhs_index);
try {
auto result = apply_operation<Int>(lhs, rhs, op);
benchmark::DoNotOptimize(std::move(result));
} catch (const std::overflow_error &) {
continue;
}
}
}
constexpr std::size_t kBigintLimbs = 3;
constexpr std::size_t kLargeBigintLimbs = 32;
constexpr std::uint64_t kLargePowExponent = 32;
constexpr std::uint64_t negation_seed(bool bigint) noexcept {
return 0x2d2d2d2dULL + (bigint ? 0x300U : 0U);
}
template <bool Left>
void
bench_bigint_shift(benchmark::State &state, std::uint64_t seed, std::size_t limbs, int shift) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto value = next_cache_value(cache, index);
t81::core::bigint result = Left ? (value << shift) : (value >> shift);
benchmark::DoNotOptimize(result);
}
}
void bench_bigint_decimal_to_string(benchmark::State &state, const t81::core::bigint &value) {
while (state.KeepRunning()) {
auto text = t81::io::to_decimal(value);
benchmark::DoNotOptimize(std::move(text));
}
}
void bench_bigint_decimal_from_string(benchmark::State &state, const std::string &text) {
while (state.KeepRunning()) {
auto parsed = t81::io::from_string<t81::core::bigint>(text, 10);
benchmark::DoNotOptimize(std::move(parsed));
}
}
void bench_bigint_base81_to_string(benchmark::State &state, const t81::core::bigint &value) {
while (state.KeepRunning()) {
auto text = t81::io::to_string(value, 81);
benchmark::DoNotOptimize(std::move(text));
}
}
void bench_bigint_base81_from_string(benchmark::State &state, const std::string &text) {
while (state.KeepRunning()) {
auto parsed = t81::io::from_string<t81::core::bigint>(text, 81);
benchmark::DoNotOptimize(std::move(parsed));
}
}
void
bench_bigint_multiply_large(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto lhs_cache =
create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
const auto rhs_cache =
create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
std::size_t lhs_index = 0;
std::size_t rhs_index = 0;
while (state.KeepRunning()) {
const auto lhs = next_cache_value(lhs_cache, lhs_index);
const auto rhs = next_cache_value(rhs_cache, rhs_index);
auto result = lhs * rhs;
benchmark::DoNotOptimize(std::move(result));
}
}
void bench_bigint_pow(benchmark::State &state,
std::uint64_t seed,
std::size_t limbs,
std::uint64_t exponent) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto base = next_cache_value(cache, index);
auto result = bigint_pow(base.abs(), exponent);
benchmark::DoNotOptimize(std::move(result));
}
}
void bench_bigint_pow_large(benchmark::State &state,
std::uint64_t seed,
std::size_t limbs,
std::uint64_t exponent) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto base = next_cache_value(cache, index);
auto result = bigint_pow(base.abs(), exponent);
benchmark::DoNotOptimize(std::move(result));
}
}
void bench_bigint_gcd(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, true);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto a = next_cache_value(cache, index);
const auto b = next_cache_value(cache, index);
auto result = bigint_gcd(a.abs(), b.abs());
benchmark::DoNotOptimize(std::move(result));
}
}
void bench_bigint_gcd_large(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, true);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto a = next_cache_value(cache, index);
const auto b = next_cache_value(cache, index);
auto result = bigint_gcd(a.abs(), b.abs());
benchmark::DoNotOptimize(std::move(result));
}
}
void
bench_bigint_serialization(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto cache = create_random_cache<t81::core::bigint>(rng, limbs, kCacheSize, false);
std::size_t index = 0;
while (state.KeepRunning()) {
const auto value = next_cache_value(cache, index);
const auto serialized = serialize_bigint(value);
auto decoded = deserialize_bigint(serialized);
benchmark::DoNotOptimize(std::move(decoded));
}
}
void bench_random_bigint(benchmark::State &state, std::uint64_t seed, std::size_t limbs) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
while (state.KeepRunning()) {
auto value = t81::util::random_bigint(rng, limbs, true);
benchmark::DoNotOptimize(std::move(value));
}
}
void bench_montgomery_mul(benchmark::State &state,
std::uint64_t seed,
const t81::core::bigint &modulus) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto context = t81::core::MontgomeryContext<t81::core::bigint>(modulus);
auto lhs_cache = create_random_cache<t81::core::bigint>(rng, 2, kCacheSize, false);
auto rhs_cache = create_random_cache<t81::core::bigint>(rng, 2, kCacheSize, false);
for (auto &value : lhs_cache) {
value = context.to_montgomery(value);
}
for (auto &value : rhs_cache) {
value = context.to_montgomery(value);
}
std::size_t lhs_index = 0;
std::size_t rhs_index = 0;
while (state.KeepRunning()) {
const auto lhs = next_cache_value(lhs_cache, lhs_index);
const auto rhs = next_cache_value(rhs_cache, rhs_index);
auto result = context.mul(lhs, rhs);
benchmark::DoNotOptimize(std::move(result));
}
}
void bench_montgomery_mul_large(benchmark::State &state,
std::uint64_t seed,
const t81::core::bigint &modulus) {
std::mt19937_64 rng(seed + static_cast<std::uint64_t>(state.thread_index()));
const auto context = t81::core::MontgomeryContext<t81::core::bigint>(modulus);
auto lhs_cache =
create_random_cache<t81::core::bigint>(rng, kLargeBigintLimbs, kCacheSize, false);
auto rhs_cache =
create_random_cache<t81::core::bigint>(rng, kLargeBigintLimbs, kCacheSize, false);
for (auto &value : lhs_cache) {
value = context.to_montgomery(value);
}
for (auto &value : rhs_cache) {
value = context.to_montgomery(value);
}
std::size_t lhs_index = 0;
std::size_t rhs_index = 0;
while (state.KeepRunning()) {
const auto lhs = next_cache_value(lhs_cache, lhs_index);
const auto rhs = next_cache_value(rhs_cache, rhs_index);
auto result = context.mul(lhs, rhs);
benchmark::DoNotOptimize(std::move(result));
}
}
} // namespace
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::limb>,
limb_add,
ArithmeticOp::Add,
seed_offset(ArithmeticOp::Add, false),
0);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::limb>,
limb_subtract,
ArithmeticOp::Subtract,
seed_offset(ArithmeticOp::Subtract, false),
0);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::limb>,
limb_multiply,
ArithmeticOp::Multiply,
seed_offset(ArithmeticOp::Multiply, false),
0);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::limb>,
limb_divide,
ArithmeticOp::Divide,
seed_offset(ArithmeticOp::Divide, false),
0);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::limb>,
limb_modulo,
ArithmeticOp::Modulo,
seed_offset(ArithmeticOp::Modulo, false),
0);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::bigint>,
bigint_add,
ArithmeticOp::Add,
seed_offset(ArithmeticOp::Add, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::bigint>,
bigint_subtract,
ArithmeticOp::Subtract,
seed_offset(ArithmeticOp::Subtract, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::bigint>,
bigint_multiply,
ArithmeticOp::Multiply,
seed_offset(ArithmeticOp::Multiply, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::bigint>,
bigint_divide,
ArithmeticOp::Divide,
seed_offset(ArithmeticOp::Divide, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_arithmetic<t81::core::bigint>,
bigint_modulo,
ArithmeticOp::Modulo,
seed_offset(ArithmeticOp::Modulo, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_bigint_multiply_large,
bigint_multiply_large,
0xfeedc0d5,
kLargeBigintLimbs);
BENCHMARK_CAPTURE(bench_negation<t81::core::limb>, limb_negate, negation_seed(false), 0);
BENCHMARK_CAPTURE(bench_negation<t81::core::bigint>,
bigint_negate,
negation_seed(true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_equal,
CompareOp::Equal,
seed_offset(CompareOp::Equal, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_not_equal,
CompareOp::NotEqual,
seed_offset(CompareOp::NotEqual, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_less,
CompareOp::Less,
seed_offset(CompareOp::Less, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_less_equal,
CompareOp::LessEqual,
seed_offset(CompareOp::LessEqual, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_greater,
CompareOp::Greater,
seed_offset(CompareOp::Greater, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::limb>,
limb_greater_equal,
CompareOp::GreaterEqual,
seed_offset(CompareOp::GreaterEqual, false),
0);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_equal,
CompareOp::Equal,
seed_offset(CompareOp::Equal, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_not_equal,
CompareOp::NotEqual,
seed_offset(CompareOp::NotEqual, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_less,
CompareOp::Less,
seed_offset(CompareOp::Less, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_less_equal,
CompareOp::LessEqual,
seed_offset(CompareOp::LessEqual, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_greater,
CompareOp::Greater,
seed_offset(CompareOp::Greater, true),
kBigintLimbs);
BENCHMARK_CAPTURE(bench_compare<t81::core::bigint>,
bigint_greater_equal,
CompareOp::GreaterEqual,
seed_offset(CompareOp::GreaterEqual, true),
kBigintLimbs);
const auto decimal_100_text = decimal_string(100);
const auto decimal_1000_text = decimal_string(1000);
const auto decimal_100_value = t81::io::from_string<t81::core::bigint>(decimal_100_text, 10);
const auto decimal_1000_value = t81::io::from_string<t81::core::bigint>(decimal_1000_text, 10);
const auto base81_100_text = base81_string(100);
const auto base81_256_text = base81_string(256);
const auto base81_100_value = t81::io::from_string<t81::core::bigint>(base81_100_text, 81);
const auto base81_256_value = t81::io::from_string<t81::core::bigint>(base81_256_text, 81);
const auto large_bigint_value = build_large_bigint(kLargeBigintLimbs);
BENCHMARK_CAPTURE(bench_bigint_shift<true>, shift_left_1, 0xabcde01, kBigintLimbs, 1);
BENCHMARK_CAPTURE(bench_bigint_shift<true>, shift_left_10, 0xabcde02, kBigintLimbs, 10);
BENCHMARK_CAPTURE(bench_bigint_shift<true>, shift_left_64, 0xabcde03, kBigintLimbs, 64);
BENCHMARK_CAPTURE(bench_bigint_shift<true>, shift_left_512, 0xabcde04, kBigintLimbs, 512);
BENCHMARK_CAPTURE(bench_bigint_shift<false>, shift_right_1, 0xabcde05, kBigintLimbs, 1);
BENCHMARK_CAPTURE(bench_bigint_shift<false>, shift_right_10, 0xabcde06, kBigintLimbs, 10);
BENCHMARK_CAPTURE(bench_bigint_shift<false>, shift_right_64, 0xabcde07, kBigintLimbs, 64);
BENCHMARK_CAPTURE(bench_bigint_shift<false>, shift_right_512, 0xabcde08, kBigintLimbs, 512);
BENCHMARK_CAPTURE(bench_bigint_decimal_to_string, decimal_to_string_100, decimal_100_value);
BENCHMARK_CAPTURE(bench_bigint_decimal_to_string, decimal_to_string_1000, decimal_1000_value);
BENCHMARK_CAPTURE(bench_bigint_decimal_from_string, decimal_from_string_100, decimal_100_text);
BENCHMARK_CAPTURE(bench_bigint_decimal_from_string, decimal_from_string_1000, decimal_1000_text);
BENCHMARK_CAPTURE(bench_bigint_base81_to_string, base81_to_string_100, base81_100_value);
BENCHMARK_CAPTURE(bench_bigint_base81_to_string, base81_to_string_256, base81_256_value);
BENCHMARK_CAPTURE(bench_bigint_base81_from_string, base81_from_string_100, base81_100_text);
BENCHMARK_CAPTURE(bench_bigint_base81_from_string, base81_from_string_256, base81_256_text);
BENCHMARK_CAPTURE(bench_bigint_pow, bigint_pow_128, 0xfeedc0de, kBigintLimbs, 128);
BENCHMARK_CAPTURE(bench_bigint_pow, bigint_pow_512, 0xfeedc0df, kBigintLimbs, 512);
BENCHMARK_CAPTURE(
bench_bigint_pow_large, bigint_pow_large, 0xfeedc0d2, kLargeBigintLimbs, kLargePowExponent);
BENCHMARK_CAPTURE(bench_bigint_gcd, bigint_gcd_small, 0xc0deba5e, kBigintLimbs);
BENCHMARK_CAPTURE(bench_bigint_gcd_large, bigint_gcd_large, 0xc0deba5f, kLargeBigintLimbs);
BENCHMARK_CAPTURE(bench_bigint_serialization, bigint_serialize_small, 0xbaadc0de, kBigintLimbs);
BENCHMARK_CAPTURE(bench_random_bigint, random_bigint_small, 0xfeedf00d, kBigintLimbs);
const t81::core::bigint mont_modulus = t81::core::bigint(197);
const t81::core::bigint mont_modulus_large = large_bigint_value;
BENCHMARK_CAPTURE(bench_montgomery_mul, montgomery_mul_small, 0xdeadbeef, mont_modulus);
BENCHMARK_CAPTURE(bench_montgomery_mul_large, montgomery_mul_large, 0xdeadface, mont_modulus_large);
BENCHMARK_MAIN();