Debian Codegraph @

js/src/jit-test/tests/wasm/compare-select-i32-i64.js

raw
1
2 // Comprehensively test wasm compare-then-select, for all combinations of
3 //
4 // compare in i32 i64
5 // select in i32 i64
6 // compare-op in eq ne lt_s lt_u gt_s gt_u le_s le_u ge_s ge_u
7 //
8 // and using comparison values from all 4 quadrant points of the range,
9 // including at least one either side, so as to catch off-by-one comparison
10 // errors. In total 9000 tests.
11
12 const cmpVals32
13 = [ 0x00000000, 0x00000001, 0x00000002,
14 0x3fffffff, 0x40000000, 0x40000001,
15 0x7fffffff, 0x80000000, 0x80000001,
16 0xbfffffff, 0xc0000000, 0xc0000001,
17 0xfffffffd, 0xfffffffe, 0xffffffff ];
18
19 const cmpVals64
20 = [ 0x0000000000000000n, 0x0000000000000001n, 0x0000000000000002n,
21 0x3fffffffffffffffn, 0x4000000000000000n, 0x4000000000000001n,
22 0x7fffffffffffffffn, 0x8000000000000000n, 0x8000000000000001n,
23 0xbfffffffffffffffn, 0xc000000000000000n, 0xc000000000000001n,
24 0xfffffffffffffffdn, 0xfffffffffffffffen, 0xffffffffffffffffn ];
25
26 const selVal32L = 0x55551234;
27 const selVal32R = 0x55554321;
28
29 const selVal64L = 0x5555555555554771n;
30 const selVal64R = 0x5555555555551337n;
31
32 function getCmpVals(cmpTy) {
33 if (cmpTy === 'i32') {
34 return cmpVals32;
35 } else {
36 assertEq(cmpTy, 'i64');
37 return cmpVals64;
38 }
39 }
40
41 function classifyResult(selTy, result) {
42 if (selTy === 'i32') {
43 if (result === selVal32L) {
44 return '0';
45 }
46 if (result === selVal32R) {
47 return '1';
48 }
49 } else {
50 assertEq(selTy, 'i64');
51 if (result === selVal64L) {
52 return '2';
53 }
54 if (result === selVal64R) {
55 return '3';
56 }
57 }
58 // Anything that is not '0', '1', '2' or '3' will cause the final
59 // summary-string comparison below to fail.
60 return 'BAD';
61 }
62
63 let actualSummaryString = '';
64
65 for ( cmpTy of [ 'i32', 'i64' ] ) {
66 for ( selTy of [ 'i32', 'i64' ] ) {
67 for ( cmpOp of [ 'eq', 'ne',
68 'lt_s', 'lt_u', 'gt_s', 'gt_u',
69 'le_s', 'le_u', 'ge_s', 'ge_u' ] ) {
70 let t =
71 `(module
72 (func (export "f")
73 (param $p1 ${cmpTy}) (param $p2 ${cmpTy})
74 (param $p3 ${selTy}) (param $p4 ${selTy})
75 (result ${selTy})
76 (select (local.get $p3)
77 (local.get $p4)
78 (${cmpTy}.${cmpOp} (local.get $p1) (local.get $p2)))
79 )
80 )`;
81 let i = new WebAssembly.Instance(
82 new WebAssembly.Module(wasmTextToBinary(t)));
83 let cmpVals = getCmpVals(cmpTy);
84 let selValL, selValR;
85 if (selTy === 'i32') {
86 selValL = selVal32L;
87 selValR = selVal32R;
88 } else {
89 assertEq(selTy, 'i64');
90 selValL = selVal64L;
91 selValR = selVal64R;
92 }
93 for ( cmpValL of cmpVals ) {
94 for ( cmpValR of cmpVals ) {
95 let res = i.exports.f(cmpValL, cmpValR, selValL, selValR);
96 // We expect res to be one of selVal<selTy>{L,R} values.
97 // Check that and add its summary to the running string.
98 let classified = classifyResult(selTy, res);
99 actualSummaryString += classified;
100 }
101 }
102 }
103 }
104 }
105
106 // We expect to run exactly 9000 tests:
107 // 2 cmp types x 2 sel types x 10 conditions (= 40 wasm functions)
108 // x 15 cmp argLs x 15 cmp argRs = 9000
109 assertEq(actualSummaryString.length, 9000);
110
111 // The expected summary string, one char for each test, encoded per
112 // function classifyResult above. 150 lines of 60 chars each.
113
114 let expectedSummaryString
115 =
116 '011111111111111101111111111111110111111111111111011111111111' +
117 '111101111111111111110111111111111111011111111111111101111111' +
118 '111111110111111111111111011111111111111101111111111111110111' +
119 '111111111111011111111111111101111111111111110100000000000000' +
120 '010000000000000001000000000000000100000000000000010000000000' +
121 '000001000000000000000100000000000000010000000000000001000000' +
122 '000000000100000000000000010000000000000001000000000000000100' +
123 '000000000000010000000000000001100000011111111110000011111111' +
124 '111000011111111111100011111111111110011111111111111011111111' +
125 '111111111111111000000010000000000000011000000000000011100000' +
126 '000000011110000000000011111000000000011111100000000011111110' +
127 '000000011111111100000000000000110000000000000111000000000000' +
128 '111100000000000111110000000000111111000000000111111100000000' +
129 '111111110000000111111111000000111111111100000111111111110000' +
130 '111111111111000111111111111100111111111111110111111111111111' +
131 '111111100000000011111100000000001111100000000000111100000000' +
132 '000011100000000000001100000000000000100000000111111111111111' +
133 '111111101111111111111100111111111111100011111111111100001111' +
134 '111111100000111111111100000011111111100000001111111111111111' +
135 '011111111111111001111111111111000111111111111000011111111111' +
136 '000001111111111000000111111111000000011111111000000001111111' +
137 '000000000111111000000000011111000000000001111000000000000111' +
138 '000000000000011000000000000001000000011111111100000011111111' +
139 '110000011111111111000011111111111100011111111111110011111111' +
140 '111111011111111000000000000000000000010000000000000011000000' +
141 '000000011100000000000011110000000000011111000000000011111100' +
142 '000000011111110000000000000000100000000000000110000000000000' +
143 '111000000000000111100000000000111110000000000111111000000000' +
144 '111111100000000111111110000000111111111000000111111111100000' +
145 '111111111110000111111111111000111111111111100111111111111110' +
146 '011111100000000001111100000000000111100000000000011100000000' +
147 '000001100000000000000100000000000000000000000111111101111111' +
148 '111111100111111111111100011111111111100001111111111100000111' +
149 '111111100000011111111100000001111111100000000011111111111111' +
150 '001111111111111000111111111111000011111111111000001111111111' +
151 '000000111111111000000011111111000000001111111000000000111111' +
152 '000000000011111000000000001111000000000000111000000000000011' +
153 '000000000000001000000000000000233333333333333323333333333333' +
154 '332333333333333333233333333333333323333333333333332333333333' +
155 '333333233333333333333323333333333333332333333333333333233333' +
156 '333333333323333333333333332333333333333333233333333333333323' +
157 '333333333333332322222222222222232222222222222223222222222222' +
158 '222322222222222222232222222222222223222222222222222322222222' +
159 '222222232222222222222223222222222222222322222222222222232222' +
160 '222222222223222222222222222322222222222222232222222222222223' +
161 '322222233333333332222233333333333222233333333333322233333333' +
162 '333332233333333333333233333333333333333333333222222232222222' +
163 '222222233222222222222233322222222222233332222222222233333222' +
164 '222222233333322222222233333332222222233333333322222222222222' +
165 '332222222222222333222222222222333322222222222333332222222222' +
166 '333333222222222333333322222222333333332222222333333333222222' +
167 '333333333322222333333333332222333333333333222333333333333322' +
168 '333333333333332333333333333333333333322222222233333322222222' +
169 '223333322222222222333322222222222233322222222222223322222222' +
170 '222222322222222333333333333333333333323333333333333322333333' +
171 '333333322233333333333322223333333333322222333333333322222233' +
172 '333333322222223333333333333333233333333333333223333333333333' +
173 '222333333333333222233333333333222223333333333222222333333333' +
174 '222222233333333222222223333333222222222333333222222222233333' +
175 '222222222223333222222222222333222222222222233222222222222223' +
176 '222222233333333322222233333333332222233333333333222233333333' +
177 '333322233333333333332233333333333333233333333222222222222222' +
178 '222222232222222222222233222222222222233322222222222233332222' +
179 '222222233333222222222233333322222222233333332222222222222222' +
180 '322222222222222332222222222222333222222222222333322222222222' +
181 '333332222222222333333222222222333333322222222333333332222222' +
182 '333333333222222333333333322222333333333332222333333333333222' +
183 '333333333333322333333333333332233333322222222223333322222222' +
184 '222333322222222222233322222222222223322222222222222322222222' +
185 '222222222222222333333323333333333333322333333333333322233333' +
186 '333333322223333333333322222333333333322222233333333322222223' +
187 '333333322222222233333333333333223333333333333222333333333333' +
188 '222233333333333222223333333333222222333333333222222233333333' +
189 '222222223333333222222222333333222222222233333222222222223333' +
190 '222222222222333222222222222233222222222222223222222222222222' +
191 '011111111111111101111111111111110111111111111111011111111111' +
192 '111101111111111111110111111111111111011111111111111101111111' +
193 '111111110111111111111111011111111111111101111111111111110111' +
194 '111111111111011111111111111101111111111111110100000000000000' +
195 '010000000000000001000000000000000100000000000000010000000000' +
196 '000001000000000000000100000000000000010000000000000001000000' +
197 '000000000100000000000000010000000000000001000000000000000100' +
198 '000000000000010000000000000001100000011111111110000011111111' +
199 '111000011111111111100011111111111110011111111111111011111111' +
200 '111111111111111000000010000000000000011000000000000011100000' +
201 '000000011110000000000011111000000000011111100000000011111110' +
202 '000000011111111100000000000000110000000000000111000000000000' +
203 '111100000000000111110000000000111111000000000111111100000000' +
204 '111111110000000111111111000000111111111100000111111111110000' +
205 '111111111111000111111111111100111111111111110111111111111111' +
206 '111111100000000011111100000000001111100000000000111100000000' +
207 '000011100000000000001100000000000000100000000111111111111111' +
208 '111111101111111111111100111111111111100011111111111100001111' +
209 '111111100000111111111100000011111111100000001111111111111111' +
210 '011111111111111001111111111111000111111111111000011111111111' +
211 '000001111111111000000111111111000000011111111000000001111111' +
212 '000000000111111000000000011111000000000001111000000000000111' +
213 '000000000000011000000000000001000000011111111100000011111111' +
214 '110000011111111111000011111111111100011111111111110011111111' +
215 '111111011111111000000000000000000000010000000000000011000000' +
216 '000000011100000000000011110000000000011111000000000011111100' +
217 '000000011111110000000000000000100000000000000110000000000000' +
218 '111000000000000111100000000000111110000000000111111000000000' +
219 '111111100000000111111110000000111111111000000111111111100000' +
220 '111111111110000111111111111000111111111111100111111111111110' +
221 '011111100000000001111100000000000111100000000000011100000000' +
222 '000001100000000000000100000000000000000000000111111101111111' +
223 '111111100111111111111100011111111111100001111111111100000111' +
224 '111111100000011111111100000001111111100000000011111111111111' +
225 '001111111111111000111111111111000011111111111000001111111111' +
226 '000000111111111000000011111111000000001111111000000000111111' +
227 '000000000011111000000000001111000000000000111000000000000011' +
228 '000000000000001000000000000000233333333333333323333333333333' +
229 '332333333333333333233333333333333323333333333333332333333333' +
230 '333333233333333333333323333333333333332333333333333333233333' +
231 '333333333323333333333333332333333333333333233333333333333323' +
232 '333333333333332322222222222222232222222222222223222222222222' +
233 '222322222222222222232222222222222223222222222222222322222222' +
234 '222222232222222222222223222222222222222322222222222222232222' +
235 '222222222223222222222222222322222222222222232222222222222223' +
236 '322222233333333332222233333333333222233333333333322233333333' +
237 '333332233333333333333233333333333333333333333222222232222222' +
238 '222222233222222222222233322222222222233332222222222233333222' +
239 '222222233333322222222233333332222222233333333322222222222222' +
240 '332222222222222333222222222222333322222222222333332222222222' +
241 '333333222222222333333322222222333333332222222333333333222222' +
242 '333333333322222333333333332222333333333333222333333333333322' +
243 '333333333333332333333333333333333333322222222233333322222222' +
244 '223333322222222222333322222222222233322222222222223322222222' +
245 '222222322222222333333333333333333333323333333333333322333333' +
246 '333333322233333333333322223333333333322222333333333322222233' +
247 '333333322222223333333333333333233333333333333223333333333333' +
248 '222333333333333222233333333333222223333333333222222333333333' +
249 '222222233333333222222223333333222222222333333222222222233333' +
250 '222222222223333222222222222333222222222222233222222222222223' +
251 '222222233333333322222233333333332222233333333333222233333333' +
252 '333322233333333333332233333333333333233333333222222222222222' +
253 '222222232222222222222233222222222222233322222222222233332222' +
254 '222222233333222222222233333322222222233333332222222222222222' +
255 '322222222222222332222222222222333222222222222333322222222222' +
256 '333332222222222333333222222222333333322222222333333332222222' +
257 '333333333222222333333333322222333333333332222333333333333222' +
258 '333333333333322333333333333332233333322222222223333322222222' +
259 '222333322222222222233322222222222223322222222222222322222222' +
260 '222222222222222333333323333333333333322333333333333322233333' +
261 '333333322223333333333322222333333333322222233333333322222223' +
262 '333333322222222233333333333333223333333333333222333333333333' +
263 '222233333333333222223333333333222222333333333222222233333333' +
264 '222222223333333222222222333333222222222233333222222222223333' +
265 '222222222222333222222222222233222222222222223222222222222222';
266
267 assertEq(expectedSummaryString.length, 9000); // stay sane
268
269 assertEq(actualSummaryString, expectedSummaryString);