summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/ion-adhoc-multiplatform.js
blob: 221ddf78c88155560ee79568412028babe3da73b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
// |jit-test| skip-if: !hasDisassembler() || wasmCompileMode() != "ion" || getBuildConfiguration().windows || (!getBuildConfiguration().x64 && !getBuildConfiguration().x86 && !getBuildConfiguration().arm64 && !getBuildConfiguration().arm); include:adhoc-multiplatform-test.js
//
// These tests push wasm functions through the ion pipe and specify an expected
// disassembly output on all 4 primary targets, x64 / x86 / arm64 / arm(32).
// Results must be provided for the first 3, but can optionally be skipped
// for arm(32).
//
// Hence: disassembler is needed, compiler must be ion.
//
// Windows is disallowed because the argument registers are different from on
// Linux, and matching both is both difficult and not of much value.

// Tests are "end-to-end" in the sense that we don't care whether the
// tested-for code improvement is done by MIR optimisation, or later in the
// pipe.  Observed defects are marked with FIXMEs for future easy finding.


// Note that identities involving AND, OR and XOR are tested by
// binop-x64-ion-folding.js

// Multiplication with magic constant on the left
//
//    0 * x =>  0
//    1 * x =>  x
//   -1 * x =>  -x
//    2 * x =>  x + x
//    4 * x =>  x << 2

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_zeroL") (param $p1 i32) (result i32)
       (i32.mul (i32.const 0) (local.get $p1))))`,
    "mul32_zeroL",
    {x64:   // FIXME move folding to MIR level
            // First we move edi to eax unnecessarily via ecx (bug 1752520),
            // then we overwrite eax.  Presumably because the folding
            // 0 * x => 0 is done at the LIR level, not the MIR level, hence
            // the now-pointless WasmParameter node is not DCE'd away, since
            // DCE only happens at the MIR level.  In fact all targets suffer
            // from the latter problem, but on x86 no_prefix_x86:true
            // hides it, and on arm32/64 the pointless move is correctly
            // transformed by RA into a no-op.
            `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             33 c0     xor %eax, %eax`,
     x86:   `33 c0     xor %eax, %eax`,
     arm64: `2a1f03e0  mov w0, wzr`,
     arm:   `e3a00000  mov r0, #0`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_zeroL") (param $p1 i64) (result i64)
       (i64.mul (i64.const 0) (local.get $p1))))`,
    "mul64_zeroL",
    // FIXME folding happened, zero-creation insns could be improved
    {x64:   // Same shenanigans as above.  Also, on xor, REX.W is redundant.
            `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 33 c0  xor %rax, %rax`,
     x86:   `33 c0     xor %eax, %eax
             33 d2     xor %edx, %edx`,
     arm64: `aa1f03e0  mov x0, xzr`,
     arm:   // bizarrely inconsistent with the 32-bit case
            `e0200000  eor r0, r0, r0
             e0211001  eor r1, r1, r1` },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_oneL") (param $p1 i32) (result i32)
       (i32.mul (i32.const 1) (local.get $p1))))`,
    "mul32_oneL",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_oneL") (param $p1 i64) (result i64)
       (i64.mul (i64.const 1) (local.get $p1))))`,
    "mul64_oneL",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_minusOneL") (param $p1 i32) (result i32)
       (i32.mul (i32.const -1) (local.get $p1))))`,
    "mul32_minusOneL",
    {x64:   `f7 d8     neg %eax`,
     x86:   `f7 d8     neg %eax`,
     arm64: `4b0003e0  neg w0, w0`,
     arm:   `e2600000  rsb r0, r0, #0`},
    {x86: {no_prefix:true}, x64: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_minusOneL") (param $p1 i64) (result i64)
       (i64.mul (i64.const -1) (local.get $p1))))`,
    "mul64_minusOneL",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 f7 d8  neg %rax`,
     x86:   `f7 d8     neg %eax
             83 d2 00  adc \\$0x00, %edx
             f7 da     neg %edx`,
     arm64: `cb0003e0  neg  x0, x0`,
     arm:   `e2700000  rsbs r0, r0, #0
             e2e11000  rsc  r1, r1, #0`},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_twoL") (param $p1 i32) (result i32)
       (i32.mul (i32.const 2) (local.get $p1))))`,
    "mul32_twoL",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             03 c0     add %eax, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             03 c0     add %eax, %eax`,
     arm64: `0b000000  add w0, w0, w0`,
     arm:   `e0900000  adds r0, r0, r0`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_twoL") (param $p1 i64) (result i64)
       (i64.mul (i64.const 2) (local.get $p1))))`,
    "mul64_twoL",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 03 c0  add %rax, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax
             03 c0     add %eax, %eax
             13 d2     adc %edx, %edx`,
     arm64: `8b000000  add  x0, x0, x0`,
     arm:   `e0900000  adds r0, r0, r0
             e0a11001  adc  r1, r1, r1`},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_fourL") (param $p1 i32) (result i32)
       (i32.mul (i32.const 4) (local.get $p1))))`,
    "mul32_fourL",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             c1 e0 02  shl \\$0x02, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             c1 e0 02  shl \\$0x02, %eax`,
     arm64: `531e7400  lsl w0, w0, #2`,
     arm:   `e1a00100  mov r0, r0, lsl #2`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_fourL") (param $p1 i64) (result i64)
       (i64.mul (i64.const 4) (local.get $p1))))`,
    "mul64_fourL",
    {x64:   `48 89 f9     mov %rdi, %rcx
             48 89 c8     mov %rcx, %rax
             48 c1 e0 02  shl \\$0x02, %rax`,
     x86:   `8b 55 14     movl 0x14\\(%rbp\\), %edx
             8b 45 10     movl 0x10\\(%rbp\\), %eax
             0f a4 c2 02  shld \\$0x02, %eax, %edx
             c1 e0 02     shl \\$0x02, %eax`,
     arm64: `d37ef400     lsl x0, x0, #2`,
     arm:   `e1a01101     mov r1, r1, lsl #2
             e1811f20     orr r1, r1, r0, lsr #30
             e1a00100     mov r0, r0, lsl #2`},
    {x86: {no_prefix:true}}
);

// Multiplication with magic constant on the right
//
//  x * 0  =>  0
//  x * 1  =>  x
//  x * -1 =>  -x
//  x * 2  =>  x + x
//  x * 4  =>  x << 2

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_zeroR") (param $p1 i32) (result i32)
       (i32.mul (local.get $p1) (i32.const 0))))`,
    "mul32_zeroR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             33 c0     xor %eax, %eax`,
     x86:   `33 c0     xor %eax, %eax`,
     arm64: `2a1f03e0  mov w0, wzr`,
     arm:   `e3a00000  mov r0, #0`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_zeroR") (param $p1 i64) (result i64)
       (i64.mul (local.get $p1) (i64.const 0))))`,
    "mul64_zeroR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 33 c0  xor %rax, %rax`,     // REX.W is redundant
     x86:   `33 c0     xor %eax, %eax
             33 d2     xor %edx, %edx`,
     arm64: `aa1f03e0  mov x0, xzr`,
     arm:   `e0200000  eor r0, r0, r0
             e0211001  eor r1, r1, r1` },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_oneR") (param $p1 i32) (result i32)
       (i32.mul (local.get $p1) (i32.const 1))))`,
    "mul32_oneR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_oneR") (param $p1 i64) (result i64)
       (i64.mul (local.get $p1) (i64.const 1))))`,
    "mul64_oneR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_minusOneR") (param $p1 i32) (result i32)
       (i32.mul (local.get $p1) (i32.const -1))))`,
    "mul32_minusOneR",
    {x64:   `f7 d8     neg %eax`,
     x86:   `f7 d8     neg %eax`,
     arm64: `4b0003e0  neg w0, w0`,
     arm:   `e2600000  rsb r0, r0, #0`},
    {x86: {no_prefix:true}, x64: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_minusOneR") (param $p1 i64) (result i64)
       (i64.mul (local.get $p1) (i64.const -1))))`,
    "mul64_minusOneR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 f7 d8  neg %rax`,
     x86:   `f7 d8     neg %eax
             83 d2 00  adc \\$0x00, %edx
             f7 da     neg %edx`,
     arm64: `cb0003e0  neg  x0, x0`,
     arm:   `e2700000  rsbs r0, r0, #0
             e2e11000  rsc  r1, r1, #0`},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_twoR") (param $p1 i32) (result i32)
       (i32.mul (local.get $p1) (i32.const 2))))`,
    "mul32_twoR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             03 c0     add %eax, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             03 c0     add %eax, %eax`,
     arm64: `0b000000  add w0, w0, w0`,
     arm:   `e0900000  adds r0, r0, r0`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_twoR") (param $p1 i64) (result i64)
       (i64.mul (local.get $p1) (i64.const 2))))`,
    "mul64_twoR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 03 c0  add %rax, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax
             03 c0     add %eax, %eax
             13 d2     adc %edx, %edx`,
     arm64: `8b000000  add  x0, x0, x0`,
     arm:   `e0900000  adds r0, r0, r0
             e0a11001  adc  r1, r1, r1`},
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "mul32_fourR") (param $p1 i32) (result i32)
       (i32.mul (local.get $p1) (i32.const 4))))`,
    "mul32_fourR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             c1 e0 02  shl \\$0x02, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             c1 e0 02  shl \\$0x02, %eax`,
     arm64: `531e7400  lsl w0, w0, #2`,
     arm:   `e1a00100  mov r0, r0, lsl #2`},
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "mul64_fourR") (param $p1 i64) (result i64)
       (i64.mul (local.get $p1) (i64.const 4))))`,
    "mul64_fourR",
    {x64:   `48 89 f9     mov %rdi, %rcx
             48 89 c8     mov %rcx, %rax
             48 c1 e0 02  shl \\$0x02, %rax`,
     x86:   `8b 55 14     movl 0x14\\(%rbp\\), %edx
             8b 45 10     movl 0x10\\(%rbp\\), %eax
             0f a4 c2 02  shld \\$0x02, %eax, %edx
             c1 e0 02     shl \\$0x02, %eax`,
     arm64: `d37ef400     lsl x0, x0, #2`,
     arm:   `e1a01101     mov r1, r1, lsl #2
             e1811f20     orr r1, r1, r0, lsr #30
             e1a00100     mov r0, r0, lsl #2`
    },
    {x86: {no_prefix:true}}
);

// Shifts by zero (the right arg is zero)
//
// x >> 0  =>  x  (any shift kind: shl, shrU, shrS)

codegenTestMultiplatform_adhoc(
    `(module (func (export "shl32_zeroR") (param $p1 i32) (result i32)
       (i32.shl (local.get $p1) (i32.const 0))))`,
    "shl32_zeroR",
    // FIXME check these are consistently folded out at the MIR level
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: // Regalloc badness, plus not folded out at the MIR level
            `2a0003e2  mov w2, w0
             2a0203e1  mov w1, w2
             53007c20  lsr w0, w1, #0`, // Uhh.  lsr ?!
     arm:   `e1a02000  mov r2, r0
             e1a01002  mov r1, r2
             e1a00001  mov r0, r1`
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "shl64_zeroR") (param $p1 i64) (result i64)
       (i64.shl (local.get $p1) (i64.const 0))))`,
    "shl64_zeroR",
    // FIXME why is this code so much better than the 32-bit case?
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``, // no-op
     arm:   ``  // no-op
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "shrU32_zeroR") (param $p1 i32) (result i32)
       (i32.shr_u (local.get $p1) (i32.const 0))))`,
    "shrU32_zeroR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: `2a0003e2  mov w2, w0
             2a0203e1  mov w1, w2
             2a0103e0  mov w0, w1`,
     arm:   `e1a02000  mov r2, r0
             e1a01002  mov r1, r2
             e1a00001  mov r0, r1`
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "shrU64_zeroR") (param $p1 i64) (result i64)
       (i64.shr_u (local.get $p1) (i64.const 0))))`,
    "shrU64_zeroR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "shrS32_zeroR") (param $p1 i32) (result i32)
       (i32.shr_s (local.get $p1) (i32.const 0))))`,
    "shrS32_zeroR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: `2a0003e2  mov w2, w0
             2a0203e1  mov w1, w2
             13007c20  sbfx w0, w1, #0, #32`,
     arm:   `e1a02000  mov r2, r0
             e1a01002  mov r1, r2
             e1a00001  mov r0, r1`
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "shrS64_zeroR") (param $p1 i64) (result i64)
       (i64.shr_s (local.get $p1) (i64.const 0))))`,
    "shrS64_zeroR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);

// Identities involving addition
//
//  x + 0   =>  x
//  0 + x   =>  x
//  x + x   =>  x << 1

codegenTestMultiplatform_adhoc(
    `(module (func (export "add32_zeroR") (param $p1 i32) (result i32)
       (i32.add (local.get $p1) (i32.const 0))))`,
    "add32_zeroR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "add64_zeroR") (param $p1 i64) (result i64)
       (i64.add (local.get $p1) (i64.const 0))))`,
    "add64_zeroR",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "add32_zeroL") (param $p1 i32) (result i32)
       (i32.add (i32.const 0) (local.get $p1))))`,
    "add32_zeroL",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "add64_zeroL") (param $p1 i64) (result i64)
       (i64.add (i64.const 0) (local.get $p1))))`,
    "add64_zeroL",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "add32_self") (param $p1 i32) (result i32)
       (i32.add (local.get $p1) (local.get $p1))))`,
    "add32_self",
    {x64:   `8b cf  mov  %edi, %ecx
             8b c1  mov  %ecx, %eax
             03 c1  add  %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             03 45 10  addl 0x10\\(%rbp\\), %eax`,
     arm64: `0b000000  add  w0, w0, w0`,
     arm:   `e0900000  adds r0, r0, r0 `
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "add64_self") (param $p1 i64) (result i64)
       (i64.add (local.get $p1) (local.get $p1))))`,
    "add64_self",
    // FIXME outstandingly bad 32-bit sequences, probably due to the RA
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 03 c1  add %rcx, %rax`,
     x86:   // -0x21524111 is 0xDEADBEEF
            `8b 5d 14        movl 0x14\\(%rbp\\), %ebx
             8b 4d 10        movl 0x10\\(%rbp\\), %ecx
             bf ef be ad de  mov \\$-0x21524111, %edi
             8b 55 14        movl 0x14\\(%rbp\\), %edx
             8b 45 10        movl 0x10\\(%rbp\\), %eax
             03 c1           add %ecx, %eax
             13 d3           adc %ebx, %edx`,
     arm64: `8b000000  add  x0, x0, x0`,
     arm:   // play Musical Chairs for a while
            `e1a03001  mov  r3, r1
             e1a02000  mov  r2, r0
             e1a05003  mov  r5, r3
             e1a04002  mov  r4, r2
             e1a01003  mov  r1, r3
             e1a00002  mov  r0, r2
             e0900004  adds r0, r0, r4
             e0a11005  adc  r1, r1, r5`
    },
    {x86: {no_prefix:true}}
);

// Identities involving subtraction
//
//  x - 0   =>  x
//  0 - x   =>  -x
//  x - x   =>  0

codegenTestMultiplatform_adhoc(
    `(module (func (export "sub32_zeroR") (param $p1 i32) (result i32)
       (i32.sub (local.get $p1) (i32.const 0))))`,
    "sub32_zeroR",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax`,
     arm64: ``,
     arm:   ``
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "sub64_zeroR") (param $p1 i64) (result i64)
       (i64.sub (local.get $p1) (i64.const 0))))`,
    "sub64_zeroR",
    // FIXME folding missing for all 4 targets
    {x64:   `48 89 f9     mov %rdi, %rcx
             48 89 c8     mov %rcx, %rax
             48 83 e8 00  sub \\$0x00, %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax
             83 ea 00  sub  \\$0x00, %edx`,
     arm64: ``,
     arm:   `e2500000  subs r0, r0, #0
             e2c11000  sbc  r1, r1, #0`
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "sub32_zeroL") (param $p1 i32) (result i32)
       (i32.sub (i32.const 0) (local.get $p1))))`,
    "sub32_zeroL",
    {x64:   `8b cf     mov %edi, %ecx
             8b c1     mov %ecx, %eax
             f7 d8     neg %eax`,
     x86:   `8b 45 10  movl 0x10\\(%rbp\\), %eax
             f7 d8     neg %eax`,
     arm64: `4b0003e0  neg w0, w0 `,
     arm:   `e2600000  rsb r0, r0, #0`
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "sub64_zeroL") (param $p1 i64) (result i64)
       (i64.sub (i64.const 0) (local.get $p1))))`,
    "sub64_zeroL",
    {x64:   `48 89 f9  mov %rdi, %rcx
             48 89 c8  mov %rcx, %rax
             48 f7 d8  neg %rax`,
     x86:   `8b 55 14  movl 0x14\\(%rbp\\), %edx
             8b 45 10  movl 0x10\\(%rbp\\), %eax
             f7 d8     neg %eax
             83 d2 00  adc \\$0x00, %edx
             f7 da     neg %edx`,
     arm64: `cb0003e0  neg  x0, x0`,
     arm:   `e2700000  rsbs r0, r0, #0
             e2e11000  rsc  r1, r1, #0`
    },
    {x86: {no_prefix:true}}
);

