Commit Graph

25 Commits

Author SHA1 Message Date
Marcus Nilsson
21c827e8af LibWasm: Parse and validate array types
This patch makes this parse
```wat
(module
  (type $a (array i32))
)
```
2026-02-10 13:00:16 +01:00
Marcus Nilsson
5fa9747105 LibWasm: Parse and validate typeuse references
This adds parsing of `(ref typeidx)` and validates that `typeidx` is a
valid index. Currently, nullability of the reference is lost.

A bug causing the code below to fail parsing has been fixed.
```wat
(module
  (type $T (struct (field i32) (field f32)))
  (type $T1 (struct (field i32) (field f32)))
  (; many more types... ;)
  (type $T64 (struct (field i32) (field f32)))
  (type $f (func (result (ref null $T64))))
)
```

The spec tests type-equivalence.{0,1,3,13} have been disabled as they
were previously false positives.
2026-02-10 13:00:16 +01:00
Marcus Nilsson
bfa51c2555 LibWasm: Parse struct types and support multiple types in type section
This patch adds support for parsing structs in the type section.

It also removes the assumption that all types in the type section are
function types, adding appropriate validation.

Spec tests struct.3 and struct.4 have been disable as this would
require expanding `ValueType` to include more heap-types.
2026-02-04 14:29:22 +01:00
Ali Mohammad Pur
6b61b5bda7 LibWasm: Reduce StructureInstructionArgs' meta parameter size to 32b
Even this is overkill, but 64b fits in a register so no need to reduce
it further.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
9a74bf87d8 LibWasm: Minimize runtime overhead for block/branch ops
Preevaluate arity and params to avoid pointer chasing at exec time.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
921373a045 LibWasm: Implement call argument forwarding using call records 2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
6ede78aa0a LibWasm: Validate compiled instruction stream
This helps catch a bunch of miscompilations early.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
a72127c39d LibWasm: Move out addresses into their own allocation
Instead of trying to indirectly load 2x64 bits from *cc, load addresses
directly from their own contiguous allocation.

This allows a future optimisation where we defer loading addresses to
reduce memory port pressure.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
70f839ccb2 LibWasm: Take call arguments as references and recycle the allocations
This opens the way for a allocated-at-start call frame optimisation
(that will come in a future commit).
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
b89ecfc6bc LibWasm: Split parameters from locals 2026-02-02 14:11:49 +01:00
Luke Wilde
1ff15a3b44 LibWasm: Add missing tag section validation
This also removes the duplicate tag type.
2026-01-08 18:49:24 +01:00
Andreas Kling
09e22e31c2 LibWasm: Use u32 for *Type and InstructionPointer typedefs
We were already parsing these as u32, so it was completely wasted
storage. This shrinks Wasm::Instruction by 16 bytes.
2025-12-21 12:08:41 -06:00
Ali Mohammad Pur
92c0cbc453 LibWasm+LibWeb: Stub wasm-gc's heap reference types
WPT inserts these into all modules regardless of whether they're used,
so let's just parse and ignore them.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
d99f663b1a LibWasm: Implement parsing/validation for proposal exception-handling
Actual execution traps for now.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
ddb35dcb5f LibWasm: Accept proposal 'memory64' (but don't actually run it)
This is a WIP implementation.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
02b3c4f8a9 LibWasm: Utilise direct threading if/when possible
~50% performance improvement on coremark.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Ali Mohammad Pur
22448b0c35 LibWasm: Move the interpreter IP out of the configuration object
This, along with moving the sources and destination out of the config
object, makes it so we don't have to double-deref to get to them on each
instruction, leading to a ~15% perf improvement on dispatch.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
f7bdc596b4 LibWasm: Avoid allocations for the label stack as much as possible
Namely, find an upper bound at validation time so we can allocate the
space when entering the frame.

Also drop labels at once instead of popping them off one at a time now
that we're using a Vector.
2025-08-26 15:20:33 +02:00
ayeteadoe
070392307a LibWasm: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
Ali Mohammad Pur
0e5ecef848 LibWasm: Try really hard to avoid touching the value stack
This commit adds a register allocator, with 8 available "register"
slots.
In testing with various random blobs, this moves anywhere from 30% to
74% of value accesses into predefined slots, and is about a ~20% perf
increase end-to-end.

To actually make this usable, a few structural changes were also made:
- we no longer do one instruction per interpret call
- trapping is an (unlikely) exit condition
- the label and frame stacks are replaced with linked lists with a huge
  node cache size, as we only need to touch the last element and
  push/pop is very frequent.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
dc67f0ad4e LibWasm: Hold on to the stack depth for expressions in the validator
This allows preallocating the value stack when pushing frames, avoiding
repeated reallocs and copies.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
3f77aa8521 LibWasm: Try to avoid vcalls on very busy stream read functions
This was a bottleneck when parsing, in general.
2025-08-08 12:54:06 +02:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00