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

浏览该文件的源代码.

宏定义

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

函数

mp_size_t lmmp_pow_win2_ (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_)
值:
if (rsq) { \
if (b##_i_##n >= rn) \
lmmp_mul_(dst, b##_i_, b##_i_##n, sq, rn); \
else \
lmmp_mul_(dst, sq, rn, b##_i_, b##_i_##n); \
rn += b##_i_##n; \
rn -= (dst[rn - 1] == 0) ? 1 : 0; \
rsq = false; \
} else { \
if (b##_i_##n >= rn) \
lmmp_mul_(sq, b##_i_, b##_i_##n, dst, rn); \
else \
lmmp_mul_(sq, dst, rn, b##_i_, b##_i_##n); \
rn += b##_i_##n; \
rn -= (sq[rn - 1] == 0) ? 1 : 0; \
rsq = true; \
}
#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_win2.c 第 29 行定义.

◆ new_b

#define new_b ( _i_)
值:
mp_limb_t * mp_ptr
定义 lmmp.h:96
uint64_t mp_limb_t
定义 lmmp.h:92
#define restrict
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define TALLOC_TYPE(n, type)

被这些函数引用 lmmp_pow_win2_().

函数说明

◆ lmmp_pow_win2_()

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

在文件 pow_win2.c 第 48 行定义.

48 {
49 lmmp_param_assert(exp > 0);
51 lmmp_param_assert(dst != NULL);
53
54#define b1 base
55#define b1n n
56#define new_b(_i_) mp_ptr restrict b##_i_ = TALLOC_TYPE(b##_i_##n, mp_limb_t)
57
58 mp_size_t b2n = n << 1, b3n = b2n + n;
59 new_b(2);
60 new_b(3);
61
62 lmmp_sqr_(b2, b1, b1n);
63 b2n = b1n << 1;
64 b2n -= b2[b2n - 1] == 0 ? 1 : 0;
65 lmmp_mul_(b3, b2, b2n, b1, b1n);
66 b3n = b2n + b1n;
67 b3n -= b3[b3n - 1] == 0 ? 1 : 0;
68
69 bool rsq = true;
71 rn = 1;
72 int i = 31, j;
73 while ((exp & (0x3ull << ((i--) * 2))) == 0);
74
75 /*
76 模拟一次,让最后一次计算结果恰好是dst,避免最后一次可能的拷贝
77 */
78 for (j = i + 1; j != -1; --j) {
79 int p = (exp & (0x3ull << (j * 2))) >> (j * 2);
80 if (p != 0)
81 rsq = !rsq;
82 }
83 if (rsq) {
84 dst[0] = 1;
85 rsq = false;
86 } else {
87 sq[0] = 1;
88 rsq = true;
89 }
90
91 for (++i; i != -1; --i) {
92 int p = (exp & (0x3ull << (i * 2))) >> (i * 2);
93 if (p == 0) {
94 ;
95 } else if (p == 1) {
96 mul_b(1)
97 } else if (p == 2) {
98 mul_b(2)
99 } else {
100 mul_b(3)
101 }
102
103 if (i > 0) {
104 if (rsq) {
105 lmmp_sqr_(dst, sq, rn);
106 rn <<= 1;
107 rn -= (dst[rn - 1] == 0) ? 1 : 0;
108 lmmp_sqr_(sq, dst, rn);
109 rn <<= 1;
110 rn -= (sq[rn - 1] == 0) ? 1 : 0;
111 } else {
112 lmmp_sqr_(sq, dst, rn);
113 rn <<= 1;
114 rn -= (sq[rn - 1] == 0) ? 1 : 0;
115 lmmp_sqr_(dst, sq, rn);
116 rn <<= 1;
117 rn -= (dst[rn - 1] == 0) ? 1 : 0;
118 }
119 }
120 }
121 lmmp_debug_assert(rsq == false);
122
123 TEMP_FREE;
124 return rn;
125
126#undef b1
127#undef b1n
128#undef new_b
129}
#define lmmp_sqr_
uint64_t mp_size_t
定义 lmmp.h:93
#define lmmp_debug_assert(x)
定义 lmmp.h:498
#define lmmp_param_assert(x)
定义 lmmp.h:509
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 b1
#define b2
#define b3
#define b2n
#define mul_b(i)
#define b1n
#define new_b(_i_)
#define TEMP_DECL
#define TEMP_FREE
#define BALLOC_TYPE(n, type)

引用了 b1, b1n, b2, b2n, b3, BALLOC_TYPE, lmmp_debug_assert, lmmp_mul_(), lmmp_param_assert, lmmp_pow_win2_(), lmmp_sqr_, mul_b, n, new_b, restrict, TEMP_DECL , 以及 TEMP_FREE.

函数调用图: