Skip to content

WIP: new Wasmi bytecode #1148

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

Closed
wants to merge 27 commits into from
Closed

WIP: new Wasmi bytecode #1148

wants to merge 27 commits into from

Conversation

Robbepop
Copy link
Member

@Robbepop Robbepop commented Aug 2, 2024

This PR adds the wasmi_ir crate to the Wasmi workspace which defines the new Wasmi bytecode, its encoding and decoding as well as utility definitions.

This does not yet use the new Wasmi bytecode in the Wasmi crate.
This is the first step towards #1101.

ToDo

  • Visit API
    • CheckedOpDecoder::visit
    • UncheckedOpDecoder::visit
    • OpEncoder::{visit, pop_visit}
  • Dispatch API
    • UncheckedOpDecoder::dispatch
    • UncheckedOpVariantDecoder::decode
  • Patch API
    • OpEncoder::patch
  • Iterator API
    • OpEncoder::iter yielding Op.
    • OpEncoder::iter_mut yielding OpMut.
  • Create Wasm br.table equivalent Wasmi bytecode operator and efficient encoding.
  • Trait EncodeSize and trait FixedEncodeSize and impls.
    • Used to improve error checking of OpEncoder::patch.
  • Have OpEncoder::get_mut API to quickly and easily mutate encoded Op.
  • Operators variants with 16-bit encoded immediate values:
    • i32 variants: saving 2 bytes per operator.
    • i64 variants: saving 6 bytes per operator.
  • f64-operator variants with 32-bit encoded immediate values.
    • This saves 4 bytes per operator and immediate.

Follow-Ups

  • Make every encoding 2 byte aligned so that most field (which are 2 byte in encoded size) have aligned memory access when decoded.
  • Maybe create fused i32.{and,or,xor}+i32.eqz fused operators as they exist in the current Wasmi bytecode.
  • Maybe re-create {copy, return}.span and copy.span.non-overlapping.
    • This is a much more efficient encoding scheme in certain scenarios. It has to be decided how common those scenarios actually are to make an assessment of how useful those operators are going to be.

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 14.53488% with 588 lines in your changes missing coverage. Please review.

Project coverage is 78.02%. Comparing base (37d1449) to head (79844de).
Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
crates/ir/src/encode.rs 8.94% 234 Missing ⚠️
crates/ir/src/decode.rs 15.47% 224 Missing ⚠️
crates/ir/src/primitive.rs 4.22% 68 Missing ⚠️
crates/ir/src/enum.rs 0.00% 39 Missing ⚠️
crates/ir/src/slice.rs 60.00% 14 Missing ⚠️
crates/ir/src/dispatch.rs 0.00% 7 Missing ⚠️
crates/ir/src/visit.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1148      +/-   ##
==========================================
- Coverage   79.73%   78.02%   -1.72%     
==========================================
  Files         296      304       +8     
  Lines       25433    26121     +688     
==========================================
+ Hits        20280    20380     +100     
- Misses       5153     5741     +588     

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

@Robbepop Robbepop force-pushed the rf-wasmi-bytecode branch 4 times, most recently from b716285 to 1b92892 Compare August 5, 2024 12:15
@Robbepop Robbepop force-pushed the rf-wasmi-bytecode branch 4 times, most recently from 23a5865 to eeb535a Compare August 14, 2024 20:06
@Robbepop Robbepop mentioned this pull request Aug 26, 2024
8 tasks
@Robbepop
Copy link
Member Author

Robbepop commented Sep 18, 2024

Superseeded by #1152.

We probably need a new attempt at this more involved Wasmi bytecode attempt at a later point in time.
This PR turned out to be far too complex to justify the new IR with way too much unsafe Rust code.

Fortunately, #1152 turned out to be pretty simple and should still be able to deliver the possibility to implement new dispatching routines (and more) on top of it.

Closed.

@Robbepop Robbepop closed this Sep 18, 2024
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.

1 participant