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

浏览该文件的源代码.

结构体

struct  DivexactCtx
 Copyright (C) 2026 HJimmyK (Jericho Knox) 更多...

函数

static double bench_divexact (mp_size_t nn, mp_size_t dn, const bench_options *o)
static void free_divexact_ctx (const DivexactCtx *c)
int main (void)
static DivexactCtx make_divexact_ctx (mp_size_t nn, mp_size_t dn, mp_limb_t seed)
static void run_narrow (void)
static void run_square (void)
static void run_wide (void)

变量

static const mp_size_t DIVX_NARROW [][2]
static const mp_size_t DIVX_SQUARE [][2]
static const mp_size_t DIVX_WIDE [][2]

结构体说明

◆ DivexactCtx

struct DivexactCtx

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

在文件 divexact.c 第 36 行定义.

DivexactCtx 的协作图:
成员变量
mp_ptr d
mp_ptr dst
mp_ptr np
mp_ptr q
mp_size_t qa
mp_size_t qn

函数说明

◆ bench_divexact()

double bench_divexact ( mp_size_t nn,
mp_size_t dn,
const bench_options * o )
static

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

77 {
78 DivexactCtx c = make_divexact_ctx(nn, dn, 0x9e3779b97f4a7c15ull + (mp_limb_t)nn * 31 + dn);
79 double us;
80 BENCH_MEASURE(us, o, lmmp_divexact_(c.dst, c.np, nn, c.d, dn); bench_sink += c.dst[0];);
82 return us;
83}
uint64_t mp_limb_t
定义 lmmp.h:92
void lmmp_divexact_(mp_ptr dst, mp_srcptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn)
精确除法([dst,nn]=[np,nn]/[dp,dn],且余数必须为0)
static DivexactCtx make_divexact_ctx(mp_size_t nn, mp_size_t dn, mp_limb_t seed)
static void free_divexact_ctx(const DivexactCtx *c)
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define BENCH_MEASURE(result, options,...)
定义 perf.h:93

引用了 bench_divexact(), BENCH_MEASURE, DivexactCtx::d, DivexactCtx::dst, free_divexact_ctx(), lmmp_divexact_(), make_divexact_ctx() , 以及 DivexactCtx::np.

被这些函数引用 bench_divexact(), run_narrow(), run_square() , 以及 run_wide().

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

◆ free_divexact_ctx()

void free_divexact_ctx ( const DivexactCtx * c)
static

在文件 divexact.c 第 70 行定义.

70 {
71 lmmp_free(c->q);
72 lmmp_free(c->d);
73 lmmp_free(c->np);
74 lmmp_free(c->dst);
75}
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)

引用了 DivexactCtx::d, DivexactCtx::dst, free_divexact_ctx(), lmmp_free(), DivexactCtx::np , 以及 DivexactCtx::q.

被这些函数引用 bench_divexact() , 以及 free_divexact_ctx().

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

◆ main()

int main ( void )

在文件 divexact.c 第 121 行定义.

121 {
122 setvbuf(stdout, NULL, _IONBF, 0);
124 puts("[numth/divexact/wide]");
125 run_wide();
126 puts("[numth/divexact/square]");
127 run_square();
128 puts("[numth/divexact/narrow]");
129 run_narrow();
131 return 0;
132}
void lmmp_global_init(void)
全局初始化函数(线程局部的)
void lmmp_global_deinit(void)
全局释放函数(线程局部的)
static void run_wide(void)
static void run_square(void)
static void run_narrow(void)

引用了 lmmp_global_deinit(), lmmp_global_init(), main(), run_narrow(), run_square() , 以及 run_wide().

函数调用图:

◆ make_divexact_ctx()

DivexactCtx make_divexact_ctx ( mp_size_t nn,
mp_size_t dn,
mp_limb_t seed )
static

在文件 divexact.c 第 45 行定义.

45 {
47 c.qn = nn - dn + 1;
48 c.qa = c.qn - 1;
49 c.q = alloc_limbs(c.qa);
50 c.d = alloc_limbs(dn);
51 c.np = alloc_limbs(nn);
52 c.dst = alloc_limbs(c.qn + 1);
53 lmmp_seed_random_(c.q, c.qa, seed, 1);
54 lmmp_seed_random_(c.d, dn, seed * 3 + 1, 1);
55 c.d[0] |= 1;
56 /* lmmp_mul_ 要求 na >= nb:窄窗形态商短于除数,需交换 */
57 if (c.qa >= dn)
58 lmmp_mul_(c.np, c.q, c.qa, c.d, dn);
59 else
60 lmmp_mul_(c.np, c.d, dn, c.q, c.qa);
61 c.dst[c.qn] = 0x5eed5eed5eed5eedull;
62 lmmp_divexact_(c.dst, c.np, nn, c.d, dn);
63 if (memcmp(c.dst, c.q, (size_t)c.qa * sizeof(mp_limb_t)) != 0 || c.dst[c.qa] != 0) {
64 printf("divexact bench: WRONG QUOTIENT at nn=%lld dn=%lld\n", (long long)nn,
65 (long long)dn);
66 }
67 return c;
68}
void lmmp_mul_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_srcptr numb, mp_size_t nb)
不等长乘法操作 [dst,na+nb] = [numa,na] * [numb,nb]
mp_size_t lmmp_seed_random_(mp_ptr dst, mp_size_t n, mp_limb_t seed, unsigned seed_type)
生成随机大整数(0 - B^n-1 均匀分布)
mp_size_t qa
mp_size_t qn

引用了 DivexactCtx::d, DivexactCtx::dst, lmmp_divexact_(), lmmp_mul_(), lmmp_seed_random_(), make_divexact_ctx(), DivexactCtx::np, DivexactCtx::q, DivexactCtx::qa , 以及 DivexactCtx::qn.

被这些函数引用 bench_divexact() , 以及 make_divexact_ctx().

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

◆ run_narrow()

void run_narrow ( void )
static

在文件 divexact.c 第 114 行定义.

114 {
115 for (size_t i = 0; i < ARRAY_SIZE(DIVX_NARROW); ++i) {
116 const mp_size_t * sz = DIVX_NARROW[i];
117 report_ab("divexact narrow nn,dn", sz[0], sz[1], bench_divexact(sz[0], sz[1], &bench_default), 0);
118 }
119}
uint64_t mp_size_t
定义 lmmp.h:93
static double bench_divexact(mp_size_t nn, mp_size_t dn, const bench_options *o)
static const mp_size_t DIVX_NARROW[][2]
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 perf.h:40

引用了 ARRAY_SIZE, bench_divexact(), DIVX_NARROW , 以及 run_narrow().

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

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

◆ run_square()

void run_square ( void )
static

在文件 divexact.c 第 107 行定义.

107 {
108 for (size_t i = 0; i < ARRAY_SIZE(DIVX_SQUARE); ++i) {
109 const mp_size_t * sz = DIVX_SQUARE[i];
110 report_ab("divexact square nn,dn", sz[0], sz[1], bench_divexact(sz[0], sz[1], &bench_default), 0);
111 }
112}
static const mp_size_t DIVX_SQUARE[][2]

引用了 ARRAY_SIZE, bench_divexact(), DIVX_SQUARE , 以及 run_square().

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

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

◆ run_wide()

void run_wide ( void )
static

在文件 divexact.c 第 100 行定义.

100 {
101 for (size_t i = 0; i < ARRAY_SIZE(DIVX_WIDE); ++i) {
102 const mp_size_t * sz = DIVX_WIDE[i];
103 report_ab("divexact wide nn,dn", sz[0], sz[1], bench_divexact(sz[0], sz[1], &bench_default), 0);
104 }
105}
static const mp_size_t DIVX_WIDE[][2]

引用了 ARRAY_SIZE, bench_divexact(), DIVX_WIDE , 以及 run_wide().

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

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

变量说明

◆ DIVX_NARROW

const mp_size_t DIVX_NARROW[][2]
static
初始值:
= {
{24, 16}, {48, 32}, {64, 48}, {72, 48},
}

在文件 divexact.c 第 96 行定义.

被这些函数引用 run_narrow().

◆ DIVX_SQUARE

const mp_size_t DIVX_SQUARE[][2]
static
初始值:
= {
{8, 4}, {16, 8}, {32, 16}, {64, 32}, {96, 48},
}

在文件 divexact.c 第 91 行定义.

被这些函数引用 run_square().

◆ DIVX_WIDE

const mp_size_t DIVX_WIDE[][2]
static
初始值:
= {
{16, 3}, {32, 6}, {64, 12}, {128, 24}, {256, 48}, {512, 48},
}

在文件 divexact.c 第 86 行定义.

被这些函数引用 run_wide().