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

浏览该文件的源代码.

函数

mp_limb_t lmmp_div_basecase_ (mp_ptr restrict dstq, mp_ptr restrict numa, mp_size_t na, mp_srcptr restrict numb, mp_size_t nb, mp_limb_t inv21)
 Copyright (C) 2026 HJimmyK (Jericho Knox)

函数说明

◆ lmmp_div_basecase_()

mp_limb_t lmmp_div_basecase_ ( mp_ptr restrict dstq,
mp_ptr restrict numa,
mp_size_t na,
mp_srcptr restrict numb,
mp_size_t nb,
mp_limb_t inv21 )

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

在文件 div_basecase.c 第 28 行定义.

35 {
36 lmmp_param_assert(na >= nb);
37 lmmp_param_assert(nb >= 3);
38 lmmp_param_assert(dstq != NULL && numa != NULL && numb != NULL);
40 mp_size_t nq = na - nb;
41
42 numa += na;
43
44 mp_limb_t qh = lmmp_cmp_(numa - nb, numb, nb) >= 0;
45 if (qh) {
46 lmmp_sub_n_(numa - nb, numa - nb, numb, nb);
47 }
48
49 nb -= 2;
50 numa -= 2;
51
52 mp_limb_t d1 = numb[nb + 1], d0 = numb[nb + 0];
53 mp_limb_t rh = numa[1], rl = numa[0];
54
55 while (nq) {
56 mp_limb_t q;
57 --numa;
58 if (rh == d1 && rl == d0) {
59 q = LIMB_MAX;
60 numa[1] = rl;
61 lmmp_submul_1_(numa - nb, numb, nb + 2, q);
62 rh = numa[1];
63 rl = numa[0];
64 } else {
65 mp_limb_t cy, cy1, r0, r1, n0 = numa[0];
66 _udiv_qr_3by2(q, r1, r0, rh, rl, n0, d1, d0, inv21);
67 cy = lmmp_submul_1_(numa - nb, numb, nb, q);
68 cy1 = r0 < cy;
69 r0 -= cy;
70 cy = r1 < cy1;
71 r1 -= cy1;
72 if (cy) {
73 numa[0] = r0;
74 numa[1] = r1;
75 lmmp_add_n_(numa - nb, numa - nb, numb, nb + 2);
76 rh = numa[1];
77 rl = numa[0];
78 --q;
79 } else {
80 rh = r1;
81 rl = r0;
82 }
83 }
84 dstq[--nq] = q;
85 }
86 numa[1] = rh;
87 numa[0] = rl;
88 return qh;
89}
#define LIMB_B_2
uint64_t mp_size_t
定义 lmmp.h:93
#define LIMB_MAX
定义 lmmp.h:105
uint64_t mp_limb_t
定义 lmmp.h:92
#define lmmp_param_assert(x)
定义 lmmp.h:509
int lmmp_cmp_(mp_srcptr numa, mp_srcptr numb, mp_size_t n)
比较函数
定义 cmp.c:26
mp_limb_t lmmp_submul_1_(mp_ptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t b)
乘以单limb并累减操作 [numa,n] -= [numb,n] * b
mp_limb_t lmmp_sub_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
无借位的n位减法 [dst,n] = [numa,n] - [numb,n]
定义 sub_n.c:84
mp_limb_t lmmp_add_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
无进位的n位加法 [dst,n] = [numa,n] + [numb,n]
定义 add_n.c:76
#define _udiv_qr_3by2(q, r1, r0, n2, n1, n0, d1, d0, dinv)
#define r1
#define r0
#define numb

引用了 _udiv_qr_3by2, LIMB_B_2, LIMB_MAX, lmmp_add_n_(), lmmp_cmp_(), lmmp_div_basecase_(), lmmp_param_assert, lmmp_sub_n_(), lmmp_submul_1_(), numb, r0, r1 , 以及 restrict.

函数调用图: