LibJS: Flatten Operand to 32-bit index in bytecode instruction stream

While we're in the bytecode compiler, we want to know which type of
Operand we're dealing with, but once we've generated the bytecode
stream, we only ever need its index.

This patch simplifies Operand by removing the aarch64 bitfield hacks
and makes it 32-bit on all platforms. We keep 3 type bits in the high
bits of the index while compiling, and then zero them out when
flattening the final bytecode stream.

This makes bytecode more compact on x86_64, and avoids bit twiddling
on aarch64. Everyone wins something!

When stringifying bytecode for debugging output, we now have an API in
Executable that can look at a raw operand index and tell you what type
of operand it was, based on known quantities of each type in the stack
frame.
This commit is contained in:
Andreas Kling
2025-11-22 12:27:51 +01:00
committed by Andreas Kling
parent 3248f5bc59
commit 9f822345bf
Notes: github-actions[bot] 2025-12-10 03:48:09 +00:00
7 changed files with 51 additions and 48 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021-2025, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -115,4 +115,15 @@ UnrealizedSourceRange Executable::source_range_at(size_t offset) const
};
}
Operand Executable::original_operand_from_raw(u32 raw) const
{
if (raw < number_of_registers)
return Operand { Operand::Type::Register, raw };
if (raw < local_index_base)
return Operand { Operand::Type::Constant, raw - static_cast<u32>(number_of_registers) };
if (raw < argument_index_base)
return Operand { Operand::Type::Local, raw - static_cast<u32>(local_index_base) };
return Operand { Operand::Type::Argument, raw - static_cast<u32>(argument_index_base) };
}
}