Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ testcase*.json
perf.data*
miri-wast/
report/
target-*/
19 changes: 16 additions & 3 deletions Cargo.lock

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

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ object = { workspace = true, features = ['std'] }
wasmtime-test-macros = { path = "crates/test-macros" }
pulley-interpreter = { workspace = true, features = ["disas"] }
wasm-encoder = { workspace = true }
cranelift-native = { workspace = true }
cranelift-native = { workspace = true, features = ["std"] }
futures = { workspace = true }
rand = { workspace = true }

Expand Down Expand Up @@ -285,7 +285,7 @@ wasmtime-core = { path = "crates/core", version = "=47.0.0", package = 'wasmtime
wasmtime-wmemcheck = { path = "crates/wmemcheck", version = "=47.0.0", package = 'wasmtime-internal-wmemcheck' }
wasmtime-c-api-macros = { path = "crates/c-api-macros", version = "=47.0.0", package = 'wasmtime-internal-c-api-macros' }
wasmtime-cache = { path = "crates/cache", version = "=47.0.0", package = 'wasmtime-internal-cache' }
wasmtime-cranelift = { path = "crates/cranelift", version = "=47.0.0", package = 'wasmtime-internal-cranelift' }
wasmtime-cranelift = { path = "crates/cranelift", version = "=47.0.0", package = 'wasmtime-internal-cranelift', default-features = false }
wasmtime-winch = { path = "crates/winch", version = "=47.0.0", package = 'wasmtime-internal-winch' }
wasmtime-explorer = { path = "crates/explorer", version = "=47.0.0", package = 'wasmtime-internal-explorer' }
wasmtime-fiber = { path = "crates/fiber", version = "=47.0.0", package = 'wasmtime-internal-fiber' }
Expand All @@ -311,21 +311,21 @@ pulley-macros = { path = 'pulley/macros', version = "=47.0.0" }
# Cranelift crates in this workspace
cranelift-assembler-x64 = { path = "cranelift/assembler-x64", version = "0.134.0" }
cranelift-codegen = { path = "cranelift/codegen", version = "0.134.0", default-features = false, features = ["unwind"] }
cranelift-frontend = { path = "cranelift/frontend", version = "0.134.0" }
cranelift-frontend = { path = "cranelift/frontend", version = "0.134.0", default-features = false }
cranelift-entity = { path = "cranelift/entity", version = "0.134.0" }
cranelift-native = { path = "cranelift/native", version = "0.134.0" }
cranelift-module = { path = "cranelift/module", version = "0.134.0" }
cranelift-interpreter = { path = "cranelift/interpreter", version = "0.134.0" }
cranelift-reader = { path = "cranelift/reader", version = "0.134.0" }
cranelift-native = { path = "cranelift/native", version = "0.134.0", default-features = false }
cranelift-module = { path = "cranelift/module", version = "0.134.0", default-features = false }
cranelift-interpreter = { path = "cranelift/interpreter", version = "0.134.0", default-features = false }
cranelift-reader = { path = "cranelift/reader", version = "0.134.0", default-features = false }
cranelift-filetests = { path = "cranelift/filetests" }
cranelift-object = { path = "cranelift/object", version = "0.134.0" }
cranelift-jit = { path = "cranelift/jit", version = "0.134.0" }
cranelift-object = { path = "cranelift/object", version = "0.134.0", default-features = false }
cranelift-jit = { path = "cranelift/jit", version = "0.134.0", default-features = false }
cranelift-fuzzgen = { path = "cranelift/fuzzgen" }
cranelift-bforest = { path = "cranelift/bforest", version = "0.134.0" }
cranelift-bitset = { path = "cranelift/bitset", version = "0.134.0" }
cranelift-control = { path = "cranelift/control", version = "0.134.0", default-features = false }
cranelift-srcgen = { path = "cranelift/srcgen", version = "0.134.0" }
cranelift = { path = "cranelift/umbrella", version = "0.134.0" }
cranelift = { path = "cranelift/umbrella", version = "0.134.0", default-features = false }

# Winch crates in this workspace.
winch-codegen = { path = "winch/codegen", version = "=47.0.0" }
Expand All @@ -341,7 +341,7 @@ component-async-tests = { path = "crates/misc/component-async-tests" }

# Bytecode Alliance maintained dependencies:
# ---------------------------
regalloc2 = "0.15.1"
regalloc2 = { version = "0.15.1", default-features = false }
wasip1 = { version = "1.0.0", default-features = false }

# cap-std family:
Expand Down Expand Up @@ -393,7 +393,7 @@ capstone = { version = "0.14.0", default-features = false, features = ['full', '
smallvec = { version = "1.15.1", features = ["union"] }
tracing = { version = "0.1.41", default-features = false }
bitflags = "2.9.4"
thiserror = "2.0.17"
thiserror = { version = "2.0.17", default-features = false }
async-trait = "0.1.89"
heck = "0.5"
similar = "3.1.1"
Expand Down Expand Up @@ -456,6 +456,7 @@ pin-project-lite = "0.2.14"
sha2 = { version = "0.10.2", default-features = false }
gdbstub = "0.7.10"
gdbstub_arch = "0.3.3"
spin = { version = "0.12.0", default-features = false, features = ["mutex", "spin_mutex"] }

# =============================================================================
#
Expand Down Expand Up @@ -669,7 +670,7 @@ harness = false
name = "thread_eager_init"
harness = false

[[bench]]
[[bench]]
name = "trap"
harness = false

Expand Down
2 changes: 1 addition & 1 deletion cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cranelift-entity = { workspace = true }
cranelift-interpreter = { workspace = true }
cranelift-reader = { workspace = true }
cranelift-frontend = { workspace = true }
cranelift-native = { workspace = true }
cranelift-native = { workspace = true, features = ["std"] }
cranelift-filetests = { workspace = true }
cranelift-module = { workspace = true }
cranelift-object = { workspace = true }
Expand Down
8 changes: 1 addition & 7 deletions cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ default = ["std", "unwind", "host-arch", "timing"]
# The "std" feature enables use of libstd. The "core" feature enables use
# of some minimal std-like replacement libraries. At least one of these two
# features need to be enabled.
std = ["serde?/std", "rustc-hash/std", "gimli/std", "cranelift-control/fuzz"]

# The "core" feature used to enable a hashmap workaround, but is now
# deprecated (we (i) always use hashbrown, and (ii) don't support a
# no_std build anymore). The feature remains for backward
# compatibility as a no-op.
core = []
std = ["serde?/std", "rustc-hash/std", "gimli/std", "cranelift-control/fuzz", "regalloc2/std"]

# Enable the `to_capstone` method on TargetIsa, for constructing a Capstone
# context, and the `disassemble` method on `MachBufferFinalized`.
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![deny(missing_docs)]
// Display feature requirements in the documentation when building on docs.rs
#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]
#![cfg_attr(not(test), no_std)]
// Various bits and pieces of this crate might only be used for one platform or
// another, but it's not really too useful to learn about that all the time. On
// CI we build at least one version of this crate with `--features all-arch`
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspace = true
cranelift-codegen = { workspace = true, features = ["disas", "timing"] }
cranelift-frontend = { workspace = true }
cranelift-interpreter = { workspace = true }
cranelift-native = { workspace = true }
cranelift-native = { workspace = true, features = ["std"] }
cranelift-reader = { workspace = true }
cranelift-jit = { workspace = true, features = ["wasmtime-unwinder"] }
cranelift-module = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion cranelift/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ cranelift-codegen = { workspace = true, features = ['x86'] }
[features]
default = ["std"]
std = ["cranelift-codegen/std"]
core = ["cranelift-codegen/core"]
2 changes: 1 addition & 1 deletion cranelift/frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
//! ```
#![deny(missing_docs)]
#![no_std]
#![cfg_attr(not(test), no_std)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion cranelift/fuzzgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workspace = true

[dependencies]
cranelift = { workspace = true }
cranelift-native = { workspace = true }
cranelift-native = { workspace = true, features = ["std"] }

anyhow = { workspace = true, features = ['std'] }
arbitrary = { workspace = true }
Expand Down
9 changes: 6 additions & 3 deletions cranelift/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ workspace = true
[dependencies]
cranelift-codegen = { workspace = true }
cranelift-entity = { workspace = true }
hashbrown = { workspace = true }
libm = { workspace = true }
log = { workspace = true }
smallvec = { workspace = true }
thiserror = { workspace = true }

[target.x86_64-pc-windows-gnu.dependencies]
libm = { workspace = true }

[dev-dependencies]
cranelift-frontend = { workspace = true }
cranelift-reader = { workspace = true }

[features]
default = ["std"]
std = ["cranelift-codegen/std", "thiserror/std"]
5 changes: 5 additions & 0 deletions cranelift/interpreter/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! Implements the function environment (e.g. a name-to-function mapping) for interpretation.
use cranelift_codegen::ir::{FuncRef, Function};
use cranelift_entity::{PrimaryMap, entity_impl};
use std::string::{String, ToString};

#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;

/// A function store contains all of the functions that are accessible to an interpreter.
Expand Down
7 changes: 4 additions & 3 deletions cranelift/interpreter/src/frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Implements a call frame (activation record) for the Cranelift interpreter.
use std::vec::Vec;

use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::{Function, Value as ValueRef, types};
Expand Down Expand Up @@ -69,7 +70,7 @@ impl<'a> Frame<'a> {
pub fn set(&mut self, name: ValueRef, value: DataValue) -> Option<DataValue> {
assert!(name.index() < self.registers.len());
trace!("Set {name} -> {value}");
std::mem::replace(&mut self.registers[name.index()], Some(value))
core::mem::replace(&mut self.registers[name.index()], Some(value))
}

/// Assign to multiple SSA references; see `set`.
Expand All @@ -88,10 +89,10 @@ impl<'a> Frame<'a> {
trace!("Renaming {old_names:?} -> {new_names:?}");
assert_eq!(old_names.len(), new_names.len());
let new_registers = vec![None; self.registers.len()];
let mut old_registers = std::mem::replace(&mut self.registers, new_registers);
let mut old_registers = core::mem::replace(&mut self.registers, new_registers);
self.registers = vec![None; self.registers.len()];
for (&on, &nn) in old_names.iter().zip(new_names) {
let value = std::mem::replace(&mut old_registers[on.index()], None);
let value = core::mem::replace(&mut old_registers[on.index()], None);
self.registers[nn.index()] = value;
}
}
Expand Down
4 changes: 3 additions & 1 deletion cranelift/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::instruction::DfgInstructionContext;
use crate::state::{InterpreterFunctionRef, MemoryError, State};
use crate::step::{ControlFlow, CraneliftTrap, StepError, step};
use crate::value::{DataValueExt, ValueError};
use core::iter;
use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::{
ArgumentPurpose, Block, Endianness, ExternalName, FuncRef, Function, GlobalValue,
Expand All @@ -17,7 +18,8 @@ use cranelift_codegen::ir::{
use log::trace;
use smallvec::SmallVec;
use std::fmt::Debug;
use std::iter;
use std::string::{String, ToString};
use std::vec::Vec;
use thiserror::Error;

/// The Cranelift interpreter; this contains some high-level functions to control the interpreter's
Expand Down
9 changes: 9 additions & 0 deletions cranelift/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
//!
//! This module is a project for interpreting Cranelift IR.

#![cfg_attr(not(test), no_std)]

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc as std;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;

pub mod address;
pub mod environment;
pub mod frame;
Expand Down
5 changes: 4 additions & 1 deletion cranelift/interpreter/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::frame::Frame;
use crate::instruction::InstructionContext;
use crate::state::{InterpreterFunctionRef, MemoryError, State};
use crate::value::{DataValueExt, ValueConversionKind, ValueError, ValueResult};
use core::ops::RangeFrom;
use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
use cranelift_codegen::ir::{
Expand All @@ -13,8 +14,10 @@ use cranelift_codegen::ir::{
};
use log::trace;
use smallvec::{SmallVec, smallvec};
use std::borrow::ToOwned;
use std::fmt::Debug;
use std::ops::RangeFrom;
use std::string::String;
use std::vec::Vec;
use thiserror::Error;

/// Ensures that all types in args are the same as expected by the signature
Expand Down
22 changes: 1 addition & 21 deletions cranelift/interpreter/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum ValueError {
#[error("unable to convert value into type {0}")]
InvalidValue(Type),
#[error("unable to convert to primitive integer")]
InvalidInteger(#[from] std::num::TryFromIntError),
InvalidInteger(#[from] core::num::TryFromIntError),
#[error("unable to cast data value")]
InvalidDataValueCast(#[from] DataValueCastFailure),
#[error("performed a division by zero")]
Expand Down Expand Up @@ -628,31 +628,11 @@ impl DataValueExt for DataValue {
fn fma(self, b: Self, c: Self) -> ValueResult<Self> {
match (self, b, c) {
(DataValue::F32(a), DataValue::F32(b), DataValue::F32(c)) => {
// The `fma` function for `x86_64-pc-windows-gnu` is incorrect. Use `libm`'s instead.
// See: https://github.com/bytecodealliance/wasmtime/issues/4512
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "gnu"))]
let res = libm::fmaf(a.as_f32(), b.as_f32(), c.as_f32());

#[cfg(not(all(
target_arch = "x86_64",
target_os = "windows",
target_env = "gnu"
)))]
let res = a.as_f32().mul_add(b.as_f32(), c.as_f32());

Ok(DataValue::F32(res.into()))
}
(DataValue::F64(a), DataValue::F64(b), DataValue::F64(c)) => {
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "gnu"))]
let res = libm::fma(a.as_f64(), b.as_f64(), c.as_f64());

#[cfg(not(all(
target_arch = "x86_64",
target_os = "windows",
target_env = "gnu"
)))]
let res = a.as_f64().mul_add(b.as_f64(), c.as_f64());

Ok(DataValue::F64(res.into()))
}
(a, _b, _c) => Err(ValueError::InvalidType(ValueTypeClass::Float, a.ty())),
Expand Down
Loading
Loading