diff options
| author | kcbanner <kcbanner@gmail.com> | 2022-12-29 13:44:40 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-01-02 13:55:45 -0700 |
| commit | 9c70315854735ab9ecd572e327f41ea547033f09 (patch) | |
| tree | 758a4a381e90af513771cde4287d60d476c173d0 /test/behavior/math.zig | |
| parent | 0251ce1e1bdf47765fc7280aab1816b50084c0b8 (diff) | |
| download | zig-9c70315854735ab9ecd572e327f41ea547033f09.tar.gz zig-9c70315854735ab9ecd572e327f41ea547033f09.zip | |
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)
Diffstat (limited to 'test/behavior/math.zig')
| -rw-r--r-- | test/behavior/math.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 5252efe2fa..0f2139dcfe 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -377,6 +377,23 @@ fn testBinaryNot(x: u16) !void { try expect(~x == 0b0101010101010101); } + +test "binary not 128-bit" { + try expect(comptime x: { + break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa; + }); + try expect(comptime x: { + break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)); + }); + + try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa); + try testBinaryNot128(i128, @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa))); +} + +fn testBinaryNot128(comptime Type: type, x: Type) !void { + try expect(~x == @as(Type, 0x55555555_55555555_55555555_55555555)); +} + test "division" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
