LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
extract_bits.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#include "../../../include/lammp/impl/inlines.h"
18
19
23 if (n == 1) {
24 int lb = lmmp_limb_bits_(num[0]);
25 if (lb <= bits) {
26 *ext = num[0];
27 return 0;
28 } else {
29 *ext = num[0] >> (lb - bits);
30 return lb - bits;
31 }
32 } else {
33 int lb = lmmp_limb_bits_(num[n - 1]);
34 if (lb < bits) {
35 *ext = num[n - 1] << (bits - lb);
36 *ext |= num[n - 2] >> (LIMB_BITS - bits + lb);
37 return LIMB_BITS * (n - 1) - (bits - lb);
38 } else if (lb == bits) {
39 *ext = num[n - 1];
40 return LIMB_BITS * (n - 1);
41 } else {
42 *ext = num[n - 1] >> (lb - bits);
43 return LIMB_BITS * (n - 1) + (lb - bits);
44 }
45 }
46}
mp_bitcnt_t lmmp_extract_bits_(mp_srcptr restrict num, mp_size_t n, mp_limb_t *restrict ext, int bits)
Copyright (C) 2026 HJimmyK(Jericho Knox)
#define lmmp_limb_bits_
Definition inlines.h:162
size_t mp_bitcnt_t
Definition lmmp.h:82
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 lmmp_param_assert(x)
Definition lmmp.h:401
#define n