LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
div_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#include "mparam.h"
25
26static double bench_div_1(mp_size_t n, const bench_options *o) {
27 mp_ptr a = alloc_limbs(n), q = alloc_limbs(n + 1);
28 fill_random(a, n, 0x0123456789abcdefull + n);
29 mp_limb_t x = 0x9e3779b97f4a7c15ull;
30 double us;
31 BENCH_MEASURE(us, o, bench_sink += lmmp_div_1_(q, a, n, x););
32 lmmp_free(a);
33 lmmp_free(q);
34 return us;
35}
36
37static double bench_div_1_s(mp_size_t n, const bench_options *o) {
38 mp_ptr a = alloc_limbs(n), q = alloc_limbs(n + 1);
39 fill_random(a, n, 0x0123456789abcdf1ull + n);
40 mp_limb_t x = 0x9e3779b97f4a7c15ull | LIMB_B_2;
41 double us;
42 BENCH_MEASURE(us, o,
43 mp_limb_t save = a[0];
44 bench_sink += lmmp_div_1_s_(q, a, n, x);
45 a[0] = save;
46 );
47 lmmp_free(a);
48 lmmp_free(q);
49 return us;
50}
51
52static double bench_mod_1(mp_size_t n, const bench_options *o) {
53 mp_ptr a = alloc_limbs(n);
54 fill_random(a, n, 0x3141592653589793ull + n);
55 mp_limb_t x = 0x9e3779b97f4a7c15ull;
56 double us;
57 BENCH_MEASURE(us, o, bench_sink += lmmp_mod_1_(a, n, x););
58 lmmp_free(a);
59 return us;
60}
61
62int main(void) {
63 setvbuf(stdout, NULL, _IONBF, 0);
65 puts("[lmmpn/div_1]");
66 run_limb_sizes("div_1", bench_div_1);
67 run_limb_sizes("div_1_s", bench_div_1_s);
68 run_limb_sizes("mod_1", bench_mod_1);
70 return 0;
71}
static double bench_mod_1(mp_size_t n, const bench_options *o)
定义 div_1.c:52
static double bench_div_1(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 div_1.c:26
static double bench_div_1_s(mp_size_t n, const bench_options *o)
定义 div_1.c:37
#define LIMB_B_2
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_div_1_s_(mp_ptr dstq, mp_ptr numa, mp_size_t na, mp_limb_t x)
单精度数除法(除数为1个limb)
mp_limb_t lmmp_div_1_(mp_ptr dstq, mp_srcptr numa, mp_size_t na, mp_limb_t x)
单精度数除法
定义 div.c:137
mp_limb_t lmmp_mod_1_(mp_srcptr numa, mp_size_t na, mp_limb_t x)
单精度数取余
定义 div.c:38
#define n
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93