Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuse i32.{and,or, xor} + [i32.eqz] + br_if Wasm instructions #796

Merged
merged 11 commits into from
Nov 24, 2023

Conversation

Robbepop
Copy link
Member

@Robbepop Robbepop commented Nov 24, 2023

Closes #791.

Added a new fuse benchmark that shows the performance improvements gained in this PR. The improvements in this artificial .wat file are 25% compared to the current master branch which already implements branch+cmp fusion. On master each iteration executes 5 wasmi instructions whereas this PR gets it down to just 4 explaining the 25% performance improvement. Generally the gains are low for non-artificial tests such as tiny_keccak or coremark.wasm because they do not profit a lot from this op-code fusion in their hot loops it seems.

TODO

  • Tests for i32.{and,or,xor}[_imm16] + i32.eqz fusion.
  • Tests for i32.{and,or,xor}[_imm16] + br_if fusion.
  • Tests for i32.{and,or,xor}[_imm16] + i32.eqz + br_if fusion.

There is no need for i64 counterparts since in Wasm only i32 types are used as conditional "bool" types.
We added these instruction to provide optimizations for encode_eqz.
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2023

Codecov Report

Attention: 171 lines in your changes are missing coverage. Please review.

Comparison is base (ea3a29c) 81.29% compared to head (47a8421) 81.07%.

Files Patch % Lines
crates/wasmi/src/engine/regmach/translator/mod.rs 43.03% 90 Missing ⚠️
crates/wasmi/src/engine/regmach/executor/instrs.rs 0.00% 24 Missing ⚠️
...mi/src/engine/regmach/translator/visit_register.rs 0.00% 21 Missing ⚠️
...smi/src/engine/regmach/translator/instr_encoder.rs 55.00% 18 Missing ⚠️
.../wasmi/src/engine/regmach/translator/result_mut.rs 5.55% 17 Missing ⚠️
...rates/wasmi/src/engine/regmach/translator/visit.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #796      +/-   ##
==========================================
- Coverage   81.29%   81.07%   -0.23%     
==========================================
  Files         273      273              
  Lines       25085    25204     +119     
==========================================
+ Hits        20394    20435      +41     
- Misses       4691     4769      +78     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@paritytech-cicd-pr
Copy link

paritytech-cicd-pr commented Nov 24, 2023

BENCHMARKS

