diff --git a/Cargo.lock b/Cargo.lock index b626972d2b73..ef60912d729b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,6 +647,7 @@ dependencies = [ "serde", "serde_derive", "similar", + "smallvec", "target-lexicon", "thiserror", "toml", diff --git a/cranelift/filetests/Cargo.toml b/cranelift/filetests/Cargo.toml index f3618d0de8ca..6338683390b3 100644 --- a/cranelift/filetests/Cargo.toml +++ b/cranelift/filetests/Cargo.toml @@ -26,7 +26,7 @@ num_cpus = "1.8.0" target-lexicon = { workspace = true } thiserror = { workspace = true } anyhow = { workspace = true } -similar ={ workspace = true } +similar = { workspace = true } wat.workspace = true toml = { workspace = true } serde = { workspace = true } @@ -34,3 +34,4 @@ serde_derive = { workspace = true } cranelift-wasm.workspace = true wasmparser.workspace = true cranelift.workspace = true +smallvec = { workspace = true } diff --git a/cranelift/filetests/filetests/runtests/call_libcall.clif b/cranelift/filetests/filetests/runtests/call_libcall.clif index 5956fca9575e..5201b771d1aa 100644 --- a/cranelift/filetests/filetests/runtests/call_libcall.clif +++ b/cranelift/filetests/filetests/runtests/call_libcall.clif @@ -1,6 +1,9 @@ +test interpret test run target x86_64 -; AArch64 Does not have these libcalls +target aarch64 +target aarch64 sign_return_address +target aarch64 has_pauth sign_return_address target s390x target riscv64 target riscv64 has_c has_zcb diff --git a/cranelift/filetests/src/test_interpret.rs b/cranelift/filetests/src/test_interpret.rs index f8d2f1b57b48..c9ed846316db 100644 --- a/cranelift/filetests/src/test_interpret.rs +++ b/cranelift/filetests/src/test_interpret.rs @@ -6,15 +6,17 @@ use crate::runone::FileUpdate; use crate::subtest::SubTest; use anyhow::Context; -use cranelift_codegen::ir::Function; +use cranelift_codegen::data_value::DataValue; +use cranelift_codegen::ir::{Function, LibCall}; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings::Flags; use cranelift_codegen::{self, ir}; use cranelift_interpreter::environment::FunctionStore; -use cranelift_interpreter::interpreter::{Interpreter, InterpreterState}; +use cranelift_interpreter::interpreter::{Interpreter, InterpreterState, LibCallValues}; use cranelift_interpreter::step::ControlFlow; use cranelift_reader::{parse_run_command, Details, TestCommand, TestFile}; use log::{info, trace}; +use smallvec::smallvec; use std::borrow::Cow; struct TestInterpret; @@ -83,7 +85,20 @@ fn run_test(func_store: &FunctionStore, func: &Function, details: &Details) -> a .run(|func_name, run_args| { // Rebuild the interpreter state on every run to ensure that we don't accidentally depend on // some leftover state - let state = InterpreterState::default().with_function_store(func_store.clone()); + let state = InterpreterState::default() + .with_function_store(func_store.clone()) + .with_libcall_handler(|libcall: LibCall, args: LibCallValues| { + use LibCall::*; + Ok(smallvec![match (libcall, &args[..]) { + (CeilF32, [DataValue::F32(a)]) => DataValue::F32(a.ceil()), + (CeilF64, [DataValue::F64(a)]) => DataValue::F64(a.ceil()), + (FloorF32, [DataValue::F32(a)]) => DataValue::F32(a.floor()), + (FloorF64, [DataValue::F64(a)]) => DataValue::F64(a.floor()), + (TruncF32, [DataValue::F32(a)]) => DataValue::F32(a.trunc()), + (TruncF64, [DataValue::F64(a)]) => DataValue::F64(a.trunc()), + _ => unreachable!(), + }]) + }); let mut args = Vec::with_capacity(run_args.len()); args.extend_from_slice(run_args);