|
| 1 | +;;! target = "pulley64" |
| 2 | +;;! test = "compile" |
| 3 | + |
| 4 | +;; Small test of a loop extracted from "coremark-minimal.wasm" here: |
| 5 | +;; https://github.com/wasmi-labs/wasmi-benchmarks/blob/d045a88246d3ac9b0b80b188feda54b89ca126b5/benches/res/wasm/coremark-minimal.wasm |
| 6 | +;; |
| 7 | +;; This doesn't reproduce the exact regalloc decisions but does currently show |
| 8 | +;; something suboptimal for Pulley which is at the end of the loop it's |
| 9 | +;; currently: |
| 10 | +;; |
| 11 | +;; * `br_if_not32` to exit the loop |
| 12 | +;; * `xmov` to move some registers in place |
| 13 | +;; * `jump` to resume the loop |
| 14 | +;; |
| 15 | +;; Ideally to minimize Pulley opcodes this would skip the `xmov` and `jump` |
| 16 | +;; with different register allocation and the back-edge would be a single |
| 17 | +;; conditional branch. |
| 18 | + |
| 19 | +(module |
| 20 | + (memory 10) |
| 21 | + (func (param $p1 i32) (param $p2 i32) (param $cnt i32) |
| 22 | + (param $stride i32) |
| 23 | + (result i32) |
| 24 | + (local $accum i32) |
| 25 | + loop |
| 26 | + local.get $accum |
| 27 | + |
| 28 | + local.get $p1 |
| 29 | + i32.load16_u |
| 30 | + local.get $p2 |
| 31 | + i32.load16_u |
| 32 | + i32.mul |
| 33 | + local.tee $accum |
| 34 | + i32.const 2 |
| 35 | + i32.shr_u |
| 36 | + i32.const 15 |
| 37 | + i32.and |
| 38 | + local.get $accum |
| 39 | + i32.const 5 |
| 40 | + i32.shr_u |
| 41 | + i32.const 127 |
| 42 | + i32.and |
| 43 | + i32.mul |
| 44 | + i32.add |
| 45 | + local.set $accum |
| 46 | + |
| 47 | + local.get $p2 |
| 48 | + i32.const 2 |
| 49 | + i32.add |
| 50 | + local.set $p2 |
| 51 | + |
| 52 | + local.get $p1 |
| 53 | + local.get $stride |
| 54 | + i32.add |
| 55 | + local.set $p1 |
| 56 | + |
| 57 | + local.get $cnt |
| 58 | + i32.const -1 |
| 59 | + i32.add |
| 60 | + local.tee $cnt |
| 61 | + |
| 62 | + br_if 0 |
| 63 | + end |
| 64 | + |
| 65 | + call $other |
| 66 | + |
| 67 | + (local.get $accum) |
| 68 | + ) |
| 69 | + |
| 70 | + (func $other) |
| 71 | +) |
| 72 | +;; wasm[0]::function[0]: |
| 73 | +;; push_frame_save 16, x16 |
| 74 | +;; xzero x6 |
| 75 | +;; xload64le_o32 x11, x0, 80 |
| 76 | +;; xload64le_o32 x13, x0, 88 |
| 77 | +;; xload16le_u32_g32 x12, x11, x13, x2, 0 |
| 78 | +;; xload16le_u32_g32 x13, x11, x13, x3, 0 |
| 79 | +;; xsub32_u8 x4, x4, 1 |
| 80 | +;; xmul32 x12, x12, x13 |
| 81 | +;; xshr32_u_u6 x13, x12, 2 |
| 82 | +;; xband32_s8 x13, x13, 15 |
| 83 | +;; xshr32_u_u6 x12, x12, 5 |
| 84 | +;; xband32_s8 x12, x12, 127 |
| 85 | +;; xmadd32 x6, x13, x12, x6 |
| 86 | +;; xmov x16, x6 |
| 87 | +;; xadd32 x2, x2, x5 |
| 88 | +;; xadd32_u8 x3, x3, 2 |
| 89 | +;; br_if_not32 x4, 0xe // target = 0x53 |
| 90 | +;; 4b: xmov x6, x16 |
| 91 | +;; jump -0x40 // target = 0xe |
| 92 | +;; 53: call2 x0, x0, 0x10 // target = 0x63 |
| 93 | +;; xmov x0, x16 |
| 94 | +;; pop_frame_restore 16, x16 |
| 95 | +;; ret |
| 96 | +;; |
| 97 | +;; wasm[0]::function[1]::other: |
| 98 | +;; push_frame |
| 99 | +;; pop_frame |
| 100 | +;; ret |
0 commit comments