LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
mul_1.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 "limb_sizes.h"
24
25static double bench_mul_1(mp_size_t n, const bench_options *o) {
26 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n + 1);
27 fill_random(a, n, 0x0a0b0c0d0e0f0102ull + n);
28 mp_limb_t x = 0x9e3779b97f4a7c15ull;
29 double us;
30 BENCH_MEASURE(us, o, bench_sink += lmmp_mul_1_(d, a, n, x););
31 lmmp_free(a);
32 lmmp_free(d);
33 return us;
34}
35
36static double bench_addmul_1(mp_size_t n, const bench_options *o) {
37 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n + 1);
38 fill_random(a, n, 0x1112131415161718ull + n);
39 fill_random(d, n, 0x2122232425262728ull + n);
40 mp_limb_t x = 0x9e3779b97f4a7c15ull;
41 double us;
42 BENCH_MEASURE(us, o, bench_sink += lmmp_addmul_1_(d, a, n, x););
43 lmmp_free(a);
44 lmmp_free(d);
45 return us;
46}
47
48static double bench_submul_1(mp_size_t n, const bench_options *o) {
49 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n + 1);
50 fill_random(a, n, 0x3132333435363738ull + n);
51 fill_random(d, n, 0x4142434445464748ull + n);
52 mp_limb_t x = 0x9e3779b97f4a7c15ull;
53 double us;
54 BENCH_MEASURE(us, o, bench_sink += lmmp_submul_1_(d, a, n, x););
55 lmmp_free(a);
56 lmmp_free(d);
57 return us;
58}
59
60int main(void) {
61 setvbuf(stdout, NULL, _IONBF, 0);
63 puts("[lmmpn/mul_1]");
64 run_limb_sizes("mul_1", bench_mul_1);
65 run_limb_sizes("addmul_1", bench_addmul_1);
66 run_limb_sizes("submul_1", bench_submul_1);
68 return 0;
69}
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)
全局初始化函数(线程局部的)
uint64_t mp_limb_t
定义 lmmp.h:92
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
mp_limb_t lmmp_addmul_1_(mp_ptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t b)
乘以单limb并累加操作 [numa,n] += [numb,n] * b
定义 mul_1.c:76
mp_limb_t lmmp_mul_1_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_limb_t x)
乘以单limb操作 [dst,na] = [numa,na] * x
定义 mul_1.c:27
mp_limb_t lmmp_submul_1_(mp_ptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t b)
乘以单limb并累减操作 [numa,n] -= [numb,n] * b
#define n
static double bench_addmul_1(mp_size_t n, const bench_options *o)
定义 mul_1.c:36
static double bench_mul_1(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 mul_1.c:25
static double bench_submul_1(mp_size_t n, const bench_options *o)
定义 mul_1.c:48
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93