Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
415 commits
Select commit Hold shift + click to select a range
5d4c97a
update wasmi_ir2 constructor usage
Robbepop Oct 4, 2025
3d27335
add Stack::drop_n method
Robbepop Oct 4, 2025
8ef6b98
fix bug in Wasm loop translation
Robbepop Oct 4, 2025
abb1260
make pin_label_if_unpinned encode the currently staged operator
Robbepop Oct 4, 2025
2f0eef6
fix bug in move_operands_to_temp and add pre-condition
Robbepop Oct 4, 2025
8c15514
fix stack adjustment when translating calls
Robbepop Oct 4, 2025
4b10b41
always directly encode copies
Robbepop Oct 4, 2025
edcba64
apply rustfmt
Robbepop Oct 4, 2025
e7bbbb0
opt adjust_stack_for_call
Robbepop Oct 4, 2025
0a25749
add new wasmi crate features
Robbepop Oct 6, 2025
be817ce
initial handler definitions
Robbepop Oct 7, 2025
6121fdf
remove Sp::{get,set}_i32 methods
Robbepop Oct 8, 2025
b8fc361
add binary i32 operators
Robbepop Oct 8, 2025
577cc28
add binary i64 operators
Robbepop Oct 8, 2025
089de75
add binary i64 handlers to op_code_to_handler
Robbepop Oct 8, 2025
7367b22
add i{32,64}.[not]{and,or} handlers
Robbepop Oct 8, 2025
44bee96
add binary f32 and f64 handlers
Robbepop Oct 8, 2025
593810b
add cmp+branch handlers
Robbepop Oct 8, 2025
81822bd
add select operator handlers
Robbepop Oct 8, 2025
ec03dc8
move handler into directory
Robbepop Oct 11, 2025
df52cd5
put evals into their own submodule
Robbepop Oct 11, 2025
97faf8a
move handler utilities into utils submodule
Robbepop Oct 11, 2025
740d564
move handler state into state submodule
Robbepop Oct 11, 2025
f81b786
move remainings handler parts into their respective submodules
Robbepop Oct 11, 2025
02fc3d5
add repr(transparent) to Ip and Sp
Robbepop Oct 11, 2025
a766dd1
allow optional , in unwrap_result macro
Robbepop Oct 11, 2025
03901b1
add load operator handlers
Robbepop Oct 11, 2025
2de73f4
return &mut [u8] in memory_bytes utility
Robbepop Oct 12, 2025
4d48806
add load dispatch handlers
Robbepop Oct 12, 2025
6283f42
add store operator handlers
Robbepop Oct 12, 2025
6d6192f
add copy execution handlers
Robbepop Oct 13, 2025
d0e61dd
add copy_span execution handler
Robbepop Oct 13, 2025
c1c8321
refactor unwrap_result
Robbepop Oct 13, 2025
d7da04b
add trap execution handler
Robbepop Oct 13, 2025
f9db0b3
add consume_fuel execution handler
Robbepop Oct 13, 2025
da109fa
add offset_ip utility method
Robbepop Oct 13, 2025
e1f8c25
add branch execution handler
Robbepop Oct 13, 2025
3d95ea6
add missing handlers to op_code_to_handler
Robbepop Oct 13, 2025
cf5e9ce
add global execution handlers
Robbepop Oct 14, 2025
65ef626
implement Stack, ValueStack and CallStack
Robbepop Oct 15, 2025
479384f
improve and fix CallStack::pop method
Robbepop Oct 15, 2025
a58f1af
improve call execution utils
Robbepop Oct 15, 2025
d77ef63
add call_internal execution handler
Robbepop Oct 15, 2025
126e504
properly zero initialize new cells
Robbepop Oct 15, 2025
1c0e244
dont zero overwrite parameter cells
Robbepop Oct 15, 2025
d2bc751
apply rustfmt
Robbepop Oct 15, 2025
aaad2cb
add call_internal execution handler to op_code_to_handler
Robbepop Oct 16, 2025
978557c
add extract_mem0 utility
Robbepop Oct 16, 2025
20c28af
add return execution handler
Robbepop Oct 16, 2025
ffa049d
apply clippy suggestions
Robbepop Oct 16, 2025
37de320
add and use exec_return utility macro
Robbepop Oct 16, 2025
dae5540
add exec_copy_span utility method
Robbepop Oct 16, 2025
e2a8a33
add remaining return execution handlers
Robbepop Oct 16, 2025
ffa80ef
add type guards to dispatch macro
Robbepop Oct 17, 2025
530bc36
add break_with_trap utility macro
Robbepop Oct 17, 2025
1233d03
refactor Stack::push_frame API
Robbepop Oct 17, 2025
ce39c53
add call_imported execution handler partially
Robbepop Oct 17, 2025
e527114
fix bug in call_imported exec handler
Robbepop Oct 18, 2025
cd6df59
fix minor formatting issue
Robbepop Oct 18, 2025
97d0dce
move dispatch! to end of func body
Robbepop Oct 18, 2025
d2cb68a
properly update instance related data if necessary
Robbepop Oct 18, 2025
7746eca
refactor dispatch utilities
Robbepop Oct 20, 2025
43c65b5
add missing import in exec.rs
Robbepop Oct 20, 2025
323b063
add wip-state call_indirect execution handler
Robbepop Oct 20, 2025
b04c7f1
redesign utility trait to handle optionally fallible handlers
Robbepop Oct 20, 2025
7a52905
simplify call handlers slightly
Robbepop Oct 21, 2025
dc8aa38
add Copy bounds to Sp::{get,set} methods
Robbepop Oct 21, 2025
a30b635
properly implement dispatch macros
Robbepop Oct 21, 2025
b8d1f03
redesign Done type
Robbepop Oct 21, 2025
1d1a066
add execute_ops entry points
Robbepop Oct 21, 2025
579ac60
fix a bug in IpDecoder::decode
Robbepop Oct 21, 2025
59ee0f0
rename ExtendToResult -> IntoTrapResult
Robbepop Oct 21, 2025
0d9a00a
remove break_if_trap macro
Robbepop Oct 21, 2025
7f4cbcc
refactor/redesign VmState API
Robbepop Oct 22, 2025
701ae46
add Debug derives to [{Value,Call}]Stack types
Robbepop Oct 22, 2025
3f26c6a
add missing APIs to [{Call,Value}]Stack types
Robbepop Oct 22, 2025
01221b6
add missing imports
Robbepop Oct 22, 2025
650c682
add debug_asssert to ValueStack::push
Robbepop Oct 22, 2025
053511f
properly adjust return and return_span handlers
Robbepop Oct 22, 2025
cd8041c
improve macro hygiene of compile_or_get_func
Robbepop Oct 22, 2025
cd664df
add utils::compile_or_get_func method
Robbepop Oct 22, 2025
456408a
make op_code_to_handler public
Robbepop Oct 22, 2025
c22d6c4
add WasmFuncCall type and API
Robbepop Oct 22, 2025
dfc0911
add Sp::as_slice method
Robbepop Oct 22, 2025
5142eed
add missing new line separator
Robbepop Oct 22, 2025
6113af4
properly re-export handler definitions
Robbepop Oct 22, 2025
241ad79
implement direct-threading encoding in translator
Robbepop Oct 22, 2025
b2a2d48
initial EngineExecutor impls using WasmFuncCall
Robbepop Oct 22, 2025
a356aa5
mark EngineStacks Send and Sync
Robbepop Oct 22, 2025
1a34015
remove unused DEFAULT_MEMORY_INDEX constant
Robbepop Oct 22, 2025
a6bb611
silence warnings
Robbepop Oct 22, 2025
6288c91
properly use {Read,Write}As traits in Sp's API
Robbepop Oct 22, 2025
de532d4
remove old executor code
Robbepop Oct 22, 2025
92ce25f
rename parameter
Robbepop Oct 22, 2025
eabac08
re-design Sp::new constructor
Robbepop Oct 22, 2025
cbcc921
fix miri reported UB with direct-threading
Robbepop Oct 22, 2025
cacb7ea
apply rustfmt
Robbepop Oct 23, 2025
353dd08
fix trace_offset calculation
Robbepop Oct 23, 2025
d0dd0ce
add compact and trampolines crate features to wasmi_wast crate
Robbepop Oct 23, 2025
43a8719
use imported OpCode
Robbepop Oct 24, 2025
19f0277
fix updating callee_sp in call handlers
Robbepop Oct 24, 2025
86f9cfb
use unreachable_unchecked in Ip::decode
Robbepop Oct 24, 2025
8ef2e03
use same ip in decode and fetch
Robbepop Oct 24, 2025
01ba43e
fix integer-overflow bug in encode_return
Robbepop Oct 24, 2025
34aac6d
use unreachable_unreached in op_code_to_handler
Robbepop Oct 24, 2025
e753c98
fix bug in strip-noop optimization in copy_span
Robbepop Oct 24, 2025
474d602
properly use and encode copy_span_{asc,des}
Robbepop Oct 24, 2025
1dce060
remove commented out code
Robbepop Oct 24, 2025
4c7935a
add #[inline(..)] annotations important for indirect-threading
Robbepop Oct 24, 2025
d706086
fix translation of fused cmp+br for f{32,64} ops
Robbepop Oct 24, 2025
d13975b
apply rustfmt
Robbepop Oct 24, 2025
904d805
fix bugs translating br_if with copying values
Robbepop Oct 24, 2025
0f0bb78
add Mem0Ptr and Mem0Len types
Robbepop Oct 24, 2025
3538bc3
add extra-checks crate feature to wasmi_wast crate
Robbepop Oct 24, 2025
5403c72
update imports for Mem0 -> Mem0Ptr renaming
Robbepop Oct 24, 2025
6a0d8c2
add memory.{size,grow} execution handlers
Robbepop Oct 24, 2025
67d95f1
dedup code in CallStack
Robbepop Oct 25, 2025
dc627d6
optimize CallStack instance caching
Robbepop Oct 25, 2025
909f491
add UpdateBranchOffset impl for ir::BranchOffset
Robbepop Oct 25, 2025
4683f66
swap len_targets and index fields in br_table ops
Robbepop Oct 25, 2025
1f0cf6a
fix bug pushing a zero-sized function frame
Robbepop Oct 25, 2025
cb5eecc
move debug_asserts into copy_span_{asc,des}
Robbepop Oct 25, 2025
52f5c3f
fix bugs in br_table translation
Robbepop Oct 25, 2025
90f7498
add br_table execution handlers
Robbepop Oct 25, 2025
fb2e7dc
generate instance execution getters via macro
Robbepop Oct 25, 2025
fc51756
fix parameter names in generated code
Robbepop Oct 25, 2025
ab8c32c
change fields of global ops to improve alignment
Robbepop Oct 25, 2025
58e7133
use new store internal errors in executor
Robbepop Oct 27, 2025
6a429fc
reorder Done impls
Robbepop Oct 28, 2025
7b8ddf9
add done macro
Robbepop Oct 28, 2025
0ef1c08
use done macro in trap execution handler
Robbepop Oct 28, 2025
f965695
add return to done macro expansion
Robbepop Oct 28, 2025
1bca83c
use done macro everywhere that makes sense
Robbepop Oct 28, 2025
388ef1c
remove unneeded compile_or_get_func macro params
Robbepop Oct 28, 2025
43e2d63
use debug_assert in done method
Robbepop Oct 28, 2025
2591db1
remove unused Done type
Robbepop Oct 28, 2025
0fa668e
add #[inline(always)] annotations to push_frame API
Robbepop Oct 29, 2025
4f0cb82
replace exec_return macro with function
Robbepop Oct 29, 2025
27f96a3
add return_call_internal execution handler
Robbepop Oct 29, 2025
9bb179c
add remaining return_call* execution handlers
Robbepop Oct 29, 2025
2105776
rename params in push_frame
Robbepop Oct 30, 2025
46928e0
refactor Stack internals
Robbepop Oct 30, 2025
2dd929f
use unreachable_unchecked in CallStack::pop
Robbepop Oct 30, 2025
709bbe6
add Inst abstraction type
Robbepop Oct 31, 2025
30745e6
make dispatching host functions use Inst instead of &Instance
Robbepop Nov 1, 2025
eb16970
add Stack::prepare_host_frame API
Robbepop Nov 1, 2025
2491fde
rename var bindings
Robbepop Nov 1, 2025
da47fa5
support host function calls in call_{imported,indirect}
Robbepop Nov 1, 2025
42e71b5
properly use explicit dangling Sp instead of null
Robbepop Nov 1, 2025
ebffd64
fix bug in memory.grow execution handler
Robbepop Nov 1, 2025
89f1df8
improve debug assert message
Robbepop Nov 1, 2025
793d488
fix bug in Stack::pop_frame
Robbepop Nov 1, 2025
5cdac84
disable known failing wast tests
Robbepop Nov 1, 2025
29194f7
use wasm API for f{32,64}.ne execution handlers
Robbepop Nov 1, 2025
c7903f4
fix bug with f32.ne translation
Robbepop Nov 1, 2025
1cec963
fix bug in ValueStack::replace
Robbepop Nov 2, 2025
e81f6a8
use return in dispatch! macro expansion
Robbepop Nov 3, 2025
e07aac9
add and use DoneReason::out_of_fuel constructor
Robbepop Nov 3, 2025
0c943f1
fix bug in memory.fill translation
Robbepop Nov 3, 2025
f579f23
add resolve_data_mut utility
Robbepop Nov 3, 2025
a7acbea
add bulk-memory execution handlers
Robbepop Nov 3, 2025
0b57854
enable some passing spec testsuite tests
Robbepop Nov 3, 2025
8f7584f
add and use consume_fuel utility macro
Robbepop Nov 3, 2025
5138e53
allow optional trailing comma in done! macro
Robbepop Nov 3, 2025
502d473
move eval submodule below others
Robbepop Nov 3, 2025
7e90e0c
implement Done in terms of ControlFlow
Robbepop Nov 3, 2025
3be2583
add memory_copy_within helper method
Robbepop Nov 3, 2025
0874e09
apply rustfmt
Robbepop Nov 3, 2025
4a2e8ea
add Control type alias which is less confusing
Robbepop Nov 3, 2025
0c52f74
restrict visibility of some module re-exports
Robbepop Nov 3, 2025
4ddb07f
rename utility traits
Robbepop Nov 3, 2025
cd70801
move ControlBreak + impl down
Robbepop Nov 4, 2025
ae1dff1
remove unused ControlContinue with trampolines
Robbepop Nov 4, 2025
eda3d07
add state to Break variant
Robbepop Nov 4, 2025
5956059
simplify ErrorKind::as_trap_code
Robbepop Nov 4, 2025
6089047
add TrapCode::OutOfSystemMemory
Robbepop Nov 4, 2025
0c500d6
adjust Break type for new TrapCode
Robbepop Nov 4, 2025
e9bf5e2
add ExecutionOutcome type
Robbepop Nov 4, 2025
b98b40a
update comment
Robbepop Nov 5, 2025
f483df3
add IntoControl utility trait
Robbepop Nov 5, 2025
613c251
add memory_slice and memory_slice_mut helper methods
Robbepop Nov 5, 2025
1876f4f
use new utilities in execution handlers where possible
Robbepop Nov 5, 2025
54e13fe
remove no longer used IntoTrapResult utility trait
Robbepop Nov 5, 2025
715b3d0
remove some unused or dead code
Robbepop Nov 5, 2025
e5e15e7
remove unused import
Robbepop Nov 5, 2025
ac278c0
fix intra doc links
Robbepop Nov 5, 2025
419d8c4
swap lhs and rhs for circuiting cmps to avoid some memory accesses
Robbepop Nov 5, 2025
afebdc4
add call_wasm utility function
Robbepop Nov 5, 2025
13d9fc3
add and use call_host utility function
Robbepop Nov 5, 2025
d5e527c
add return_call_wasm utility function
Robbepop Nov 5, 2025
3228eff
optimize return operator execution handling
Robbepop Nov 5, 2025
61d0196
add and use call_wasm_or_host utility function
Robbepop Nov 5, 2025
cb1a42d
switch param order
Robbepop Nov 5, 2025
99324ba
fix field ordering of TableSet operations
Robbepop Nov 5, 2025
ff5a649
fix type check bug in visit_table_set
Robbepop Nov 5, 2025
c6836ec
implement bulk-table operator execution handlers
Robbepop Nov 5, 2025
8cffdfa
enable many Wast tests that are now passing
Robbepop Nov 5, 2025
bb2a8f7
change unimplemented -> panic
Robbepop Nov 6, 2025
88d5cbe
add wide-arithmetic execution handlers
Robbepop Nov 6, 2025
950c5e9
fix bug in host function calls with zero frame size
Robbepop Nov 7, 2025
8e79ca3
remove some dead code
Robbepop Nov 7, 2025
b47c031
implement host function calls in return_call[_indirect]
Robbepop Nov 8, 2025
932af05
refactor and simplify executor in preparation of resumable functions
Robbepop Nov 9, 2025
4972620
remove unused frame_size field
Robbepop Nov 10, 2025
df5370f
use Inst instead of Instance in WasmFuncCall
Robbepop Nov 10, 2025
b93117b
add Stack::sync_ip API
Robbepop Nov 10, 2025
a425bb5
add and use out_of_fuel! utility macro
Robbepop Nov 10, 2025
5ba94ca
implement call resumption after running out of fuel
Robbepop Nov 10, 2025
a03c646
add cfg guard to op_code_to_handler match
Robbepop Nov 10, 2025
6686ab0
implement call resumption after host call error
Robbepop Nov 10, 2025
bcff3ca
rename DoneReason::CompileError -> Error + add docs
Robbepop Nov 10, 2025
3f120cd
disallow resumption when a host tail call would return
Robbepop Nov 10, 2025
783c849
remove unused utility function
Robbepop Nov 11, 2025
043b985
reformat code slightly
Robbepop Nov 11, 2025
41de85f
initial implementation for root host function calls
Robbepop Nov 11, 2025
eb472f3
remove overly strict debug_assert
Robbepop Nov 11, 2025
7227278
swap parameters of ResumableCall* types
Robbepop Nov 11, 2025
e939c42
use proper byte sizes for ValueStack setup
Robbepop Nov 11, 2025
87702f2
add missing import
Robbepop Nov 11, 2025
185e7a1
move comment
Robbepop Nov 11, 2025
fc7e2a5
use sp_or_dangling in restore_frame
Robbepop Nov 11, 2025
3fe078f
add ValueStack::grow_if_needed method
Robbepop Nov 11, 2025
cd7b743
make use of ValueStack::grow_if_needed
Robbepop Nov 11, 2025
a377fca
fix bug after using ValueStack::grow_if_needed
Robbepop Nov 11, 2025
090290d
relaxed debug_assert and add comment
Robbepop Nov 12, 2025
c47e75f
disable SIMD specific Wast test for now
Robbepop Nov 12, 2025
3c9bef1
fix bug in ValueStack::prepare_host_frame
Robbepop Nov 12, 2025
bdc2354
add default features to wasmi_wast
Robbepop Nov 12, 2025
2459cfe
simplify memory_bytes utility method
Robbepop Nov 12, 2025
4b704b4
use trampolines and extra-checks features in the fuzzer
Robbepop Nov 12, 2025
04fe981
fix, refactor and clean-up ValueStack::replace
Robbepop Nov 12, 2025
0d9e520
disable simd and relaxed-simd in the fuzzer for now
Robbepop Nov 12, 2025
3082129
remove short-circuiting from wasmi_i32_and
Robbepop Nov 12, 2025
b4e005a
mirror i32.and evaluation fix for i64.and
Robbepop Nov 12, 2025
2648bc6
rename new crate features
Robbepop Nov 13, 2025
1dd6342
add codegen-units=1 to release profile
Robbepop Nov 14, 2025
75ab76b
simplify the Done type
Robbepop Nov 14, 2025
ad02823
fix some incorrect execution handler identifiers
Robbepop Nov 14, 2025
401d5d8
fix for_each_op expansion
Robbepop Nov 14, 2025
79c28e7
add stubs for all unimplemented simd operators
Robbepop Nov 14, 2025
e10ad47
apply rustfmt
Robbepop Nov 14, 2025
da42d5f
use for_each_op to implement op_code_to_handler
Robbepop Nov 14, 2025
1bd060a
move control macros to utils
Robbepop Nov 14, 2025
28e2a1e
move WasmFuncCall and HostFuncCall into func submodule
Robbepop Nov 14, 2025
3d644e4
move dispatch.rs -> dispatch/mod.rs
Robbepop Nov 14, 2025
9829410
move execute_until_done into its respective backend
Robbepop Nov 14, 2025
f061182
move dispatch macro into its respective backend
Robbepop Nov 14, 2025
f9772a2
move NextState into its respective backend
Robbepop Nov 14, 2025
a019d59
move control_break into its respective backend
Robbepop Nov 14, 2025
89a95ff
move Done type into its respective backend
Robbepop Nov 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ codegen-units = 1
[profile.miri]
inherits = "dev"
debug-assertions = false

[profile.release]
codegen-units = 1
5 changes: 5 additions & 0 deletions crates/core/src/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ generate_trap_code! {
/// desire on the part of the embedder to trap the interpreter rather than
/// merely fail the growth operation.
GrowthOperationLimited = 10,

/// This trap is raised when a WebAssembly operation demanded a memory
/// allocation and the host system could not supply the requested amount.
OutOfSystemMemory = 11,
}

impl TrapCode {
Expand All @@ -358,6 +362,7 @@ impl TrapCode {
Self::BadSignature => "indirect call type mismatch",
Self::OutOfFuel => "all fuel consumed by WebAssembly",
Self::GrowthOperationLimited => "growth operation limited",
Self::OutOfSystemMemory => "out of system memory",
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions crates/core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait Integer: Sized + Unsigned {
/// Signed shift-right `self` by `other`.
fn shr_s(lhs: Self, rhs: Self) -> Self;
/// Unsigned shift-right `self` by `other`.
fn shr_u(lhs: Self, rhs: Self) -> Self;
fn shr_u(lhs: Self::Uint, rhs: Self::Uint) -> Self::Uint;
/// Get left bit rotation result.
fn rotl(lhs: Self, rhs: Self) -> Self;
/// Get right bit rotation result.
Expand Down Expand Up @@ -130,25 +130,14 @@ pub trait Integer: Sized + Unsigned {
pub trait Unsigned {
/// The unsigned type.
type Uint;

/// Converts `self` losslessly to the unsigned type.
fn to_unsigned(self) -> Self::Uint;
}

impl Unsigned for i32 {
type Uint = u32;
#[inline]
fn to_unsigned(self) -> Self::Uint {
self as _
}
}

impl Unsigned for i64 {
type Uint = u64;
#[inline]
fn to_unsigned(self) -> Self::Uint {
self as _
}
}

/// Float-point value.
Expand Down Expand Up @@ -270,8 +259,8 @@ macro_rules! impl_integer {
lhs.wrapping_shr(rhs as u32)
}
#[inline]
fn shr_u(lhs: Self, rhs: Self) -> Self {
lhs.to_unsigned().wrapping_shr(rhs as u32) as _
fn shr_u(lhs: Self::Uint, rhs: Self::Uint) -> Self::Uint {
lhs.wrapping_shr(rhs as u32) as _
}
#[inline]
fn rotl(lhs: Self, rhs: Self) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl_untyped_val! {
fn i64_shl(lhs: i64, rhs: i64) -> i64 = Integer::shl;
fn i32_shr_s(lhs: i32, rhs: i32) -> i32 = Integer::shr_s;
fn i64_shr_s(lhs: i64, rhs: i64) -> i64 = Integer::shr_s;
fn i32_shr_u(lhs: i32, rhs: i32) -> i32 = Integer::shr_u;
fn i64_shr_u(lhs: i64, rhs: i64) -> i64 = Integer::shr_u;
fn i32_shr_u(lhs: u32, rhs: u32) -> u32 = <i32 as Integer>::shr_u;
fn i64_shr_u(lhs: u64, rhs: u64) -> u64 = <i64 as Integer>::shr_u;
fn i32_rotl(lhs: i32, rhs: i32) -> i32 = Integer::rotl;
fn i64_rotl(lhs: i64, rhs: i64) -> i64 = Integer::rotl;
fn i32_rotr(lhs: i32, rhs: i32) -> i32 = Integer::rotr;
Expand Down
2 changes: 1 addition & 1 deletion crates/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude.workspace = true
publish = false

[dependencies]
wasmi = { workspace = true, features = ["std", "simd"] }
wasmi = { workspace = true, features = ["std", "simd", "portable-dispatch", "extra-checks"] }
wasmtime = { workspace = true, optional = true, features = [
"cranelift",
"runtime",
Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl Arbitrary<'_> for FuzzSmithConfig {
custom_page_sizes_enabled: true,
bulk_memory_enabled: true,
reference_types_enabled: false, // TODO: re-enable reference-types for differential fuzzing
simd_enabled: true,
relaxed_simd_enabled: true,
simd_enabled: false,
relaxed_simd_enabled: false,
multi_value_enabled: true,
memory64_enabled: true,
saturating_float_to_int_enabled: true,
Expand Down
4 changes: 3 additions & 1 deletion crates/fuzz/src/oracle/wasmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ impl From<wasmi::Error> for FuzzError {
| TrapCode::BadConversionToInteger => crate::TrapCode::BadConversionToInteger,
| TrapCode::StackOverflow => crate::TrapCode::StackOverflow,
| TrapCode::BadSignature => crate::TrapCode::BadSignature,
| TrapCode::OutOfFuel | TrapCode::GrowthOperationLimited => return FuzzError::Other,
| TrapCode::OutOfFuel
| TrapCode::GrowthOperationLimited
| TrapCode::OutOfSystemMemory => return FuzzError::Other,
};
FuzzError::Trap(trap_code)
}
Expand Down
4 changes: 3 additions & 1 deletion crates/ir2/build/display/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ impl Display for DisplayOp<&'_ Isa> {
{indent}#[macro_export]\n\
{indent}macro_rules! for_each_op {{\n\
{indent} ($mac:ident) => {{\n\
{for_each_op_body},\n\
{indent} $mac! {{\n\
{for_each_op_body},\n\
{indent} }}\n\
{indent} }};\n\
{indent}}}\n\
"
Expand Down
8 changes: 4 additions & 4 deletions crates/ir2/build/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,15 @@ fn add_control_ops(isa: &mut Isa) {
Op::from(GenericOp::new(
Ident::BranchTable,
[
Field::new(Ident::Index, FieldTy::Slot),
Field::new(Ident::LenTargets, FieldTy::U32),
Field::new(Ident::Index, FieldTy::Slot),
],
)),
Op::from(GenericOp::new(
Ident::BranchTableSpan,
[
Field::new(Ident::Index, FieldTy::Slot),
Field::new(Ident::LenTargets, FieldTy::U32),
Field::new(Ident::Index, FieldTy::Slot),
Field::new(Ident::Values, FieldTy::SlotSpan),
Field::new(Ident::LenValues, FieldTy::U16),
],
Expand Down Expand Up @@ -542,8 +542,8 @@ fn add_global_ops(isa: &mut Isa) {
Op::from(GenericOp::new(
Ident::GlobalGet,
[
Field::new(Ident::Result, FieldTy::Slot),
Field::new(Ident::Global, FieldTy::Global),
Field::new(Ident::Result, FieldTy::Slot),
],
)),
Op::from(GenericOp::new(
Expand All @@ -563,8 +563,8 @@ fn add_global_ops(isa: &mut Isa) {
Op::from(GenericOp::new(
Ident::GlobalSet64,
[
Field::new(Ident::Global, FieldTy::Global),
Field::new(Ident::Value, FieldTy::U64),
Field::new(Ident::Global, FieldTy::Global),
],
)),
];
Expand Down
11 changes: 9 additions & 2 deletions crates/wasmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [
[dependencies]
wasmi_core = { workspace = true }
wasmi_collections = { workspace = true }
wasmi_ir = { workspace = true }
wasmi_ir2 = { workspace = true }
wasmparser = { workspace = true, features = ["validate", "features"] }
wat = { workspace = true, optional = true }
spin = { version = "0.9", default-features = false, features = [
Expand Down Expand Up @@ -51,7 +51,14 @@ prefer-btree-collections = [
"wasmparser/prefer-btree-collections",
]
wat = ["dep:wat", "std"]
simd = ["wasmi_core/simd", "wasmi_ir/simd", "wasmparser/simd"]
simd = ["wasmi_core/simd", "wasmi_ir2/simd", "wasmparser/simd"]

# Enables a portable dispatch scheme that avoids tail-call reliance.
# Recommended for targets without stable or guaranteed tail-call support.
portable-dispatch = []
# Enables an indirect dispatch scheme using op-codes instead of
# embedded function pointers for more compact bytecode.
indirect-dispatch = []

# Enables extra checks performed during Wasmi bytecode execution.
#
Expand Down
54 changes: 20 additions & 34 deletions crates/wasmi/src/engine/code_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use super::{FuncTranslationDriver, FuncTranslator, TranslationError, ValidatingFuncTranslator};
use crate::{
collections::arena::{Arena, ArenaIndex},
core::{Fuel, FuelCostsProvider, UntypedVal},
core::{Fuel, FuelCostsProvider},
engine::{utils::unreachable_unchecked, ResumableOutOfFuelError},
errors::FuelError,
ir::{index::InternalFunc, Op},
ir::index::InternalFunc,
module::{FuncIdx, ModuleHeader},
Config,
Error,
Expand All @@ -28,6 +28,9 @@ use core::{
use spin::Mutex;
use wasmparser::{FuncToValidate, ValidatorResources, WasmFeatures};

#[cfg(doc)]
use crate::ir::Op;

/// A reference to a compiled function stored in the [`CodeMap`] of an [`Engine`](crate::Engine).
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct EngineFunc(u32);
Expand Down Expand Up @@ -785,9 +788,7 @@ impl<'a> From<&'a [u8]> for SmallByteSlice {
#[derive(Debug)]
pub struct CompiledFuncEntity {
/// The sequence of [`Op`] of the [`CompiledFuncEntity`].
instrs: Pin<Box<[Op]>>,
/// The constant values local to the [`EngineFunc`].
consts: Pin<Box<[UntypedVal]>>,
ops: Pin<Box<[u8]>>,
/// The number of stack slots used by the [`EngineFunc`] in total.
///
/// # Note
Expand All @@ -802,31 +803,25 @@ impl CompiledFuncEntity {
///
/// # Panics
///
/// - If `instrs` is empty.
/// - If `instrs` contains more than `i32::MAX` instructions.
pub fn new<I, C>(len_stack_slots: u16, instrs: I, consts: C) -> Self
where
I: IntoIterator<Item = Op>,
C: IntoIterator<Item = UntypedVal>,
{
let instrs: Pin<Box<[Op]>> = Pin::new(instrs.into_iter().collect());
let consts: Pin<Box<[UntypedVal]>> = Pin::new(consts.into_iter().collect());
/// - If `ops` is empty.
/// - If `ops` contains more than `i32::MAX` encoded bytes.
pub fn new(len_stack_slots: u16, ops: &[u8]) -> Self {
let ops: Pin<Box<[u8]>> = Pin::new(ops.into());
assert!(
!instrs.is_empty(),
!ops.is_empty(),
"compiled functions must have at least one instruction"
);
assert!(
// Generally, Wasmi has no issues with more than `i32::MAX` instructions.
// However, Wasmi's branch instructions can jump across at most `i32::MAX`
// forwards or `i32::MIN` instructions backwards and thus having more than
// `i32::MAX` instructions might introduce problems.
instrs.len() <= i32::MAX as usize,
ops.len() <= i32::MAX as usize,
"compiled function has too many instructions: {}",
instrs.len(),
ops.len(),
);
Self {
instrs,
consts,
ops,
len_stack_slots,
}
}
Expand All @@ -835,10 +830,8 @@ impl CompiledFuncEntity {
/// A shared reference to the data of a [`EngineFunc`].
#[derive(Debug, Copy, Clone)]
pub struct CompiledFuncRef<'a> {
/// The sequence of [`Op`] of the [`CompiledFuncEntity`].
instrs: Pin<&'a [Op]>,
/// The constant values local to the [`EngineFunc`].
consts: Pin<&'a [UntypedVal]>,
/// The sequence of encoded [`Op`]s of the [`CompiledFuncEntity`].
ops: Pin<&'a [u8]>,
/// The number of stack slots used by the [`EngineFunc`] in total.
len_stack_slots: u16,
}
Expand All @@ -847,29 +840,22 @@ impl<'a> From<&'a CompiledFuncEntity> for CompiledFuncRef<'a> {
#[inline]
fn from(func: &'a CompiledFuncEntity) -> Self {
Self {
instrs: func.instrs.as_ref(),
consts: func.consts.as_ref(),
ops: func.ops.as_ref(),
len_stack_slots: func.len_stack_slots,
}
}
}

impl<'a> CompiledFuncRef<'a> {
/// Returns the sequence of [`Op`] of the [`EngineFunc`].
/// Returns the sequence of encoded [`Op`]s of the [`EngineFunc`].
#[inline]
pub fn instrs(&self) -> &'a [Op] {
self.instrs.get_ref()
pub fn ops(&self) -> &'a [u8] {
self.ops.get_ref()
}

/// Returns the number of stack slots used by the [`EngineFunc`].
#[inline]
pub fn len_stack_slots(&self) -> u16 {
self.len_stack_slots
}

/// Returns the function local constant values of the [`EngineFunc`].
#[inline]
pub fn consts(&self) -> &'a [UntypedVal] {
self.consts.get_ref()
}
}
Loading
Loading