authorgravatar for samy2014@free.frsamy007 <samy2014@free.fr> 2025-04-16 11:10:22+02:00
committergravatar for samy2014@free.frsamy007 <samy2014@free.fr> 2025-04-16 11:10:22+02:00
log8ae9ac6df46b9aa10e6098585c0f987d70eae61b
tree89df505ff5d9b59132cf0c5ce28c037d7cce0a35
parentc813b6a9006e33462fd34b81077216fc7ed36f20

improve test syntax for better stack trace in case of failure


1 files changed, 177 insertions(+), 205 deletions(-)

lib/std/math/big/int.zig+177-205
......@@ -4244,7 +4244,6 @@ test "llshl shift by whole number of limb" {
42444244
42454245 var r: [10]Limb = @splat(padding);
42464246
4247 // arbitrary numbers known to fit ?
42484247 const A: Limb = @truncate(0xCCCCCCCCCCCCCCCCCCCCCCC);
42494248 const B: Limb = @truncate(0x22222222222222222222222);
42504249
......@@ -4270,62 +4269,57 @@ test llshl {
42704269 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
42714270
42724271 // zig fmt: off
4273 const cases: Cases = &.{
4274 .{0, &.{0}, &.{0}},
4275 .{0, &.{1}, &.{1}},
4276 .{0, &.{125484842448}, &.{125484842448}},
4277 .{0, &.{0xdeadbeef}, &.{0xdeadbeef}},
4278 .{0, &.{maxint}, &.{maxint}},
4279 .{0, &.{left_one}, &.{left_one}},
4280 .{0, &.{0, 1}, &.{0, 1}},
4281 .{0, &.{1, 2}, &.{1, 2}},
4282 .{0, &.{left_one, 1}, &.{left_one, 1}},
4283 .{1, &.{0}, &.{0}},
4284 .{1, &.{2}, &.{1}},
4285 .{1, &.{250969684896}, &.{125484842448}},
4286 .{1, &.{0x1bd5b7dde}, &.{0xdeadbeef}},
4287 .{1, &.{0xfffffffffffffffe, 1}, &.{maxint}},
4288 .{1, &.{0, 1}, &.{left_one}},
4289 .{1, &.{0, 2}, &.{0, 1}},
4290 .{1, &.{2, 4}, &.{1, 2}},
4291 .{1, &.{0, 3}, &.{left_one, 1}},
4292 .{5, &.{32}, &.{1}},
4293 .{5, &.{4015514958336}, &.{125484842448}},
4294 .{5, &.{0x1bd5b7dde0}, &.{0xdeadbeef}},
4295 .{5, &.{0xffffffffffffffe0, 0x1f}, &.{maxint}},
4296 .{5, &.{0, 16}, &.{left_one}},
4297 .{5, &.{0, 32}, &.{0, 1}},
4298 .{5, &.{32, 64}, &.{1, 2}},
4299 .{5, &.{0, 48}, &.{left_one, 1}},
4300 .{64, &.{0, 1}, &.{1}},
4301 .{64, &.{0, 125484842448}, &.{125484842448}},
4302 .{64, &.{0, 0xdeadbeef}, &.{0xdeadbeef}},
4303 .{64, &.{0, maxint}, &.{maxint}},
4304 .{64, &.{0, left_one}, &.{left_one}},
4305 .{64, &.{0, 0, 1}, &.{0, 1}},
4306 .{64, &.{0, 1, 2}, &.{1, 2}},
4307 .{64, &.{0, left_one, 1}, &.{left_one, 1}},
4308 .{35, &.{0x800000000}, &.{1}},
4309 .{35, &.{13534986488655118336, 233}, &.{125484842448}},
4310 .{35, &.{0xf56df77800000000, 6}, &.{0xdeadbeef}},
4311 .{35, &.{0xfffffff800000000, 0x7ffffffff}, &.{maxint}},
4312 .{35, &.{0, 17179869184}, &.{left_one}},
4313 .{35, &.{0, 0x800000000}, &.{0, 1}},
4314 .{35, &.{0x800000000, 0x1000000000}, &.{1, 2}},
4315 .{35, &.{0, 0xc00000000}, &.{left_one, 1}},
4316 .{70, &.{0, 64}, &.{1}},
4317 .{70, &.{0, 8031029916672}, &.{125484842448}},
4318 .{70, &.{0, 0x37ab6fbbc0}, &.{0xdeadbeef}},
4319 .{70, &.{0, 0xffffffffffffffc0, 63}, &.{maxint}},
4320 .{70, &.{0, 0, 32}, &.{left_one}},
4321 .{70, &.{0, 0, 64}, &.{0, 1}},
4322 .{70, &.{0, 64, 128}, &.{1, 2}},
4323 .{70, &.{0, 0, 0x60}, &.{left_one, 1}},
4324 };
4272 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4273 try testOneShiftCase(.llshl, .{0, &.{1}, &.{1}});
4274 try testOneShiftCase(.llshl, .{0, &.{125484842448}, &.{125484842448}});
4275 try testOneShiftCase(.llshl, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}});
4276 try testOneShiftCase(.llshl, .{0, &.{maxint}, &.{maxint}});
4277 try testOneShiftCase(.llshl, .{0, &.{left_one}, &.{left_one}});
4278 try testOneShiftCase(.llshl, .{0, &.{0, 1}, &.{0, 1}});
4279 try testOneShiftCase(.llshl, .{0, &.{1, 2}, &.{1, 2}});
4280 try testOneShiftCase(.llshl, .{0, &.{left_one, 1}, &.{left_one, 1}});
4281 try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}});
4282 try testOneShiftCase(.llshl, .{1, &.{2}, &.{1}});
4283 try testOneShiftCase(.llshl, .{1, &.{250969684896}, &.{125484842448}});
4284 try testOneShiftCase(.llshl, .{1, &.{0x1bd5b7dde}, &.{0xdeadbeef}});
4285 try testOneShiftCase(.llshl, .{1, &.{0xfffffffffffffffe, 1}, &.{maxint}});
4286 try testOneShiftCase(.llshl, .{1, &.{0, 1}, &.{left_one}});
4287 try testOneShiftCase(.llshl, .{1, &.{0, 2}, &.{0, 1}});
4288 try testOneShiftCase(.llshl, .{1, &.{2, 4}, &.{1, 2}});
4289 try testOneShiftCase(.llshl, .{1, &.{0, 3}, &.{left_one, 1}});
4290 try testOneShiftCase(.llshl, .{5, &.{32}, &.{1}});
4291 try testOneShiftCase(.llshl, .{5, &.{4015514958336}, &.{125484842448}});
4292 try testOneShiftCase(.llshl, .{5, &.{0x1bd5b7dde0}, &.{0xdeadbeef}});
4293 try testOneShiftCase(.llshl, .{5, &.{0xffffffffffffffe0, 0x1f}, &.{maxint}});
4294 try testOneShiftCase(.llshl, .{5, &.{0, 16}, &.{left_one}});
4295 try testOneShiftCase(.llshl, .{5, &.{0, 32}, &.{0, 1}});
4296 try testOneShiftCase(.llshl, .{5, &.{32, 64}, &.{1, 2}});
4297 try testOneShiftCase(.llshl, .{5, &.{0, 48}, &.{left_one, 1}});
4298 try testOneShiftCase(.llshl, .{64, &.{0, 1}, &.{1}});
4299 try testOneShiftCase(.llshl, .{64, &.{0, 125484842448}, &.{125484842448}});
4300 try testOneShiftCase(.llshl, .{64, &.{0, 0xdeadbeef}, &.{0xdeadbeef}});
4301 try testOneShiftCase(.llshl, .{64, &.{0, maxint}, &.{maxint}});
4302 try testOneShiftCase(.llshl, .{64, &.{0, left_one}, &.{left_one}});
4303 try testOneShiftCase(.llshl, .{64, &.{0, 0, 1}, &.{0, 1}});
4304 try testOneShiftCase(.llshl, .{64, &.{0, 1, 2}, &.{1, 2}});
4305 try testOneShiftCase(.llshl, .{64, &.{0, left_one, 1}, &.{left_one, 1}});
4306 try testOneShiftCase(.llshl, .{35, &.{0x800000000}, &.{1}});
4307 try testOneShiftCase(.llshl, .{35, &.{13534986488655118336, 233}, &.{125484842448}});
4308 try testOneShiftCase(.llshl, .{35, &.{0xf56df77800000000, 6}, &.{0xdeadbeef}});
4309 try testOneShiftCase(.llshl, .{35, &.{0xfffffff800000000, 0x7ffffffff}, &.{maxint}});
4310 try testOneShiftCase(.llshl, .{35, &.{0, 17179869184}, &.{left_one}});
4311 try testOneShiftCase(.llshl, .{35, &.{0, 0x800000000}, &.{0, 1}});
4312 try testOneShiftCase(.llshl, .{35, &.{0x800000000, 0x1000000000}, &.{1, 2}});
4313 try testOneShiftCase(.llshl, .{35, &.{0, 0xc00000000}, &.{left_one, 1}});
4314 try testOneShiftCase(.llshl, .{70, &.{0, 64}, &.{1}});
4315 try testOneShiftCase(.llshl, .{70, &.{0, 8031029916672}, &.{125484842448}});
4316 try testOneShiftCase(.llshl, .{70, &.{0, 0x37ab6fbbc0}, &.{0xdeadbeef}});
4317 try testOneShiftCase(.llshl, .{70, &.{0, 0xffffffffffffffc0, 63}, &.{maxint}});
4318 try testOneShiftCase(.llshl, .{70, &.{0, 0, 32}, &.{left_one}});
4319 try testOneShiftCase(.llshl, .{70, &.{0, 0, 64}, &.{0, 1}});
4320 try testOneShiftCase(.llshl, .{70, &.{0, 64, 128}, &.{1, 2}});
4321 try testOneShiftCase(.llshl, .{70, &.{0, 0, 0x60}, &.{left_one, 1}});
43254322 // zig fmt: on
4326
4327 try test_shift_cases(llshl, cases);
4328 try test_shift_cases_aliasing(llshl, cases, -1);
43294323}
43304324
43314325test "llshl shift 0" {
......@@ -4333,68 +4327,58 @@ test "llshl shift 0" {
43334327 if (n <= 20) return error.SkipZigTest;
43344328
43354329 // zig fmt: off
4336 const cases = &.{
4337 .{0, &.{0}, &.{0}},
4338 .{1, &.{0}, &.{0}},
4339 .{5, &.{0}, &.{0}},
4340 .{13, &.{0}, &.{0}},
4341 .{20, &.{0}, &.{0}},
4342 .{0, &.{0, 0}, &.{0, 0}},
4343 .{2, &.{0, 0}, &.{0, 0}},
4344 .{7, &.{0, 0}, &.{0, 0}},
4345 .{11, &.{0, 0}, &.{0, 0}},
4346 .{19, &.{0, 0}, &.{0, 0}},
4347
4348 .{0, &.{0}, &.{0}},
4349 .{n, &.{0, 0}, &.{0}},
4350 .{2*n, &.{0, 0, 0}, &.{0}},
4351 .{3*n, &.{0, 0, 0, 0}, &.{0}},
4352 .{4*n, &.{0, 0, 0, 0, 0}, &.{0}},
4353 .{0, &.{0, 0}, &.{0, 0}},
4354 .{n, &.{0, 0, 0}, &.{0, 0}},
4355 .{2*n, &.{0, 0, 0, 0}, &.{0, 0}},
4356 .{3*n, &.{0, 0, 0, 0, 0}, &.{0, 0}},
4357 .{4*n, &.{0, 0, 0, 0, 0, 0}, &.{0, 0}},
4358 };
4330 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4331 try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}});
4332 try testOneShiftCase(.llshl, .{5, &.{0}, &.{0}});
4333 try testOneShiftCase(.llshl, .{13, &.{0}, &.{0}});
4334 try testOneShiftCase(.llshl, .{20, &.{0}, &.{0}});
4335 try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}});
4336 try testOneShiftCase(.llshl, .{2, &.{0, 0}, &.{0, 0}});
4337 try testOneShiftCase(.llshl, .{7, &.{0, 0}, &.{0, 0}});
4338 try testOneShiftCase(.llshl, .{11, &.{0, 0}, &.{0, 0}});
4339 try testOneShiftCase(.llshl, .{19, &.{0, 0}, &.{0, 0}});
4340
4341 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4342 try testOneShiftCase(.llshl, .{n, &.{0, 0}, &.{0}});
4343 try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0}, &.{0}});
4344 try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0}, &.{0}});
4345 try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0}, &.{0}});
4346 try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}});
4347 try testOneShiftCase(.llshl, .{n, &.{0, 0, 0}, &.{0, 0}});
4348 try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0, 0}, &.{0, 0}});
4349 try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0, 0}, &.{0, 0}});
4350 try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0, 0}, &.{0, 0}});
43594351 // zig fmt: on
4360
4361 try test_shift_cases(llshl, cases);
4362 try test_shift_cases_aliasing(llshl, cases, -1);
43634352}
43644353
43654354test "llshr shift 0" {
43664355 const n = @bitSizeOf(Limb);
43674356
43684357 // zig fmt: off
4369 const cases = &.{
4370 .{0, &.{0}, &.{0}},
4371 .{1, &.{0}, &.{0}},
4372 .{5, &.{0}, &.{0}},
4373 .{13, &.{0}, &.{0}},
4374 .{20, &.{0}, &.{0}},
4375 .{0, &.{0, 0}, &.{0, 0}},
4376 .{2, &.{0}, &.{0, 0}},
4377 .{7, &.{0}, &.{0, 0}},
4378 .{11, &.{0}, &.{0, 0}},
4379 .{19, &.{0}, &.{0, 0}},
4380
4381 .{n, &.{0}, &.{0}},
4382 .{2*n, &.{0}, &.{0}},
4383 .{3*n, &.{0}, &.{0}},
4384 .{4*n, &.{0}, &.{0}},
4385 .{n, &.{0}, &.{0, 0}},
4386 .{2*n, &.{0}, &.{0, 0}},
4387 .{3*n, &.{0}, &.{0, 0}},
4388 .{4*n, &.{0}, &.{0, 0}},
4389
4390 .{1, &.{}, &.{}},
4391 .{2, &.{}, &.{}},
4392 .{64, &.{}, &.{}},
4393 };
4358 try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}});
4359 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4360 try testOneShiftCase(.llshr, .{5, &.{0}, &.{0}});
4361 try testOneShiftCase(.llshr, .{13, &.{0}, &.{0}});
4362 try testOneShiftCase(.llshr, .{20, &.{0}, &.{0}});
4363 try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}});
4364 try testOneShiftCase(.llshr, .{2, &.{0}, &.{0, 0}});
4365 try testOneShiftCase(.llshr, .{7, &.{0}, &.{0, 0}});
4366 try testOneShiftCase(.llshr, .{11, &.{0}, &.{0, 0}});
4367 try testOneShiftCase(.llshr, .{19, &.{0}, &.{0, 0}});
4368
4369 try testOneShiftCase(.llshr, .{n, &.{0}, &.{0}});
4370 try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0}});
4371 try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0}});
4372 try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0}});
4373 try testOneShiftCase(.llshr, .{n, &.{0}, &.{0, 0}});
4374 try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0, 0}});
4375 try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0, 0}});
4376 try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0, 0}});
4377
4378 try testOneShiftCase(.llshr, .{1, &.{}, &.{}});
4379 try testOneShiftCase(.llshr, .{2, &.{}, &.{}});
4380 try testOneShiftCase(.llshr, .{64, &.{}, &.{}});
43944381 // zig fmt: on
4395
4396 try test_shift_cases(llshr, cases);
4397 try test_shift_cases_aliasing(llshr, cases, 1);
43984382}
43994383
44004384test "llshr to 0" {
......@@ -4402,19 +4386,14 @@ test "llshr to 0" {
44024386 if (n != 64 and n != 32) return error.SkipZigTest;
44034387
44044388 // zig fmt: off
4405 const cases = &.{
4406 .{1, &.{0}, &.{0}},
4407 .{1, &.{0}, &.{1}},
4408 .{5, &.{0}, &.{1}},
4409 .{65, &.{0}, &.{0, 1}},
4410 .{193, &.{0}, &.{0, 0, std.math.maxInt(Limb)}},
4411 .{193, &.{0}, &.{std.math.maxInt(Limb), 1, std.math.maxInt(Limb)}},
4412 .{193, &.{0}, &.{0xdeadbeef, 0xabcdefab, 0x1234}},
4413 };
4389 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4390 try testOneShiftCase(.llshr, .{1, &.{0}, &.{1}});
4391 try testOneShiftCase(.llshr, .{5, &.{0}, &.{1}});
4392 try testOneShiftCase(.llshr, .{65, &.{0}, &.{0, 1}});
4393 try testOneShiftCase(.llshr, .{193, &.{0}, &.{0, 0, std.math.maxInt(Limb)}});
4394 try testOneShiftCase(.llshr, .{193, &.{0}, &.{std.math.maxInt(Limb), 1, std.math.maxInt(Limb)}});
4395 try testOneShiftCase(.llshr, .{193, &.{0}, &.{0xdeadbeef, 0xabcdefab, 0x1234}});
44144396 // zig fmt: on
4415
4416 try test_shift_cases(llshr, cases);
4417 try test_shift_cases_aliasing(llshr, cases, 1);
44184397}
44194398
44204399test "llshr single" {
......@@ -4425,30 +4404,25 @@ test "llshr single" {
44254404 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
44264405
44274406 // zig fmt: off
4428 const cases: Cases = &.{
4429 .{0, &.{0}, &.{0}},
4430 .{0, &.{1}, &.{1}},
4431 .{0, &.{125484842448}, &.{125484842448}},
4432 .{0, &.{0xdeadbeef}, &.{0xdeadbeef}},
4433 .{0, &.{maxint}, &.{maxint}},
4434 .{0, &.{left_one}, &.{left_one}},
4435 .{1, &.{0}, &.{0}},
4436 .{1, &.{1}, &.{2}},
4437 .{1, &.{62742421224}, &.{125484842448}},
4438 .{1, &.{62742421223}, &.{125484842447}},
4439 .{1, &.{0x6f56df77}, &.{0xdeadbeef}},
4440 .{1, &.{0x7fffffffffffffff}, &.{maxint}},
4441 .{1, &.{0x4000000000000000}, &.{left_one}},
4442 .{8, &.{1}, &.{256}},
4443 .{8, &.{490175165}, &.{125484842448}},
4444 .{8, &.{0xdeadbe}, &.{0xdeadbeef}},
4445 .{8, &.{0xffffffffffffff}, &.{maxint}},
4446 .{8, &.{0x80000000000000}, &.{left_one}},
4447 };
4407 try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}});
4408 try testOneShiftCase(.llshr, .{0, &.{1}, &.{1}});
4409 try testOneShiftCase(.llshr, .{0, &.{125484842448}, &.{125484842448}});
4410 try testOneShiftCase(.llshr, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}});
4411 try testOneShiftCase(.llshr, .{0, &.{maxint}, &.{maxint}});
4412 try testOneShiftCase(.llshr, .{0, &.{left_one}, &.{left_one}});
4413 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4414 try testOneShiftCase(.llshr, .{1, &.{1}, &.{2}});
4415 try testOneShiftCase(.llshr, .{1, &.{62742421224}, &.{125484842448}});
4416 try testOneShiftCase(.llshr, .{1, &.{62742421223}, &.{125484842447}});
4417 try testOneShiftCase(.llshr, .{1, &.{0x6f56df77}, &.{0xdeadbeef}});
4418 try testOneShiftCase(.llshr, .{1, &.{0x7fffffffffffffff}, &.{maxint}});
4419 try testOneShiftCase(.llshr, .{1, &.{0x4000000000000000}, &.{left_one}});
4420 try testOneShiftCase(.llshr, .{8, &.{1}, &.{256}});
4421 try testOneShiftCase(.llshr, .{8, &.{490175165}, &.{125484842448}});
4422 try testOneShiftCase(.llshr, .{8, &.{0xdeadbe}, &.{0xdeadbeef}});
4423 try testOneShiftCase(.llshr, .{8, &.{0xffffffffffffff}, &.{maxint}});
4424 try testOneShiftCase(.llshr, .{8, &.{0x80000000000000}, &.{left_one}});
44484425 // zig fmt: on
4449
4450 try test_shift_cases(llshr, cases);
4451 try test_shift_cases_aliasing(llshr, cases, 1);
44524426}
44534427
44544428test llshr {
......@@ -4459,65 +4433,65 @@ test llshr {
44594433 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
44604434
44614435 // zig fmt: off
4462 const cases: Cases = &.{
4463 .{0, &.{0, 0}, &.{0, 0}},
4464 .{0, &.{0, 1}, &.{0, 1}},
4465 .{0, &.{15, 1}, &.{15, 1}},
4466 .{0, &.{987656565, 123456789456}, &.{987656565, 123456789456}},
4467 .{0, &.{0xfeebdaed, 0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}},
4468 .{0, &.{1, maxint}, &.{1, maxint}},
4469 .{0, &.{0, left_one}, &.{0, left_one}},
4470 .{1, &.{0}, &.{0, 0}},
4471 .{1, &.{left_one}, &.{0, 1}},
4472 .{1, &.{0x8000000000000007}, &.{15, 1}},
4473 .{1, &.{493828282, 61728394728}, &.{987656565, 123456789456}},
4474 .{1, &.{0x800000007f75ed76, 0x6f56df77}, &.{0xfeebdaed, 0xdeadbeef}},
4475 .{1, &.{left_one, 0x7fffffffffffffff}, &.{1, maxint}},
4476 .{1, &.{0, 0x4000000000000000}, &.{0, left_one}},
4477 .{64, &.{0}, &.{0, 0}},
4478 .{64, &.{1}, &.{0, 1}},
4479 .{64, &.{1}, &.{15, 1}},
4480 .{64, &.{123456789456}, &.{987656565, 123456789456}},
4481 .{64, &.{0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}},
4482 .{64, &.{maxint}, &.{1, maxint}},
4483 .{64, &.{left_one}, &.{0, left_one}},
4484 .{72, &.{0}, &.{0, 0}},
4485 .{72, &.{0}, &.{0, 1}},
4486 .{72, &.{0}, &.{15, 1}},
4487 .{72, &.{482253083}, &.{987656565, 123456789456}},
4488 .{72, &.{0xdeadbe}, &.{0xfeebdaed, 0xdeadbeef}},
4489 .{72, &.{0xffffffffffffff}, &.{1, maxint}},
4490 .{72, &.{0x80000000000000}, &.{0, left_one}},
4491 };
4436 try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}});
4437 try testOneShiftCase(.llshr, .{0, &.{0, 1}, &.{0, 1}});
4438 try testOneShiftCase(.llshr, .{0, &.{15, 1}, &.{15, 1}});
4439 try testOneShiftCase(.llshr, .{0, &.{987656565, 123456789456}, &.{987656565, 123456789456}});
4440 try testOneShiftCase(.llshr, .{0, &.{0xfeebdaed, 0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}});
4441 try testOneShiftCase(.llshr, .{0, &.{1, maxint}, &.{1, maxint}});
4442 try testOneShiftCase(.llshr, .{0, &.{0, left_one}, &.{0, left_one}});
4443 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0, 0}});
4444 try testOneShiftCase(.llshr, .{1, &.{left_one}, &.{0, 1}});
4445 try testOneShiftCase(.llshr, .{1, &.{0x8000000000000007}, &.{15, 1}});
4446 try testOneShiftCase(.llshr, .{1, &.{493828282, 61728394728}, &.{987656565, 123456789456}});
4447 try testOneShiftCase(.llshr, .{1, &.{0x800000007f75ed76, 0x6f56df77}, &.{0xfeebdaed, 0xdeadbeef}});
4448 try testOneShiftCase(.llshr, .{1, &.{left_one, 0x7fffffffffffffff}, &.{1, maxint}});
4449 try testOneShiftCase(.llshr, .{1, &.{0, 0x4000000000000000}, &.{0, left_one}});
4450 try testOneShiftCase(.llshr, .{64, &.{0}, &.{0, 0}});
4451 try testOneShiftCase(.llshr, .{64, &.{1}, &.{0, 1}});
4452 try testOneShiftCase(.llshr, .{64, &.{1}, &.{15, 1}});
4453 try testOneShiftCase(.llshr, .{64, &.{123456789456}, &.{987656565, 123456789456}});
4454 try testOneShiftCase(.llshr, .{64, &.{0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}});
4455 try testOneShiftCase(.llshr, .{64, &.{maxint}, &.{1, maxint}});
4456 try testOneShiftCase(.llshr, .{64, &.{left_one}, &.{0, left_one}});
4457 try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 0}});
4458 try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 1}});
4459 try testOneShiftCase(.llshr, .{72, &.{0}, &.{15, 1}});
4460 try testOneShiftCase(.llshr, .{72, &.{482253083}, &.{987656565, 123456789456}});
4461 try testOneShiftCase(.llshr, .{72, &.{0xdeadbe}, &.{0xfeebdaed, 0xdeadbeef}});
4462 try testOneShiftCase(.llshr, .{72, &.{0xffffffffffffff}, &.{1, maxint}});
4463 try testOneShiftCase(.llshr, .{72, &.{0x80000000000000}, &.{0, left_one}});
44924464 // zig fmt: on
4465}
44934466
4494 try test_shift_cases(llshr, cases);
4495 try test_shift_cases_aliasing(llshr, cases, 1);
4467const Case = struct { usize, []const Limb, []const Limb };
4468
4469fn testOneShiftCase(comptime function: enum { llshr, llshl }, case: Case) !void {
4470 const func = if (function == .llshl) llshl else llshr;
4471 const shift_direction = if (function == .llshl) -1 else 1;
4472
4473 try testOneShiftCaseNoAliasing(func, case);
4474 try testOneShiftCaseAliasing(func, case, shift_direction);
44964475}
44974476
4498const Cases = []const struct { usize, []const Limb, []const Limb };
4499fn test_shift_cases(func: fn ([]Limb, []const Limb, usize) usize, cases: Cases) !void {
4477fn testOneShiftCaseNoAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case) !void {
45004478 const padding = std.math.maxInt(Limb);
45014479 var r: [20]Limb = @splat(padding);
45024480
4503 for (cases) |case| {
4504 const shift = case[0];
4505 const expected = case[1];
4506 const data = case[2];
4481 const shift = case[0];
4482 const expected = case[1];
4483 const data = case[2];
45074484
4508 std.debug.assert(expected.len <= 20);
4485 std.debug.assert(expected.len <= 20);
45094486
4510 @memset(&r, padding);
4511 const len = func(&r, data, shift);
4487 const len = func(&r, data, shift);
45124488
4513 try std.testing.expectEqual(expected.len, len);
4514 try std.testing.expectEqualSlices(Limb, expected, r[0..len]);
4515 for (r[len..]) |x|
4516 try std.testing.expectEqual(padding, x);
4517 }
4489 try std.testing.expectEqual(expected.len, len);
4490 try std.testing.expectEqualSlices(Limb, expected, r[0..len]);
4491 try std.testing.expect(mem.allEqual(Limb, r[len..], padding));
45184492}
45194493
4520fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases: Cases, shift_direction: isize) !void {
4494fn testOneShiftCaseAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case, shift_direction: isize) !void {
45214495 const padding = std.math.maxInt(Limb);
45224496 var r: [60]Limb = @splat(padding);
45234497 const base = 20;
......@@ -4525,22 +4499,20 @@ fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases
45254499 assert(shift_direction == 1 or shift_direction == -1);
45264500
45274501 for (0..10) |limb_shift| {
4528 for (cases) |case| {
4529 const shift = case[0];
4530 const expected = case[1];
4531 const data = case[2];
4502 const shift = case[0];
4503 const expected = case[1];
4504 const data = case[2];
45324505
4533 std.debug.assert(expected.len <= 20);
4506 std.debug.assert(expected.len <= 20);
45344507
4535 @memset(&r, padding);
4536 const final_limb_base: usize = @intCast(base + shift_direction * @as(isize, @intCast(limb_shift)));
4537 const written_data = r[final_limb_base..][0..data.len];
4538 @memcpy(written_data, data);
4508 @memset(&r, padding);
4509 const final_limb_base: usize = @intCast(base + shift_direction * @as(isize, @intCast(limb_shift)));
4510 const written_data = r[final_limb_base..][0..data.len];
4511 @memcpy(written_data, data);
45394512
4540 const len = func(r[base..], written_data, shift);
4513 const len = func(r[base..], written_data, shift);
45414514
4542 try std.testing.expectEqual(expected.len, len);
4543 try std.testing.expectEqualSlices(Limb, expected, r[base .. base + len]);
4544 }
4515 try std.testing.expectEqual(expected.len, len);
4516 try std.testing.expectEqualSlices(Limb, expected, r[base .. base + len]);
45454517 }
45464518}