NATIVEWASMTIME
BENCHMARKMASTERPRDIFFMASTERPRDIFFWASMTIME OVERHEAD
execute/
bare_call_0
1.55ms 1.58ms 🔴 2.35% 1.11ms 1.10ms 🟢 -1.42% 🟢 -31%
execute/
bare_call_0/typed
1.25ms 1.17ms 🟢 -6.61% 801.13µs 802.82µs ⚪ 0.21% 🟢 -31%
execute/
bare_call_1
1.60ms 1.64ms 🔴 2.72% 1.26ms 1.32ms 🔴 4.78% 🟢 -19%
execute/
bare_call_16
2.64ms 2.55ms 🔴 -2.69% 3.53ms 3.50ms 🔴 -0.61% 🟢 37%
execute/
bare_call_16/typed
1.56ms 1.68ms 🔴 8.25% 1.94ms 1.98ms 🔴 2.48% 🟢 18%
execute/
bare_call_1/typed
1.29ms 1.41ms 🔴 8.90% 981.24µs 983.40µs ⚪ 0.34% 🟢 -30%
execute/
bare_call_4
1.77ms 1.85ms 🔴 4.10% 1.67ms 1.64ms 🟢 -1.58% 🟢 -11%
execute/
bare_call_4/typed
1.23ms 1.25ms 🔴 2.35% 1.08ms 1.08ms ⚪ -0.49% 🟢 -14%
execute/
br_table
1.64ms 1.35ms 🟢 -17.18% 1.17ms 1.18ms ⚪ 0.84% 🟢 -13%
execute/
count_until
546.24µs 545.95µs ⚪ -0.04% 1.69ms 1.70ms ⚪ 0.12% 🔴 211%
execute/
factorial_iterative
321.57µs 322.19µs ⚪ 0.15% 806.55µs 793.65µs 🟢 -1.47% 🔴 146%
execute/
factorial_recursive
497.78µs 490.71µs 🟢 -1.41% 968.06µs 974.06µs ⚪ 0.57% 🟡 98%
execute/
fibonacci_iter
1.40ms 1.40ms ⚪ 0.33% 3.73ms 3.81ms 🔴 1.84% 🔴 172%
execute/
fibonacci_rec
3.99ms 3.97ms ⚪ -0.31% 8.59ms 8.59ms ⚪ 0.03% 🔴 116%
execute/
fibonacci_tail
857.41µs 855.59µs ⚪ -0.21% 2.19ms 2.19ms ⚪ 0.11% 🔴 156%
execute/
global_bump
747.14µs 740.43µs ⚪ -0.92% 2.19ms 2.74ms 🔴 25.31% 🔴 270%
execute/
global_const
659.38µs 660.60µs ⚪ 0.20% 2.45ms 2.44ms ⚪ -0.43% 🔴 269%
execute/
host_calls
36.14µs 37.71µs ⚪ 1.12% 39.84µs 39.70µs ⚪ -0.29% 🟢 5%
execute/
memory_fill
1.15ms 1.22ms 🔴 5.64% 3.32ms 3.33ms ⚪ 0.30% 🔴 174%
execute/
memory_sum
1.19ms 1.18ms ⚪ -0.67% 3.28ms 3.30ms ⚪ 0.45% 🔴 179%
execute/
memory_vec_add
2.35ms 2.34ms ⚪ -0.08% 7.41ms 7.40ms ⚪ -0.10% 🔴 216%
execute/
recursive_is_even
664.02µs 661.74µs ⚪ -0.36% 1.47ms 1.45ms 🟢 -1.25% 🔴 119%
execute/
recursive_ok
94.41µs 94.49µs ⚪ 0.15% 200.02µs 201.34µs ⚪ 0.70% 🔴 113%
execute/
recursive_scan
129.20µs 129.56µs ⚪ 0.27% 284.81µs 285.81µs ⚪ 0.37% 🔴 121%
execute/
recursive_trap
8.81µs 8.85µs ⚪ 0.44% 20.85µs 20.84µs ⚪ -0.06% 🔴 136%
execute/
regex_redux
459.00µs 460.97µs ⚪ 0.45% 1.23ms 1.24ms ⚪ 0.67% 🔴 169%
execute/
rev_complement
425.75µs 434.94µs 🔴 2.19% 1.14ms 1.15ms ⚪ 0.53% 🔴 164%
execute/
tiny_keccak
320.98µs 324.18µs ⚪ -0.25% 1.10ms 1.09ms ⚪ -0.83% 🔴 238%
execute/
trunc_f2i
737.41µs 733.28µs ⚪ -0.54% 1.71ms 1.71ms ⚪ -0.01% 🔴 134%
instantiate/
wasm_kernel
53.13µs 56.85µs 🔴 5.67% 59.86µs 56.55µs 🟢 -5.93% 🟢 -1%
translate/
erc1155
208.80µs 205.82µs 🟢 -1.42% 375.50µs 360.05µs 🟢 -4.31% 🟡 75%
translate/
erc20
103.18µs 103.57µs ⚪ 0.45% 181.46µs 174.37µs 🟢 -3.85% 🟡 68%
translate/
erc721
146.60µs 145.35µs ⚪ -0.88% 262.24µs 251.88µs 🟢 -4.05% 🟡 73%
translate/
spidermonkey
64.27ms 64.25ms ⚪ -0.20% 0.00ns 0.00ns 🟢 -3.63% 🟢 -100%
translate/
wasm_kernel
4.26ms 4.23ms ⚪ -0.46% 6.85ms 6.60ms 🟢 -3.63% 🟡 56%

Link to pipeline

@Robbepop Robbepop merged commit 91a956b into master Nov 24, 2023
13 checks passed
@Robbepop Robbepop deleted the rf-add-br-and-or-xor branch November 24, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add i32.{and,or,xor} [+ i32.eqz] + br_if instruction fusion
3 participants