LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
mat22_sqr.c 文件参考
#include "mparam.h"
#include "numth/mat22_mul.h"
#include "support/perf.h"
mat22_sqr.c 的引用(Include)关系图:

浏览该文件的源代码.

类型定义

typedef void(*) sqr_fn(lmmp_mat22_t *, const lmmp_mat22_t *, mp_ptr)
 Copyright (C) 2026 HJimmyK (Jericho Knox)

函数

int main (void)
static bool matrix_equal (const lmmp_mat22_t *a, const lmmp_mat22_t *b)
static lmmp_mat22_t matrix_view (mp_ptr storage, mp_size_t stride)
static double measure_sqr (sqr_fn fn, lmmp_mat22_t *dst, const lmmp_mat22_t *a, mp_ptr scratch)

类型定义说明

◆ sqr_fn

typedef void(*) sqr_fn(lmmp_mat22_t *, const lmmp_mat22_t *, mp_ptr)

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 mat22_sqr.c 第 27 行定义.

函数说明

◆ main()

int main ( void )

在文件 mat22_sqr.c 第 52 行定义.

52 {
53 enum { MIN_N = 8, MAX_N = 80, SAMPLES = 5, OUT_CAP = 2 * MAX_N + 4 };
55 mp_ptr storage = alloc_limbs(4 * MAX_N + 8 * OUT_CAP + 15 * MAX_N + 14);
56 lmmp_mat22_t a = matrix_view(storage, MAX_N);
57 lmmp_mat22_t basecase = matrix_view(storage + 4 * MAX_N, OUT_CAP);
58 lmmp_mat22_t strassen = matrix_view(storage + 4 * MAX_N + 4 * OUT_CAP, OUT_CAP);
59 mp_ptr scratch = storage + 4 * MAX_N + 8 * OUT_CAP;
60
61 printf("Current MAT22_SQR_STRASSEN_THRESHOLD = %u\n", (unsigned)MAT22_SQR_STRASSEN_THRESHOLD);
62 puts("limbs basecase us Strassen us");
63 unsigned streak = 0, crossover = 0;
64 int result = EXIT_SUCCESS;
65
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) {
69 a.n[i][j] = n;
70 fill_random(a.p[i][j], n, 0x2733ba7a11665d4full + 4 * n + 2 * i + j);
71 }
72 }
73
74 lmmp_internal_numth_mat22_sqr_basecase(&basecase, &a, scratch);
75 lmmp_internal_numth_mat22_sqr_strassen(&strassen, &a, scratch);
76 if (!matrix_equal(&basecase, &strassen)) {
77 fprintf(stderr, "Matrix square results differ at %u limbs\n", n);
78 result = EXIT_FAILURE;
79 break;
80 }
81
82 double times_base[SAMPLES], times_strassen[SAMPLES];
83 for (unsigned i = 0; i < SAMPLES; ++i) {
84 if (i % 2 == 0) {
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);
87 } else {
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);
90 }
91 }
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)
97 crossover = n - 2;
98 }
99
100 if (result == EXIT_SUCCESS) {
101 if (crossover)
102 printf("First three consecutive Strassen wins begin at %u limbs\n", crossover);
103 else
104 puts("No three consecutive Strassen wins in the sampled range");
105 }
106 lmmp_free(storage);
108 return result;
109}
mp_limb_t * mp_ptr
定义 lmmp.h:96
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
void lmmp_global_init(void)
全局初始化函数(线程局部的)
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
mp_ptr p[2][2]
mp_size_t n[2][2]
Copyright (C) 2026 HJimmyK (Jericho Knox)
static bool matrix_equal(const lmmp_mat22_t *a, const lmmp_mat22_t *b)
static double measure_sqr(sqr_fn fn, lmmp_mat22_t *dst, const lmmp_mat22_t *a, mp_ptr scratch)
static lmmp_mat22_t matrix_view(mp_ptr storage, mp_size_t stride)
#define n
#define scratch
#define MAT22_SQR_STRASSEN_THRESHOLD
@ BENCH_MEDIAN
定义 perf.h:42
const size_t MAX_N
Copyright (C) 2026 HJimmyK (Jericho Knox)

引用了 BENCH_MEDIAN, lmmp_free(), lmmp_global_deinit(), lmmp_global_init(), main(), MAT22_SQR_STRASSEN_THRESHOLD, matrix_equal(), matrix_view(), MAX_N, measure_sqr(), lmmp_mat22_t::n, n, lmmp_mat22_t::p , 以及 scratch.

函数调用图:

◆ matrix_equal()

bool matrix_equal ( const lmmp_mat22_t * a,
const lmmp_mat22_t * b )
static

在文件 mat22_sqr.c 第 34 行定义.

34 {
35 for (size_t i = 0; i < 2; ++i) {
36 for (size_t j = 0; j < 2; ++j) {
37 mp_size_t n = a->n[i][j];
38 if (n != b->n[i][j] || lmmp_cmp_(a->p[i][j], b->p[i][j], n) != 0)
39 return false;
40 }
41 }
42 return true;
43}
uint64_t mp_size_t
定义 lmmp.h:93
int lmmp_cmp_(mp_srcptr numa, mp_srcptr numb, mp_size_t n)
比较函数
定义 cmp.c:26

引用了 lmmp_cmp_(), matrix_equal(), lmmp_mat22_t::n, n , 以及 lmmp_mat22_t::p.

被这些函数引用 main() , 以及 matrix_equal().

函数调用图:
这是这个函数的调用关系图:

◆ matrix_view()

lmmp_mat22_t matrix_view ( mp_ptr storage,
mp_size_t stride )
static

在文件 mat22_sqr.c 第 29 行定义.

29 {
30 return (lmmp_mat22_t){.p = {{storage, storage + stride},
31 {storage + 2 * stride, storage + 3 * stride}}};
32}

引用了 matrix_view().

被这些函数引用 main() , 以及 matrix_view().

函数调用图:
这是这个函数的调用关系图:

◆ measure_sqr()

double measure_sqr ( sqr_fn fn,
lmmp_mat22_t * dst,
const lmmp_mat22_t * a,
mp_ptr scratch )
static

在文件 mat22_sqr.c 第 45 行定义.

45 {
46 const bench_options options = {BENCH_MIN, 1, 0.001, 0.05, 1ull << 22};
47 double us;
48 BENCH_MEASURE(us, &options, fn(dst, a, scratch););
49 return us;
50}
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93
@ BENCH_MIN
定义 perf.h:42

引用了 BENCH_MEASURE, BENCH_MIN, measure_sqr() , 以及 scratch.

被这些函数引用 main() , 以及 measure_sqr().

函数调用图:
这是这个函数的调用关系图: