Debian Codegraph @

js/src/jit-test/tests/wasm/ion-adhoc-multiplatform.js

raw
1 // |jit-test| skip-if: !hasDisassembler() || wasmCompileMode() != "ion" || getBuildConfiguration("windows") || (!getBuildConfiguration("x64") && !getBuildConfiguration("x86") && !getBuildConfiguration("arm64") && !getBuildConfiguration("arm")); include:adhoc-multiplatform-test.js
2 //
3 // These tests push wasm functions through the ion pipe and specify an expected
4 // disassembly output on all 4 primary targets, x64 / x86 / arm64 / arm(32).
5 // Results must be provided for the first 3, but can optionally be skipped
6 // for arm(32).
7 //
8 // Hence: disassembler is needed, compiler must be ion.
9 //
10 // Windows is disallowed because the argument registers are different from on
11 // Linux, and matching both is both difficult and not of much value.
12
13 // Tests are "end-to-end" in the sense that we don't care whether the
14 // tested-for code improvement is done by MIR optimisation, or later in the
15 // pipe. Observed defects are marked with FIXMEs for future easy finding.
16
17
18 // Note that identities involving AND, OR and XOR are tested by
19 // binop-x64-ion-folding.js
20
21 // Multiplication with magic constant on the left
22 //
23 // 0 * x => 0
24 // 1 * x => x
25 // -1 * x => -x
26 // 2 * x => x + x
27 // 4 * x => x << 2
28
29 codegenTestMultiplatform_adhoc(
30 `(module (func (export "mul32_zeroL") (param $p1 i32) (result i32)
31 (i32.mul (i32.const 0) (local.get $p1))))`,
32 "mul32_zeroL",
33 {x64: // FIXME move folding to MIR level
34 // First we move edi to eax unnecessarily via ecx (bug 1752520),
35 // then we overwrite eax. Presumably because the folding
36 // 0 * x => 0 is done at the LIR level, not the MIR level, hence
37 // the now-pointless WasmParameter node is not DCE'd away, since
38 // DCE only happens at the MIR level. In fact all targets suffer
39 // from the latter problem, but on x86 no_prefix_x86:true
40 // hides it, and on arm32/64 the pointless move is correctly
41 // transformed by RA into a no-op.
42 `8b cf mov %edi, %ecx
43 8b c1 mov %ecx, %eax
44 33 c0 xor %eax, %eax`,
45 x86: `33 c0 xor %eax, %eax`,
46 arm64: `2a1f03e0 mov w0, wzr`,
47 arm: `e3a00000 mov r0, #0`},
48 {x86: {no_prefix:true}}
49 );
50 codegenTestMultiplatform_adhoc(
51 `(module (func (export "mul64_zeroL") (param $p1 i64) (result i64)
52 (i64.mul (i64.const 0) (local.get $p1))))`,
53 "mul64_zeroL",
54 // FIXME folding happened, zero-creation insns could be improved
55 {x64: // Same shenanigans as above. Also, on xor, REX.W is redundant.
56 `48 89 f9 mov %rdi, %rcx
57 48 89 c8 mov %rcx, %rax
58 48 33 c0 xor %rax, %rax`,
59 x86: `33 c0 xor %eax, %eax
60 33 d2 xor %edx, %edx`,
61 arm64: `aa1f03e0 mov x0, xzr`,
62 arm: // bizarrely inconsistent with the 32-bit case
63 `e0200000 eor r0, r0, r0
64 e0211001 eor r1, r1, r1` },
65 {x86: {no_prefix:true}}
66 );
67
68 codegenTestMultiplatform_adhoc(
69 `(module (func (export "mul32_oneL") (param $p1 i32) (result i32)
70 (i32.mul (i32.const 1) (local.get $p1))))`,
71 "mul32_oneL",
72 {x64: `8b cf mov %edi, %ecx
73 8b c1 mov %ecx, %eax`,
74 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
75 arm64: ``,
76 arm: ``},
77 {x86: {no_prefix:true}}
78 );
79 codegenTestMultiplatform_adhoc(
80 `(module (func (export "mul64_oneL") (param $p1 i64) (result i64)
81 (i64.mul (i64.const 1) (local.get $p1))))`,
82 "mul64_oneL",
83 {x64: `48 89 f9 mov %rdi, %rcx
84 48 89 c8 mov %rcx, %rax`,
85 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
86 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
87 arm64: ``,
88 arm: ``},
89 {x86: {no_prefix:true}}
90 );
91
92 codegenTestMultiplatform_adhoc(
93 `(module (func (export "mul32_minusOneL") (param $p1 i32) (result i32)
94 (i32.mul (i32.const -1) (local.get $p1))))`,
95 "mul32_minusOneL",
96 {x64: `f7 d8 neg %eax`,
97 x86: `f7 d8 neg %eax`,
98 arm64: `4b0003e0 neg w0, w0`,
99 arm: `e2600000 rsb r0, r0, #0`},
100 {x86: {no_prefix:true}, x64: {no_prefix:true}}
101 );
102 codegenTestMultiplatform_adhoc(
103 `(module (func (export "mul64_minusOneL") (param $p1 i64) (result i64)
104 (i64.mul (i64.const -1) (local.get $p1))))`,
105 "mul64_minusOneL",
106 {x64: `48 89 f9 mov %rdi, %rcx
107 48 89 c8 mov %rcx, %rax
108 48 f7 d8 neg %rax`,
109 x86: `f7 d8 neg %eax
110 83 d2 00 adc \\$0x00, %edx
111 f7 da neg %edx`,
112 arm64: `cb0003e0 neg x0, x0`,
113 arm: `e2700000 rsbs r0, r0, #0
114 e2e11000 rsc r1, r1, #0`},
115 {x86: {no_prefix:true}}
116 );
117
118 codegenTestMultiplatform_adhoc(
119 `(module (func (export "mul32_twoL") (param $p1 i32) (result i32)
120 (i32.mul (i32.const 2) (local.get $p1))))`,
121 "mul32_twoL",
122 {x64: `8b cf mov %edi, %ecx
123 8b c1 mov %ecx, %eax
124 03 c0 add %eax, %eax`,
125 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
126 03 c0 add %eax, %eax`,
127 arm64: `0b000000 add w0, w0, w0`,
128 arm: `e0900000 adds r0, r0, r0`},
129 {x86: {no_prefix:true}}
130 );
131 codegenTestMultiplatform_adhoc(
132 `(module (func (export "mul64_twoL") (param $p1 i64) (result i64)
133 (i64.mul (i64.const 2) (local.get $p1))))`,
134 "mul64_twoL",
135 {x64: `48 89 f9 mov %rdi, %rcx
136 48 89 c8 mov %rcx, %rax
137 48 03 c0 add %rax, %rax`,
138 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
139 8b 45 10 movl 0x10\\(%rbp\\), %eax
140 03 c0 add %eax, %eax
141 13 d2 adc %edx, %edx`,
142 arm64: `8b000000 add x0, x0, x0`,
143 arm: `e0900000 adds r0, r0, r0
144 e0a11001 adc r1, r1, r1`},
145 {x86: {no_prefix:true}}
146 );
147
148 codegenTestMultiplatform_adhoc(
149 `(module (func (export "mul32_fourL") (param $p1 i32) (result i32)
150 (i32.mul (i32.const 4) (local.get $p1))))`,
151 "mul32_fourL",
152 {x64: `8b cf mov %edi, %ecx
153 8b c1 mov %ecx, %eax
154 c1 e0 02 shl \\$0x02, %eax`,
155 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
156 c1 e0 02 shl \\$0x02, %eax`,
157 arm64: `531e7400 lsl w0, w0, #2`,
158 arm: `e1a00100 mov r0, r0, lsl #2`},
159 {x86: {no_prefix:true}}
160 );
161 codegenTestMultiplatform_adhoc(
162 `(module (func (export "mul64_fourL") (param $p1 i64) (result i64)
163 (i64.mul (i64.const 4) (local.get $p1))))`,
164 "mul64_fourL",
165 {x64: `48 89 f9 mov %rdi, %rcx
166 48 89 c8 mov %rcx, %rax
167 48 c1 e0 02 shl \\$0x02, %rax`,
168 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
169 8b 45 10 movl 0x10\\(%rbp\\), %eax
170 0f a4 c2 02 shld \\$0x02, %eax, %edx
171 c1 e0 02 shl \\$0x02, %eax`,
172 arm64: `d37ef400 lsl x0, x0, #2`,
173 arm: `e1a01101 mov r1, r1, lsl #2
174 e1811f20 orr r1, r1, r0, lsr #30
175 e1a00100 mov r0, r0, lsl #2`},
176 {x86: {no_prefix:true}}
177 );
178
179 // Multiplication with magic constant on the right
180 //
181 // x * 0 => 0
182 // x * 1 => x
183 // x * -1 => -x
184 // x * 2 => x + x
185 // x * 4 => x << 2
186
187 codegenTestMultiplatform_adhoc(
188 `(module (func (export "mul32_zeroR") (param $p1 i32) (result i32)
189 (i32.mul (local.get $p1) (i32.const 0))))`,
190 "mul32_zeroR",
191 {x64: `8b cf mov %edi, %ecx
192 8b c1 mov %ecx, %eax
193 33 c0 xor %eax, %eax`,
194 x86: `33 c0 xor %eax, %eax`,
195 arm64: `2a1f03e0 mov w0, wzr`,
196 arm: `e3a00000 mov r0, #0`},
197 {x86: {no_prefix:true}}
198 );
199 codegenTestMultiplatform_adhoc(
200 `(module (func (export "mul64_zeroR") (param $p1 i64) (result i64)
201 (i64.mul (local.get $p1) (i64.const 0))))`,
202 "mul64_zeroR",
203 {x64: `48 89 f9 mov %rdi, %rcx
204 48 89 c8 mov %rcx, %rax
205 48 33 c0 xor %rax, %rax`, // REX.W is redundant
206 x86: `33 c0 xor %eax, %eax
207 33 d2 xor %edx, %edx`,
208 arm64: `aa1f03e0 mov x0, xzr`,
209 arm: `e0200000 eor r0, r0, r0
210 e0211001 eor r1, r1, r1` },
211 {x86: {no_prefix:true}}
212 );
213
214 codegenTestMultiplatform_adhoc(
215 `(module (func (export "mul32_oneR") (param $p1 i32) (result i32)
216 (i32.mul (local.get $p1) (i32.const 1))))`,
217 "mul32_oneR",
218 {x64: `8b cf mov %edi, %ecx
219 8b c1 mov %ecx, %eax`,
220 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
221 arm64: ``,
222 arm: ``},
223 {x86: {no_prefix:true}}
224 );
225 codegenTestMultiplatform_adhoc(
226 `(module (func (export "mul64_oneR") (param $p1 i64) (result i64)
227 (i64.mul (local.get $p1) (i64.const 1))))`,
228 "mul64_oneR",
229 {x64: `48 89 f9 mov %rdi, %rcx
230 48 89 c8 mov %rcx, %rax`,
231 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
232 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
233 arm64: ``,
234 arm: ``},
235 {x86: {no_prefix:true}}
236 );
237
238 codegenTestMultiplatform_adhoc(
239 `(module (func (export "mul32_minusOneR") (param $p1 i32) (result i32)
240 (i32.mul (local.get $p1) (i32.const -1))))`,
241 "mul32_minusOneR",
242 {x64: `f7 d8 neg %eax`,
243 x86: `f7 d8 neg %eax`,
244 arm64: `4b0003e0 neg w0, w0`,
245 arm: `e2600000 rsb r0, r0, #0`},
246 {x86: {no_prefix:true}, x64: {no_prefix:true}}
247 );
248 codegenTestMultiplatform_adhoc(
249 `(module (func (export "mul64_minusOneR") (param $p1 i64) (result i64)
250 (i64.mul (local.get $p1) (i64.const -1))))`,
251 "mul64_minusOneR",
252 {x64: `48 89 f9 mov %rdi, %rcx
253 48 89 c8 mov %rcx, %rax
254 48 f7 d8 neg %rax`,
255 x86: `f7 d8 neg %eax
256 83 d2 00 adc \\$0x00, %edx
257 f7 da neg %edx`,
258 arm64: `cb0003e0 neg x0, x0`,
259 arm: `e2700000 rsbs r0, r0, #0
260 e2e11000 rsc r1, r1, #0`},
261 {x86: {no_prefix:true}}
262 );
263
264 codegenTestMultiplatform_adhoc(
265 `(module (func (export "mul32_twoR") (param $p1 i32) (result i32)
266 (i32.mul (local.get $p1) (i32.const 2))))`,
267 "mul32_twoR",
268 {x64: `8b cf mov %edi, %ecx
269 8b c1 mov %ecx, %eax
270 03 c0 add %eax, %eax`,
271 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
272 03 c0 add %eax, %eax`,
273 arm64: `0b000000 add w0, w0, w0`,
274 arm: `e0900000 adds r0, r0, r0`},
275 {x86: {no_prefix:true}}
276 );
277 codegenTestMultiplatform_adhoc(
278 `(module (func (export "mul64_twoR") (param $p1 i64) (result i64)
279 (i64.mul (local.get $p1) (i64.const 2))))`,
280 "mul64_twoR",
281 {x64: `48 89 f9 mov %rdi, %rcx
282 48 89 c8 mov %rcx, %rax
283 48 03 c0 add %rax, %rax`,
284 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
285 8b 45 10 movl 0x10\\(%rbp\\), %eax
286 03 c0 add %eax, %eax
287 13 d2 adc %edx, %edx`,
288 arm64: `8b000000 add x0, x0, x0`,
289 arm: `e0900000 adds r0, r0, r0
290 e0a11001 adc r1, r1, r1`},
291 {x86: {no_prefix:true}}
292 );
293
294 codegenTestMultiplatform_adhoc(
295 `(module (func (export "mul32_fourR") (param $p1 i32) (result i32)
296 (i32.mul (local.get $p1) (i32.const 4))))`,
297 "mul32_fourR",
298 {x64: `8b cf mov %edi, %ecx
299 8b c1 mov %ecx, %eax
300 c1 e0 02 shl \\$0x02, %eax`,
301 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
302 c1 e0 02 shl \\$0x02, %eax`,
303 arm64: `531e7400 lsl w0, w0, #2`,
304 arm: `e1a00100 mov r0, r0, lsl #2`},
305 {x86: {no_prefix:true}}
306 );
307 codegenTestMultiplatform_adhoc(
308 `(module (func (export "mul64_fourR") (param $p1 i64) (result i64)
309 (i64.mul (local.get $p1) (i64.const 4))))`,
310 "mul64_fourR",
311 {x64: `48 89 f9 mov %rdi, %rcx
312 48 89 c8 mov %rcx, %rax
313 48 c1 e0 02 shl \\$0x02, %rax`,
314 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
315 8b 45 10 movl 0x10\\(%rbp\\), %eax
316 0f a4 c2 02 shld \\$0x02, %eax, %edx
317 c1 e0 02 shl \\$0x02, %eax`,
318 arm64: `d37ef400 lsl x0, x0, #2`,
319 arm: `e1a01101 mov r1, r1, lsl #2
320 e1811f20 orr r1, r1, r0, lsr #30
321 e1a00100 mov r0, r0, lsl #2`
322 },
323 {x86: {no_prefix:true}}
324 );
325
326 // Shifts by zero (the right arg is zero)
327 //
328 // x >> 0 => x (any shift kind: shl, shrU, shrS)
329
330 codegenTestMultiplatform_adhoc(
331 `(module (func (export "shl32_zeroR") (param $p1 i32) (result i32)
332 (i32.shl (local.get $p1) (i32.const 0))))`,
333 "shl32_zeroR",
334 // FIXME check these are consistently folded out at the MIR level
335 {x64: `8b cf mov %edi, %ecx
336 8b c1 mov %ecx, %eax`,
337 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
338 arm64: // Regalloc badness, plus not folded out at the MIR level
339 `2a0003e2 mov w2, w0
340 2a0203e1 mov w1, w2
341 53007c20 lsr w0, w1, #0`, // Uhh. lsr ?!
342 arm: `e1a02000 mov r2, r0
343 e1a01002 mov r1, r2
344 e1a00001 mov r0, r1`
345 },
346 {x86: {no_prefix:true}}
347 );
348 codegenTestMultiplatform_adhoc(
349 `(module (func (export "shl64_zeroR") (param $p1 i64) (result i64)
350 (i64.shl (local.get $p1) (i64.const 0))))`,
351 "shl64_zeroR",
352 // FIXME why is this code so much better than the 32-bit case?
353 {x64: `48 89 f9 mov %rdi, %rcx
354 48 89 c8 mov %rcx, %rax`,
355 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
356 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
357 arm64: ``, // no-op
358 arm: `` // no-op
359 },
360 {x86: {no_prefix:true}}
361 );
362
363 codegenTestMultiplatform_adhoc(
364 `(module (func (export "shrU32_zeroR") (param $p1 i32) (result i32)
365 (i32.shr_u (local.get $p1) (i32.const 0))))`,
366 "shrU32_zeroR",
367 {x64: `8b cf mov %edi, %ecx
368 8b c1 mov %ecx, %eax`,
369 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
370 arm64: `2a0003e2 mov w2, w0
371 2a0203e1 mov w1, w2
372 2a0103e0 mov w0, w1`,
373 arm: `e1a02000 mov r2, r0
374 e1a01002 mov r1, r2
375 e1a00001 mov r0, r1`
376 },
377 {x86: {no_prefix:true}}
378 );
379 codegenTestMultiplatform_adhoc(
380 `(module (func (export "shrU64_zeroR") (param $p1 i64) (result i64)
381 (i64.shr_u (local.get $p1) (i64.const 0))))`,
382 "shrU64_zeroR",
383 {x64: `48 89 f9 mov %rdi, %rcx
384 48 89 c8 mov %rcx, %rax`,
385 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
386 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
387 arm64: ``,
388 arm: ``
389 },
390 {x86: {no_prefix:true}}
391 );
392
393 codegenTestMultiplatform_adhoc(
394 `(module (func (export "shrS32_zeroR") (param $p1 i32) (result i32)
395 (i32.shr_s (local.get $p1) (i32.const 0))))`,
396 "shrS32_zeroR",
397 {x64: `8b cf mov %edi, %ecx
398 8b c1 mov %ecx, %eax`,
399 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
400 arm64: `2a0003e2 mov w2, w0
401 2a0203e1 mov w1, w2
402 13007c20 sbfx w0, w1, #0, #32`,
403 arm: `e1a02000 mov r2, r0
404 e1a01002 mov r1, r2
405 e1a00001 mov r0, r1`
406 },
407 {x86: {no_prefix:true}}
408 );
409 codegenTestMultiplatform_adhoc(
410 `(module (func (export "shrS64_zeroR") (param $p1 i64) (result i64)
411 (i64.shr_s (local.get $p1) (i64.const 0))))`,
412 "shrS64_zeroR",
413 {x64: `48 89 f9 mov %rdi, %rcx
414 48 89 c8 mov %rcx, %rax`,
415 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
416 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
417 arm64: ``,
418 arm: ``
419 },
420 {x86: {no_prefix:true}}
421 );
422
423 // Identities involving addition
424 //
425 // x + 0 => x
426 // 0 + x => x
427 // x + x => x << 1
428
429 codegenTestMultiplatform_adhoc(
430 `(module (func (export "add32_zeroR") (param $p1 i32) (result i32)
431 (i32.add (local.get $p1) (i32.const 0))))`,
432 "add32_zeroR",
433 {x64: `8b cf mov %edi, %ecx
434 8b c1 mov %ecx, %eax`,
435 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
436 arm64: ``,
437 arm: ``
438 },
439 {x86: {no_prefix:true}}
440 );
441 codegenTestMultiplatform_adhoc(
442 `(module (func (export "add64_zeroR") (param $p1 i64) (result i64)
443 (i64.add (local.get $p1) (i64.const 0))))`,
444 "add64_zeroR",
445 {x64: `48 89 f9 mov %rdi, %rcx
446 48 89 c8 mov %rcx, %rax`,
447 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
448 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
449 arm64: ``,
450 arm: ``
451 },
452 {x86: {no_prefix:true}}
453 );
454
455 codegenTestMultiplatform_adhoc(
456 `(module (func (export "add32_zeroL") (param $p1 i32) (result i32)
457 (i32.add (i32.const 0) (local.get $p1))))`,
458 "add32_zeroL",
459 {x64: `8b cf mov %edi, %ecx
460 8b c1 mov %ecx, %eax`,
461 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
462 arm64: ``,
463 arm: ``
464 },
465 {x86: {no_prefix:true}}
466 );
467 codegenTestMultiplatform_adhoc(
468 `(module (func (export "add64_zeroL") (param $p1 i64) (result i64)
469 (i64.add (i64.const 0) (local.get $p1))))`,
470 "add64_zeroL",
471 {x64: `48 89 f9 mov %rdi, %rcx
472 48 89 c8 mov %rcx, %rax`,
473 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
474 8b 45 10 movl 0x10\\(%rbp\\), %eax`,
475 arm64: ``,
476 arm: ``
477 },
478 {x86: {no_prefix:true}}
479 );
480
481 codegenTestMultiplatform_adhoc(
482 `(module (func (export "add32_self") (param $p1 i32) (result i32)
483 (i32.add (local.get $p1) (local.get $p1))))`,
484 "add32_self",
485 {x64: `8b cf mov %edi, %ecx
486 8b c1 mov %ecx, %eax
487 03 c1 add %ecx, %eax`,
488 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
489 03 45 10 addl 0x10\\(%rbp\\), %eax`,
490 arm64: `0b000000 add w0, w0, w0`,
491 arm: `e0900000 adds r0, r0, r0 `
492 },
493 {x86: {no_prefix:true}}
494 );
495 codegenTestMultiplatform_adhoc(
496 `(module (func (export "add64_self") (param $p1 i64) (result i64)
497 (i64.add (local.get $p1) (local.get $p1))))`,
498 "add64_self",
499 // FIXME outstandingly bad 32-bit sequences, probably due to the RA
500 {x64: `48 89 f9 mov %rdi, %rcx
501 48 89 c8 mov %rcx, %rax
502 48 03 c1 add %rcx, %rax`,
503 x86: // -0x21524111 is 0xDEADBEEF
504 `8b 5d 14 movl 0x14\\(%rbp\\), %ebx
505 8b 4d 10 movl 0x10\\(%rbp\\), %ecx
506 bf ef be ad de mov \\$-0x21524111, %edi
507 8b 55 14 movl 0x14\\(%rbp\\), %edx
508 8b 45 10 movl 0x10\\(%rbp\\), %eax
509 03 c1 add %ecx, %eax
510 13 d3 adc %ebx, %edx`,
511 arm64: `8b000000 add x0, x0, x0`,
512 arm: // play Musical Chairs for a while
513 `e1a03001 mov r3, r1
514 e1a02000 mov r2, r0
515 e1a05003 mov r5, r3
516 e1a04002 mov r4, r2
517 e1a01003 mov r1, r3
518 e1a00002 mov r0, r2
519 e0900004 adds r0, r0, r4
520 e0a11005 adc r1, r1, r5`
521 },
522 {x86: {no_prefix:true}}
523 );
524
525 // Identities involving subtraction
526 //
527 // x - 0 => x
528 // 0 - x => -x
529 // x - x => 0
530
531 codegenTestMultiplatform_adhoc(
532 `(module (func (export "sub32_zeroR") (param $p1 i32) (result i32)
533 (i32.sub (local.get $p1) (i32.const 0))))`,
534 "sub32_zeroR",
535 {x64: `8b cf mov %edi, %ecx
536 8b c1 mov %ecx, %eax`,
537 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax`,
538 arm64: ``,
539 arm: ``
540 },
541 {x86: {no_prefix:true}}
542 );
543 codegenTestMultiplatform_adhoc(
544 `(module (func (export "sub64_zeroR") (param $p1 i64) (result i64)
545 (i64.sub (local.get $p1) (i64.const 0))))`,
546 "sub64_zeroR",
547 // FIXME folding missing for all 4 targets
548 {x64: `48 89 f9 mov %rdi, %rcx
549 48 89 c8 mov %rcx, %rax
550 48 83 e8 00 sub \\$0x00, %rax`,
551 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
552 8b 45 10 movl 0x10\\(%rbp\\), %eax
553 83 ea 00 sub \\$0x00, %edx`,
554 arm64: ``,
555 arm: `e2500000 subs r0, r0, #0
556 e2c11000 sbc r1, r1, #0`
557 },
558 {x86: {no_prefix:true}}
559 );
560
561 codegenTestMultiplatform_adhoc(
562 `(module (func (export "sub32_zeroL") (param $p1 i32) (result i32)
563 (i32.sub (i32.const 0) (local.get $p1))))`,
564 "sub32_zeroL",
565 {x64: `8b cf mov %edi, %ecx
566 8b c1 mov %ecx, %eax
567 f7 d8 neg %eax`,
568 x86: `8b 45 10 movl 0x10\\(%rbp\\), %eax
569 f7 d8 neg %eax`,
570 arm64: `4b0003e0 neg w0, w0 `,
571 arm: `e2600000 rsb r0, r0, #0`
572 },
573 {x86: {no_prefix:true}}
574 );
575 codegenTestMultiplatform_adhoc(
576 `(module (func (export "sub64_zeroL") (param $p1 i64) (result i64)
577 (i64.sub (i64.const 0) (local.get $p1))))`,
578 "sub64_zeroL",
579 {x64: `48 89 f9 mov %rdi, %rcx
580 48 89 c8 mov %rcx, %rax
581 48 f7 d8 neg %rax`,
582 x86: `8b 55 14 movl 0x14\\(%rbp\\), %edx
583 8b 45 10 movl 0x10\\(%rbp\\), %eax
584 f7 d8 neg %eax
585 83 d2 00 adc \\$0x00, %edx
586 f7 da neg %edx`,
587 arm64: `cb0003e0 neg x0, x0`,
588 arm: `e2700000 rsbs r0, r0, #0
589 e2e11000 rsc r1, r1, #0`
590 },
591 {x86: {no_prefix:true}}
592 );
593
594 codegenTestMultiplatform_adhoc(
595 `(module (func (export "sub32_self") (param $p1 i32) (result i32)
596 (i32.sub (local.get $p1) (local.get $p1))))`,
597 "sub32_self",
598 {x64: `33 c0 xor %eax, %eax`,
599 x86: `33 c0 xor %eax, %eax`,
600 arm64: `52800000 mov w0, #0x0`,
601 arm: `e3a00000 mov r0, #0`
602 },
603 {x86: {no_prefix:true}}
604 );
605 codegenTestMultiplatform_adhoc(
606 `(module (func (export "sub64_self") (param $p1 i64) (result i64)
607 (i64.sub (local.get $p1) (local.get $p1))))`,
608 "sub64_self",
609 // FIXME folding missing for all 4 targets
610 {x64: `48 89 f9 mov %rdi, %rcx
611 48 89 c8 mov %rcx, %rax
612 48 2b c1 sub %rcx, %rax`,
613 x86: // -0x21524111 is 0xDEADBEEF
614 `8b 5d 14 movl 0x14\\(%rbp\\), %ebx
615 8b 4d 10 movl 0x10\\(%rbp\\), %ecx
616 bf ef be ad de mov \\$-0x21524111, %edi
617 8b 55 14 movl 0x14\\(%rbp\\), %edx
618 8b 45 10 movl 0x10\\(%rbp\\), %eax
619 2b c1 sub %ecx, %eax
620 1b d3 sbb %ebx, %edx`,
621 arm64: `cb000000 sub x0, x0, x0`,
622 arm: `e1a03001 mov r3, r1
623 e1a02000 mov r2, r0
624 e1a05003 mov r5, r3
625 e1a04002 mov r4, r2
626 e1a01003 mov r1, r3
627 e1a00002 mov r0, r2
628 e0500004 subs r0, r0, r4
629 e0c11005 sbc r1, r1, r5`
630 },
631 {x86: {no_prefix:true}}
632 );