Skip to content

Commit 3c2a2bb

Browse files
committed
LibJS: Shrink JS::Bytecode::Operand from 8 bytes to 4 bytes
This packs the bytecode much better and gives us a decent performance boost on throughput-focused benchmarks. Measured on my M3 MacBook Pro: - 4.7% speedup on Kraken - 2.3% speedup on Octane - 2.7% speedup on JetStream1
1 parent 70411a1 commit 3c2a2bb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Libraries/LibJS/Bytecode/Operand.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JS::Bytecode {
1313

1414
class Operand {
1515
public:
16-
enum class Type {
16+
enum class Type : u8 {
1717
Invalid,
1818
Register,
1919
Local,
@@ -26,6 +26,7 @@ class Operand {
2626
: m_type(type)
2727
, m_index(index)
2828
{
29+
VERIFY((index & 0x3fffffff) == index);
2930
}
3031

3132
explicit Operand(Register);
@@ -42,10 +43,12 @@ class Operand {
4243
void offset_index_by(u32 offset) { m_index += offset; }
4344

4445
private:
45-
Type m_type {};
46-
u32 m_index { 0 };
46+
Type m_type : 2 {};
47+
u32 m_index : 30 { 0 };
4748
};
4849

50+
static_assert(sizeof(Operand) == 4);
51+
4952
}
5053

5154
namespace AK {

0 commit comments

Comments
 (0)