47 for (
mp_size_t i = 0; i <
n; ++i) a[i] = UINT64_MAX;
59TEST_CASE(
"asm/boundary", mul_1_addmul_submul_extremes) {
61 mp_ptr a = alloc_limbs(
n), d = alloc_limbs(
n + 1),
t = alloc_limbs(
n + 2),
62 acc = alloc_limbs(
n + 1), acc2 = alloc_limbs(
n + 1);
63 for (
mp_size_t i = 0; i <
n; ++i) a[i] = UINT64_MAX;
72 for (
mp_size_t i = 0; i <
n; ++i) acc[i] = UINT64_MAX;
75 memcpy(acc2, acc,
n * 8);
83 memcpy(acc2, acc,
n * 8);
93 u64 seed = 0x1234567890abcdeful;
95 mp_ptr a = alloc_limbs(
n), orig = alloc_limbs(
n), ref = alloc_limbs(
n);
96 for (
mp_size_t i = 0; i <
n; ++i) a[i] = xorshift64(&seed);
97 memcpy(orig, a,
n * 8);
100 const size_t s_values[] = {1, 7, 31, 63};
101 for (
size_t s_index = 0; s_index <
ARRAY_SIZE(s_values); ++s_index) {
102 size_t s = s_values[s_index];
103 memcpy(a, orig,
n * 8);
109 memcpy(a, orig,
n * 8);
129 ob.
buf = alloc_limbs(ob.
cap);
131 ob.
sep = alloc_limbs(
n);
132 ob.
src = alloc_limbs(
n);
145 u64 seed = 0x9e3779b97f4a7c15ull ^ (ob->
n * 31 + ob->
g);
146 random_limbs(ob->
src, ob->
n, &seed);
150 for (
size_t i = 0; i < ob->
cap; ++i)
151 ob->
buf[i] = 0xA5A5DEADBEEF00F0ull ^ (i * 0x9e37u + (
u64)w * 7u);
157 return w == 100 ? ob->
sep : ob->
numa + w;
162 for (
size_t i = 0; i < ob->
cap; ++i) {
163 if (w != 100 && ob->
buf + i >= dst && ob->
buf + i < dst + ob->
n)
165 if (ob->
buf[i] != ob->
snap[i]) {
179 for (
size_t k = 0;
k < 64; ++
k) {
180 mp_ptr eshl = alloc_limbs(
n), eshr = alloc_limbs(
n);
186 const int ws_shl[] = {100, 0};
187 for (
size_t w_index = 0; w_index <
ARRAY_SIZE(ws_shl); ++w_index) {
188 int w = ws_shl[w_index];
195 const int ws_shr[] = {100, 0, -1, -2, -3};
196 for (
size_t w_index = 0; w_index <
ARRAY_SIZE(ws_shr); ++w_index) {
197 int w = ws_shr[w_index];
214 u64 seed = 0xc0ffee1234567890ul;
219 const size_t k_values[] = {1, 5, 32, 63};
220 for (
size_t k_index = 0; k_index <
ARRAY_SIZE(k_values); ++k_index) {
221 size_t k = k_values[k_index];
223 mp_limb_t cshr = (xorshift64(&seed) >> (64 -
k)) << (64 -
k);
227 mp_ptr eshl = alloc_limbs(
n), eshr = alloc_limbs(
n);
233 const int ws_shl[] = {100, 0};
234 for (
size_t w_index = 0; w_index <
ARRAY_SIZE(ws_shl); ++w_index) {
235 int w = ws_shl[w_index];
242 const int ws_shr[] = {100, 0, -1, -2, -3};
243 for (
size_t w_index = 0; w_index <
ARRAY_SIZE(ws_shr); ++w_index) {
244 int w = ws_shr[w_index];
258TEST_CASE(
"asm/boundary", div_1_by_one_and_power_of_two) {
259 u64 seed = 0xf00dface12345678ull;
260 const mp_size_t n_values[] = {1, 2, 5, 16};
261 for (
size_t n_index = 0; n_index <
ARRAY_SIZE(n_values); ++n_index) {
263 mp_ptr a = alloc_limbs(
n), q = alloc_limbs(
n + 1),
t = alloc_limbs(
n + 2);
264 for (
mp_size_t i = 0; i <
n; ++i) a[i] = xorshift64(&seed);
273 u64 x = 1ull << ((seed & 63) ? (seed & 63) : 1);
279 u64 ovf = add_small_inplace(
t,
n + 1, r);
292 u64 seed = 0x0123456789abcdeful;
293 for (
int i = 0; i < 200; ++i) {
303 u64 mod = xorshift64(&seed) | 3;
304 u64 a = xorshift64(&seed) % mod;
305 u64 b = xorshift64(&seed) % mod;
319 TEST_RUN(
"asm/boundary", add_nc_sub_nc_all_ones);
320 TEST_RUN(
"asm/boundary", mul_1_addmul_submul_extremes);
321 TEST_RUN(
"asm/boundary", shl_shr_inplace);
322 TEST_RUN(
"asm/boundary", shl_shr_overlap_family);
323 TEST_RUN(
"asm/boundary", shl_shr_c_overlap_family);
324 TEST_RUN(
"asm/boundary", div_1_by_one_and_power_of_two);
325 TEST_RUN(
"asm/boundary", inv_and_mulmod_boundary);
#define lmmp_copy(dst, src, n)
const mp_limb_t * mp_srcptr
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
mp_limb_t u64
Copyright (C) 2026 HJimmyK (Jericho Knox)
void test_asm_boundary(void)
Copyright (C) 2026 HJimmyK (Jericho Knox)
mp_limb_t lmmp_div_1_(mp_ptr dstq, mp_srcptr numa, mp_size_t na, mp_limb_t x)
单精度数除法
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位
mp_limb_t lmmp_shr_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shr)
右移操作 [dst,na] = [numa,na]>>shr,dst的高shr位填充0
mp_limb_t lmmp_shl_c_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shl, mp_limb_t c)
带进位的左移操作 [dst,na] = [numa,na]<<shl,dst的低shl位填充c的低shl位
mp_limb_t lmmp_add_nc_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
带进位的n位加法 [dst,n] = [numa,n] + [numb,n] + c
mp_limb_t lmmp_shl_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_size_t shl)
左移操作 [dst,na] = [numa,na]<<shl,dst的低shl位填充0
mp_limb_t lmmp_addmul_1_(mp_ptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t b)
乘以单limb并累加操作 [numa,n] += [numb,n] * b
mp_limb_t lmmp_mul_1_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_limb_t x)
乘以单limb操作 [dst,na] = [numa,na] * x
mp_limb_t lmmp_submul_1_(mp_ptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t b)
乘以单limb并累减操作 [numa,n] -= [numb,n] * b
mp_limb_t lmmp_sub_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
无借位的n位减法 [dst,n] = [numa,n] - [numb,n]
mp_limb_t lmmp_inv_1_(mp_limb_t x)
1阶逆元计算 (inv1)
mp_limb_t lmmp_sub_nc_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n, mp_limb_t c)
带借位的n位减法 [dst,n] = [numa,n] - [numb,n] - c
mp_limb_t lmmp_add_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
无进位的n位加法 [dst,n] = [numa,n] + [numb,n]
ulong lmmp_mulmod_ulong_(ulong a, ulong b, ulong mod, ulongp q)
计算两个无符号整数的乘积,对mod取模,商放入 q 中
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define TEST_CHECK_MSG(cond, msg)
#define TEST_CASE(category, name)
#define TEST_CHECK_EQ(a, b)
#define TEST_RUN(category, name)
static void overlap_buf_check_guard(const overlap_buf_t *ob, int w, const char *tag)
static void overlap_buf_refill(overlap_buf_t *ob, int w)
static mp_ptr overlap_buf_dst_of(const overlap_buf_t *ob, int w)
static void overlap_buf_set_src(overlap_buf_t *ob)
static void overlap_buf_free(overlap_buf_t *ob)
static overlap_buf_t overlap_buf_create(mp_size_t n, size_t g)