codegenTestMultiplatform_adhoc(
    `(module (func (export "sub32_self") (param $p1 i32) (result i32)
       (i32.sub (local.get $p1) (local.get $p1))))`,
    "sub32_self",
    {x64:   `33 c0  xor %eax, %eax`,
     x86:   `33 c0  xor %eax, %eax`,
     arm64: `52800000  mov w0, #0x0`,
     arm:   `e3a00000  mov r0, #0`
    },
    {x86: {no_prefix:true}}
);
codegenTestMultiplatform_adhoc(
    `(module (func (export "sub64_self") (param $p1 i64) (result i64)
       (i64.sub (local.get $p1) (local.get $p1))))`,
    "sub64_self",
    // FIXME folding missing for all 4 targets
    {x64:   `48 89 f9        mov %rdi, %rcx
             48 89 c8        mov %rcx, %rax
             48 2b c1        sub %rcx, %rax`,
     x86:   // -0x21524111 is 0xDEADBEEF
            `8b 5d 14        movl 0x14\\(%rbp\\), %ebx
             8b 4d 10        movl 0x10\\(%rbp\\), %ecx
             bf ef be ad de  mov  \\$-0x21524111, %edi
             8b 55 14        movl 0x14\\(%rbp\\), %edx
             8b 45 10        movl 0x10\\(%rbp\\), %eax
             2b c1           sub %ecx, %eax
             1b d3           sbb %ebx, %edx`,
     arm64: `cb000000  sub  x0, x0, x0`,
     arm:   `e1a03001  mov  r3, r1
             e1a02000  mov  r2, r0
             e1a05003  mov  r5, r3
             e1a04002  mov  r4, r2
             e1a01003  mov  r1, r3
             e1a00002  mov  r0, r2
             e0500004  subs r0, r0, r4
             e0c11005  sbc  r1, r1, r5`
    },
    {x86: {no_prefix:true}}
);