summaryrefslogtreecommitdiff
path: root/crates/types/src
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-08-08 18:30:29 +0200
committerHenry <mail@henrygressmann.de>2026-08-08 18:30:29 +0200
commit676be92cde66d7c20bfe11d64bfc3f5762c4c46e (patch)
tree537702525e0b7d04ca8007c7a53aab8fcfca7050 /crates/types/src
parentd0c74255f9d6c57a243cf34037af0e8f371504b3 (diff)
chore: store globals in different lanes based on size
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types/src')
-rw-r--r--crates/types/src/instructions.rs7
-rw-r--r--crates/types/src/lib.rs41
2 files changed, 40 insertions, 8 deletions
diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs
index 1160fa5..b920ac7 100644
--- a/crates/types/src/instructions.rs
+++ b/crates/types/src/instructions.rs
@@ -239,10 +239,9 @@ pub enum Instruction {
// > Variable Instructions
// See <https://webassembly.github.io/spec/core/binary/instructions.html#variable-instructions>
- GlobalGet(GlobalAddr),
- LocalGet32(LocalAddr), LocalSet32(LocalAddr), LocalTee32(LocalAddr), GlobalSet32(GlobalAddr),
- LocalGet64(LocalAddr), LocalSet64(LocalAddr), LocalTee64(LocalAddr), GlobalSet64(GlobalAddr),
- LocalGet128(LocalAddr), LocalSet128(LocalAddr), LocalTee128(LocalAddr), GlobalSet128(GlobalAddr),
+ GlobalGet32(GlobalAddr), LocalGet32(LocalAddr), LocalSet32(LocalAddr), LocalTee32(LocalAddr), GlobalSet32(GlobalAddr),
+ GlobalGet64(GlobalAddr), LocalGet64(LocalAddr), LocalSet64(LocalAddr), LocalTee64(LocalAddr), GlobalSet64(GlobalAddr),
+ GlobalGet128(GlobalAddr), LocalGet128(LocalAddr), LocalSet128(LocalAddr), LocalTee128(LocalAddr), GlobalSet128(GlobalAddr),
// > Memory Instructions
I32Load(MemoryArg),
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index c461296..0fd4e81 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -362,6 +362,39 @@ impl ExternVal {
}
}
+/// The physical storage lane used by a [`WasmType`].
+#[derive(Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "debug", derive(Debug))]
+pub enum ValueLane {
+ /// A 32-bit value or reference.
+ S32,
+ /// A 64-bit value.
+ S64,
+ /// A 128-bit SIMD value.
+ S128,
+}
+
+impl ValueLane {
+ /// Selects one of three values based on this lane.
+ pub fn select<T>(self, s32: T, s64: T, s128: T) -> T {
+ match self {
+ Self::S32 => s32,
+ Self::S64 => s64,
+ Self::S128 => s128,
+ }
+ }
+}
+
+impl From<&WasmType> for ValueLane {
+ fn from(ty: &WasmType) -> Self {
+ match ty {
+ WasmType::I32 | WasmType::F32 | WasmType::Ref(_) => Self::S32,
+ WasmType::I64 | WasmType::F64 => Self::S64,
+ WasmType::V128 => Self::S128,
+ }
+ }
+}
+
#[derive(Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
@@ -384,10 +417,10 @@ impl<'a> FromIterator<&'a WasmType> for ValueCounts {
let mut counts = Self::default();
for ty in iter {
- match ty {
- WasmType::I32 | WasmType::F32 | WasmType::Ref(_) => counts.c32 += 1,
- WasmType::I64 | WasmType::F64 => counts.c64 += 1,
- WasmType::V128 => counts.c128 += 1,
+ match ValueLane::from(ty) {
+ ValueLane::S32 => counts.c32 += 1,
+ ValueLane::S64 => counts.c64 += 1,
+ ValueLane::S128 => counts.c128 += 1,
}
}
counts