Andreas Kling
eb789e790e
Everywhere: Use AK::SaturatingMath and remove Checked saturating APIs
...
Port all callers of Checked<T>::saturating_add/sub/mul to the new
standalone functions in AK/SaturatingMath.h, and remove the old
APIs from Checked.
2026-03-21 18:20:09 -05:00
Jelle Raaijmakers
bd9bc10eb2
LibWasm: Remove Vector size checks in (return_)call_indirect
...
These are followed by `Vector::operator==` which immediately compares
sizes as well.
2026-03-07 16:05:20 +01:00
Jelle Raaijmakers
fa1417114e
LibWasm: Implement call_ref and return_call_ref instructions
...
These are part of the typed function references proposal, which is now
widely used by toolchains like wasm-bindgen. This makes sites like
wordsalad.online load in Ladybird.
2026-03-07 16:05:20 +01:00
Jelle Raaijmakers
f764b881bc
LibWasm: Add reference type subtyping to the validator
...
The typed function references proposal requires subtype checking: e.g.
(ref $t) is a subtype of (ref func), and a non-nullable reference is a
subtype of its nullable counterpart. This is needed for correct
validation of `call_ref` and `return_call_ref`.
2026-03-07 16:05:20 +01:00
Jelle Raaijmakers
f78fa73a48
LibWasm: Remove unused current_module field
2026-03-07 16:05:20 +01:00
Ali Mohammad Pur
0e7fb1386e
LibWasm: Use the right indices for i64 constlocal fused ops
...
Also aligns the i32 ones to use the same detection logic as the i64
cases.
2026-02-23 00:22:47 +01:00
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
27a66c33c5
LibWasm: Validate struct types and type section
...
Spec tests struct.{3,4} are enabled again as they are now correctly
validated.
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
Rocco Corsi
d2ddf5d91d
LibWasm: Disable direct threading on debug+gcc15
...
In preperation for Ubuntu 26.04 LTS, which will most likely come default
with GNU GCC 15.2.0 (but should have versions 14 and 16 available),
found that musttail/tail-call optimization fails for non-release builds.
Testing done on Ubuntu 25.10 which has GNU GCC 15.2.0 as default,
checking: Release, Debug, All_Debug, Sanitizer, and Distribution.
Fixes : #6745
2026-02-10 01:58:40 +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
0dc39e9bfd
LibWasm: Use the source_value() mechanism in binary_numeric_operation
...
This avoids a bunch of extra stack ops and some unnecessary loads for
registers.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
9964c64446
LibWasm: Implement the i32 const/local fusions for i64 too
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
a0ce33e616
LibWasm: Preserve the right number of values on loop entry
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
a5db31943e
LibWasm: Fix return_call label stack shrink
...
The label stack should be shrunk to the frame's label_index (exclusive),
not label_index + 1. Also add the missing shrink call for
return_call_indirect.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
f6d6144d2f
LibWasm: Skip some checks in release_arguments_allocation when no frame
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
9d7c56d7ab
LibWasm: Defer the load of addresses until after dispatch
...
This unlocks a significant (+50%) performance improvement that previous
commits have been building up towards.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
7f5ca14f58
LibWasm: Specialize instruction dispatch for all-stack cases too
2026-02-02 14:11:49 +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
2d15ef7372
LibWasm: Remove all runtime VERIFYs from the 'block' handler
...
All of these are already checked at the verification stage, so downgrade
them to ASSERTs.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
0e6943b17d
LibWasm: Avoid unnecessary bounds checks in memory ops
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
ae9ced65b7
LibWasm: Add a bunch more fused ops
...
- synthetic_argument_set, synthetic_argument_tee
- synthetic_local_get_0..7, synthetic_local_set_0..7
- synthetic_br_nostack, synthetic_br_if_nostack
- synthetic_local_copy for local-to-local copies
- synthetic_i32_{sub,mul,and,or,xor,shl,shru,shrs}2local
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
f180d90c20
LibWasm: Re-add trace logging to handlers
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
0d5363caff
LibWasm: Compress current_ip + addresses into one u64 field
...
This saves a register, which then consequently saves us from spilling on
the stack (in most places that matter).
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
446240da63
LibWasm: Specialise source/dest accesses based on stack access
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
be9d8288ef
LibWasm: Take call arguments and results on registers if possible
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
Ali Mohammad Pur
ac979648bd
AK+LibJS: Zero out new Vector allocs instead of calling trivial ctor
...
As JS::Value is marked "trivial" without actually being trivial, make
the one user that would lead to garbage JS::Value entries provide a
default value instead.
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
c9f4d87c3a
LibWasm: Ensure alignment values larger than 64 are rejected
...
The instruction would be rejected for _much_ smaller values, but we
shouldn't try to calculate (u64)1<<x with x>64.
2025-12-12 19:12:53 +01:00
Ali Mohammad Pur
b93c17e5e7
LibWasm: Implement (n)madd/vetor dot arguments the right way
...
Previously we were reading the arguments in an incorrect order, and
placing the result in the wrong slot.
This also removes the hacky implementation of accumulative relaxed dot,
and just implements it directly as a new operator.
2025-12-12 19:12:53 +01:00
Ali Mohammad Pur
651c64ebac
LibWasm: Better handle oversized table allocation requests
2025-12-12 19:12:53 +01:00
Rocco Corsi
c9e9208dca
LibWasm: Make debug messages have unique wording
2025-12-12 19:12:19 +01:00
Rocco Corsi
bc77eb5869
LibWasm: Memory access out of bound debug enabled permanently
2025-12-12 01:26:30 +01:00
Ali Mohammad Pur
c8043dbb73
LibWasm: Disable direct threading entirely if musttail is not available
...
Otherwise we can end up crashing due to stack overflow (see #7009 ).
2025-12-08 02:22:13 +01:00
Undefine
7bccd65b4a
LibWasm: Make sure try_table creates a new frame while validating
...
The spec says that while validating this opcode a new label should
be pushed.
Fixes a crash in instance.wast on WPT.
2025-10-19 17:28:11 +02:00
Undefine
07c86542b6
LibWasm: Properly read and validate limits for I64 memories and tables
...
Since memory64 got merged into the spec the minimum value for limits
is now actualy 64-bit and the maximum sizes for memories and tables
for I64 address types were increased.
Fixes 5 tests in memory64.wast nad 8 tests in table64.wast on WPT.
2025-10-19 17:28:11 +02:00
Undefine
692195ae88
LibWasm: Cast to long double before checking if trunactions is in range
...
I found that this fixes some precision issues while comparing to values
on the edge of the limits.
Fixes 6 tests in conversions.wast on WPT.
2025-10-19 17:28:11 +02: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
8138c2f48b
LibWasm: Follow the updated spec on instantiation
...
The spec now permits access to all globals for all segment initializers,
as well as previously-defined globals for the global initializers.
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
d6f3f5fd51
LibWasm: Implement proposal 'relaxed-simd'
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
77237af33f
LibWasm: Add support for proposal 'extended-const'
2025-10-15 01:26:29 +02:00