aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/vector.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-04 12:21:31 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-04 12:23:49 -0700
commitac2333ee63b3c0af8a075d325e2313c9b255a46e (patch)
tree8e5d07a4aaa946c1c681428adafde533d58f5c59 /test/behavior/vector.zig
parenta28f2e0dd2d7b78464115bca4968f7c0befa6b28 (diff)
downloadzig-ac2333ee63b3c0af8a075d325e2313c9b255a46e.tar.gz
zig-ac2333ee63b3c0af8a075d325e2313c9b255a46e.zip
stage2: fix Type max/min int calculation
This was an attempt to move saturating_arithmetic.zig to the "passing for stage2" section, which did not pan out due to the discovery of 2 prerequisite items that need to be done, but I did make a bug fix along the way of the calculation of max/min integers. This commit also simplifies the saturating arithmetic behavior tests to depend on less of the zig language that is not related to saturating arithmetic.
Diffstat (limited to 'test/behavior/vector.zig')
-rw-r--r--test/behavior/vector.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig
index b673542f8b..7ab1cd59ed 100644
--- a/test/behavior/vector.zig
+++ b/test/behavior/vector.zig
@@ -647,3 +647,53 @@ test "mask parameter of @shuffle is comptime scope" {
});
_ = shuffled;
}
+
+test "saturating add" {
+ const S = struct {
+ fn doTheTest() !void {
+ const u8x3 = std.meta.Vector(3, u8);
+ try expectEqual(u8x3{ 255, 255, 255 }, (u8x3{ 255, 254, 1 } +| u8x3{ 1, 2, 255 }));
+ const i8x3 = std.meta.Vector(3, i8);
+ try expectEqual(i8x3{ 127, 127, 127 }, (i8x3{ 127, 126, 1 } +| i8x3{ 1, 2, 127 }));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "saturating subtraction" {
+ const S = struct {
+ fn doTheTest() !void {
+ const u8x3 = std.meta.Vector(3, u8);
+ try expectEqual(u8x3{ 0, 0, 0 }, (u8x3{ 0, 0, 0 } -| u8x3{ 255, 255, 255 }));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "saturating multiplication" {
+ // TODO: once #9660 has been solved, remove this line
+ if (std.builtin.target.cpu.arch == .wasm32) return error.SkipZigTest;
+
+ const S = struct {
+ fn doTheTest() !void {
+ const u8x3 = std.meta.Vector(3, u8);
+ try expectEqual(u8x3{ 255, 255, 255 }, (u8x3{ 2, 2, 2 } *| u8x3{ 255, 255, 255 }));
+ }
+ };
+
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "saturating shift-left" {
+ const S = struct {
+ fn doTheTest() !void {
+ const u8x3 = std.meta.Vector(3, u8);
+ try expectEqual(u8x3{ 255, 255, 255 }, (u8x3{ 255, 255, 255 } <<| u8x3{ 1, 1, 1 }));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}