authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-06-19 17:27:29+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-06-19 17:27:56+02:00
log4957c7cbbd5ffa2c44970cc34a9274ae42f0f3fb
tree9909b54b07498925ff6a2365f4536dc781d509f5
parenta50147bfff1224d090b13ed934eda97dbfd6432b
signaturelock-open Commit is signed but in an unrecognized format.

wasm: enable passing behavior tests

This also splits the test cases for addition and subtraction as the wasm backend does not yet provide support for 128bit saturating arithmetic.

1 files changed, 52 insertions(+), 10 deletions(-)

test/behavior/saturating_arithmetic.zig+52-10
......@@ -5,7 +5,6 @@ const maxInt = std.math.maxInt;
55const expect = std.testing.expect;
66
77test "saturating add" {
8 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
98 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
109 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1110 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
......@@ -20,8 +19,6 @@ test "saturating add" {
2019 try testSatAdd(i2, 1, -1, 0);
2120 try testSatAdd(i2, -1, -1, -2);
2221 try testSatAdd(i64, maxInt(i64), 1, maxInt(i64));
23 try testSatAdd(i128, maxInt(i128), -maxInt(i128), 0);
24 try testSatAdd(i128, minInt(i128), maxInt(i128), -1);
2522 try testSatAdd(i8, 127, 127, 127);
2623 try testSatAdd(u2, 0, 0, 0);
2724 try testSatAdd(u2, 0, 1, 1);
......@@ -29,7 +26,6 @@ test "saturating add" {
2926 try testSatAdd(u8, 255, 255, 255);
3027 try testSatAdd(u2, 3, 2, 3);
3128 try testSatAdd(u3, 7, 1, 7);
32 try testSatAdd(u128, maxInt(u128), 1, maxInt(u128));
3329 }
3430
3531 fn testSatAdd(comptime T: type, lhs: T, rhs: T, expected: T) !void {
......@@ -54,12 +50,36 @@ test "saturating add" {
5450 comptime try S.testSatAdd(comptime_int, 7, -593423721213448152027139550640105366508, -593423721213448152027139550640105366501);
5551}
5652
57test "saturating subtraction" {
53test "saturating add 128bit" {
5854 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
5955 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
6056 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
6157 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
6258 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
59 const S = struct {
60 fn doTheTest() !void {
61 try testSatAdd(i128, maxInt(i128), -maxInt(i128), 0);
62 try testSatAdd(i128, minInt(i128), maxInt(i128), -1);
63 try testSatAdd(u128, maxInt(u128), 1, maxInt(u128));
64 }
65 fn testSatAdd(comptime T: type, lhs: T, rhs: T, expected: T) !void {
66 try expect((lhs +| rhs) == expected);
67
68 var x = lhs;
69 x +|= rhs;
70 try expect(x == expected);
71 }
72 };
73
74 try S.doTheTest();
75 comptime try S.doTheTest();
76}
77
78test "saturating subtraction" {
79 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
80 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
81 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
82 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
6383
6484 const S = struct {
6585 fn doTheTest() !void {
......@@ -71,14 +91,11 @@ test "saturating subtraction" {
7191 try testSatSub(i2, 1, -1, 1);
7292 try testSatSub(i2, -2, -2, 0);
7393 try testSatSub(i64, minInt(i64), 1, minInt(i64));
74 try testSatSub(i128, maxInt(i128), -1, maxInt(i128));
75 try testSatSub(i128, minInt(i128), -maxInt(i128), -1);
7694 try testSatSub(u2, 0, 0, 0);
7795 try testSatSub(u2, 0, 1, 0);
7896 try testSatSub(u5, 0, 31, 0);
7997 try testSatSub(u8, 10, 3, 7);
8098 try testSatSub(u8, 0, 255, 0);
81 try testSatSub(u128, 0, maxInt(u128), 0);
8299 }
83100
84101 fn testSatSub(comptime T: type, lhs: T, rhs: T, expected: T) !void {
......@@ -103,6 +120,33 @@ test "saturating subtraction" {
103120 comptime try S.testSatSub(comptime_int, 7, -593423721213448152027139550640105366508, 593423721213448152027139550640105366515);
104121}
105122
123test "saturating subtraction 128bit" {
124 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
125 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
126 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
127 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
128 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
129
130 const S = struct {
131 fn doTheTest() !void {
132 try testSatSub(i128, maxInt(i128), -1, maxInt(i128));
133 try testSatSub(i128, minInt(i128), -maxInt(i128), -1);
134 try testSatSub(u128, 0, maxInt(u128), 0);
135 }
136
137 fn testSatSub(comptime T: type, lhs: T, rhs: T, expected: T) !void {
138 try expect((lhs -| rhs) == expected);
139
140 var x = lhs;
141 x -|= rhs;
142 try expect(x == expected);
143 }
144 };
145
146 try S.doTheTest();
147 comptime try S.doTheTest();
148}
149
106150test "saturating multiplication" {
107151 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
108152 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
......@@ -153,7 +197,6 @@ test "saturating multiplication" {
153197}
154198
155199test "saturating shift-left" {
156 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
157200 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
158201 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
159202 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
......@@ -193,7 +236,6 @@ test "saturating shift-left" {
193236}
194237
195238test "saturating shl uses the LHS type" {
196 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
197239 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
198240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
199241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO