LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
shl.c
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK(Jericho Knox)
3 *
4 * This file is part of LAMMP.
5 *
6 * LAMMP is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License (LGPL) as published
8 * by the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed WITHOUT ANY WARRANTY.
12 *
13 * See <https://www.gnu.org/licenses/>.
14 */
15
16#include "../../../../include/lammp/lmmpn.h"
17
18
20 if (shr == 0) {
22 return 0;
23 } else {
24 const mp_limb_t rshr = LIMB_BITS - shr;
27 numa += na;
28 dst += na;
29 low_limb = *--numa;
30 retval = low_limb >> rshr;
31 high_limb = (low_limb << shr);
32 while (--na != 0) {
33 low_limb = *--numa;
34 *--dst = high_limb | (low_limb >> rshr);
35 high_limb = (low_limb << shr);
36 }
37 *--dst = high_limb;
38 return retval;
39 }
40}
41
43 if (shr == 0) {
45 return 0;
46 } else {
47 const mp_limb_t rshr = LIMB_BITS - shr;
50 numa += na;
51 dst += na;
52 low_limb = *--numa;
53 retval = low_limb >> rshr;
54 high_limb = (low_limb << shr);
55 while (--na != 0) {
56 low_limb = *--numa;
57 *--dst = high_limb | (low_limb >> rshr);
58 high_limb = (low_limb << shr);
59 }
60 c &= ((mp_limb_t)1 << shr) - 1;
61 *--dst = high_limb | c;
62 return retval;
63 }
64}
65
67 mp_size_t i, c = 0, mb = 0;
68
69 for (i = 0; i < n; i++) {
70 mp_limb_t a, b, r;
71 a = numa[i];
72 b = (numb[i] << 1) + mb;
73 mb = numb[i] >> (LIMB_BITS - 1);
74 r = a + c;
75 c = (r < c);
76 r += b;
77 c += (r < b);
78 dst[i] = r;
79 }
80 return c + mb;
81}
82
84 mp_size_t i, c = 0, mb = 0;
85
86 for (i = 0; i < n; i++) {
87 mp_limb_t a, b;
88 a = numa[i];
89 b = (numb[i] << 1) + mb;
90 mb = numb[i] >> (LIMB_BITS - 1);
91 b += c;
92 c = (b < c);
93 c += (a < b);
94 dst[i] = a - b;
95 }
96 return c + mb;
97}
#define c
mp_limb_t * mp_ptr
Definition lmmp.h:80
#define lmmp_copy(dst, src, n)
Definition lmmp.h:367
uint64_t mp_size_t
Definition lmmp.h:77
const mp_limb_t * mp_srcptr
Definition lmmp.h:81
uint64_t mp_limb_t
Definition lmmp.h:76
#define LIMB_BITS
Definition lmmp.h:86
#define numb
#define n
mp_limb_t lmmp_shl_c_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr, mp_limb_t c)
带进位的大数左移操作 [dst,na] = [numa,na]<<shl,dst的低shl位填充c的低shl位
Definition shl.c:42
mp_limb_t lmmp_subshl1_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
减法结合左移1位操作 [dst,n] = [numa,n] - ([numb,n] << 1)
Definition shl.c:83
mp_limb_t lmmp_shl_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr)
Copyright (C) 2026 HJimmyK(Jericho Knox)
Definition shl.c:19
mp_limb_t lmmp_addshl1_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
加法结合左移1位操作 [dst,n] = [numa,n] + ([numb,n] << 1)
Definition shl.c:66