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

浏览该文件的源代码.

宏定义

#define b1   base
#define b1n   n
#define mul_b(_i_)
 Copyright (C) 2026 HJimmyK (Jericho Knox)

函数

mp_size_t lmmp_pow_basecase_ (mp_ptr restrict dst, mp_size_t rn, mp_srcptr restrict base, mp_size_t n, ulong exp)

宏定义说明

◆ b1

#define b1   base

◆ b1n

#define b1n   n

◆ mul_b

#define mul_b ( _i_)
值:
lmmp_mul_(dst, sq, rn, b##_i_, b##_i_##n); \
rn += b##_i_##n; \
rn -= (dst[rn - 1] == 0) ? 1 : 0
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]
#define n

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

在文件 pow_basecase.c 第 30 行定义.

函数说明

◆ lmmp_pow_basecase_()

mp_size_t lmmp_pow_basecase_ ( mp_ptr restrict dst,
mp_size_t rn,
mp_srcptr restrict base,
mp_size_t n,
ulong exp )

在文件 pow_basecase.c 第 35 行定义.

35 {
36 lmmp_param_assert(exp >= 3);
37 lmmp_param_assert(exp % 2 == 1);
39
40#define b1 base
41#define b1n n
43 rn = n;
44 lmmp_copy(dst, base, n);
45 lmmp_sqr_(sq, dst, rn);
46 rn <<= 1;
47 rn -= (sq[rn - 1] == 0) ? 1 : 0;
48 int lz = lmmp_leading_zeros_(exp);
49 int i = 62 - lz;
50 exp <<= lz + 1;
51/*
52 For the intermediate 0, we will skip it entirely until the next 1,
53 and then perform a multiplication. This can reduce the extra copying
54 caused by sparse 1s and improve efficiency.
55 */
56 for ( ; i > 0; ) {
57 lz = lmmp_leading_zeros_(exp);
58 if (lz == 0) {
59 mul_b(1);
60
61 lmmp_sqr_(sq, dst, rn);
62 rn <<= 1;
63 rn -= (sq[rn - 1] == 0) ? 1 : 0;
64 --i;
65 exp <<= 1;
66 } else {
67 int j = 2;
68 if (lz & 1) {
69 lmmp_copy(dst, sq, rn);
70 lmmp_sqr_(sq, dst, rn);
71 rn <<= 1;
72 rn -= (sq[rn - 1] == 0);
73 ++j;
74 for (; j <= lz; j += 2) {
75 lmmp_sqr_(dst, sq, rn);
76 rn <<= 1;
77 rn -= (dst[rn - 1] == 0);
78 lmmp_sqr_(sq, dst, rn);
79 rn <<= 1;
80 rn -= (sq[rn - 1] == 0);
81 }
82 } else {
83 for (; j <= lz; j += 2) {
84 lmmp_sqr_(dst, sq, rn);
85 rn <<= 1;
86 rn -= (dst[rn - 1] == 0);
87 lmmp_sqr_(sq, dst, rn);
88 rn <<= 1;
89 rn -= (sq[rn - 1] == 0);
90 }
91 }
92
93 i -= lz;
94 exp <<= lz;
95 }
96 }
98
99 mul_b(1);
100
101 TEMP_FREE;
102 return rn;
103
104#undef b1
105#undef b1n
106#undef new_b
107}
#define lmmp_leading_zeros_
#define lmmp_sqr_
#define LIMB_B_2
mp_limb_t * mp_ptr
定义 lmmp.h:96
#define lmmp_copy(dst, src, n)
定义 lmmp.h:474
#define lmmp_debug_assert(x)
定义 lmmp.h:498
uint64_t mp_limb_t
定义 lmmp.h:92
#define lmmp_param_assert(x)
定义 lmmp.h:509
#define mul_b(i)
#define restrict
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define TEMP_DECL
#define TEMP_FREE
#define TALLOC_TYPE(n, type)

引用了 LIMB_B_2, lmmp_copy, lmmp_debug_assert, lmmp_leading_zeros_, lmmp_param_assert, lmmp_pow_basecase_(), lmmp_sqr_, mul_b, n, restrict, TALLOC_TYPE, TEMP_DECL , 以及 TEMP_FREE.

函数调用图: