From 8418f692b54f527cee2e15260a825c69475511a3 Mon Sep 17 00:00:00 2001 From: Bela Stoyan Date: Wed, 2 Dec 2026 10:15:15 +0100 Subject: [PATCH] Call out_of_gas and new_epoch through PreserveAll trampolines --- crates/cranelift/src/compiler.rs | 10 +- crates/cranelift/src/compiler/component.rs | 8 +- crates/cranelift/src/func_environ.rs | 94 ++++++-- crates/environ/src/key.rs | 35 +-- crates/environ/src/module_artifacts.rs | 4 +- crates/wasmtime/src/compile.rs | 18 +- src/commands/objdump.rs | 2 +- tests/all/epoch_interruption.rs | 62 ++++++ tests/all/fuel.rs | 206 ++++++++++++++++++ tests/disas/debug.wat | 2 +- tests/disas/epoch-interruption-x86.wat | 53 ++--- tests/disas/epoch-interruption.wat | 36 +-- .../disas/epoch-loop-live-values-aarch64.wat | 101 +++++++++ tests/disas/epoch-loop-live-values-x64.wat | 122 +++++++++++ tests/disas/fuel-loop-live-values-aarch64.wat | 103 +++++++++ tests/disas/fuel-loop-live-values-x64.wat | 129 +++++++++++ tests/disas/gc/array-copy-with-fuel.wat | 190 ++++++++-------- tests/disas/guest-debugging.wat | 2 +- tests/disas/memory-copy-epochs.wat | 54 ++--- tests/disas/memory-copy-fuel-const-len.wat | 172 +++++++-------- tests/disas/memory-copy-fuel.wat | 72 +++--- tests/disas/memory-watchpoints.wat | 2 +- tests/disas/pulley/epoch-simple.wat | 10 +- 23 files changed, 1130 insertions(+), 357 deletions(-) create mode 100644 tests/disas/epoch-loop-live-values-aarch64.wat create mode 100644 tests/disas/epoch-loop-live-values-x64.wat create mode 100644 tests/disas/fuel-loop-live-values-aarch64.wat create mode 100644 tests/disas/fuel-loop-live-values-x64.wat diff --git a/crates/cranelift/src/compiler.rs b/crates/cranelift/src/compiler.rs index 5a98b08d8c84..7b0c9f65b7a8 100644 --- a/crates/cranelift/src/compiler.rs +++ b/crates/cranelift/src/compiler.rs @@ -364,9 +364,9 @@ impl Compiler { let (builtin_func_index, wasm_sig) = match key { FuncKey::WasmToBuiltinTrampoline(builtin) => (builtin, sigs.wasm_signature(builtin)), - FuncKey::PatchableToBuiltinTrampoline(builtin) => { + FuncKey::PreserveAllToBuiltinTrampoline(builtin) => { let mut sig = sigs.wasm_signature(builtin); - // Patchable functions cannot return anything. We + // `preserve_all` functions cannot return anything. We // raise any errors that occur below so this is fine. sig.returns.clear(); sig.call_conv = CallConv::PreserveAll; @@ -703,7 +703,7 @@ impl wasmtime_environ::Compiler for Compiler { panic!("use `compile_function` instead") } - FuncKey::WasmToBuiltinTrampoline(..) | FuncKey::PatchableToBuiltinTrampoline(_) => { + FuncKey::WasmToBuiltinTrampoline(..) | FuncKey::PreserveAllToBuiltinTrampoline(_) => { self.compile_wasm_to_builtin(key, symbol) } @@ -744,7 +744,7 @@ impl wasmtime_environ::Compiler for Compiler { ), // Delegate to a helper to finish compiling this. Abi::Wasm => self.compile_module_startup(translation, types, key, ty), - Abi::Patchable => unreachable!(), + Abi::PreserveAll => unreachable!(), } } } @@ -1176,7 +1176,7 @@ impl InliningCompiler for Compiler { None => Cow::Borrowed(symbol), Some(Abi::Wasm) => Cow::Owned(format!("{symbol}_wasm_call")), Some(Abi::Array) => Cow::Owned(format!("{symbol}_array_call")), - Some(Abi::Patchable) => Cow::Owned(format!("{symbol}_patchable_call")), + Some(Abi::PreserveAll) => Cow::Owned(format!("{symbol}_preserve_all_call")), }; let compiled_func = if let Some(input) = input { diff --git a/crates/cranelift/src/compiler/component.rs b/crates/cranelift/src/compiler/component.rs index 4b3f611e55db..ae7dda6983ce 100644 --- a/crates/cranelift/src/compiler/component.rs +++ b/crates/cranelift/src/compiler/component.rs @@ -1662,8 +1662,8 @@ impl ComponentCompiler for Compiler { )?); } - Abi::Patchable => unreachable!( - "We should not be compiling a patchable-ABI trampoline for a component function" + Abi::PreserveAll => unreachable!( + "We should not be compiling a preserve_all-ABI trampoline for a component function" ), } @@ -1742,9 +1742,9 @@ impl ComponentCompiler for Compiler { )?); } - Abi::Patchable => { + Abi::PreserveAll => { unreachable!( - "We should not be compiling a patchable trampoline for a component intrinsic" + "We should not be compiling a preserve_all trampoline for a component intrinsic" ) } } diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index f5b12101899e..f97554cf5b07 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -91,6 +91,8 @@ pub(crate) struct BuiltinFunctions { builtins: [Option; BuiltinFunctionIndex::len() as usize], breakpoint_trampoline: Option, + out_of_gas_preserve_all: Option, + new_epoch_preserve_all: Option, } impl BuiltinFunctions { @@ -99,6 +101,8 @@ impl BuiltinFunctions { types: BuiltinFunctionSignatures::new(compiler), builtins: [None; BuiltinFunctionIndex::len() as usize], breakpoint_trampoline: None, + out_of_gas_preserve_all: None, + new_epoch_preserve_all: None, } } @@ -127,24 +131,63 @@ impl BuiltinFunctions { f } + /// A call to the `out_of_gas` builtin through its `PreserveAll` + /// trampoline. + /// + /// Fuel checks sit at function entries and in every loop header. A call + /// with the normal Wasm ABI there clobbers all caller-saved registers on a + /// path that is almost never taken, which forces every value that is live + /// across the check into a callee-saved register or a stack slot. The + /// `PreserveAll` trampoline clobbers nothing, so values stay in whatever + /// registers they are in. The trampoline returns nothing and raises the + /// builtin's trap itself. + pub(crate) fn out_of_gas_preserve_all(&mut self, func: &mut Function) -> ir::FuncRef { + let ptr = self.types.pointer_type; + *self.out_of_gas_preserve_all.get_or_insert_with(|| { + Self::preserve_all(func, ptr, BuiltinFunctionIndex::out_of_gas(), false) + }) + } + + /// Like `out_of_gas_preserve_all`, for the `new_epoch` builtin. The new + /// deadline is not returned and has to be reloaded from the store. + pub(crate) fn new_epoch_preserve_all(&mut self, func: &mut Function) -> ir::FuncRef { + let ptr = self.types.pointer_type; + *self.new_epoch_preserve_all.get_or_insert_with(|| { + Self::preserve_all(func, ptr, BuiltinFunctionIndex::new_epoch(), false) + }) + } + + /// Imports `builtin` through its `PreserveAll` trampoline, which takes + /// only the vmctx, returns nothing and raises the builtin's trap itself. + fn preserve_all( + func: &mut Function, + pointer_type: ir::Type, + builtin: BuiltinFunctionIndex, + patchable: bool, + ) -> ir::FuncRef { + let mut signature = ir::Signature::new(CallConv::PreserveAll); + signature.params.push(ir::AbiParam::special( + pointer_type, + ir::ArgumentPurpose::VMContext, + )); + let signature = func.import_signature(signature); + let key = FuncKey::PreserveAllToBuiltinTrampoline(builtin); + let (namespace, index) = key.into_raw_parts(); + let name = ir::ExternalName::User( + func.declare_imported_user_function(ir::UserExternalName { namespace, index }), + ); + func.import_function(ir::ExtFuncData { + name, + signature, + colocated: true, + patchable, + }) + } + pub(crate) fn patchable_breakpoint(&mut self, func: &mut Function) -> ir::FuncRef { + let ptr = self.types.pointer_type; *self.breakpoint_trampoline.get_or_insert_with(|| { - let mut signature = ir::Signature::new(CallConv::PreserveAll); - signature - .params - .push(ir::AbiParam::new(self.types.pointer_type)); - let signature = func.import_signature(signature); - let key = FuncKey::PatchableToBuiltinTrampoline(BuiltinFunctionIndex::breakpoint()); - let (namespace, index) = key.into_raw_parts(); - let name = ir::ExternalName::User( - func.declare_imported_user_function(ir::UserExternalName { namespace, index }), - ); - func.import_function(ir::ExtFuncData { - name, - signature, - colocated: true, - patchable: true, - }) + Self::preserve_all(func, ptr, BuiltinFunctionIndex::breakpoint(), true) }) } } @@ -785,6 +828,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { fn fuel_check(&mut self, builder: &mut FunctionBuilder) { self.fuel_increment_var(builder); let out_of_gas_block = builder.create_block(); + builder.set_cold_block(out_of_gas_block); let continuation_block = builder.create_block(); // Note that our fuel is encoded as adding positive values to a @@ -812,7 +856,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { // intrinsic may alter how much fuel is in the system. builder.switch_to_block(out_of_gas_block); self.fuel_save_from_var(builder); - let out_of_gas = self.builtin_functions.out_of_gas(builder.func); + let out_of_gas = self.builtin_functions.out_of_gas_preserve_all(builder.func); let vmctx = self.vmctx_val(&mut builder.cursor()); self.call_builtin(builder, out_of_gas, &[vmctx]); self.fuel_load_into_var(builder); @@ -964,12 +1008,18 @@ impl<'module_environment> FuncEnvironment<'module_environment> { builder.def_var(self.epoch_deadline_var, deadline); self.epoch_check_cached(builder, cur_epoch_value, continuation_block); - let new_epoch = self.builtin_functions.new_epoch(builder.func); + // Like the fuel check, call through a `PreserveAll` trampoline so the + // (cold) call does not clobber registers in loop headers. It does not + // return the new deadline, so reload it. + let new_epoch = self.builtin_functions.new_epoch_preserve_all(builder.func); let vmctx = self.vmctx_val(&mut builder.cursor()); - // new_epoch() returns the new deadline, so we don't have to - // reload it. - let call = self.call_builtin(builder, new_epoch, &[vmctx]); - let new_deadline = *builder.func.dfg.inst_results(call).first().unwrap(); + self.call_builtin(builder, new_epoch, &[vmctx]); + let vmstore_ctx = self.get_vmstore_context_ptr(builder); + let new_deadline = self + .alias_regions + .vm_store_context() + .epoch_deadline() + .load(&mut builder.cursor(), vmstore_ctx); builder.def_var(self.epoch_deadline_var, new_deadline); builder.ins().jump(continuation_block, &[]); builder.seal_block(continuation_block); diff --git a/crates/environ/src/key.rs b/crates/environ/src/key.rs index 66bc7c189a8d..c5cc69728af1 100644 --- a/crates/environ/src/key.rs +++ b/crates/environ/src/key.rs @@ -29,8 +29,8 @@ pub enum FuncKeyKind { /// A trampoline from a Wasm-caller to the given builtin. WasmToBuiltinTrampoline = FuncKey::new_kind(0b0011), - /// A trampoline from the patchable ABI to the given builtin. - PatchableToBuiltinTrampoline = FuncKey::new_kind(0b0100), + /// A trampoline from the `preserve_all` ABI to the given builtin. + PreserveAllToBuiltinTrampoline = FuncKey::new_kind(0b0100), /// A Pulley-specific host call. PulleyHostCall = FuncKey::new_kind(0b0101), @@ -73,8 +73,8 @@ impl FuncKeyKind { x if x == Self::ArrayToWasmTrampoline.into() => Self::ArrayToWasmTrampoline, x if x == Self::WasmToArrayTrampoline.into() => Self::WasmToArrayTrampoline, x if x == Self::WasmToBuiltinTrampoline.into() => Self::WasmToBuiltinTrampoline, - x if x == Self::PatchableToBuiltinTrampoline.into() => { - Self::PatchableToBuiltinTrampoline + x if x == Self::PreserveAllToBuiltinTrampoline.into() => { + Self::PreserveAllToBuiltinTrampoline } x if x == Self::PulleyHostCall.into() => Self::PulleyHostCall, x if x == Self::ModuleStartup.into() => Self::ModuleStartup, @@ -135,7 +135,7 @@ impl FuncKeyNamespace { | FuncKeyKind::ModuleStartup => Self(raw), FuncKeyKind::WasmToArrayTrampoline | FuncKeyKind::WasmToBuiltinTrampoline - | FuncKeyKind::PatchableToBuiltinTrampoline + | FuncKeyKind::PreserveAllToBuiltinTrampoline | FuncKeyKind::PulleyHostCall => { assert_eq!(raw & FuncKey::MODULE_MASK, 0); Self(raw) @@ -206,10 +206,10 @@ pub enum Abi { Wasm = 0, /// The "array" ABI, or suitable to be an `array_call` field. Array = 1, - /// The "patchable" ABI. Signature same as Wasm ABI, but + /// The `preserve_all` ABI. Signature same as Wasm ABI, but /// Cranelift-level (machine-level) ABI is different (no /// clobbers). - Patchable = 2, + PreserveAll = 2, } impl Abi { @@ -217,7 +217,7 @@ impl Abi { match raw { x if x == Self::Wasm.into_raw() => Self::Wasm, x if x == Self::Array.into_raw() => Self::Array, - x if x == Self::Patchable.into_raw() => Self::Patchable, + x if x == Self::PreserveAll.into_raw() => Self::PreserveAll, _ => panic!("invalid raw representation passed to `Abi::from_raw`: {raw}"), } } @@ -246,8 +246,11 @@ pub enum FuncKey { /// A Pulley-specific host call. PulleyHostCall(HostCall), - /// A trampoline from the patchable ABI to the given builtin. - PatchableToBuiltinTrampoline(BuiltinFunctionIndex), + /// A trampoline from the `preserve_all` ABI to the given builtin. + /// + /// Debugger breakpoints call it from patchable call sites, and fuel and + /// epoch checks from ordinary ones. + PreserveAllToBuiltinTrampoline(BuiltinFunctionIndex), /// A Wasm-caller to component builtin trampoline. #[cfg(feature = "component-model")] @@ -322,8 +325,8 @@ impl FuncKey { let index = builtin.index(); (namespace, index) } - FuncKey::PatchableToBuiltinTrampoline(builtin) => { - let namespace = FuncKeyKind::PatchableToBuiltinTrampoline.into_raw(); + FuncKey::PreserveAllToBuiltinTrampoline(builtin) => { + let namespace = FuncKeyKind::PreserveAllToBuiltinTrampoline.into_raw(); let index = builtin.index(); (namespace, index) } @@ -388,7 +391,7 @@ impl FuncKey { FuncKey::ArrayToWasmTrampoline(_, _) => Abi::Array, FuncKey::WasmToArrayTrampoline(_) => Abi::Wasm, FuncKey::WasmToBuiltinTrampoline(_) => Abi::Wasm, - FuncKey::PatchableToBuiltinTrampoline(_) => Abi::Patchable, + FuncKey::PreserveAllToBuiltinTrampoline(_) => Abi::PreserveAll, FuncKey::PulleyHostCall(_) => Abi::Wasm, #[cfg(feature = "component-model")] FuncKey::ComponentTrampoline(abi, _) => abi, @@ -454,10 +457,10 @@ impl FuncKey { let builtin = BuiltinFunctionIndex::from_u32(b); Self::WasmToBuiltinTrampoline(builtin) } - FuncKeyKind::PatchableToBuiltinTrampoline => { + FuncKeyKind::PreserveAllToBuiltinTrampoline => { assert_eq!(a & Self::MODULE_MASK, 0); let builtin = BuiltinFunctionIndex::from_u32(b); - Self::PatchableToBuiltinTrampoline(builtin) + Self::PreserveAllToBuiltinTrampoline(builtin) } FuncKeyKind::PulleyHostCall => { assert_eq!(a & Self::MODULE_MASK, 0); @@ -588,7 +591,7 @@ impl FuncKey { | Self::ModuleStartup(..) => false, Self::WasmToArrayTrampoline(..) | Self::WasmToBuiltinTrampoline(..) - | Self::PatchableToBuiltinTrampoline(..) + | Self::PreserveAllToBuiltinTrampoline(..) | Self::PulleyHostCall(..) => true, #[cfg(feature = "component-model")] Self::ComponentTrampoline(..) diff --git a/crates/environ/src/module_artifacts.rs b/crates/environ/src/module_artifacts.rs index f8091f9c848e..02b5ff44b44e 100644 --- a/crates/environ/src/module_artifacts.rs +++ b/crates/environ/src/module_artifacts.rs @@ -552,7 +552,7 @@ impl CompiledFunctionsTable { FuncKeyKind::ArrayToWasmTrampoline | FuncKeyKind::WasmToBuiltinTrampoline - | FuncKeyKind::PatchableToBuiltinTrampoline + | FuncKeyKind::PreserveAllToBuiltinTrampoline | FuncKeyKind::ModuleStartup => false, // `FactInlineIntrinsic` never names a compiled function, so it is @@ -571,7 +571,7 @@ impl CompiledFunctionsTable { FuncKeyKind::ArrayToWasmTrampoline | FuncKeyKind::WasmToArrayTrampoline | FuncKeyKind::WasmToBuiltinTrampoline - | FuncKeyKind::PatchableToBuiltinTrampoline + | FuncKeyKind::PreserveAllToBuiltinTrampoline | FuncKeyKind::PulleyHostCall | FuncKeyKind::ModuleStartup => false, #[cfg(feature = "component-model")] diff --git a/crates/wasmtime/src/compile.rs b/crates/wasmtime/src/compile.rs index d7b0eea65c0f..40a992b557e9 100644 --- a/crates/wasmtime/src/compile.rs +++ b/crates/wasmtime/src/compile.rs @@ -361,7 +361,7 @@ impl<'a> CompileInputs<'a> { match abi { Abi::Wasm => "wasm-call", Abi::Array => "array-call", - Abi::Patchable => "patchable-call", + Abi::PreserveAll => "preserve-all-call", }, intrinsic.name(), ); @@ -390,7 +390,7 @@ impl<'a> CompileInputs<'a> { match abi { Abi::Wasm => "wasm-call", Abi::Array => "array-call", - Abi::Patchable => "patchable-call", + Abi::PreserveAll => "preserve-all-call", }, trampoline.symbol_name(), ); @@ -994,7 +994,7 @@ fn is_inlining_function(key: FuncKey) -> bool { FuncKey::ArrayToWasmTrampoline(..) | FuncKey::WasmToArrayTrampoline(..) | FuncKey::WasmToBuiltinTrampoline(..) - | FuncKey::PatchableToBuiltinTrampoline(..) + | FuncKey::PreserveAllToBuiltinTrampoline(..) | FuncKey::ModuleStartup(..) => false, FuncKey::ComponentTrampoline(..) | FuncKey::ResourceDropTrampoline => false, @@ -1024,6 +1024,8 @@ fn compile_required_builtins<'a>( raw_outputs: &mut Vec>, ) -> Result<()> { let compiler = engine.try_compiler()?; + // Keyed by `FuncKey`, since each trampoline kind of a builtin is a + // separate function. let mut builtins = HashSet::new(); let mut new_inputs: Vec> = Vec::new(); @@ -1033,8 +1035,8 @@ fn compile_required_builtins<'a>( FuncKey::WasmToBuiltinTrampoline(builtin) => { format!("wasmtime_builtin_{}", builtin.name()) } - FuncKey::PatchableToBuiltinTrampoline(builtin) => { - format!("wasmtime_patchable_builtin_{}", builtin.name()) + FuncKey::PreserveAllToBuiltinTrampoline(builtin) => { + format!("wasmtime_preserve_all_builtin_{}", builtin.name()) } _ => unreachable!(), }; @@ -1058,9 +1060,9 @@ fn compile_required_builtins<'a>( for output in raw_outputs.iter() { for reloc in compiler.compiled_function_relocation_targets(&*output.function.code) { match reloc { - FuncKey::WasmToBuiltinTrampoline(builtin) - | FuncKey::PatchableToBuiltinTrampoline(builtin) => { - if builtins.insert(builtin) { + FuncKey::WasmToBuiltinTrampoline(_) + | FuncKey::PreserveAllToBuiltinTrampoline(_) => { + if builtins.insert(reloc) { new_inputs.push(compile_builtin(reloc)); } } diff --git a/src/commands/objdump.rs b/src/commands/objdump.rs index c579ee39d9e1..b65fc74c522d 100644 --- a/src/commands/objdump.rs +++ b/src/commands/objdump.rs @@ -215,7 +215,7 @@ impl ObjdumpCommand { let bytes = &text[sym.address() as usize..][..sym.size() as usize]; let kind = if name.starts_with("wasmtime_builtin") - || name.starts_with("wasmtime_patchable_builtin") + || name.starts_with("wasmtime_preserve_all_builtin") { Func::Builtin } else if name.contains("]::function[") { diff --git a/tests/all/epoch_interruption.rs b/tests/all/epoch_interruption.rs index d94cf57f6c4d..7e34dfb96e0a 100644 --- a/tests/all/epoch_interruption.rs +++ b/tests/all/epoch_interruption.rs @@ -565,3 +565,65 @@ fn epoch_deadline_never_equals_sentinel(config: &mut Config) -> Result<()> { run.call(&mut store, ())?; Ok(()) } + +/// Runs `live_values_across_loop_header_wat` with an epoch deadline that is +/// always reached, so every loop header calls `new_epoch` and returns into +/// the loop with all the live values; the checksum must not change. +async fn epoch_preserves_values_live_across_loop_header( + config: &mut Config, + mode: InterruptMode, +) -> Result<(usize, usize)> { + use crate::fuel::{ + clobbering_between_polls, live_values_across_loop_header_expected, + live_values_across_loop_header_wat, + }; + const ITERATIONS: i32 = 200; + let expected = live_values_across_loop_header_expected(config, ITERATIONS)?; + + let engine = build_engine(config)?; + let module = Module::new(&engine, live_values_across_loop_header_wat())?; + let mut store = Store::new(&engine, 0); + // A deadline 0 ticks ahead is reached at once, and stays reached after + // every update below. + store.set_epoch_deadline(0); + match mode { + InterruptMode::Yield(delta) => store.epoch_deadline_async_yield_and_update(delta), + InterruptMode::Callback(callback) => store.epoch_deadline_callback(callback), + InterruptMode::Trap => unreachable!(), + } + let instance = Instance::new_async(&mut store, &module, &[]).await?; + let run = instance.get_typed_func::(&mut store, "run")?; + let (result, yields) = clobbering_between_polls(run.call_async(&mut store, ITERATIONS)).await; + assert_eq!(result?, expected); + Ok((yields, *store.data())) +} + +#[wasmtime_test(wasm_features(simd))] +async fn epoch_callback_continue_preserves_live_values(config: &mut Config) -> Result<()> { + let (yields, callbacks) = epoch_preserves_values_live_across_loop_header( + config, + InterruptMode::Callback(|mut cx| { + *cx.data_mut() += 1; + crate::fuel::clobber_caller_saved_registers(); + Ok(UpdateDeadline::Continue(0)) + }), + ) + .await?; + assert_eq!(yields, 0); + assert!( + callbacks >= 200, + "expected a callback per iteration, got {callbacks}" + ); + Ok(()) +} + +#[wasmtime_test(wasm_features(simd))] +async fn epoch_yield_preserves_live_values(config: &mut Config) -> Result<()> { + let (yields, _) = + epoch_preserves_values_live_across_loop_header(config, InterruptMode::Yield(0)).await?; + assert!( + yields >= 200, + "expected a yield per iteration, got {yields}" + ); + Ok(()) +} diff --git a/tests/all/fuel.rs b/tests/all/fuel.rs index dd380d358535..793f61a9f2fd 100644 --- a/tests/all/fuel.rs +++ b/tests/all/fuel.rs @@ -458,3 +458,209 @@ fn else_and_end_operator_cost_on_taken_paths(config: &mut Config) -> Result<()> Ok(()) } + +/// A module whose `run` function keeps 16 `i64`, 16 `v128` and 8 `f64` +/// values live across the header of a loop that runs `n` times, and returns +/// a checksum over all of them. +/// +/// The fuel and epoch checks in that loop header call into the host when +/// fuel or the epoch deadline runs out. The values are live across that +/// call, so a call that does not preserve them changes the checksum. Each +/// value depends on the previous iteration, and every lane of every vector +/// feeds the checksum, so a lost or half-restored register shows up. +pub(crate) fn live_values_across_loop_header_wat() -> String { + const INTS: usize = 16; + const VECS: usize = 16; + const FLOATS: usize = 8; + + let mut locals = String::new(); + let mut init = String::new(); + let mut body = String::new(); + let mut sum = String::from("(local.set $sum (i64.const 0))\n"); + for i in 0..INTS { + locals.push_str(&format!("(local $x{i} i64)\n")); + init.push_str(&format!( + "(local.set $x{i} (i64.const {}))\n", + 0x0123_4567_89ab_cdefu64.wrapping_mul(i as u64 + 1) as i64 + )); + body.push_str(&format!( + "(local.set $x{i} (i64.add (i64.rotl (local.get $x{i}) (i64.const {})) (i64.xor (local.get $x{j}) (i64.const {}))))\n", + i + 1, + i as i64 * 7 + 3, + j = (i + 1) % INTS, + )); + sum.push_str(&format!( + "(local.set $sum (i64.add (i64.rotl (local.get $sum) (i64.const 5)) (local.get $x{i})))\n" + )); + } + for i in 0..VECS { + locals.push_str(&format!("(local $v{i} v128)\n")); + init.push_str(&format!( + "(local.set $v{i} (v128.const i32x4 {} {} {} {}))\n", + i * 4 + 1, + i * 4 + 2, + i * 4 + 3, + i * 4 + 4, + )); + body.push_str(&format!( + "(local.set $v{i} (v128.xor (i32x4.add (i32x4.mul (local.get $v{i}) (v128.const i32x4 3 5 7 11)) (local.get $v{j})) (v128.const i32x4 {i} 0x5a5a5a5a {i} 0x3c3c3c3c)))\n", + j = (i + 1) % VECS, + )); + for lane in 0..2 { + sum.push_str(&format!( + "(local.set $sum (i64.add (i64.rotl (local.get $sum) (i64.const 5)) (i64x2.extract_lane {lane} (local.get $v{i}))))\n" + )); + } + } + for i in 0..FLOATS { + locals.push_str(&format!("(local $f{i} f64)\n")); + init.push_str(&format!("(local.set $f{i} (f64.const {}.25))\n", i + 1)); + body.push_str(&format!( + "(local.set $f{i} (f64.add (f64.mul (local.get $f{i}) (f64.const 0.5)) (local.get $f{j})))\n", + j = (i + 1) % FLOATS, + )); + sum.push_str(&format!( + "(local.set $sum (i64.add (i64.rotl (local.get $sum) (i64.const 5)) (i64.reinterpret_f64 (local.get $f{i}))))\n" + )); + } + + format!( + r#" + (module + (func (export "run") (param $n i32) (result i64) + (local $sum i64) + {locals} + {init} + (loop $l + {body} + (br_if $l (local.tee $n (i32.sub (local.get $n) (i32.const 1))))) + {sum} + (local.get $sum))) + "# + ) +} + +/// Runs `live_values_across_loop_header_wat` without any instrumentation, +/// for the checksum the instrumented runs must reproduce. +pub(crate) fn live_values_across_loop_header_expected(config: &Config, n: i32) -> Result { + let mut config = config.clone(); + config.consume_fuel(false); + config.epoch_interruption(false); + let engine = Engine::new(&config)?; + let module = Module::new(&engine, live_values_across_loop_header_wat())?; + let mut store = Store::new(&engine, ()); + let instance = Instance::new(&mut store, &module, &[])?; + let run = instance.get_typed_func::(&mut store, "run")?; + run.call(&mut store, n) +} + +#[wasmtime_test(wasm_features(simd))] +#[cfg_attr(miri, ignore)] +async fn fuel_yield_preserves_values_live_across_loop_header(config: &mut Config) -> Result<()> { + const ITERATIONS: i32 = 200; + let expected = live_values_across_loop_header_expected(config, ITERATIONS)?; + + config.consume_fuel(true); + let engine = Engine::new(&config)?; + let module = Module::new(&engine, live_values_across_loop_header_wat())?; + let mut store = Store::new(&engine, ()); + store.set_fuel(u64::MAX)?; + // Fuel for the interval runs out within every iteration, so the loop + // header's check calls `out_of_gas`, which refuels, yields and returns + // into the loop with all the live values. The registers are overwritten + // before every resume. + store.fuel_async_yield_interval(Some(1))?; + let instance = Instance::new_async(&mut store, &module, &[]).await?; + let run = instance.get_typed_func::(&mut store, "run")?; + let (result, yields) = clobbering_between_polls(run.call_async(&mut store, ITERATIONS)).await; + assert_eq!(result?, expected); + assert!( + yields >= ITERATIONS as usize, + "expected a yield per iteration, got {yields}" + ); + Ok(()) +} + +/// Overwrites every register the native calling convention lets a callee +/// clobber, including all vector registers in full. +/// +/// Host code between a builtin call and the return into Wasm usually leaves +/// most registers alone. Tests that check that Wasm values survive such a call +/// run this on the host side, so a missing save fails reliably instead of +/// depending on what the host happened to do. +#[inline(never)] +pub(crate) fn clobber_caller_saved_registers() { + #[cfg(target_arch = "x86_64")] + unsafe { + core::arch::asm!( + "mov rax, -1", "mov rcx, -1", "mov rdx, -1", "mov rsi, -1", "mov rdi, -1", + "mov r8, -1", "mov r9, -1", "mov r10, -1", "mov r11, -1", + "pcmpeqd xmm0, xmm0", "pcmpeqd xmm1, xmm1", "pcmpeqd xmm2, xmm2", "pcmpeqd xmm3, xmm3", + "pcmpeqd xmm4, xmm4", "pcmpeqd xmm5, xmm5", "pcmpeqd xmm6, xmm6", "pcmpeqd xmm7, xmm7", + "pcmpeqd xmm8, xmm8", "pcmpeqd xmm9, xmm9", "pcmpeqd xmm10, xmm10", "pcmpeqd xmm11, xmm11", + "pcmpeqd xmm12, xmm12", "pcmpeqd xmm13, xmm13", "pcmpeqd xmm14, xmm14", "pcmpeqd xmm15, xmm15", + out("rax") _, out("rcx") _, out("rdx") _, out("rsi") _, out("rdi") _, + out("r8") _, out("r9") _, out("r10") _, out("r11") _, + out("xmm0") _, out("xmm1") _, out("xmm2") _, out("xmm3") _, + out("xmm4") _, out("xmm5") _, out("xmm6") _, out("xmm7") _, + out("xmm8") _, out("xmm9") _, out("xmm10") _, out("xmm11") _, + out("xmm12") _, out("xmm13") _, out("xmm14") _, out("xmm15") _, + ); + } + // On aarch64 only the low 64 bits of v8-v15 are callee-saved, so all 32 + // vector registers are overwritten; Rust saves and restores the low + // halves of v8-v15 around this block, which leaves their high halves + // overwritten. + #[cfg(target_arch = "aarch64")] + unsafe { + core::arch::asm!( + "mov x0, #-1", "mov x1, #-1", "mov x2, #-1", "mov x3, #-1", "mov x4, #-1", + "mov x5, #-1", "mov x6, #-1", "mov x7, #-1", "mov x8, #-1", "mov x9, #-1", + "mov x10, #-1", "mov x11, #-1", "mov x12, #-1", "mov x13, #-1", "mov x14, #-1", + "mov x15, #-1", "mov x16, #-1", "mov x17, #-1", + "movi v0.16b, #0xff", "movi v1.16b, #0xff", "movi v2.16b, #0xff", "movi v3.16b, #0xff", + "movi v4.16b, #0xff", "movi v5.16b, #0xff", "movi v6.16b, #0xff", "movi v7.16b, #0xff", + "movi v8.16b, #0xff", "movi v9.16b, #0xff", "movi v10.16b, #0xff", "movi v11.16b, #0xff", + "movi v12.16b, #0xff", "movi v13.16b, #0xff", "movi v14.16b, #0xff", "movi v15.16b, #0xff", + "movi v16.16b, #0xff", "movi v17.16b, #0xff", "movi v18.16b, #0xff", "movi v19.16b, #0xff", + "movi v20.16b, #0xff", "movi v21.16b, #0xff", "movi v22.16b, #0xff", "movi v23.16b, #0xff", + "movi v24.16b, #0xff", "movi v25.16b, #0xff", "movi v26.16b, #0xff", "movi v27.16b, #0xff", + "movi v28.16b, #0xff", "movi v29.16b, #0xff", "movi v30.16b, #0xff", "movi v31.16b, #0xff", + out("x0") _, out("x1") _, out("x2") _, out("x3") _, out("x4") _, + out("x5") _, out("x6") _, out("x7") _, out("x8") _, out("x9") _, + out("x10") _, out("x11") _, out("x12") _, out("x13") _, out("x14") _, + out("x15") _, out("x16") _, out("x17") _, + out("v0") _, out("v1") _, out("v2") _, out("v3") _, + out("v4") _, out("v5") _, out("v6") _, out("v7") _, + out("v8") _, out("v9") _, out("v10") _, out("v11") _, + out("v12") _, out("v13") _, out("v14") _, out("v15") _, + out("v16") _, out("v17") _, out("v18") _, out("v19") _, + out("v20") _, out("v21") _, out("v22") _, out("v23") _, + out("v24") _, out("v25") _, out("v26") _, out("v27") _, + out("v28") _, out("v29") _, out("v30") _, out("v31") _, + ); + } +} + +/// Polls `future` to completion like `CountPending`, overwriting the +/// caller-saved registers before every poll, i.e. before every resume of a +/// suspended Wasm fiber. +pub(crate) async fn clobbering_between_polls( + future: F, +) -> (F::Output, usize) { + let mut future = std::pin::pin!(future); + let mut pending = 0; + let output = std::future::poll_fn(|cx| { + clobber_caller_saved_registers(); + match future.as_mut().poll(cx) { + std::task::Poll::Ready(output) => std::task::Poll::Ready(output), + std::task::Poll::Pending => { + pending += 1; + cx.waker().wake_by_ref(); + std::task::Poll::Pending + } + } + }) + .await; + (output, pending) +} diff --git a/tests/disas/debug.wat b/tests/disas/debug.wat index a0760ba53778..4ae1ba7098c3 100644 --- a/tests/disas/debug.wat +++ b/tests/disas/debug.wat @@ -158,7 +158,7 @@ ;; 1f2: callq *%rax ;; 1f4: ud2 ;; -;; wasmtime_patchable_builtin_breakpoint: +;; wasmtime_preserve_all_builtin_breakpoint: ;; pushq %rbp ;; movq %rsp, %rbp ;; subq $0x160, %rsp diff --git a/tests/disas/epoch-interruption-x86.wat b/tests/disas/epoch-interruption-x86.wat index 410164f096cd..4ff44d6b6d1d 100644 --- a/tests/disas/epoch-interruption-x86.wat +++ b/tests/disas/epoch-interruption-x86.wat @@ -9,35 +9,26 @@ ;; movq %rsp, %rbp ;; movq 8(%rdi), %r10 ;; movq 0x10(%r10), %r10 -;; addq $0x30, %r10 +;; addq $0x10, %r10 ;; cmpq %rsp, %r10 -;; ja 0x90 -;; 19: subq $0x20, %rsp -;; movq %r12, (%rsp) -;; movq %r13, 8(%rsp) -;; movq %r14, 0x10(%rsp) -;; movq 0x18(%rdi), %r13 -;; movq (%r13), %rcx -;; movq 8(%rdi), %r12 -;; movq 8(%r12), %rax -;; cmpq %rax, %rcx -;; jae 0x57 -;; 45: movq (%r13), %rcx -;; cmpq %rax, %rcx -;; jae 0x67 -;; jmp 0x45 -;; 57: movq %rdi, %r14 -;; callq 0xec -;; movq %r14, %rdi -;; jmp 0x45 -;; 67: movq %rdi, %r14 -;; movq 8(%r12), %rax -;; cmpq %rax, %rcx -;; jae 0x80 -;; 78: movq %r14, %rdi -;; jmp 0x45 -;; 80: movq %r14, %rdi -;; callq 0xec -;; movq %r14, %rdi -;; jmp 0x45 -;; 90: ud2 +;; ja 0x6b +;; 19: movq 0x18(%rdi), %rax +;; movq (%rax), %rdx +;; movq 8(%rdi), %rcx +;; movq 8(%rcx), %r8 +;; cmpq %r8, %rdx +;; jae 0x42 +;; 31: movq (%rax), %rdx +;; cmpq %r8, %rdx +;; jae 0x50 +;; jmp 0x31 +;; 42: callq 0xc7 +;; movq 8(%rcx), %r8 +;; jmp 0x31 +;; 50: movq 8(%rcx), %r8 +;; cmpq %r8, %rdx +;; jb 0x31 +;; 5d: callq 0xc7 +;; movq 8(%rcx), %r8 +;; jmp 0x31 +;; 6b: ud2 diff --git a/tests/disas/epoch-interruption.wat b/tests/disas/epoch-interruption.wat index 1677601a5cb1..b7c7008413ca 100644 --- a/tests/disas/epoch-interruption.wat +++ b/tests/disas/epoch-interruption.wat @@ -13,8 +13,8 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i64 tail -;; fn0 = colocated u805306368:12 sig0 +;; sig0 = (i64 vmctx) preserve_all +;; fn0 = colocated u1073741824:12 sig0 ;; stack_limit = gv2 ;; ;; block0(v0: i64, v1: i64): @@ -26,26 +26,28 @@ ;; @0016 brif v6, block3, block2(v5) ;; ;; block3 cold: -;; @0016 v7 = call fn0(v0) -;; @0016 jump block2(v7) +;; @0016 call fn0(v0) +;; @0016 v8 = load.i64 notrap aligned region4 v4+8 +;; @0016 jump block2(v8) ;; -;; block2(v18: i64): -;; @0017 jump block4(v18) +;; block2(v20: i64): +;; @0017 jump block4(v20) ;; -;; block4(v10: i64): -;; @0017 v9 = load.i64 notrap aligned region3 v2 -;; @0017 v11 = icmp uge v9, v10 -;; @0017 brif v11, block7, block6(v10) +;; block4(v11: i64): +;; @0017 v10 = load.i64 notrap aligned region3 v2 +;; @0017 v12 = icmp uge v10, v11 +;; @0017 brif v12, block7, block6(v11) ;; ;; block7 cold: -;; @0017 v13 = load.i64 notrap aligned region4 v4+8 -;; @0017 v14 = icmp.i64 uge v9, v13 -;; @0017 brif v14, block8, block6(v13) +;; @0017 v14 = load.i64 notrap aligned region4 v4+8 +;; @0017 v15 = icmp.i64 uge v10, v14 +;; @0017 brif v15, block8, block6(v14) ;; ;; block8 cold: -;; @0017 v15 = call fn0(v0) -;; @0017 jump block6(v15) +;; @0017 call fn0(v0) +;; @0017 v17 = load.i64 notrap aligned region4 v4+8 +;; @0017 jump block6(v17) ;; -;; block6(v19: i64): -;; @0019 jump block4(v19) +;; block6(v21: i64): +;; @0019 jump block4(v21) ;; } diff --git a/tests/disas/epoch-loop-live-values-aarch64.wat b/tests/disas/epoch-loop-live-values-aarch64.wat new file mode 100644 index 000000000000..71c25e929c5f --- /dev/null +++ b/tests/disas/epoch-loop-live-values-aarch64.wat @@ -0,0 +1,101 @@ +;;! target = "aarch64" +;;! test = "compile" +;;! flags = ["-Wepoch-interruption=y"] + +;; Twelve values live across a loop header, more than there are callee-saved +;; registers. The epoch check's call into the host is out of line and preserves +;; all registers, so it adds no spills of its own. + +(module + (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i32) (result i64) + (loop $l + (local.set 0 (i64.add (local.get 0) (local.get 1))) + (local.set 1 (i64.add (local.get 1) (local.get 2))) + (local.set 2 (i64.add (local.get 2) (local.get 3))) + (local.set 3 (i64.add (local.get 3) (local.get 4))) + (local.set 4 (i64.add (local.get 4) (local.get 5))) + (local.set 5 (i64.add (local.get 5) (local.get 6))) + (local.set 6 (i64.add (local.get 6) (local.get 7))) + (local.set 7 (i64.add (local.get 7) (local.get 8))) + (local.set 8 (i64.add (local.get 8) (local.get 9))) + (local.set 9 (i64.add (local.get 9) (local.get 10))) + (local.set 10 (i64.add (local.get 10) (local.get 11))) + (local.set 11 (i64.add (local.get 11) (local.get 0))) + (br_if $l (local.tee 12 (i32.sub (local.get 12) (i32.const 1))))) + (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (local.get 0) (local.get 1)) (local.get 2)) (local.get 3)) (local.get 4)) (local.get 5)) (local.get 6)) (local.get 7)) (local.get 8)) (local.get 9)) (local.get 10)) (local.get 11)))) +;; wasm[0]::function[0]: +;; stp x29, x30, [sp, #-0x10]! +;; mov x29, sp +;; ldur x16, [x2, #8] +;; ldur x16, [x16, #0x10] +;; add x16, x16, #0x30 +;; cmp sp, x16 +;; b.lo #0x128 +;; 1c: str x21, [sp, #-0x10]! +;; stp x19, x20, [sp, #-0x10]! +;; mov x21, x7 +;; ldur x7, [sp, #0x30] +;; ldur x8, [sp, #0x38] +;; ldur x9, [sp, #0x40] +;; ldur x10, [sp, #0x48] +;; ldur x3, [sp, #0x50] +;; ldur x15, [sp, #0x58] +;; ldur x1, [sp, #0x60] +;; ldur x20, [sp, #0x68] +;; ldur w11, [sp, #0x70] +;; ldr x12, [x2, #0x18] +;; ldr x19, [x12] +;; ldr x13, [x2, #8] +;; ldr x14, [x13, #8] +;; cmp x19, x14 +;; b.hs #0xf8 +;; 64: mov x19, x2 +;; ldr x2, [x12] +;; cmp x2, x14 +;; b.hs #0x10c +;; 74: sub w11, w11, #1 +;; add x4, x4, x5 +;; add x5, x5, x6 +;; mov x2, x21 +;; add x6, x6, x2 +;; add x2, x2, x7 +;; add x7, x7, x8 +;; add x8, x8, x9 +;; add x9, x9, x10 +;; add x10, x10, x3 +;; add x3, x3, x15 +;; add x15, x15, x1 +;; add x1, x1, x20 +;; add x20, x20, x4 +;; cbz w11, #0xb8 +;; b0: mov x21, x2 +;; b #0x68 +;; b8: add x4, x4, x5 +;; add x4, x4, x6 +;; add x2, x4, x2 +;; add x2, x2, x7 +;; add x2, x2, x8 +;; add x2, x2, x9 +;; add x2, x2, x10 +;; add x2, x2, x3 +;; add x2, x2, x15 +;; add x1, x2, x1 +;; add x2, x1, x20 +;; ldp x19, x20, [sp], #0x10 +;; ldr x21, [sp], #0x10 +;; ldp x29, x30, [sp], #0x10 +;; add sp, sp, #0x50 +;; ret +;; f8: mov x0, x2 +;; fc: mov x19, x2 +;; 100: bl #0x20c +;; 104: ldr x14, [x13, #8] +;; 108: b #0x68 +;; 10c: ldr x14, [x13, #8] +;; 110: cmp x2, x14 +;; 114: b.lo #0x74 +;; 118: mov x0, x19 +;; 11c: bl #0x20c +;; 120: ldr x14, [x13, #8] +;; 124: b #0x74 +;; 128: udf #0xc11f diff --git a/tests/disas/epoch-loop-live-values-x64.wat b/tests/disas/epoch-loop-live-values-x64.wat new file mode 100644 index 000000000000..975bc6099433 --- /dev/null +++ b/tests/disas/epoch-loop-live-values-x64.wat @@ -0,0 +1,122 @@ +;;! target = "x86_64" +;;! test = "compile" +;;! flags = ["-Wepoch-interruption=y"] + +;; Twelve values live across a loop header, more than there are callee-saved +;; registers. The epoch check's call into the host is out of line and preserves +;; all registers, so it adds no spills of its own. + +(module + (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i32) (result i64) + (loop $l + (local.set 0 (i64.add (local.get 0) (local.get 1))) + (local.set 1 (i64.add (local.get 1) (local.get 2))) + (local.set 2 (i64.add (local.get 2) (local.get 3))) + (local.set 3 (i64.add (local.get 3) (local.get 4))) + (local.set 4 (i64.add (local.get 4) (local.get 5))) + (local.set 5 (i64.add (local.get 5) (local.get 6))) + (local.set 6 (i64.add (local.get 6) (local.get 7))) + (local.set 7 (i64.add (local.get 7) (local.get 8))) + (local.set 8 (i64.add (local.get 8) (local.get 9))) + (local.set 9 (i64.add (local.get 9) (local.get 10))) + (local.set 10 (i64.add (local.get 10) (local.get 11))) + (local.set 11 (i64.add (local.get 11) (local.get 0))) + (br_if $l (local.tee 12 (i32.sub (local.get 12) (i32.const 1))))) + (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (local.get 0) (local.get 1)) (local.get 2)) (local.get 3)) (local.get 4)) (local.get 5)) (local.get 6)) (local.get 7)) (local.get 8)) (local.get 9)) (local.get 10)) (local.get 11)))) +;; wasm[0]::function[0]: +;; pushq %rbp +;; movq %rsp, %rbp +;; movq 8(%rdi), %r10 +;; movq 0x10(%r10), %r10 +;; addq $0x70, %r10 +;; cmpq %rsp, %r10 +;; ja 0x17e +;; 19: subq $0x60, %rsp +;; movq %rbx, 0x30(%rsp) +;; movq %r12, 0x38(%rsp) +;; movq %r13, 0x40(%rsp) +;; movq %r14, 0x48(%rsp) +;; movq %r15, 0x50(%rsp) +;; movq %r9, 8(%rsp) +;; movq 0x10(%rbp), %r10 +;; movq 0x18(%rbp), %r9 +;; movq 0x20(%rbp), %r11 +;; movq 0x28(%rbp), %rax +;; movq %rax, 0x10(%rsp) +;; movq 0x30(%rbp), %rsi +;; movq 0x38(%rbp), %r12 +;; movq 0x40(%rbp), %rbx +;; movq 0x48(%rbp), %rax +;; movq 0x50(%rbp), %r15 +;; movq %r15, 0x18(%rsp) +;; movq 0x18(%rdi), %r13 +;; movq %r13, %r14 +;; movq (%r14), %r13 +;; movq %r14, 0x28(%rsp) +;; movq 8(%rdi), %r15 +;; movq 8(%r15), %r14 +;; movq %r15, 0x20(%rsp) +;; cmpq %r14, %r13 +;; jae 0x13e +;; 8e: movq %rdi, (%rsp) +;; movq 0x28(%rsp), %r13 +;; movq (%r13), %r13 +;; cmpq %r14, %r13 +;; jae 0x155 +;; a4: addq %rcx, %rdx +;; addq %r8, %rcx +;; movq 8(%rsp), %r13 +;; addq %r13, %r8 +;; addq %r10, %r13 +;; addq %r9, %r10 +;; addq %r11, %r9 +;; movq 0x10(%rsp), %r15 +;; addq %r15, %r11 +;; addq %rsi, %r15 +;; addq %r12, %rsi +;; addq %rbx, %r12 +;; addq %rax, %rbx +;; addq %rdx, %rax +;; movq 0x18(%rsp), %rdi +;; subl $1, %edi +;; je 0xf9 +;; e0: movq %rdi, 0x18(%rsp) +;; movq %r15, 0x10(%rsp) +;; movq %r13, 8(%rsp) +;; movq 0x28(%rsp), %r13 +;; jmp 0x97 +;; f9: addq %rdx, %rcx +;; addq %r8, %rcx +;; addq %r13, %rcx +;; addq %r10, %rcx +;; addq %r9, %rcx +;; addq %r11, %rcx +;; addq %r15, %rcx +;; addq %rsi, %rcx +;; addq %r12, %rcx +;; addq %rbx, %rcx +;; addq %rcx, %rax +;; movq 0x30(%rsp), %rbx +;; movq 0x38(%rsp), %r12 +;; movq 0x40(%rsp), %r13 +;; movq 0x48(%rsp), %r14 +;; movq 0x50(%rsp), %r15 +;; addq $0x60, %rsp +;; movq %rbp, %rsp +;; popq %rbp +;; retq $0x50 +;; 13e: movq %rdi, (%rsp) +;; 142: callq 0x2e2 +;; 147: movq 0x20(%rsp), %rdi +;; 14c: movq 8(%rdi), %r14 +;; 150: jmp 0x92 +;; 155: movq 0x20(%rsp), %rdi +;; 15a: movq 8(%rdi), %r14 +;; 15e: cmpq %r14, %r13 +;; 161: jb 0xa4 +;; 167: movq (%rsp), %rdi +;; 16b: callq 0x2e2 +;; 170: movq 0x20(%rsp), %rdi +;; 175: movq 8(%rdi), %r14 +;; 179: jmp 0xa4 +;; 17e: ud2 diff --git a/tests/disas/fuel-loop-live-values-aarch64.wat b/tests/disas/fuel-loop-live-values-aarch64.wat new file mode 100644 index 000000000000..7b0fdd892d1e --- /dev/null +++ b/tests/disas/fuel-loop-live-values-aarch64.wat @@ -0,0 +1,103 @@ +;;! target = "aarch64" +;;! test = "compile" +;;! flags = '-Wfuel=100' + +;; Twelve values live across a loop header, more than there are callee-saved +;; registers. The fuel check's call into the host is out of line and preserves +;; all registers, so it adds no spills of its own. + +(module + (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i32) (result i64) + (loop $l + (local.set 0 (i64.add (local.get 0) (local.get 1))) + (local.set 1 (i64.add (local.get 1) (local.get 2))) + (local.set 2 (i64.add (local.get 2) (local.get 3))) + (local.set 3 (i64.add (local.get 3) (local.get 4))) + (local.set 4 (i64.add (local.get 4) (local.get 5))) + (local.set 5 (i64.add (local.get 5) (local.get 6))) + (local.set 6 (i64.add (local.get 6) (local.get 7))) + (local.set 7 (i64.add (local.get 7) (local.get 8))) + (local.set 8 (i64.add (local.get 8) (local.get 9))) + (local.set 9 (i64.add (local.get 9) (local.get 10))) + (local.set 10 (i64.add (local.get 10) (local.get 11))) + (local.set 11 (i64.add (local.get 11) (local.get 0))) + (br_if $l (local.tee 12 (i32.sub (local.get 12) (i32.const 1))))) + (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (local.get 0) (local.get 1)) (local.get 2)) (local.get 3)) (local.get 4)) (local.get 5)) (local.get 6)) (local.get 7)) (local.get 8)) (local.get 9)) (local.get 10)) (local.get 11)))) +;; wasm[0]::function[0]: +;; stp x29, x30, [sp, #-0x10]! +;; mov x29, sp +;; ldur x16, [x2, #8] +;; ldur x16, [x16, #0x10] +;; add x16, x16, #0x30 +;; cmp sp, x16 +;; b.lo #0x130 +;; 1c: str x21, [sp, #-0x10]! +;; stp x19, x20, [sp, #-0x10]! +;; mov x20, x7 +;; mov x21, x2 +;; ldur x7, [sp, #0x30] +;; ldur x8, [sp, #0x38] +;; ldur x9, [sp, #0x40] +;; ldur x10, [sp, #0x48] +;; ldur x3, [sp, #0x50] +;; ldur x2, [sp, #0x58] +;; ldur x1, [sp, #0x60] +;; ldur x19, [sp, #0x68] +;; ldur w12, [sp, #0x70] +;; mov x0, x21 +;; ldr x11, [x0, #8] +;; ldr x14, [x11] +;; add x13, x14, #1 +;; cmp x13, #0 +;; b.ge #0x104 +;; 68: cmp x13, #0 +;; b.ge #0x11c +;; 70: sub w12, w12, #1 +;; add x15, x13, #0x35 +;; add x4, x4, x5 +;; add x5, x5, x6 +;; mov x14, x20 +;; add x6, x6, x14 +;; add x14, x14, x7 +;; add x7, x7, x8 +;; add x8, x8, x9 +;; add x9, x9, x10 +;; add x10, x10, x3 +;; add x3, x3, x2 +;; add x2, x2, x1 +;; add x1, x1, x19 +;; add x19, x19, x4 +;; cbz w12, #0xbc +;; b0: mov x13, x15 +;; mov x20, x14 +;; b #0x68 +;; bc: add x12, x13, #0x4c +;; str x12, [x11] +;; add x4, x4, x5 +;; add x4, x4, x6 +;; add x4, x4, x14 +;; add x4, x4, x7 +;; add x4, x4, x8 +;; add x4, x4, x9 +;; add x4, x4, x10 +;; add x3, x4, x3 +;; add x2, x3, x2 +;; add x1, x2, x1 +;; add x2, x1, x19 +;; ldp x19, x20, [sp], #0x10 +;; ldr x21, [sp], #0x10 +;; ldp x29, x30, [sp], #0x10 +;; add sp, sp, #0x50 +;; ret +;; 104: add x13, x14, #1 +;; 108: str x13, [x11] +;; 10c: mov x0, x21 +;; 110: bl #0x214 +;; 114: ldr x13, [x11] +;; 118: b #0x68 +;; 11c: str x13, [x11] +;; 120: mov x0, x21 +;; 124: bl #0x214 +;; 128: ldr x13, [x11] +;; 12c: b #0x70 +;; 130: udf #0xc11f diff --git a/tests/disas/fuel-loop-live-values-x64.wat b/tests/disas/fuel-loop-live-values-x64.wat new file mode 100644 index 000000000000..65620590575a --- /dev/null +++ b/tests/disas/fuel-loop-live-values-x64.wat @@ -0,0 +1,129 @@ +;;! target = "x86_64" +;;! test = "compile" +;;! flags = '-Wfuel=100' + +;; Twelve values live across a loop header, more than there are callee-saved +;; registers. The fuel check's call into the host is out of line and preserves +;; all registers, so it adds no spills of its own. + +(module + (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i32) (result i64) + (loop $l + (local.set 0 (i64.add (local.get 0) (local.get 1))) + (local.set 1 (i64.add (local.get 1) (local.get 2))) + (local.set 2 (i64.add (local.get 2) (local.get 3))) + (local.set 3 (i64.add (local.get 3) (local.get 4))) + (local.set 4 (i64.add (local.get 4) (local.get 5))) + (local.set 5 (i64.add (local.get 5) (local.get 6))) + (local.set 6 (i64.add (local.get 6) (local.get 7))) + (local.set 7 (i64.add (local.get 7) (local.get 8))) + (local.set 8 (i64.add (local.get 8) (local.get 9))) + (local.set 9 (i64.add (local.get 9) (local.get 10))) + (local.set 10 (i64.add (local.get 10) (local.get 11))) + (local.set 11 (i64.add (local.get 11) (local.get 0))) + (br_if $l (local.tee 12 (i32.sub (local.get 12) (i32.const 1))))) + (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (i64.add (local.get 0) (local.get 1)) (local.get 2)) (local.get 3)) (local.get 4)) (local.get 5)) (local.get 6)) (local.get 7)) (local.get 8)) (local.get 9)) (local.get 10)) (local.get 11)))) +;; wasm[0]::function[0]: +;; pushq %rbp +;; movq %rsp, %rbp +;; movq 8(%rdi), %r10 +;; movq 0x10(%r10), %r10 +;; addq $0x80, %r10 +;; cmpq %rsp, %r10 +;; ja 0x19a +;; 1c: subq $0x70, %rsp +;; movq %rbx, 0x40(%rsp) +;; movq %r12, 0x48(%rsp) +;; movq %r13, 0x50(%rsp) +;; movq %r14, 0x58(%rsp) +;; movq %r15, 0x60(%rsp) +;; movq %r9, 8(%rsp) +;; movq %rdi, (%rsp) +;; movq %rdx, %r13 +;; movq %rcx, %rdx +;; movq %r8, %rcx +;; movq 0x10(%rbp), %r11 +;; movq %r11, 0x10(%rsp) +;; movq 0x18(%rbp), %r10 +;; movq 0x20(%rbp), %rbx +;; movq 0x28(%rbp), %r9 +;; movq 0x30(%rbp), %rdi +;; movq %rdi, 0x18(%rsp) +;; movq 0x38(%rbp), %r8 +;; movq 0x40(%rbp), %r12 +;; movq 0x48(%rbp), %rsi +;; movq 0x50(%rbp), %rax +;; movq (%rsp), %rdi +;; movq %rax, 0x20(%rsp) +;; movq 8(%rdi), %r15 +;; movq (%r15), %r14 +;; movq %r15, 0x30(%rsp) +;; leaq 1(%r14), %r15 +;; testq %r15, %r15 +;; jge 0x15f +;; 9b: testq %r15, %r15 +;; jge 0x17c +;; a4: leaq 0x35(%r15), %rax +;; movq %rax, 0x28(%rsp) +;; addq %rdx, %r13 +;; addq %rcx, %rdx +;; movq 8(%rsp), %r14 +;; addq %r14, %rcx +;; movq 0x10(%rsp), %r11 +;; addq %r11, %r14 +;; addq %r10, %r11 +;; addq %rbx, %r10 +;; addq %r9, %rbx +;; movq 0x18(%rsp), %rdi +;; addq %rdi, %r9 +;; addq %r8, %rdi +;; addq %r12, %r8 +;; addq %rsi, %r12 +;; addq %r13, %rsi +;; movq 0x20(%rsp), %rax +;; subl $1, %eax +;; je 0x10c +;; ee: movq 0x28(%rsp), %r15 +;; movq %r14, 8(%rsp) +;; movq %r11, 0x10(%rsp) +;; movq %rdi, 0x18(%rsp) +;; movq %rax, 0x20(%rsp) +;; jmp 0x9b +;; 10c: leaq 0x4c(%r15), %rax +;; movq 0x30(%rsp), %r15 +;; movq %rax, (%r15) +;; leaq (%r13, %rdx), %rax +;; addq %rcx, %rax +;; addq %r14, %rax +;; addq %r11, %rax +;; addq %r10, %rax +;; addq %rbx, %rax +;; addq %r9, %rax +;; addq %rdi, %rax +;; addq %r8, %rax +;; addq %r12, %rax +;; addq %rsi, %rax +;; movq 0x40(%rsp), %rbx +;; movq 0x48(%rsp), %r12 +;; movq 0x50(%rsp), %r13 +;; movq 0x58(%rsp), %r14 +;; movq 0x60(%rsp), %r15 +;; addq $0x70, %rsp +;; movq %rbp, %rsp +;; popq %rbp +;; retq $0x50 +;; 15f: leaq 1(%r14), %r11 +;; 163: movq 0x30(%rsp), %rax +;; 168: movq %r11, (%rax) +;; 16b: movq (%rsp), %rdi +;; 16f: callq 0x2fe +;; 174: movq (%rax), %r15 +;; 177: jmp 0x9b +;; 17c: movq 0x30(%rsp), %rax +;; 181: movq %r15, (%rax) +;; 184: movq (%rsp), %rdi +;; 188: callq 0x2fe +;; 18d: movq 0x30(%rsp), %r15 +;; 192: movq (%r15), %r15 +;; 195: jmp 0xa4 +;; 19a: ud2 diff --git a/tests/disas/gc/array-copy-with-fuel.wat b/tests/disas/gc/array-copy-with-fuel.wat index 9a0d2f247aa5..3d9ca364d853 100644 --- a/tests/disas/gc/array-copy-with-fuel.wat +++ b/tests/disas/gc/array-copy-with-fuel.wat @@ -24,15 +24,15 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i8 tail -;; fn0 = colocated u805306368:11 sig0 +;; sig0 = (i64 vmctx) preserve_all +;; fn0 = colocated u1073741824:11 sig0 ;; stack_limit = gv2 ;; ;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32): -;; v162 = stack_addr.i64 ss0 -;; store notrap aligned region7 v2, v162 -;; v163 = stack_addr.i64 ss1 -;; store notrap aligned region8 v4, v163 +;; v160 = stack_addr.i64 ss0 +;; store notrap aligned region7 v2, v160 +;; v161 = stack_addr.i64 ss1 +;; store notrap aligned region8 v4, v161 ;; @0020 v7 = load.i64 notrap aligned readonly can_move region0 v0+8 ;; @0020 v8 = load.i64 notrap aligned region2 v7 ;; @0020 v9 = iconst.i64 1 @@ -41,107 +41,107 @@ ;; @0020 v12 = icmp sge v10, v11 ; v11 = 0 ;; @0020 brif v12, block2, block3(v10) ;; -;; block2: -;; @0020 v172 = iadd.i64 v8, v9 ; v9 = 1 -;; @0020 store notrap aligned region2 v172, v7 -;; @0020 v14 = call fn0(v0), stack_map=[i32 @ ss0+0, i32 @ ss1+0] -;; @0020 v16 = load.i64 notrap aligned region2 v7 -;; @0020 jump block3(v16) +;; block2 cold: +;; @0020 v170 = iadd.i64 v8, v9 ; v9 = 1 +;; @0020 store notrap aligned region2 v170, v7 +;; @0020 call fn0(v0), stack_map=[i32 @ ss0+0, i32 @ ss1+0] +;; @0020 v15 = load.i64 notrap aligned region2 v7 +;; @0020 jump block3(v15) ;; -;; block3(v125: i64): -;; v161 = load.i32 notrap aligned region7 v162 -;; @002b trapz v161, user16 -;; @002b v24 = load.i64 notrap aligned readonly can_move region3 v7+24 -;; @002b v22 = uextend.i64 v161 -;; @002b v25 = iadd v24, v22 -;; @002b v26 = iconst.i64 16 -;; @002b v27 = iadd v25, v26 ; v26 = 16 -;; @002b v28 = load.i32 user2 readonly region5 v27 -;; @002b v30 = uextend.i64 v3 -;; @002b v31 = uextend.i64 v6 -;; @002b v34 = iadd v30, v31 -;; @002b v29 = uextend.i64 v28 -;; @002b v35 = icmp ugt v34, v29 -;; @002b trapnz v35, user17 -;; v155 = load.i32 notrap aligned region8 v163 -;; @002b trapz v155, user16 -;; @002b v46 = uextend.i64 v155 -;; @002b v49 = iadd v24, v46 -;; @002b v51 = iadd v49, v26 ; v26 = 16 -;; @002b v52 = load.i32 user2 readonly region5 v51 -;; @002b v54 = uextend.i64 v5 -;; @002b v58 = iadd v54, v31 -;; @002b v53 = uextend.i64 v52 -;; @002b v59 = icmp ugt v58, v53 -;; @002b trapnz v59, user17 -;; @002b v78 = load.i64 notrap aligned region4 v7+32 -;; @002b v40 = iconst.i64 20 -;; @002b v41 = iadd v25, v40 ; v40 = 20 -;; v165 = iconst.i64 2 -;; v166 = ishl v30, v165 ; v165 = 2 -;; @002b v45 = iadd v41, v166 -;; v170 = ishl v31, v165 ; v165 = 2 -;; @002b v80 = uadd_overflow_trap v45, v170, user2 -;; @002b v79 = iadd v24, v78 -;; @002b v81 = icmp ugt v80, v79 -;; @002b trapnz v81, user2 -;; @002b v65 = iadd v49, v40 ; v40 = 20 -;; v168 = ishl v54, v165 ; v165 = 2 -;; @002b v69 = iadd v65, v168 -;; @002b v87 = uadd_overflow_trap v69, v170, user2 -;; @002b v88 = icmp ugt v87, v79 -;; @002b trapnz v88, user2 +;; block3(v124: i64): +;; v159 = load.i32 notrap aligned region7 v160 +;; @002b trapz v159, user16 +;; @002b v23 = load.i64 notrap aligned readonly can_move region3 v7+24 +;; @002b v21 = uextend.i64 v159 +;; @002b v24 = iadd v23, v21 +;; @002b v25 = iconst.i64 16 +;; @002b v26 = iadd v24, v25 ; v25 = 16 +;; @002b v27 = load.i32 user2 readonly region5 v26 +;; @002b v29 = uextend.i64 v3 +;; @002b v30 = uextend.i64 v6 +;; @002b v33 = iadd v29, v30 +;; @002b v28 = uextend.i64 v27 +;; @002b v34 = icmp ugt v33, v28 +;; @002b trapnz v34, user17 +;; v153 = load.i32 notrap aligned region8 v161 +;; @002b trapz v153, user16 +;; @002b v45 = uextend.i64 v153 +;; @002b v48 = iadd v23, v45 +;; @002b v50 = iadd v48, v25 ; v25 = 16 +;; @002b v51 = load.i32 user2 readonly region5 v50 +;; @002b v53 = uextend.i64 v5 +;; @002b v57 = iadd v53, v30 +;; @002b v52 = uextend.i64 v51 +;; @002b v58 = icmp ugt v57, v52 +;; @002b trapnz v58, user17 +;; @002b v77 = load.i64 notrap aligned region4 v7+32 +;; @002b v39 = iconst.i64 20 +;; @002b v40 = iadd v24, v39 ; v39 = 20 +;; v163 = iconst.i64 2 +;; v164 = ishl v29, v163 ; v163 = 2 +;; @002b v44 = iadd v40, v164 +;; v168 = ishl v30, v163 ; v163 = 2 +;; @002b v79 = uadd_overflow_trap v44, v168, user2 +;; @002b v78 = iadd v23, v77 +;; @002b v80 = icmp ugt v79, v78 +;; @002b trapnz v80, user2 +;; @002b v64 = iadd v48, v39 ; v39 = 20 +;; v166 = ishl v53, v163 ; v163 = 2 +;; @002b v68 = iadd v64, v166 +;; @002b v86 = uadd_overflow_trap v68, v168, user2 +;; @002b v87 = icmp ugt v86, v78 +;; @002b trapnz v87, user2 ;; @002b brif.i32 v6, block4, block7 ;; ;; block4: -;; @002b v89 = icmp.i64 ult v45, v69 -;; @002b v94 = iadd.i64 v45, v170 -;; @002b v95 = iadd.i64 v69, v170 -;; @002b v97 = iadd.i32 v5, v6 -;; @002b v43 = iconst.i64 4 -;; @002b v120 = iconst.i32 1 -;; @002b brif v89, block5(v45, v69, v5), block6(v94, v95, v97) +;; @002b v88 = icmp.i64 ult v44, v68 +;; @002b v93 = iadd.i64 v44, v168 +;; @002b v94 = iadd.i64 v68, v168 +;; @002b v96 = iadd.i32 v5, v6 +;; @002b v42 = iconst.i64 4 +;; @002b v119 = iconst.i32 1 +;; @002b brif v88, block5(v44, v68, v5), block6(v93, v94, v96) ;; -;; block5(v98: i64, v99: i64, v100: i32): -;; @002b v103 = load.i32 user2 little region6 v99 -;; @002b store user2 little region6 v103, v98 -;; @002b v178 = iconst.i64 4 -;; @002b v179 = iadd v99, v178 ; v178 = 4 -;; @002b v110 = icmp eq v179, v95 -;; @002b v180 = iadd v98, v178 ; v178 = 4 -;; @002b v181 = iconst.i32 1 -;; @002b v182 = iadd v100, v181 ; v181 = 1 -;; @002b brif v110, block7, block5(v180, v179, v182) +;; block5(v97: i64, v98: i64, v99: i32): +;; @002b v102 = load.i32 user2 little region6 v98 +;; @002b store user2 little region6 v102, v97 +;; @002b v176 = iconst.i64 4 +;; @002b v177 = iadd v98, v176 ; v176 = 4 +;; @002b v109 = icmp eq v177, v94 +;; @002b v178 = iadd v97, v176 ; v176 = 4 +;; @002b v179 = iconst.i32 1 +;; @002b v180 = iadd v99, v179 ; v179 = 1 +;; @002b brif v109, block7, block5(v178, v177, v180) ;; -;; block6(v111: i64, v112: i64, v113: i32): -;; @002b v173 = iconst.i64 4 -;; @002b v174 = isub v112, v173 ; v173 = 4 -;; @002b v122 = load.i32 user2 little region6 v174 -;; @002b v175 = isub v111, v173 ; v173 = 4 -;; @002b store user2 little region6 v122, v175 -;; @002b v123 = icmp eq v174, v69 -;; @002b v176 = iconst.i32 1 -;; @002b v177 = isub v113, v176 ; v176 = 1 -;; @002b brif v123, block7, block6(v175, v174, v177) +;; block6(v110: i64, v111: i64, v112: i32): +;; @002b v171 = iconst.i64 4 +;; @002b v172 = isub v111, v171 ; v171 = 4 +;; @002b v121 = load.i32 user2 little region6 v172 +;; @002b v173 = isub v110, v171 ; v171 = 4 +;; @002b store user2 little region6 v121, v173 +;; @002b v122 = icmp eq v172, v68 +;; @002b v174 = iconst.i32 1 +;; @002b v175 = isub v112, v174 ; v174 = 1 +;; @002b brif v122, block7, block6(v173, v172, v175) ;; ;; block7: -;; @002b v128 = iconst.i64 6 -;; @002b v129 = iadd.i64 v125, v128 ; v128 = 6 -;; @002b v133 = iadd v129, v31 -;; @0020 v183 = iconst.i64 0 -;; @002b v184 = icmp sge v133, v183 ; v183 = 0 -;; @002b brif v184, block8, block9(v133) +;; @002b v127 = iconst.i64 6 +;; @002b v128 = iadd.i64 v124, v127 ; v127 = 6 +;; @002b v132 = iadd v128, v30 +;; @0020 v181 = iconst.i64 0 +;; @002b v182 = icmp sge v132, v181 ; v181 = 0 +;; @002b brif v182, block8, block9(v132) ;; -;; block8: -;; @002b store.i64 notrap aligned region2 v133, v7 -;; @002b v137 = call fn0(v0) -;; @002b v139 = load.i64 notrap aligned region2 v7 -;; @002b jump block9(v139) +;; block8 cold: +;; @002b store.i64 notrap aligned region2 v132, v7 +;; @002b call fn0(v0) +;; @002b v137 = load.i64 notrap aligned region2 v7 +;; @002b jump block9(v137) ;; -;; block9(v141: i64): +;; block9(v139: i64): ;; @002f jump block1 ;; ;; block1: -;; @002f store.i64 notrap aligned region2 v141, v7 +;; @002f store.i64 notrap aligned region2 v139, v7 ;; @002f return ;; } diff --git a/tests/disas/guest-debugging.wat b/tests/disas/guest-debugging.wat index c66d78385a85..f66bebee24c9 100644 --- a/tests/disas/guest-debugging.wat +++ b/tests/disas/guest-debugging.wat @@ -27,7 +27,7 @@ ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 ;; sig0 = (i64 vmctx) -> i8 tail -;; sig1 = (i64) preserve_all +;; sig1 = (i64 vmctx) preserve_all ;; fn0 = colocated u805306368:41 sig0 ;; fn1 = colocated patchable u1073741824:46 sig1 ;; stack_limit = gv2, handler = fn0 diff --git a/tests/disas/memory-copy-epochs.wat b/tests/disas/memory-copy-epochs.wat index 486f92678cce..1608a3f8955f 100644 --- a/tests/disas/memory-copy-epochs.wat +++ b/tests/disas/memory-copy-epochs.wat @@ -19,9 +19,9 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i64 tail +;; sig0 = (i64 vmctx) preserve_all ;; sig1 = (i64 vmctx, i64, i64, i64) tail -;; fn0 = colocated u805306368:12 sig0 +;; fn0 = colocated u1073741824:12 sig0 ;; fn1 = colocated u805306368:1 sig1 ;; stack_limit = gv2 ;; @@ -34,35 +34,37 @@ ;; @001e brif v9, block3, block2(v8) ;; ;; block3 cold: -;; @001e v10 = call fn0(v0) -;; @001e jump block2(v10) +;; @001e call fn0(v0) +;; @001e v11 = load.i64 notrap aligned region4 v7+8 +;; @001e jump block2(v11) ;; -;; block2(v41: i64): -;; @0025 v14 = load.i64 notrap aligned region6 v0+64 -;; @0025 v15 = uextend.i64 v2 -;; @0025 v16 = uextend.i64 v4 -;; @0025 v19 = iadd v15, v16 -;; @0025 v20 = icmp ugt v19, v14 -;; @0025 trapnz v20, heap_oob -;; @0025 v27 = uextend.i64 v3 -;; @0025 v31 = iadd v27, v16 -;; @0025 v32 = icmp ugt v31, v14 -;; @0025 trapnz v32, heap_oob -;; @0025 v21 = load.i64 notrap aligned readonly can_move region5 v0+56 -;; @0025 v25 = iadd v21, v15 -;; @0025 v37 = iadd v21, v27 -;; @0025 call fn1(v0, v25, v37, v16) -;; @0025 v40 = load.i64 notrap aligned region3 v5 -;; @0025 v42 = icmp uge v40, v41 -;; @0025 brif v42, block5, block4 +;; block2(v42: i64): +;; @0025 v15 = load.i64 notrap aligned region6 v0+64 +;; @0025 v16 = uextend.i64 v2 +;; @0025 v17 = uextend.i64 v4 +;; @0025 v20 = iadd v16, v17 +;; @0025 v21 = icmp ugt v20, v15 +;; @0025 trapnz v21, heap_oob +;; @0025 v28 = uextend.i64 v3 +;; @0025 v32 = iadd v28, v17 +;; @0025 v33 = icmp ugt v32, v15 +;; @0025 trapnz v33, heap_oob +;; @0025 v22 = load.i64 notrap aligned readonly can_move region5 v0+56 +;; @0025 v26 = iadd v22, v16 +;; @0025 v38 = iadd v22, v28 +;; @0025 call fn1(v0, v26, v38, v17) +;; @0025 v41 = load.i64 notrap aligned region3 v5 +;; @0025 v43 = icmp uge v41, v42 +;; @0025 brif v43, block5, block4 ;; ;; block5 cold: -;; @0025 v44 = load.i64 notrap aligned region4 v7+8 -;; @0025 v45 = icmp.i64 uge v40, v44 -;; @0025 brif v45, block6, block4 +;; @0025 v45 = load.i64 notrap aligned region4 v7+8 +;; @0025 v46 = icmp.i64 uge v41, v45 +;; @0025 brif v46, block6, block4 ;; ;; block6 cold: -;; @0025 v46 = call fn0(v0) +;; @0025 call fn0(v0) +;; @0025 v48 = load.i64 notrap aligned region4 v7+8 ;; @0025 jump block4 ;; ;; block4: diff --git a/tests/disas/memory-copy-fuel-const-len.wat b/tests/disas/memory-copy-fuel-const-len.wat index c55af8af65c3..c82956c2ac57 100644 --- a/tests/disas/memory-copy-fuel-const-len.wat +++ b/tests/disas/memory-copy-fuel-const-len.wat @@ -24,8 +24,8 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i8 tail -;; fn0 = colocated u805306368:11 sig0 +;; sig0 = (i64 vmctx) preserve_all +;; fn0 = colocated u1073741824:11 sig0 ;; stack_limit = gv2 ;; ;; block0(v0: i64, v1: i64, v2: i32, v3: i32): @@ -37,35 +37,35 @@ ;; @0023 v9 = icmp sge v7, v8 ; v8 = 0 ;; @0023 brif v9, block2, block3(v7) ;; -;; block2: -;; @0023 v58 = iadd.i64 v5, v6 ; v6 = 1 -;; @0023 store notrap aligned region2 v58, v4 -;; @0023 v11 = call fn0(v0) -;; @0023 v13 = load.i64 notrap aligned region2 v4 -;; @0023 jump block3(v13) -;; -;; block3(v43: i64): -;; @002a v17 = load.i64 notrap aligned region4 v0+64 -;; @002a v18 = uextend.i64 v2 -;; v47 = iconst.i64 16 -;; @002a v22 = iadd v18, v47 ; v47 = 16 -;; @002a v23 = icmp ugt v22, v17 -;; @002a trapnz v23, heap_oob -;; @002a v30 = uextend.i64 v3 -;; @002a v34 = iadd v30, v47 ; v47 = 16 -;; @002a v35 = icmp ugt v34, v17 -;; @002a trapnz v35, heap_oob -;; @002a v24 = load.i64 notrap aligned readonly can_move region3 v0+56 -;; @002a v40 = iadd v24, v30 -;; @002a v42 = load.i8x16 notrap little region5 v40 -;; @002a v28 = iadd v24, v18 -;; @002a store notrap little region5 v42, v28 +;; block2 cold: +;; @0023 v57 = iadd.i64 v5, v6 ; v6 = 1 +;; @0023 store notrap aligned region2 v57, v4 +;; @0023 call fn0(v0) +;; @0023 v12 = load.i64 notrap aligned region2 v4 +;; @0023 jump block3(v12) +;; +;; block3(v42: i64): +;; @002a v16 = load.i64 notrap aligned region4 v0+64 +;; @002a v17 = uextend.i64 v2 +;; v46 = iconst.i64 16 +;; @002a v21 = iadd v17, v46 ; v46 = 16 +;; @002a v22 = icmp ugt v21, v16 +;; @002a trapnz v22, heap_oob +;; @002a v29 = uextend.i64 v3 +;; @002a v33 = iadd v29, v46 ; v46 = 16 +;; @002a v34 = icmp ugt v33, v16 +;; @002a trapnz v34, heap_oob +;; @002a v23 = load.i64 notrap aligned readonly can_move region3 v0+56 +;; @002a v39 = iadd v23, v29 +;; @002a v41 = load.i8x16 notrap little region5 v39 +;; @002a v27 = iadd v23, v17 +;; @002a store notrap little region5 v41, v27 ;; @002e jump block1 ;; ;; block1: -;; @002e v44 = iconst.i64 20 -;; @002e v45 = iadd.i64 v43, v44 ; v44 = 20 -;; @002e store notrap aligned region2 v45, v4 +;; @002e v43 = iconst.i64 20 +;; @002e v44 = iadd.i64 v42, v43 ; v43 = 20 +;; @002e store notrap aligned region2 v44, v4 ;; @002e return ;; } ;; @@ -78,9 +78,9 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i8 tail +;; sig0 = (i64 vmctx) preserve_all ;; sig1 = (i64 vmctx, i64, i32, i64) tail -;; fn0 = colocated u805306368:11 sig0 +;; fn0 = colocated u1073741824:11 sig0 ;; fn1 = colocated u805306368:2 sig1 ;; stack_limit = gv2 ;; @@ -93,30 +93,30 @@ ;; @0030 v8 = icmp sge v6, v7 ; v7 = 0 ;; @0030 brif v8, block2, block3(v6) ;; -;; block2: -;; @0030 v43 = iadd.i64 v4, v5 ; v5 = 1 -;; @0030 store notrap aligned region2 v43, v3 -;; @0030 v10 = call fn0(v0) -;; @0030 v12 = load.i64 notrap aligned region2 v3 -;; @0030 jump block3(v12) -;; -;; block3(v29: i64): -;; @0038 v16 = load.i64 notrap aligned region4 v0+64 -;; @0038 v17 = uextend.i64 v2 -;; v33 = iconst.i64 128 -;; @0038 v21 = iadd v17, v33 ; v33 = 128 -;; @0038 v22 = icmp ugt v21, v16 -;; @0038 trapnz v22, heap_oob -;; @0038 v23 = load.i64 notrap aligned readonly can_move region3 v0+56 -;; @0038 v27 = iadd v23, v17 -;; @0033 v14 = iconst.i32 0 -;; @0038 call fn1(v0, v27, v14, v33) ; v14 = 0, v33 = 128 +;; block2 cold: +;; @0030 v42 = iadd.i64 v4, v5 ; v5 = 1 +;; @0030 store notrap aligned region2 v42, v3 +;; @0030 call fn0(v0) +;; @0030 v11 = load.i64 notrap aligned region2 v3 +;; @0030 jump block3(v11) +;; +;; block3(v28: i64): +;; @0038 v15 = load.i64 notrap aligned region4 v0+64 +;; @0038 v16 = uextend.i64 v2 +;; v32 = iconst.i64 128 +;; @0038 v20 = iadd v16, v32 ; v32 = 128 +;; @0038 v21 = icmp ugt v20, v15 +;; @0038 trapnz v21, heap_oob +;; @0038 v22 = load.i64 notrap aligned readonly can_move region3 v0+56 +;; @0038 v26 = iadd v22, v16 +;; @0033 v13 = iconst.i32 0 +;; @0038 call fn1(v0, v26, v13, v32) ; v13 = 0, v32 = 128 ;; @003b jump block1 ;; ;; block1: -;; @003b v30 = iconst.i64 132 -;; @003b v31 = iadd.i64 v29, v30 ; v30 = 132 -;; @003b store notrap aligned region2 v31, v3 +;; @003b v29 = iconst.i64 132 +;; @003b v30 = iadd.i64 v28, v29 ; v29 = 132 +;; @003b store notrap aligned region2 v30, v3 ;; @003b return ;; } ;; @@ -129,9 +129,9 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i8 tail +;; sig0 = (i64 vmctx) preserve_all ;; sig1 = (i64 vmctx, i64, i32, i64) tail -;; fn0 = colocated u805306368:11 sig0 +;; fn0 = colocated u1073741824:11 sig0 ;; fn1 = colocated u805306368:2 sig1 ;; stack_limit = gv2 ;; @@ -144,41 +144,41 @@ ;; @003d v8 = icmp sge v6, v7 ; v7 = 0 ;; @003d brif v8, block2, block3(v6) ;; -;; block2: -;; @003d v50 = iadd.i64 v4, v5 ; v5 = 1 -;; @003d store notrap aligned region2 v50, v3 -;; @003d v10 = call fn0(v0) -;; @003d v12 = load.i64 notrap aligned region2 v3 -;; @003d jump block3(v12) -;; -;; block3(v29: i64): -;; @0045 v16 = load.i64 notrap aligned region4 v0+64 -;; @0045 v17 = uextend.i64 v2 -;; v40 = iconst.i64 4096 -;; @0045 v21 = iadd v17, v40 ; v40 = 4096 -;; @0045 v22 = icmp ugt v21, v16 -;; @0045 trapnz v22, heap_oob -;; @0045 v23 = load.i64 notrap aligned readonly can_move region3 v0+56 -;; @0045 v27 = iadd v23, v17 -;; @0040 v14 = iconst.i32 0 -;; @0045 call fn1(v0, v27, v14, v40) ; v14 = 0, v40 = 4096 -;; @0045 v30 = iconst.i64 4100 -;; @0045 v31 = iadd v29, v30 ; v30 = 4100 -;; @003d v51 = iconst.i64 0 -;; @0045 v52 = icmp sge v31, v51 ; v51 = 0 -;; @0045 brif v52, block4, block5(v31) -;; -;; block4: -;; @0045 v53 = iadd.i64 v29, v30 ; v30 = 4100 -;; @0045 store notrap aligned region2 v53, v3 -;; @0045 v35 = call fn0(v0) -;; @0045 v37 = load.i64 notrap aligned region2 v3 -;; @0045 jump block5(v37) -;; -;; block5(v39: i64): +;; block2 cold: +;; @003d v48 = iadd.i64 v4, v5 ; v5 = 1 +;; @003d store notrap aligned region2 v48, v3 +;; @003d call fn0(v0) +;; @003d v11 = load.i64 notrap aligned region2 v3 +;; @003d jump block3(v11) +;; +;; block3(v28: i64): +;; @0045 v15 = load.i64 notrap aligned region4 v0+64 +;; @0045 v16 = uextend.i64 v2 +;; v38 = iconst.i64 4096 +;; @0045 v20 = iadd v16, v38 ; v38 = 4096 +;; @0045 v21 = icmp ugt v20, v15 +;; @0045 trapnz v21, heap_oob +;; @0045 v22 = load.i64 notrap aligned readonly can_move region3 v0+56 +;; @0045 v26 = iadd v22, v16 +;; @0040 v13 = iconst.i32 0 +;; @0045 call fn1(v0, v26, v13, v38) ; v13 = 0, v38 = 4096 +;; @0045 v29 = iconst.i64 4100 +;; @0045 v30 = iadd v28, v29 ; v29 = 4100 +;; @003d v49 = iconst.i64 0 +;; @0045 v50 = icmp sge v30, v49 ; v49 = 0 +;; @0045 brif v50, block4, block5(v30) +;; +;; block4 cold: +;; @0045 v51 = iadd.i64 v28, v29 ; v29 = 4100 +;; @0045 store notrap aligned region2 v51, v3 +;; @0045 call fn0(v0) +;; @0045 v35 = load.i64 notrap aligned region2 v3 +;; @0045 jump block5(v35) +;; +;; block5(v37: i64): ;; @0048 jump block1 ;; ;; block1: -;; @0048 store.i64 notrap aligned region2 v39, v3 +;; @0048 store.i64 notrap aligned region2 v37, v3 ;; @0048 return ;; } diff --git a/tests/disas/memory-copy-fuel.wat b/tests/disas/memory-copy-fuel.wat index 5558b0ed2bb0..5facec7c7186 100644 --- a/tests/disas/memory-copy-fuel.wat +++ b/tests/disas/memory-copy-fuel.wat @@ -17,9 +17,9 @@ ;; gv0 = vmctx ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 -;; sig0 = (i64 vmctx) -> i8 tail +;; sig0 = (i64 vmctx) preserve_all ;; sig1 = (i64 vmctx, i64, i64, i64) tail -;; fn0 = colocated u805306368:11 sig0 +;; fn0 = colocated u1073741824:11 sig0 ;; fn1 = colocated u805306368:1 sig1 ;; stack_limit = gv2 ;; @@ -32,45 +32,45 @@ ;; @001e v10 = icmp sge v8, v9 ; v9 = 0 ;; @001e brif v10, block2, block3(v8) ;; -;; block2: -;; @001e v61 = iadd.i64 v6, v7 ; v7 = 1 -;; @001e store notrap aligned region2 v61, v5 -;; @001e v12 = call fn0(v0) -;; @001e v14 = load.i64 notrap aligned region2 v5 -;; @001e jump block3(v14) +;; block2 cold: +;; @001e v59 = iadd.i64 v6, v7 ; v7 = 1 +;; @001e store notrap aligned region2 v59, v5 +;; @001e call fn0(v0) +;; @001e v13 = load.i64 notrap aligned region2 v5 +;; @001e jump block3(v13) ;; -;; block3(v43: i64): -;; @0025 v18 = load.i64 notrap aligned region4 v0+64 -;; @0025 v19 = uextend.i64 v2 -;; @0025 v20 = uextend.i64 v4 -;; @0025 v23 = iadd v19, v20 -;; @0025 v24 = icmp ugt v23, v18 -;; @0025 trapnz v24, heap_oob -;; @0025 v31 = uextend.i64 v3 -;; @0025 v35 = iadd v31, v20 -;; @0025 v36 = icmp ugt v35, v18 -;; @0025 trapnz v36, heap_oob -;; @0025 v25 = load.i64 notrap aligned readonly can_move region3 v0+56 -;; @0025 v29 = iadd v25, v19 -;; @0025 v41 = iadd v25, v31 -;; @0025 call fn1(v0, v29, v41, v20) -;; @0025 v44 = iconst.i64 4 -;; @0025 v45 = iadd v43, v44 ; v44 = 4 -;; @0025 v49 = iadd v45, v20 -;; @001e v62 = iconst.i64 0 -;; @0025 v63 = icmp sge v49, v62 ; v62 = 0 -;; @0025 brif v63, block4, block5(v49) +;; block3(v42: i64): +;; @0025 v17 = load.i64 notrap aligned region4 v0+64 +;; @0025 v18 = uextend.i64 v2 +;; @0025 v19 = uextend.i64 v4 +;; @0025 v22 = iadd v18, v19 +;; @0025 v23 = icmp ugt v22, v17 +;; @0025 trapnz v23, heap_oob +;; @0025 v30 = uextend.i64 v3 +;; @0025 v34 = iadd v30, v19 +;; @0025 v35 = icmp ugt v34, v17 +;; @0025 trapnz v35, heap_oob +;; @0025 v24 = load.i64 notrap aligned readonly can_move region3 v0+56 +;; @0025 v28 = iadd v24, v18 +;; @0025 v40 = iadd v24, v30 +;; @0025 call fn1(v0, v28, v40, v19) +;; @0025 v43 = iconst.i64 4 +;; @0025 v44 = iadd v42, v43 ; v43 = 4 +;; @0025 v48 = iadd v44, v19 +;; @001e v60 = iconst.i64 0 +;; @0025 v61 = icmp sge v48, v60 ; v60 = 0 +;; @0025 brif v61, block4, block5(v48) ;; -;; block4: -;; @0025 store.i64 notrap aligned region2 v49, v5 -;; @0025 v53 = call fn0(v0) -;; @0025 v55 = load.i64 notrap aligned region2 v5 -;; @0025 jump block5(v55) +;; block4 cold: +;; @0025 store.i64 notrap aligned region2 v48, v5 +;; @0025 call fn0(v0) +;; @0025 v53 = load.i64 notrap aligned region2 v5 +;; @0025 jump block5(v53) ;; -;; block5(v57: i64): +;; block5(v55: i64): ;; @0029 jump block1 ;; ;; block1: -;; @0029 store.i64 notrap aligned region2 v57, v5 +;; @0029 store.i64 notrap aligned region2 v55, v5 ;; @0029 return ;; } diff --git a/tests/disas/memory-watchpoints.wat b/tests/disas/memory-watchpoints.wat index 6ba7d983f0ce..0ab617ba8355 100644 --- a/tests/disas/memory-watchpoints.wat +++ b/tests/disas/memory-watchpoints.wat @@ -23,7 +23,7 @@ ;; gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8 ;; gv2 = load.i64 notrap aligned region1 gv1+16 ;; sig0 = (i64 vmctx) -> i8 tail -;; sig1 = (i64) preserve_all +;; sig1 = (i64 vmctx) preserve_all ;; sig2 = (i64 vmctx, i8) tail ;; sig3 = (i64 vmctx) tail ;; sig4 = (i64 vmctx, i32, i64, i32, i64, i64) -> i8 tail diff --git a/tests/disas/pulley/epoch-simple.wat b/tests/disas/pulley/epoch-simple.wat index 947f92812732..b8634f34faab 100644 --- a/tests/disas/pulley/epoch-simple.wat +++ b/tests/disas/pulley/epoch-simple.wat @@ -7,11 +7,11 @@ ) ;; wasm[0]::function[0]: ;; push_frame -;; xload64le_o32 x6, x0, 24 -;; xload64le_o32 x6, x6, 0 -;; xload64le_o32 x7, x0, 8 -;; xload64le_o32 x7, x7, 8 -;; br_if_xulteq64 x7, x6, 0x9 // target = 0x26 +;; xload64le_o32 x5, x0, 24 +;; xload64le_o32 x5, x5, 0 +;; xload64le_o32 x6, x0, 8 +;; xload64le_o32 x6, x6, 8 +;; br_if_xulteq64 x6, x5, 0x9 // target = 0x26 ;; 24: pop_frame ;; ret ;; 26: call 0x6f // target = 0x95