authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2022-12-29 13:44:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-02 13:55:45-07:00
log9c70315854735ab9ecd572e327f41ea547033f09
tree758a4a381e90af513771cde4287d60d476c173d0
parent0251ce1e1bdf47765fc7280aab1816b50084c0b8

tests: add more coverage for 128 bit operations

- fixup 128-bit atomics test to only run on x86_64 - add truncation test for 128-bit types, including non power of two targets (there was a bug with broken non-power-of-two truncation in the cbe) - add 128-bit binary not test (covers another bug fixed in the cbe)

3 files changed, 34 insertions(+), 9 deletions(-)

test/behavior/atomics.zig+4-7
......@@ -308,16 +308,13 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi
308308}
309309
310310test "atomicrmw with 128-bit ints" {
311 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
312 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
313 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
314 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
315 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
316
317 if (builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) {
311 if (builtin.cpu.arch != .x86_64) {
312 // TODO: Ideally this could use target.atomicPtrAlignment and check for IntTooBig
318313 return error.SkipZigTest;
319314 }
320315
316 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
317
321318 try testAtomicRmwInt128(.unsigned);
322319 comptime try testAtomicRmwInt128(.unsigned);
323320}
test/behavior/int128.zig+13-2
......@@ -69,6 +69,17 @@ test "truncate int128" {
6969 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
7070 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7171
72 var buff: u128 = maxInt(u128);
73 try expect(@truncate(u64, buff) == maxInt(u64));
72 {
73 var buff: u128 = maxInt(u128);
74 try expect(@truncate(u64, buff) == maxInt(u64));
75 try expect(@truncate(u90, buff) == maxInt(u90));
76 try expect(@truncate(u128, buff) == maxInt(u128));
77 }
78
79 {
80 var buff: i128 = maxInt(i128);
81 try expect(@truncate(i64, buff) == -1);
82 try expect(@truncate(i90, buff) == -1);
83 try expect(@truncate(i128, buff) == maxInt(i128));
84 }
7485}
test/behavior/math.zig+17
......@@ -377,6 +377,23 @@ fn testBinaryNot(x: u16) !void {
377377 try expect(~x == 0b0101010101010101);
378378}
379379
380
381test "binary not 128-bit" {
382 try expect(comptime x: {
383 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;
384 });
385 try expect(comptime x: {
386 break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa));
387 });
388
389 try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa);
390 try testBinaryNot128(i128, @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)));
391}
392
393fn testBinaryNot128(comptime Type: type, x: Type) !void {
394 try expect(~x == @as(Type, 0x55555555_55555555_55555555_55555555));
395}
396
380397test "division" {
381398 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
382399 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO