| ... | ... | @@ -4244,7 +4244,6 @@ test "llshl shift by whole number of limb" { |
| 4244 | 4244 | |
| 4245 | 4245 | var r: [10]Limb = @splat(padding); |
| 4246 | 4246 | |
| 4247 | | // arbitrary numbers known to fit ? |
| 4248 | 4247 | const A: Limb = @truncate(0xCCCCCCCCCCCCCCCCCCCCCCC); |
| 4249 | 4248 | const B: Limb = @truncate(0x22222222222222222222222); |
| 4250 | 4249 | |
| ... | ... | @@ -4270,62 +4269,57 @@ test llshl { |
| 4270 | 4269 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4271 | 4270 | |
| 4272 | 4271 | // 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}}); |
| 4325 | 4322 | // zig fmt: on |
| 4326 | | |
| 4327 | | try test_shift_cases(llshl, cases); |
| 4328 | | try test_shift_cases_aliasing(llshl, cases, -1); |
| 4329 | 4323 | } |
| 4330 | 4324 | |
| 4331 | 4325 | test "llshl shift 0" { |
| ... | ... | @@ -4333,68 +4327,58 @@ test "llshl shift 0" { |
| 4333 | 4327 | if (n <= 20) return error.SkipZigTest; |
| 4334 | 4328 | |
| 4335 | 4329 | // 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}}); |
| 4359 | 4351 | // zig fmt: on |
| 4360 | | |
| 4361 | | try test_shift_cases(llshl, cases); |
| 4362 | | try test_shift_cases_aliasing(llshl, cases, -1); |
| 4363 | 4352 | } |
| 4364 | 4353 | |
| 4365 | 4354 | test "llshr shift 0" { |
| 4366 | 4355 | const n = @bitSizeOf(Limb); |
| 4367 | 4356 | |
| 4368 | 4357 | // 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, &.{}, &.{}}); |
| 4394 | 4381 | // zig fmt: on |
| 4395 | | |
| 4396 | | try test_shift_cases(llshr, cases); |
| 4397 | | try test_shift_cases_aliasing(llshr, cases, 1); |
| 4398 | 4382 | } |
| 4399 | 4383 | |
| 4400 | 4384 | test "llshr to 0" { |
| ... | ... | @@ -4402,19 +4386,14 @@ test "llshr to 0" { |
| 4402 | 4386 | if (n != 64 and n != 32) return error.SkipZigTest; |
| 4403 | 4387 | |
| 4404 | 4388 | // 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}}); |
| 4414 | 4396 | // zig fmt: on |
| 4415 | | |
| 4416 | | try test_shift_cases(llshr, cases); |
| 4417 | | try test_shift_cases_aliasing(llshr, cases, 1); |
| 4418 | 4397 | } |
| 4419 | 4398 | |
| 4420 | 4399 | test "llshr single" { |
| ... | ... | @@ -4425,30 +4404,25 @@ test "llshr single" { |
| 4425 | 4404 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4426 | 4405 | |
| 4427 | 4406 | // 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}}); |
| 4448 | 4425 | // zig fmt: on |
| 4449 | | |
| 4450 | | try test_shift_cases(llshr, cases); |
| 4451 | | try test_shift_cases_aliasing(llshr, cases, 1); |
| 4452 | 4426 | } |
| 4453 | 4427 | |
| 4454 | 4428 | test llshr { |
| ... | ... | @@ -4459,65 +4433,65 @@ test llshr { |
| 4459 | 4433 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4460 | 4434 | |
| 4461 | 4435 | // 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}}); |
| 4492 | 4464 | // zig fmt: on |
| 4465 | } |
| 4493 | 4466 | |
| 4494 | | try test_shift_cases(llshr, cases); |
| 4495 | | try test_shift_cases_aliasing(llshr, cases, 1); |
| 4467 | const Case = struct { usize, []const Limb, []const Limb }; |
| 4468 | |
| 4469 | fn 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); |
| 4496 | 4475 | } |
| 4497 | 4476 | |
| 4498 | | const Cases = []const struct { usize, []const Limb, []const Limb }; |
| 4499 | | fn test_shift_cases(func: fn ([]Limb, []const Limb, usize) usize, cases: Cases) !void { |
| 4477 | fn testOneShiftCaseNoAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case) !void { |
| 4500 | 4478 | const padding = std.math.maxInt(Limb); |
| 4501 | 4479 | var r: [20]Limb = @splat(padding); |
| 4502 | 4480 | |
| 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]; |
| 4507 | 4484 | |
| 4508 | | std.debug.assert(expected.len <= 20); |
| 4485 | std.debug.assert(expected.len <= 20); |
| 4509 | 4486 | |
| 4510 | | @memset(&r, padding); |
| 4511 | | const len = func(&r, data, shift); |
| 4487 | const len = func(&r, data, shift); |
| 4512 | 4488 | |
| 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)); |
| 4518 | 4492 | } |
| 4519 | 4493 | |
| 4520 | | fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases: Cases, shift_direction: isize) !void { |
| 4494 | fn testOneShiftCaseAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case, shift_direction: isize) !void { |
| 4521 | 4495 | const padding = std.math.maxInt(Limb); |
| 4522 | 4496 | var r: [60]Limb = @splat(padding); |
| 4523 | 4497 | const base = 20; |
| ... | ... | @@ -4525,22 +4499,20 @@ fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases |
| 4525 | 4499 | assert(shift_direction == 1 or shift_direction == -1); |
| 4526 | 4500 | |
| 4527 | 4501 | 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]; |
| 4532 | 4505 | |
| 4533 | | std.debug.assert(expected.len <= 20); |
| 4506 | std.debug.assert(expected.len <= 20); |
| 4534 | 4507 | |
| 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); |
| 4539 | 4512 | |
| 4540 | | const len = func(r[base..], written_data, shift); |
| 4513 | const len = func(r[base..], written_data, shift); |
| 4541 | 4514 | |
| 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]); |
| 4545 | 4517 | } |
| 4546 | 4518 | } |