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

浏览该文件的源代码.

函数

mp_limb_t lmmp_shr1add_n_ (mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
 加法后右移1位 [dst,n] = ([numa,n] + [numb,n]) >> 1
mp_limb_t lmmp_shr1add_nc_ (mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
 带进位加法后右移1位 [dst,n] = ([numa,n] + [numb,n] + c) >> 1
mp_limb_t lmmp_shr1sub_n_ (mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
 减法后右移1位 [dst,n] = ([numa,n] - [numb,n]) >> 1
mp_limb_t lmmp_shr1sub_nc_ (mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
 带借位减法后右移1位 [dst,n] = ([numa,n] - [numb,n] - c) >> 1
mp_limb_t lmmp_shr_ (mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr)
 Copyright (C) 2026 HJimmyK (Jericho Knox)
mp_limb_t lmmp_shr_c_ (mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr, mp_limb_t c)
 带进位的右移操作 [dst,na] = [numa,na]>>shr,dst的高shr位填充c的高shr位

函数说明

◆ lmmp_shr1add_n_()

mp_limb_t lmmp_shr1add_n_ ( mp_ptr dst,
mp_srcptr numa,
mp_srcptr numb,
mp_size_t n )

加法后右移1位 [dst,n] = ([numa,n] + [numb,n]) >> 1

参数
dst结果输出指针
numa第一个加数指针
numb第二个加数指针
nlimb长度
警告
n>0, eqsep(dst,[numa|numb]), dst!=NULL, numa!=NULL, numb!=NULL
返回
右移操作产生的进位值 [0|1]

在文件 shr.c 第 65 行定义.

65 {
66 return lmmp_shr1add_nc_(dst, numa, numb, n, 0);
67}
mp_limb_t lmmp_shr1add_nc_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
带进位加法后右移1位 [dst,n] = ([numa,n] + [numb,n] + c) >> 1
定义 shr.c:53
#define numb
#define n

引用了 lmmp_shr1add_n_(), lmmp_shr1add_nc_(), n , 以及 numb.

被这些函数引用 bench_shr1add_n(), lmmp_mul_toom32_(), lmmp_mullh_(), lmmp_shr1add_n_(), lmmp_toom_couple_handling_(), lmmp_toom_interp12_(), lmmp_toom_interp16_(), lmmp_toom_interp5_(), lmmp_toom_interp6_(), lmmp_toom_interp7_() , 以及 TEST_CASE().

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

◆ lmmp_shr1add_nc_()

mp_limb_t lmmp_shr1add_nc_ ( mp_ptr dst,
mp_srcptr numa,
mp_srcptr numb,
mp_size_t n,
mp_limb_t c )

带进位加法后右移1位 [dst,n] = ([numa,n] + [numb,n] + c) >> 1

参数
dst结果输出指针
numa第一个加数指针
numb第二个加数指针
nlimb长度
c初始进位值 [0|1]
警告
n>0, c=[0|1], eqsep(dst,[numa|numb]), dst!=NULL, numa!=NULL, numb!=NULL
返回
右移操作产生的进位值 [0|1]

在文件 shr.c 第 53 行定义.

53 {
54 __uint128_t pr = (__uint128_t)numa[0] + numb[0] + c;
55 mp_limb_t l = (mp_limb_t)pr & 1;
56 for (mp_size_t i = 1; i < n; i++) {
57 __uint128_t cr = (__uint128_t)numa[i] + numb[i] + (mp_limb_t)(pr >> 64);
58 dst[i - 1] = ((mp_limb_t)pr >> 1) | ((mp_limb_t)cr << 63);
59 pr = cr;
60 }
61 dst[n - 1] = ((mp_limb_t)pr >> 1) | ((mp_limb_t)(pr >> 64) << 63);
62 return l;
63}
uint64_t mp_size_t
定义 lmmp.h:93
uint64_t mp_limb_t
定义 lmmp.h:92

引用了 lmmp_shr1add_nc_(), n , 以及 numb.

被这些函数引用 lmmp_mul_fft_crt_(), lmmp_mullh_(), lmmp_mullo_crt_(), lmmp_shr1add_n_(), lmmp_shr1add_nc_(), lmmp_sqr_fft_(), mrs_mul_core_(), mrs_sqr_core_() , 以及 TEST_CASE().

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

◆ lmmp_shr1sub_n_()

mp_limb_t lmmp_shr1sub_n_ ( mp_ptr dst,
mp_srcptr numa,
mp_srcptr numb,
mp_size_t n )

减法后右移1位 [dst,n] = ([numa,n] - [numb,n]) >> 1

参数
dst结果输出指针
numa被减数指针
numb减数指针
n操作数的位数(limb数量)
警告
n>0, eqsep(dst,[numa|numb]), dst!=NULL, numa!=NULL, numb!=NULL
返回
右移操作产生的进位值 (0或1)

在文件 shr.c 第 87 行定义.

87 {
88 return lmmp_shr1sub_nc_(dst, numa, numb, n, 0);
89}
mp_limb_t lmmp_shr1sub_nc_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
带借位减法后右移1位 [dst,n] = ([numa,n] - [numb,n] - c) >> 1
定义 shr.c:69

引用了 lmmp_shr1sub_n_(), lmmp_shr1sub_nc_(), n , 以及 numb.

被这些函数引用 bench_shr1sub_n(), lmmp_mul_toom32_(), lmmp_mullh_(), lmmp_shr1sub_n_(), lmmp_toom_couple_handling_(), lmmp_toom_interp12_(), lmmp_toom_interp16_(), lmmp_toom_interp5_(), lmmp_toom_interp6_(), lmmp_toom_interp7_() , 以及 TEST_CASE().

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

◆ lmmp_shr1sub_nc_()

mp_limb_t lmmp_shr1sub_nc_ ( mp_ptr dst,
mp_srcptr numa,
mp_srcptr numb,
mp_size_t n,
mp_limb_t c )

带借位减法后右移1位 [dst,n] = ([numa,n] - [numb,n] - c) >> 1

参数
dst结果输出指针
numa被减数指针
numb减数指针
nlimb长度
c初始借位值 [0|1]
警告
n>0, c=[0|1], eqsep(dst,[numa|numb]), dst!=NULL, numa!=NULL, numb!=NULL
返回
右移操作产生的进位值 [0|1]

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

69 {
70 mp_limb_t o = numa[0];
71 mp_limb_t u = o - numb[0];
72 mp_limb_t pr = u - c;
73 mp_limb_t d = (u > o) + (pr > u);
74 mp_limb_t l = pr & 1;
75 for (mp_size_t i = 1; i < n; i++) {
76 o = numa[i];
77 u = o - numb[i];
78 mp_limb_t r = u - d;
79 d = (u > o) + (r > u);
80 dst[i - 1] = (pr >> 1) | (r << 63);
81 pr = r;
82 }
83 dst[n - 1] = (pr >> 1) | (d << 63);
84 return l;
85}

引用了 lmmp_shr1sub_nc_(), n , 以及 numb.

被这些函数引用 lmmp_mullh_(), lmmp_shr1sub_n_(), lmmp_shr1sub_nc_() , 以及 TEST_CASE().

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

◆ lmmp_shr_()

mp_limb_t lmmp_shr_ ( mp_ptr dst,
mp_srcptr numa,
mp_size_t na,
mp_size_t shr )

Copyright (C) 2026 HJimmyK (Jericho Knox)

右移操作 [dst,na] = [numa,na]>>shr,dst的高shr位填充0

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

Copyright (C) 2026 HJimmyK (Jericho Knox)

参数
dst结果输出指针
numa源操作数指针
nalimb长度
shr右移的位数 (0~63)
警告
na>0, 0<=shr<64, eqsep(dst,numa), dst!=NULL, numa!=NULL 允许dst指针地址小于numa(即支持原地长移位操作)
返回
其最高shr个比特位填充[numa,na]被移出的shr个最低位,其余比特位为0

在文件 shr.c 第 26 行定义.

26 {
27 if (shr == 0) {
28 lmmp_copy(dst, numa, na);
29 return 0;
30 }
31 const mp_size_t rshr = LIMB_BITS - shr;
32 mp_limb_t retval = numa[0] << rshr;
33 mp_size_t i = 0;
34 for (; i + 1 < na; i++) dst[i] = (numa[i] >> shr) | (numa[i + 1] << rshr);
35 dst[i] = numa[i] >> shr;
36 return retval;
37}
#define lmmp_copy(dst, src, n)
定义 lmmp.h:474
#define LIMB_BITS
定义 lmmp.h:102

引用了 LIMB_BITS, lmmp_copy , 以及 lmmp_shr_().

被这些函数引用 bench_shr(), dec_pow_extend_(), ipn_lucas_i_(), ipn_mont_half_(), ipn_notrial_i_(), lmmp_bninv_(), lmmp_cbrt_(), lmmp_div_(), lmmp_fft_extract_coef_(), lmmp_from_decimal_(), lmmp_gcdext_derive_(), lmmp_invsqrt_newton_(), lmmp_mullh_(), lmmp_nthroot_(), lmmp_powmod_(), lmmp_shr_(), lmmp_sqrt_(), lmmp_sqrt_divide_(), lmmp_sqrt_newton_(), lmmp_to_str_divide_(), lmmp_toom_couple_handling_(), lmmp_toom_interp6_(), lmmp_toom_interp7_(), nthroot_top_limbs_(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE() , 以及 TEST_CASE().

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

◆ lmmp_shr_c_()

mp_limb_t lmmp_shr_c_ ( mp_ptr dst,
mp_srcptr numa,
mp_size_t na,
mp_size_t shr,
mp_limb_t c )

带进位的右移操作 [dst,na] = [numa,na]>>shr,dst的高shr位填充c的高shr位

参数
dst结果输出指针
numa源操作数指针
nalimb长度
shr右移的位数 (0~63)
c进位值(其低(64-shr)位必须为0)
警告
na>0, 0<=shr<64, eqsep(dst,numa), dst!=NULL, numa!=NULL c的低(64-shr)位必须为0 允许dst指针地址小于numa(即支持原地长移位操作)
返回
其最高shr个比特位填充[numa,na]被移出的shr个最低位,其余比特位为0

在文件 shr.c 第 39 行定义.

39 {
40 if (shr == 0) {
41 lmmp_copy(dst, numa, na);
42 return 0;
43 }
44 const mp_size_t rshr = LIMB_BITS - shr;
45 mp_limb_t retval = numa[0] << rshr;
46 mp_size_t i = 0;
47 for (; i + 1 < na; i++) dst[i] = (numa[i] >> shr) | (numa[i + 1] << rshr);
48 c &= ~(((mp_limb_t)1 << rshr) - 1);
49 dst[i] = (numa[i] >> shr) | c;
50 return retval;
51}

引用了 LIMB_BITS, lmmp_copy , 以及 lmmp_shr_c_().

被这些函数引用 lmmp_inv_(), lmmp_mullh_(), lmmp_shr_c_(), TEST_CASE() , 以及 TEST_CASE().

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