LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
shift.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_shl(mp_size_t n, const bench_options *o) {
26 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n);
27 fill_random(a, n, 0x9192939495969798ull + n);
28 double us;
29 BENCH_MEASURE(us, o, bench_sink += lmmp_shl_(d, a, n, 13););
30 lmmp_free(a);
31 lmmp_free(d);
32 return us;
33}
34
35static double bench_shr(mp_size_t n, const bench_options *o) {
36 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n);
37 fill_random(a, n, 0xa1a2a3a4a5a6a7a8ull + n);
38 double us;
39 BENCH_MEASURE(us, o, bench_sink += lmmp_shr_(d, a, n, 13););
40 lmmp_free(a);
41 lmmp_free(d);
42 return us;
43}
44
45static double bench_shlnot(mp_size_t n, const bench_options *o) {
46 mp_ptr a = alloc_limbs(n), d = alloc_limbs(n);
47 fill_random(a, n, 0xb1b2b3b4b5b6b7b8ull + n);
48 double us;
49 BENCH_MEASURE(us, o, bench_sink += lmmp_shlnot_(d, a, n, 13););
50 lmmp_free(a);
51 lmmp_free(d);
52 return us;
53}
54
55int main(void) {
56 setvbuf(stdout, NULL, _IONBF, 0);
58 puts("[lmmpn/shift]");
59 run_limb_sizes("shl", bench_shl);
60 run_limb_sizes("shr", bench_shr);
61 run_limb_sizes("shlnot", bench_shlnot);
63 return 0;
64}
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)
全局释放函数(线程局部的)
mp_limb_t lmmp_shlnot_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shl)
左移后按位取反操作 [dst,na] = ~([numa,na] << shl),dst的低shl位填充1
mp_limb_t lmmp_shr_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr)
右移操作 [dst,na] = [numa,na]>>shr,dst的高shr位填充0
定义 shr.c:26
mp_limb_t lmmp_shl_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shl)
左移操作 [dst,na] = [numa,na]<<shl,dst的低shl位填充0
定义 shl.c:26
#define n
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93
static double bench_shl(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 shift.c:25
static double bench_shlnot(mp_size_t n, const bench_options *o)
定义 shift.c:45
static double bench_shr(mp_size_t n, const bench_options *o)
定义 shift.c:35