LMMP
4.3.0
Lamina High-Precision Arithmetic Library
Toggle main menu visibility
载入中...
搜索中...
未找到
div_2.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
26
static
double
bench_div_2
(
mp_size_t
n
,
const
bench_options
*o) {
27
mp_ptr
a = alloc_limbs(
n
), q = alloc_limbs(
n
+ 1), b = alloc_limbs(2), bw = alloc_limbs(2);
28
fill_random(a,
n
, 0x2718281828459045ull +
n
);
29
b[1] = 0x9e3779b97f4a7c15ull |
LIMB_B_2
;
30
b[0] = 0x3141592653589793ull;
31
double
us;
32
BENCH_MEASURE
(us, o,
33
bw[0] = b[0];
34
bw[1] = b[1];
35
lmmp_div_2_
(q, a,
n
, bw);
36
bench_sink += q[0];
37
);
38
lmmp_free
(a);
39
lmmp_free
(q);
40
lmmp_free
(b);
41
lmmp_free
(bw);
42
return
us;
43
}
44
45
static
double
bench_div_2_s
(
mp_size_t
n
,
const
bench_options
*o) {
46
if
(
n
< 3)
return
0.0;
/* 除数为两个 limb 时要求 n >= 3 */
47
mp_ptr
a = alloc_limbs(
n
), q = alloc_limbs(
n
+ 1), b = alloc_limbs(2);
48
fill_random(a,
n
, 0x2718281828459046ull +
n
);
49
b[1] = 0x9e3779b97f4a7c15ull |
LIMB_B_2
;
50
b[0] = 0x3141592653589793ull;
51
double
us;
52
BENCH_MEASURE
(us, o,
53
mp_limb_t
s0 = a[0], s1 = a[1];
54
bench_sink +=
lmmp_div_2_s_
(q, a,
n
, b);
55
a[0] = s0;
56
a[1] = s1;
57
);
58
lmmp_free
(a);
59
lmmp_free
(q);
60
lmmp_free
(b);
61
return
us;
62
}
63
64
static
double
bench_mod_2
(
mp_size_t
n
,
const
bench_options
*o) {
65
mp_ptr
a = alloc_limbs(
n
), b = alloc_limbs(2), bw = alloc_limbs(2);
66
fill_random(a,
n
, 0x0badf00dcafefaceull +
n
);
67
b[1] = 0x9e3779b97f4a7c15ull |
LIMB_B_2
;
68
b[0] = 0x3141592653589793ull;
69
double
us;
70
BENCH_MEASURE
(us, o,
71
bw[0] = b[0];
72
bw[1] = b[1];
73
lmmp_mod_2_
(a,
n
, bw);
74
bench_sink += bw[0];
75
);
76
lmmp_free
(a);
77
lmmp_free
(b);
78
lmmp_free
(bw);
79
return
us;
80
}
81
82
int
main
(
void
) {
83
setvbuf(stdout, NULL, _IONBF, 0);
84
lmmp_global_init
();
85
puts(
"[lmmpn/div_2]"
);
86
run_limb_sizes(
"div_2"
,
bench_div_2
);
87
run_limb_sizes(
"div_2_s"
,
bench_div_2_s
);
88
run_limb_sizes(
"mod_2"
,
bench_mod_2
);
89
lmmp_global_deinit
();
90
return
0;
91
}
bench_div_2_s
static double bench_div_2_s(mp_size_t n, const bench_options *o)
定义
div_2.c:45
bench_div_2
static double bench_div_2(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义
div_2.c:26
bench_mod_2
static double bench_mod_2(mp_size_t n, const bench_options *o)
定义
div_2.c:64
limb_sizes.h
LIMB_B_2
#define LIMB_B_2
定义
mparam.h:40
main
int main(void)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义
main.c:26
mp_ptr
mp_limb_t * mp_ptr
定义
lmmp.h:96
mp_size_t
uint64_t mp_size_t
定义
lmmp.h:93
lmmp_free
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
定义
memory.c:437
lmmp_global_init
void lmmp_global_init(void)
全局初始化函数(线程局部的)
定义
global.c:58
mp_limb_t
uint64_t mp_limb_t
定义
lmmp.h:92
lmmp_global_deinit
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
定义
global.c:65
lmmp_div_2_
void lmmp_div_2_(mp_ptr dstq, mp_srcptr numa, mp_size_t na, mp_ptr numb)
双精度数除法 (除数为2个limb)
定义
div.c:294
lmmp_mod_2_
void lmmp_mod_2_(mp_srcptr numa, mp_size_t na, mp_ptr numb)
双精度数取余 (除数为2个limb)
定义
div.c:215
lmmp_div_2_s_
mp_limb_t lmmp_div_2_s_(mp_ptr dstq, mp_ptr numa, mp_size_t na, mp_srcptr numb)
双精度数除法(除数为2个limb)
n
#define n
BENCH_MEASURE
#define BENCH_MEASURE(result, options,...)
定义
perf.h:93
bench_options
定义
perf.h:44
src
lmmp
lmmpn
perf
div_2.c
生成于
, 为 LMMP使用
1.18.0