LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
gcd.c 文件参考
#include "support/perf.h"
#include "lmmp/lmmpn.h"
#include "lmmp/numth.h"
gcd.c 的引用(Include)关系图:

浏览该文件的源代码.

函数

static double bench_gcd_hgcd (mp_size_t n, const bench_options *o)
static double bench_gcd_lehmer (mp_size_t n, const bench_options *o)
 Copyright (C) 2026 HJimmyK (Jericho Knox)
int main (void)
static void run_hgcd (void)
static void run_lehmer (void)

函数说明

◆ bench_gcd_hgcd()

double bench_gcd_hgcd ( mp_size_t n,
const bench_options * o )
static

在文件 gcd.c 第 44 行定义.

44 {
45 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n);
46 fill_random(a, n, 0x120e3489bce1ull + n);
47 fill_random(b, n, 0x92cab5432211ull + n * 3);
48 a[n - 1] |= (mp_limb_t)1 << 63;
49 b[n - 1] >>= 1;
50 if (b[n - 1] == 0) b[n - 1] = 1;
51 a[0] |= 1;
52 b[0] |= 1; /* 契约:输入须归一化且 un>=vn */
53 double us;
54 BENCH_MEASURE(us, o, bench_sink += (mp_limb_t)lmmp_gcd_hgcd_(d, a, n, b, n););
55 lmmp_free(a);
56 lmmp_free(b);
57 lmmp_free(d);
58 return us;
59}
mp_limb_t * mp_ptr
定义 lmmp.h:96
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
uint64_t mp_limb_t
定义 lmmp.h:92
#define n
mp_size_t lmmp_gcd_hgcd_(mp_ptr dst, mp_srcptr up, mp_size_t un, mp_srcptr vp, mp_size_t vn)
计算两个无符号整数的最大公约数(hgcd 分治,长输入优选)
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93

引用了 bench_gcd_hgcd(), BENCH_MEASURE, lmmp_free(), lmmp_gcd_hgcd_() , 以及 n.

被这些函数引用 bench_gcd_hgcd() , 以及 run_hgcd().

函数调用图:
这是这个函数的调用关系图:

◆ bench_gcd_lehmer()

double bench_gcd_lehmer ( mp_size_t n,
const bench_options * o )
static

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 gcd.c 第 27 行定义.

27 {
28 mp_ptr a = alloc_limbs(n), b = alloc_limbs(n), d = alloc_limbs(n);
29 fill_random(a, n, 0x120bce34ba89eull + n);
30 fill_random(b, n, 0x2cab5423322191ull + n * 3);
31 a[n - 1] |= (mp_limb_t)1 << 63;
32 b[n - 1] >>= 1;
33 if (b[n - 1] == 0) b[n - 1] = 1;
34 a[0] |= 1;
35 b[0] |= 1; /* 契约:输入须归一化(顶 limb 非零)且 a>=b */
36 double us;
37 BENCH_MEASURE(us, o, bench_sink += (mp_limb_t)lmmp_gcd_lehmer_(d, a, n, b, n););
38 lmmp_free(a);
39 lmmp_free(b);
40 lmmp_free(d);
41 return us;
42}
mp_size_t lmmp_gcd_lehmer_(mp_ptr dst, mp_srcptr up, mp_size_t un, mp_srcptr vp, mp_size_t vn)
计算两个无符号整数的最大公约数(Lehmer算法)

引用了 bench_gcd_lehmer(), BENCH_MEASURE, lmmp_free(), lmmp_gcd_lehmer_() , 以及 n.

被这些函数引用 bench_gcd_lehmer() , 以及 run_lehmer().

函数调用图:
这是这个函数的调用关系图:

◆ main()

int main ( void )

在文件 gcd.c 第 77 行定义.

77 {
78 setvbuf(stdout, NULL, _IONBF, 0);
80 puts("[numth/gcd/lehmer]");
81 run_lehmer();
82 puts("[numth/gcd/hgcd]");
83 run_hgcd();
85 return 0;
86}
void lmmp_global_init(void)
全局初始化函数(线程局部的)
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
static void run_lehmer(void)
定义 gcd.c:61
static void run_hgcd(void)
定义 gcd.c:69

引用了 lmmp_global_deinit(), lmmp_global_init(), main(), run_hgcd() , 以及 run_lehmer().

函数调用图:

◆ run_hgcd()

void run_hgcd ( void )
static

在文件 gcd.c 第 69 行定义.

69 {
70 const mp_size_t SZ[] = {64, 1000, 5000, 20000};
71 for (size_t i = 0; i < ARRAY_SIZE(SZ); ++i) {
72 mp_size_t n = SZ[i];
73 report_n("gcd_hgcd", n, bench_gcd_hgcd(n, &bench_default), n * 8.0);
74 }
75}
uint64_t mp_size_t
定义 lmmp.h:93
static double bench_gcd_hgcd(mp_size_t n, const bench_options *o)
定义 gcd.c:44
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 perf.h:40

引用了 ARRAY_SIZE, bench_gcd_hgcd(), n , 以及 run_hgcd().

被这些函数引用 main() , 以及 run_hgcd().

函数调用图:
这是这个函数的调用关系图:

◆ run_lehmer()

void run_lehmer ( void )
static

在文件 gcd.c 第 61 行定义.

61 {
62 const mp_size_t SZ[] = {200, 1000, 2000};
63 for (size_t i = 0; i < ARRAY_SIZE(SZ); ++i) {
64 mp_size_t n = SZ[i];
65 report_n("gcd_lehmer", n, bench_gcd_lehmer(n, &bench_default), n * 8.0);
66 }
67}
static double bench_gcd_lehmer(mp_size_t n, const bench_options *o)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 gcd.c:27

引用了 ARRAY_SIZE, bench_gcd_lehmer(), n , 以及 run_lehmer().

被这些函数引用 main() , 以及 run_lehmer().

函数调用图:
这是这个函数的调用关系图: