53 enum { MIN_N = 8,
MAX_N = 80, SAMPLES = 5, OUT_CAP = 2 *
MAX_N + 4 };
62 puts(
"limbs basecase us Strassen us");
63 unsigned streak = 0, crossover = 0;
64 int result = EXIT_SUCCESS;
66 for (
unsigned n = MIN_N;
n <=
MAX_N; ++
n) {
67 for (
size_t i = 0; i < 2; ++i) {
68 for (
size_t j = 0; j < 2; ++j) {
70 fill_random(a.
p[i][j],
n, 0x2733ba7a11665d4full + 4 *
n + 2 * i + j);
74 lmmp_internal_numth_mat22_sqr_basecase(&basecase, &a,
scratch);
75 lmmp_internal_numth_mat22_sqr_strassen(&strassen, &a,
scratch);
77 fprintf(stderr,
"Matrix square results differ at %u limbs\n",
n);
78 result = EXIT_FAILURE;
82 double times_base[SAMPLES], times_strassen[SAMPLES];
83 for (
unsigned i = 0; i < SAMPLES; ++i) {
85 times_base[i] =
measure_sqr(lmmp_internal_numth_mat22_sqr_basecase, &basecase, &a,
scratch);
86 times_strassen[i] =
measure_sqr(lmmp_internal_numth_mat22_sqr_strassen, &strassen, &a,
scratch);
88 times_strassen[i] =
measure_sqr(lmmp_internal_numth_mat22_sqr_strassen, &strassen, &a,
scratch);
89 times_base[i] =
measure_sqr(lmmp_internal_numth_mat22_sqr_basecase, &basecase, &a,
scratch);
92 double base_us = bench_aggregate(times_base, SAMPLES,
BENCH_MEDIAN);
93 double strassen_us = bench_aggregate(times_strassen, SAMPLES,
BENCH_MEDIAN);
94 printf(
"%5u %15.4f %15.4f\n",
n, base_us, strassen_us);
95 streak = strassen_us < base_us ? streak + 1 : 0;
96 if (streak == 3 && crossover == 0)
100 if (result == EXIT_SUCCESS) {
102 printf(
"First three consecutive Strassen wins begin at %u limbs\n", crossover);
104 puts(
"No three consecutive Strassen wins in the sampled range");
int main(void)
Copyright (C) 2026 HJimmyK (Jericho Knox)
void(*) sqr_fn(lmmp_mat22_t *, const lmmp_mat22_t *, mp_ptr)
Copyright (C) 2026 HJimmyK (Jericho Knox)