LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
mullo.c
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK (Jericho Knox)
3 *
4 * This file is part of LMMP.
5 *
6 * LMMP is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <https://www.gnu.org/licenses/>.
19 *
20 * SPDX-License-Identifier: LGPL-3.0-or-later
21 */
22
23#include "support/perf.h"
24#include "lmmp/lmmpn.h"
25
27 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n);
28 fill_random(a, n, 0x0f0e0d0c0b0a0908ull + n);
29 fill_random(b, n, 0x0102030405060708ull + n);
30 double us;
31 BENCH_MEASURE(us, o, lmmp_mullo_basecase_(d, a, b, n); bench_sink += d[0];);
32 lmmp_free(a);
33 lmmp_free(b);
34 lmmp_free(d);
35 return us;
36}
37
38static double bench_mullo(mp_size_t n, const bench_options *o) {
39 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n);
40 fill_random(a, n, 0x120e3489bc7ull + n);
41 fill_random(b, n, 0x92cab5432217ull + n * 3);
42 double us;
43 BENCH_MEASURE(us, o, lmmp_mullo_(d, a, b, n););
44 lmmp_free(a);
45 lmmp_free(b);
46 lmmp_free(d);
47 return us;
48}
49
50static double bench_mullo_dc(mp_size_t n, const bench_options *o) {
51 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n), tp = alloc_limbs(2 * n);
52 fill_random(a, n, 0x120e3489bc8ull + n);
53 fill_random(b, n, 0x92cab5432218ull + n * 3);
54 double us;
55 BENCH_MEASURE(us, o, lmmp_mullo_dc_(d, a, b, tp, n););
56 lmmp_free(a);
57 lmmp_free(b);
58 lmmp_free(d);
60 return us;
61}
62
63static double bench_mullo_fft(mp_size_t n, const bench_options *o) {
64 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n), tp = alloc_limbs(2 * n);
65 fill_random(a, n, 0x120e3489bc9ull + n);
66 fill_random(b, n, 0x92cab5432219ull + n * 3);
67 double us;
68 BENCH_MEASURE(us, o, lmmp_mullo_fft_(d, a, b, n, tp););
69 lmmp_free(a);
70 lmmp_free(b);
71 lmmp_free(d);
73 return us;
74}
75
76static void run_mullo(void) {
77 const mp_size_t BC[] = {20, 100};
78 const mp_size_t SZ[] = {50, 500, 2000};
79 for (size_t i = 0; i < ARRAY_SIZE(BC); ++i) {
80 mp_size_t n = BC[i];
81 report_n("mullo_basecase", n, bench_mullo_basecase(n, &bench_default), n * n * 8.0);
82 }
83 for (size_t i = 0; i < ARRAY_SIZE(SZ); ++i) {
84 mp_size_t n = SZ[i];
85 report_n("mullo", n, bench_mullo(n, &bench_default), n * n * 8.0);
86 }
87 for (size_t i = 0; i < ARRAY_SIZE(SZ); ++i) {
88 mp_size_t n = SZ[i];
89 report_n("mullo_dc", n, bench_mullo_dc(n, &bench_default), n * n * 8.0);
90 }
91 for (size_t i = 0; i < ARRAY_SIZE(SZ); ++i) {
92 mp_size_t n = SZ[i];
93 report_n("mullo_fft", n, bench_mullo_fft(n, &bench_default), n * n * 8.0);
94 }
95}
96
97int main(void) {
98 setvbuf(stdout, NULL, _IONBF, 0);
100 puts("[lmmpn/mullo/mullo]");
101 run_mullo();
102 puts("[lmmpn/mullo/basecase]");
103 const mp_size_t LO[] = {50, 200};
104 for (size_t i = 0; i < ARRAY_SIZE(LO); ++i) {
105 mp_size_t n = LO[i];
106 report_n("mullo_basecase", n, bench_mullo_basecase(n, &bench_default), 0);
107 }
109 return 0;
110}
int main(void)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 main.c:26
mp_limb_t * mp_ptr
定义 lmmp.h:96
uint64_t mp_size_t
定义 lmmp.h:93
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
void lmmp_global_init(void)
全局初始化函数(线程局部的)
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
void lmmp_mullo_dc_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_ptr tp, mp_size_t n)
低位乘法 [dst,n] = [numa,n] * [numb,n] mod B^n
void lmmp_mullo_basecase_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
基础低位乘法 [dst,n] = [numa,n] * [numb,n] mod B^n
void lmmp_mullo_fft_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_ptr scratch)
低位FFT乘法 [dst,n] = [numa,n] * [numb,n] mod B^n
定义 mullo.c:68
void lmmp_mullo_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
低位乘法 [dst,n] = [numa,n] * [numb,n] mod B^n
#define tp
#define n
static double bench_mullo_dc(mp_size_t n, const bench_options *o)
定义 mullo.c:50
static double bench_mullo(mp_size_t n, const bench_options *o)
定义 mullo.c:38
static void run_mullo(void)
定义 mullo.c:76
static double bench_mullo_fft(mp_size_t n, const bench_options *o)
定义 mullo.c:63
static double bench_mullo_basecase(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 mullo.c:26
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 perf.h:40
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93