| ... | @@ -4244,7 +4244,6 @@ test "llshl shift by whole number of limb" { | ... | @@ -4244,7 +4244,6 @@ test "llshl shift by whole number of limb" { |
| 4244 | | 4244 | |
| 4245 | var r: [10]Limb = @splat(padding); | 4245 | var r: [10]Limb = @splat(padding); |
| 4246 | | 4246 | |
| 4247 | // arbitrary numbers known to fit ? | | |
| 4248 | const A: Limb = @truncate(0xCCCCCCCCCCCCCCCCCCCCCCC); | 4247 | const A: Limb = @truncate(0xCCCCCCCCCCCCCCCCCCCCCCC); |
| 4249 | const B: Limb = @truncate(0x22222222222222222222222); | 4248 | const B: Limb = @truncate(0x22222222222222222222222); |
| 4250 | | 4249 | |
| ... | @@ -4270,62 +4269,57 @@ test llshl { | ... | @@ -4270,62 +4269,57 @@ test llshl { |
| 4270 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; | 4269 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4271 | | 4270 | |
| 4272 | // zig fmt: off | 4271 | // zig fmt: off |
| 4273 | const cases: Cases = &.{ | 4272 | try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}}); |
| 4274 | .{0, &.{0}, &.{0}}, | 4273 | try testOneShiftCase(.llshl, .{0, &.{1}, &.{1}}); |
| 4275 | .{0, &.{1}, &.{1}}, | 4274 | try testOneShiftCase(.llshl, .{0, &.{125484842448}, &.{125484842448}}); |
| 4276 | .{0, &.{125484842448}, &.{125484842448}}, | 4275 | try testOneShiftCase(.llshl, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}}); |
| 4277 | .{0, &.{0xdeadbeef}, &.{0xdeadbeef}}, | 4276 | try testOneShiftCase(.llshl, .{0, &.{maxint}, &.{maxint}}); |
| 4278 | .{0, &.{maxint}, &.{maxint}}, | 4277 | try testOneShiftCase(.llshl, .{0, &.{left_one}, &.{left_one}}); |
| 4279 | .{0, &.{left_one}, &.{left_one}}, | 4278 | try testOneShiftCase(.llshl, .{0, &.{0, 1}, &.{0, 1}}); |
| 4280 | .{0, &.{0, 1}, &.{0, 1}}, | 4279 | try testOneShiftCase(.llshl, .{0, &.{1, 2}, &.{1, 2}}); |
| 4281 | .{0, &.{1, 2}, &.{1, 2}}, | 4280 | try testOneShiftCase(.llshl, .{0, &.{left_one, 1}, &.{left_one, 1}}); |
| 4282 | .{0, &.{left_one, 1}, &.{left_one, 1}}, | 4281 | try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}}); |
| 4283 | .{1, &.{0}, &.{0}}, | 4282 | try testOneShiftCase(.llshl, .{1, &.{2}, &.{1}}); |
| 4284 | .{1, &.{2}, &.{1}}, | 4283 | try testOneShiftCase(.llshl, .{1, &.{250969684896}, &.{125484842448}}); |
| 4285 | .{1, &.{250969684896}, &.{125484842448}}, | 4284 | try testOneShiftCase(.llshl, .{1, &.{0x1bd5b7dde}, &.{0xdeadbeef}}); |
| 4286 | .{1, &.{0x1bd5b7dde}, &.{0xdeadbeef}}, | 4285 | try testOneShiftCase(.llshl, .{1, &.{0xfffffffffffffffe, 1}, &.{maxint}}); |
| 4287 | .{1, &.{0xfffffffffffffffe, 1}, &.{maxint}}, | 4286 | try testOneShiftCase(.llshl, .{1, &.{0, 1}, &.{left_one}}); |
| 4288 | .{1, &.{0, 1}, &.{left_one}}, | 4287 | try testOneShiftCase(.llshl, .{1, &.{0, 2}, &.{0, 1}}); |
| 4289 | .{1, &.{0, 2}, &.{0, 1}}, | 4288 | try testOneShiftCase(.llshl, .{1, &.{2, 4}, &.{1, 2}}); |
| 4290 | .{1, &.{2, 4}, &.{1, 2}}, | 4289 | try testOneShiftCase(.llshl, .{1, &.{0, 3}, &.{left_one, 1}}); |
| 4291 | .{1, &.{0, 3}, &.{left_one, 1}}, | 4290 | try testOneShiftCase(.llshl, .{5, &.{32}, &.{1}}); |
| 4292 | .{5, &.{32}, &.{1}}, | 4291 | try testOneShiftCase(.llshl, .{5, &.{4015514958336}, &.{125484842448}}); |
| 4293 | .{5, &.{4015514958336}, &.{125484842448}}, | 4292 | try testOneShiftCase(.llshl, .{5, &.{0x1bd5b7dde0}, &.{0xdeadbeef}}); |
| 4294 | .{5, &.{0x1bd5b7dde0}, &.{0xdeadbeef}}, | 4293 | try testOneShiftCase(.llshl, .{5, &.{0xffffffffffffffe0, 0x1f}, &.{maxint}}); |
| 4295 | .{5, &.{0xffffffffffffffe0, 0x1f}, &.{maxint}}, | 4294 | try testOneShiftCase(.llshl, .{5, &.{0, 16}, &.{left_one}}); |
| 4296 | .{5, &.{0, 16}, &.{left_one}}, | 4295 | try testOneShiftCase(.llshl, .{5, &.{0, 32}, &.{0, 1}}); |
| 4297 | .{5, &.{0, 32}, &.{0, 1}}, | 4296 | try testOneShiftCase(.llshl, .{5, &.{32, 64}, &.{1, 2}}); |
| 4298 | .{5, &.{32, 64}, &.{1, 2}}, | 4297 | try testOneShiftCase(.llshl, .{5, &.{0, 48}, &.{left_one, 1}}); |
| 4299 | .{5, &.{0, 48}, &.{left_one, 1}}, | 4298 | try testOneShiftCase(.llshl, .{64, &.{0, 1}, &.{1}}); |
| 4300 | .{64, &.{0, 1}, &.{1}}, | 4299 | try testOneShiftCase(.llshl, .{64, &.{0, 125484842448}, &.{125484842448}}); |
| 4301 | .{64, &.{0, 125484842448}, &.{125484842448}}, | 4300 | try testOneShiftCase(.llshl, .{64, &.{0, 0xdeadbeef}, &.{0xdeadbeef}}); |
| 4302 | .{64, &.{0, 0xdeadbeef}, &.{0xdeadbeef}}, | 4301 | try testOneShiftCase(.llshl, .{64, &.{0, maxint}, &.{maxint}}); |
| 4303 | .{64, &.{0, maxint}, &.{maxint}}, | 4302 | try testOneShiftCase(.llshl, .{64, &.{0, left_one}, &.{left_one}}); |
| 4304 | .{64, &.{0, left_one}, &.{left_one}}, | 4303 | try testOneShiftCase(.llshl, .{64, &.{0, 0, 1}, &.{0, 1}}); |
| 4305 | .{64, &.{0, 0, 1}, &.{0, 1}}, | 4304 | try testOneShiftCase(.llshl, .{64, &.{0, 1, 2}, &.{1, 2}}); |
| 4306 | .{64, &.{0, 1, 2}, &.{1, 2}}, | 4305 | try testOneShiftCase(.llshl, .{64, &.{0, left_one, 1}, &.{left_one, 1}}); |
| 4307 | .{64, &.{0, left_one, 1}, &.{left_one, 1}}, | 4306 | try testOneShiftCase(.llshl, .{35, &.{0x800000000}, &.{1}}); |
| 4308 | .{35, &.{0x800000000}, &.{1}}, | 4307 | try testOneShiftCase(.llshl, .{35, &.{13534986488655118336, 233}, &.{125484842448}}); |
| 4309 | .{35, &.{13534986488655118336, 233}, &.{125484842448}}, | 4308 | try testOneShiftCase(.llshl, .{35, &.{0xf56df77800000000, 6}, &.{0xdeadbeef}}); |
| 4310 | .{35, &.{0xf56df77800000000, 6}, &.{0xdeadbeef}}, | 4309 | try testOneShiftCase(.llshl, .{35, &.{0xfffffff800000000, 0x7ffffffff}, &.{maxint}}); |
| 4311 | .{35, &.{0xfffffff800000000, 0x7ffffffff}, &.{maxint}}, | 4310 | try testOneShiftCase(.llshl, .{35, &.{0, 17179869184}, &.{left_one}}); |
| 4312 | .{35, &.{0, 17179869184}, &.{left_one}}, | 4311 | try testOneShiftCase(.llshl, .{35, &.{0, 0x800000000}, &.{0, 1}}); |
| 4313 | .{35, &.{0, 0x800000000}, &.{0, 1}}, | 4312 | try testOneShiftCase(.llshl, .{35, &.{0x800000000, 0x1000000000}, &.{1, 2}}); |
| 4314 | .{35, &.{0x800000000, 0x1000000000}, &.{1, 2}}, | 4313 | try testOneShiftCase(.llshl, .{35, &.{0, 0xc00000000}, &.{left_one, 1}}); |
| 4315 | .{35, &.{0, 0xc00000000}, &.{left_one, 1}}, | 4314 | try testOneShiftCase(.llshl, .{70, &.{0, 64}, &.{1}}); |
| 4316 | .{70, &.{0, 64}, &.{1}}, | 4315 | try testOneShiftCase(.llshl, .{70, &.{0, 8031029916672}, &.{125484842448}}); |
| 4317 | .{70, &.{0, 8031029916672}, &.{125484842448}}, | 4316 | try testOneShiftCase(.llshl, .{70, &.{0, 0x37ab6fbbc0}, &.{0xdeadbeef}}); |
| 4318 | .{70, &.{0, 0x37ab6fbbc0}, &.{0xdeadbeef}}, | 4317 | try testOneShiftCase(.llshl, .{70, &.{0, 0xffffffffffffffc0, 63}, &.{maxint}}); |
| 4319 | .{70, &.{0, 0xffffffffffffffc0, 63}, &.{maxint}}, | 4318 | try testOneShiftCase(.llshl, .{70, &.{0, 0, 32}, &.{left_one}}); |
| 4320 | .{70, &.{0, 0, 32}, &.{left_one}}, | 4319 | try testOneShiftCase(.llshl, .{70, &.{0, 0, 64}, &.{0, 1}}); |
| 4321 | .{70, &.{0, 0, 64}, &.{0, 1}}, | 4320 | try testOneShiftCase(.llshl, .{70, &.{0, 64, 128}, &.{1, 2}}); |
| 4322 | .{70, &.{0, 64, 128}, &.{1, 2}}, | 4321 | try testOneShiftCase(.llshl, .{70, &.{0, 0, 0x60}, &.{left_one, 1}}); |
| 4323 | .{70, &.{0, 0, 0x60}, &.{left_one, 1}}, | | |
| 4324 | }; | | |
| 4325 | // zig fmt: on | 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 | test "llshl shift 0" { | 4325 | test "llshl shift 0" { |
| ... | @@ -4333,68 +4327,58 @@ test "llshl shift 0" { | ... | @@ -4333,68 +4327,58 @@ test "llshl shift 0" { |
| 4333 | if (n <= 20) return error.SkipZigTest; | 4327 | if (n <= 20) return error.SkipZigTest; |
| 4334 | | 4328 | |
| 4335 | // zig fmt: off | 4329 | // zig fmt: off |
| 4336 | const cases = &.{ | 4330 | try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}}); |
| 4337 | .{0, &.{0}, &.{0}}, | 4331 | try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}}); |
| 4338 | .{1, &.{0}, &.{0}}, | 4332 | try testOneShiftCase(.llshl, .{5, &.{0}, &.{0}}); |
| 4339 | .{5, &.{0}, &.{0}}, | 4333 | try testOneShiftCase(.llshl, .{13, &.{0}, &.{0}}); |
| 4340 | .{13, &.{0}, &.{0}}, | 4334 | try testOneShiftCase(.llshl, .{20, &.{0}, &.{0}}); |
| 4341 | .{20, &.{0}, &.{0}}, | 4335 | try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}}); |
| 4342 | .{0, &.{0, 0}, &.{0, 0}}, | 4336 | try testOneShiftCase(.llshl, .{2, &.{0, 0}, &.{0, 0}}); |
| 4343 | .{2, &.{0, 0}, &.{0, 0}}, | 4337 | try testOneShiftCase(.llshl, .{7, &.{0, 0}, &.{0, 0}}); |
| 4344 | .{7, &.{0, 0}, &.{0, 0}}, | 4338 | try testOneShiftCase(.llshl, .{11, &.{0, 0}, &.{0, 0}}); |
| 4345 | .{11, &.{0, 0}, &.{0, 0}}, | 4339 | try testOneShiftCase(.llshl, .{19, &.{0, 0}, &.{0, 0}}); |
| 4346 | .{19, &.{0, 0}, &.{0, 0}}, | 4340 | |
| 4347 | | 4341 | try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}}); |
| 4348 | .{0, &.{0}, &.{0}}, | 4342 | try testOneShiftCase(.llshl, .{n, &.{0, 0}, &.{0}}); |
| 4349 | .{n, &.{0, 0}, &.{0}}, | 4343 | try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0}, &.{0}}); |
| 4350 | .{2*n, &.{0, 0, 0}, &.{0}}, | 4344 | try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0}, &.{0}}); |
| 4351 | .{3*n, &.{0, 0, 0, 0}, &.{0}}, | 4345 | try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0}, &.{0}}); |
| 4352 | .{4*n, &.{0, 0, 0, 0, 0}, &.{0}}, | 4346 | try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}}); |
| 4353 | .{0, &.{0, 0}, &.{0, 0}}, | 4347 | try testOneShiftCase(.llshl, .{n, &.{0, 0, 0}, &.{0, 0}}); |
| 4354 | .{n, &.{0, 0, 0}, &.{0, 0}}, | 4348 | try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0, 0}, &.{0, 0}}); |
| 4355 | .{2*n, &.{0, 0, 0, 0}, &.{0, 0}}, | 4349 | try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0, 0}, &.{0, 0}}); |
| 4356 | .{3*n, &.{0, 0, 0, 0, 0}, &.{0, 0}}, | 4350 | try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0, 0}, &.{0, 0}}); |
| 4357 | .{4*n, &.{0, 0, 0, 0, 0, 0}, &.{0, 0}}, | | |
| 4358 | }; | | |
| 4359 | // zig fmt: on | 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 | test "llshr shift 0" { | 4354 | test "llshr shift 0" { |
| 4366 | const n = @bitSizeOf(Limb); | 4355 | const n = @bitSizeOf(Limb); |
| 4367 | | 4356 | |
| 4368 | // zig fmt: off | 4357 | // zig fmt: off |
| 4369 | const cases = &.{ | 4358 | try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}}); |
| 4370 | .{0, &.{0}, &.{0}}, | 4359 | try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}}); |
| 4371 | .{1, &.{0}, &.{0}}, | 4360 | try testOneShiftCase(.llshr, .{5, &.{0}, &.{0}}); |
| 4372 | .{5, &.{0}, &.{0}}, | 4361 | try testOneShiftCase(.llshr, .{13, &.{0}, &.{0}}); |
| 4373 | .{13, &.{0}, &.{0}}, | 4362 | try testOneShiftCase(.llshr, .{20, &.{0}, &.{0}}); |
| 4374 | .{20, &.{0}, &.{0}}, | 4363 | try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}}); |
| 4375 | .{0, &.{0, 0}, &.{0, 0}}, | 4364 | try testOneShiftCase(.llshr, .{2, &.{0}, &.{0, 0}}); |
| 4376 | .{2, &.{0}, &.{0, 0}}, | 4365 | try testOneShiftCase(.llshr, .{7, &.{0}, &.{0, 0}}); |
| 4377 | .{7, &.{0}, &.{0, 0}}, | 4366 | try testOneShiftCase(.llshr, .{11, &.{0}, &.{0, 0}}); |
| 4378 | .{11, &.{0}, &.{0, 0}}, | 4367 | try testOneShiftCase(.llshr, .{19, &.{0}, &.{0, 0}}); |
| 4379 | .{19, &.{0}, &.{0, 0}}, | 4368 | |
| 4380 | | 4369 | try testOneShiftCase(.llshr, .{n, &.{0}, &.{0}}); |
| 4381 | .{n, &.{0}, &.{0}}, | 4370 | try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0}}); |
| 4382 | .{2*n, &.{0}, &.{0}}, | 4371 | try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0}}); |
| 4383 | .{3*n, &.{0}, &.{0}}, | 4372 | try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0}}); |
| 4384 | .{4*n, &.{0}, &.{0}}, | 4373 | try testOneShiftCase(.llshr, .{n, &.{0}, &.{0, 0}}); |
| 4385 | .{n, &.{0}, &.{0, 0}}, | 4374 | try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0, 0}}); |
| 4386 | .{2*n, &.{0}, &.{0, 0}}, | 4375 | try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0, 0}}); |
| 4387 | .{3*n, &.{0}, &.{0, 0}}, | 4376 | try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0, 0}}); |
| 4388 | .{4*n, &.{0}, &.{0, 0}}, | 4377 | |
| 4389 | | 4378 | try testOneShiftCase(.llshr, .{1, &.{}, &.{}}); |
| 4390 | .{1, &.{}, &.{}}, | 4379 | try testOneShiftCase(.llshr, .{2, &.{}, &.{}}); |
| 4391 | .{2, &.{}, &.{}}, | 4380 | try testOneShiftCase(.llshr, .{64, &.{}, &.{}}); |
| 4392 | .{64, &.{}, &.{}}, | | |
| 4393 | }; | | |
| 4394 | // zig fmt: on | 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 | test "llshr to 0" { | 4384 | test "llshr to 0" { |
| ... | @@ -4402,19 +4386,14 @@ test "llshr to 0" { | ... | @@ -4402,19 +4386,14 @@ test "llshr to 0" { |
| 4402 | if (n != 64 and n != 32) return error.SkipZigTest; | 4386 | if (n != 64 and n != 32) return error.SkipZigTest; |
| 4403 | | 4387 | |
| 4404 | // zig fmt: off | 4388 | // zig fmt: off |
| 4405 | const cases = &.{ | 4389 | try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}}); |
| 4406 | .{1, &.{0}, &.{0}}, | 4390 | try testOneShiftCase(.llshr, .{1, &.{0}, &.{1}}); |
| 4407 | .{1, &.{0}, &.{1}}, | 4391 | try testOneShiftCase(.llshr, .{5, &.{0}, &.{1}}); |
| 4408 | .{5, &.{0}, &.{1}}, | 4392 | try testOneShiftCase(.llshr, .{65, &.{0}, &.{0, 1}}); |
| 4409 | .{65, &.{0}, &.{0, 1}}, | 4393 | try testOneShiftCase(.llshr, .{193, &.{0}, &.{0, 0, std.math.maxInt(Limb)}}); |
| 4410 | .{193, &.{0}, &.{0, 0, std.math.maxInt(Limb)}}, | 4394 | try testOneShiftCase(.llshr, .{193, &.{0}, &.{std.math.maxInt(Limb), 1, std.math.maxInt(Limb)}}); |
| 4411 | .{193, &.{0}, &.{std.math.maxInt(Limb), 1, std.math.maxInt(Limb)}}, | 4395 | try testOneShiftCase(.llshr, .{193, &.{0}, &.{0xdeadbeef, 0xabcdefab, 0x1234}}); |
| 4412 | .{193, &.{0}, &.{0xdeadbeef, 0xabcdefab, 0x1234}}, | | |
| 4413 | }; | | |
| 4414 | // zig fmt: on | 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 | test "llshr single" { | 4399 | test "llshr single" { |
| ... | @@ -4425,30 +4404,25 @@ test "llshr single" { | ... | @@ -4425,30 +4404,25 @@ test "llshr single" { |
| 4425 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; | 4404 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4426 | | 4405 | |
| 4427 | // zig fmt: off | 4406 | // zig fmt: off |
| 4428 | const cases: Cases = &.{ | 4407 | try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}}); |
| 4429 | .{0, &.{0}, &.{0}}, | 4408 | try testOneShiftCase(.llshr, .{0, &.{1}, &.{1}}); |
| 4430 | .{0, &.{1}, &.{1}}, | 4409 | try testOneShiftCase(.llshr, .{0, &.{125484842448}, &.{125484842448}}); |
| 4431 | .{0, &.{125484842448}, &.{125484842448}}, | 4410 | try testOneShiftCase(.llshr, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}}); |
| 4432 | .{0, &.{0xdeadbeef}, &.{0xdeadbeef}}, | 4411 | try testOneShiftCase(.llshr, .{0, &.{maxint}, &.{maxint}}); |
| 4433 | .{0, &.{maxint}, &.{maxint}}, | 4412 | try testOneShiftCase(.llshr, .{0, &.{left_one}, &.{left_one}}); |
| 4434 | .{0, &.{left_one}, &.{left_one}}, | 4413 | try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}}); |
| 4435 | .{1, &.{0}, &.{0}}, | 4414 | try testOneShiftCase(.llshr, .{1, &.{1}, &.{2}}); |
| 4436 | .{1, &.{1}, &.{2}}, | 4415 | try testOneShiftCase(.llshr, .{1, &.{62742421224}, &.{125484842448}}); |
| 4437 | .{1, &.{62742421224}, &.{125484842448}}, | 4416 | try testOneShiftCase(.llshr, .{1, &.{62742421223}, &.{125484842447}}); |
| 4438 | .{1, &.{62742421223}, &.{125484842447}}, | 4417 | try testOneShiftCase(.llshr, .{1, &.{0x6f56df77}, &.{0xdeadbeef}}); |
| 4439 | .{1, &.{0x6f56df77}, &.{0xdeadbeef}}, | 4418 | try testOneShiftCase(.llshr, .{1, &.{0x7fffffffffffffff}, &.{maxint}}); |
| 4440 | .{1, &.{0x7fffffffffffffff}, &.{maxint}}, | 4419 | try testOneShiftCase(.llshr, .{1, &.{0x4000000000000000}, &.{left_one}}); |
| 4441 | .{1, &.{0x4000000000000000}, &.{left_one}}, | 4420 | try testOneShiftCase(.llshr, .{8, &.{1}, &.{256}}); |
| 4442 | .{8, &.{1}, &.{256}}, | 4421 | try testOneShiftCase(.llshr, .{8, &.{490175165}, &.{125484842448}}); |
| 4443 | .{8, &.{490175165}, &.{125484842448}}, | 4422 | try testOneShiftCase(.llshr, .{8, &.{0xdeadbe}, &.{0xdeadbeef}}); |
| 4444 | .{8, &.{0xdeadbe}, &.{0xdeadbeef}}, | 4423 | try testOneShiftCase(.llshr, .{8, &.{0xffffffffffffff}, &.{maxint}}); |
| 4445 | .{8, &.{0xffffffffffffff}, &.{maxint}}, | 4424 | try testOneShiftCase(.llshr, .{8, &.{0x80000000000000}, &.{left_one}}); |
| 4446 | .{8, &.{0x80000000000000}, &.{left_one}}, | | |
| 4447 | }; | | |
| 4448 | // zig fmt: on | 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 | test llshr { | 4428 | test llshr { |
| ... | @@ -4459,65 +4433,65 @@ test llshr { | ... | @@ -4459,65 +4433,65 @@ test llshr { |
| 4459 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; | 4433 | const maxint: Limb = 0xFFFFFFFFFFFFFFFF; |
| 4460 | | 4434 | |
| 4461 | // zig fmt: off | 4435 | // zig fmt: off |
| 4462 | const cases: Cases = &.{ | 4436 | try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}}); |
| 4463 | .{0, &.{0, 0}, &.{0, 0}}, | 4437 | try testOneShiftCase(.llshr, .{0, &.{0, 1}, &.{0, 1}}); |
| 4464 | .{0, &.{0, 1}, &.{0, 1}}, | 4438 | try testOneShiftCase(.llshr, .{0, &.{15, 1}, &.{15, 1}}); |
| 4465 | .{0, &.{15, 1}, &.{15, 1}}, | 4439 | try testOneShiftCase(.llshr, .{0, &.{987656565, 123456789456}, &.{987656565, 123456789456}}); |
| 4466 | .{0, &.{987656565, 123456789456}, &.{987656565, 123456789456}}, | 4440 | try testOneShiftCase(.llshr, .{0, &.{0xfeebdaed, 0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}}); |
| 4467 | .{0, &.{0xfeebdaed, 0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}}, | 4441 | try testOneShiftCase(.llshr, .{0, &.{1, maxint}, &.{1, maxint}}); |
| 4468 | .{0, &.{1, maxint}, &.{1, maxint}}, | 4442 | try testOneShiftCase(.llshr, .{0, &.{0, left_one}, &.{0, left_one}}); |
| 4469 | .{0, &.{0, left_one}, &.{0, left_one}}, | 4443 | try testOneShiftCase(.llshr, .{1, &.{0}, &.{0, 0}}); |
| 4470 | .{1, &.{0}, &.{0, 0}}, | 4444 | try testOneShiftCase(.llshr, .{1, &.{left_one}, &.{0, 1}}); |
| 4471 | .{1, &.{left_one}, &.{0, 1}}, | 4445 | try testOneShiftCase(.llshr, .{1, &.{0x8000000000000007}, &.{15, 1}}); |
| 4472 | .{1, &.{0x8000000000000007}, &.{15, 1}}, | 4446 | try testOneShiftCase(.llshr, .{1, &.{493828282, 61728394728}, &.{987656565, 123456789456}}); |
| 4473 | .{1, &.{493828282, 61728394728}, &.{987656565, 123456789456}}, | 4447 | try testOneShiftCase(.llshr, .{1, &.{0x800000007f75ed76, 0x6f56df77}, &.{0xfeebdaed, 0xdeadbeef}}); |
| 4474 | .{1, &.{0x800000007f75ed76, 0x6f56df77}, &.{0xfeebdaed, 0xdeadbeef}}, | 4448 | try testOneShiftCase(.llshr, .{1, &.{left_one, 0x7fffffffffffffff}, &.{1, maxint}}); |
| 4475 | .{1, &.{left_one, 0x7fffffffffffffff}, &.{1, maxint}}, | 4449 | try testOneShiftCase(.llshr, .{1, &.{0, 0x4000000000000000}, &.{0, left_one}}); |
| 4476 | .{1, &.{0, 0x4000000000000000}, &.{0, left_one}}, | 4450 | try testOneShiftCase(.llshr, .{64, &.{0}, &.{0, 0}}); |
| 4477 | .{64, &.{0}, &.{0, 0}}, | 4451 | try testOneShiftCase(.llshr, .{64, &.{1}, &.{0, 1}}); |
| 4478 | .{64, &.{1}, &.{0, 1}}, | 4452 | try testOneShiftCase(.llshr, .{64, &.{1}, &.{15, 1}}); |
| 4479 | .{64, &.{1}, &.{15, 1}}, | 4453 | try testOneShiftCase(.llshr, .{64, &.{123456789456}, &.{987656565, 123456789456}}); |
| 4480 | .{64, &.{123456789456}, &.{987656565, 123456789456}}, | 4454 | try testOneShiftCase(.llshr, .{64, &.{0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}}); |
| 4481 | .{64, &.{0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}}, | 4455 | try testOneShiftCase(.llshr, .{64, &.{maxint}, &.{1, maxint}}); |
| 4482 | .{64, &.{maxint}, &.{1, maxint}}, | 4456 | try testOneShiftCase(.llshr, .{64, &.{left_one}, &.{0, left_one}}); |
| 4483 | .{64, &.{left_one}, &.{0, left_one}}, | 4457 | try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 0}}); |
| 4484 | .{72, &.{0}, &.{0, 0}}, | 4458 | try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 1}}); |
| 4485 | .{72, &.{0}, &.{0, 1}}, | 4459 | try testOneShiftCase(.llshr, .{72, &.{0}, &.{15, 1}}); |
| 4486 | .{72, &.{0}, &.{15, 1}}, | 4460 | try testOneShiftCase(.llshr, .{72, &.{482253083}, &.{987656565, 123456789456}}); |
| 4487 | .{72, &.{482253083}, &.{987656565, 123456789456}}, | 4461 | try testOneShiftCase(.llshr, .{72, &.{0xdeadbe}, &.{0xfeebdaed, 0xdeadbeef}}); |
| 4488 | .{72, &.{0xdeadbe}, &.{0xfeebdaed, 0xdeadbeef}}, | 4462 | try testOneShiftCase(.llshr, .{72, &.{0xffffffffffffff}, &.{1, maxint}}); |
| 4489 | .{72, &.{0xffffffffffffff}, &.{1, maxint}}, | 4463 | try testOneShiftCase(.llshr, .{72, &.{0x80000000000000}, &.{0, left_one}}); |
| 4490 | .{72, &.{0x80000000000000}, &.{0, left_one}}, | | |
| 4491 | }; | | |
| 4492 | // zig fmt: on | 4464 | // zig fmt: on |
| | 4465 | } |
| 4493 | | 4466 | |
| 4494 | try test_shift_cases(llshr, cases); | 4467 | const Case = struct { usize, []const Limb, []const Limb }; |
| 4495 | try test_shift_cases_aliasing(llshr, cases, 1); | 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 }; | 4477 | fn testOneShiftCaseNoAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case) !void { |
| 4499 | fn test_shift_cases(func: fn ([]Limb, []const Limb, usize) usize, cases: Cases) !void { | | |
| 4500 | const padding = std.math.maxInt(Limb); | 4478 | const padding = std.math.maxInt(Limb); |
| 4501 | var r: [20]Limb = @splat(padding); | 4479 | var r: [20]Limb = @splat(padding); |
| 4502 | | 4480 | |
| 4503 | for (cases) |case| { | 4481 | const shift = case[0]; |
| 4504 | const shift = case[0]; | 4482 | const expected = case[1]; |
| 4505 | const expected = case[1]; | 4483 | const data = case[2]; |
| 4506 | 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); | 4487 | const len = func(&r, data, shift); |
| 4511 | const len = func(&r, data, shift); | | |
| 4512 | | 4488 | |
| 4513 | try std.testing.expectEqual(expected.len, len); | 4489 | try std.testing.expectEqual(expected.len, len); |
| 4514 | try std.testing.expectEqualSlices(Limb, expected, r[0..len]); | 4490 | try std.testing.expectEqualSlices(Limb, expected, r[0..len]); |
| 4515 | for (r[len..]) |x| | 4491 | try std.testing.expect(mem.allEqual(Limb, r[len..], padding)); |
| 4516 | try std.testing.expectEqual(padding, x); | | |
| 4517 | } | | |
| 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 | const padding = std.math.maxInt(Limb); | 4495 | const padding = std.math.maxInt(Limb); |
| 4522 | var r: [60]Limb = @splat(padding); | 4496 | var r: [60]Limb = @splat(padding); |
| 4523 | const base = 20; | 4497 | const base = 20; |
| ... | @@ -4525,22 +4499,20 @@ fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases | ... | @@ -4525,22 +4499,20 @@ fn test_shift_cases_aliasing(func: fn ([]Limb, []const Limb, usize) usize, cases |
| 4525 | assert(shift_direction == 1 or shift_direction == -1); | 4499 | assert(shift_direction == 1 or shift_direction == -1); |
| 4526 | | 4500 | |
| 4527 | for (0..10) |limb_shift| { | 4501 | for (0..10) |limb_shift| { |
| 4528 | for (cases) |case| { | 4502 | const shift = case[0]; |
| 4529 | const shift = case[0]; | 4503 | const expected = case[1]; |
| 4530 | const expected = case[1]; | 4504 | const data = case[2]; |
| 4531 | 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); | 4508 | @memset(&r, padding); |
| 4536 | const final_limb_base: usize = @intCast(base + shift_direction * @as(isize, @intCast(limb_shift))); | 4509 | 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]; | 4510 | const written_data = r[final_limb_base..][0..data.len]; |
| 4538 | @memcpy(written_data, data); | 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); | 4515 | try std.testing.expectEqual(expected.len, len); |
| 4543 | try std.testing.expectEqualSlices(Limb, expected, r[base .. base + len]); | 4516 | try std.testing.expectEqualSlices(Limb, expected, r[base .. base + len]); |
| 4544 | } | | |
| 4545 | } | 4517 | } |
| 4546 | } | 4518 | } |