Skip to content

Commit

Permalink
LibJS/Bytecode: Add fast path for LeftShift with Int32 operands
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Mar 4, 2024
1 parent 8e04791 commit a5e1e66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Userland/Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,20 @@ ThrowCompletionOr<void> RightShift::execute_impl(Bytecode::Interpreter& interpre
return {};
}

ThrowCompletionOr<void> LeftShift::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
auto const lhs = interpreter.get(m_lhs);
auto const rhs = interpreter.get(m_rhs);
if (lhs.is_int32() && rhs.is_int32() && rhs.as_i32() >= 0) {
auto const shift_count = static_cast<u32>(rhs.as_i32()) % 32;
interpreter.set(m_dst, Value(lhs.as_i32() << shift_count));
return {};
}
interpreter.set(m_dst, TRY(left_shift(vm, lhs, rhs)));
return {};
}

ThrowCompletionOr<void> LessThan::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Bytecode/Op.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Mov final : public Instruction {
O(BitwiseXor, bitwise_xor) \
O(GreaterThan, greater_than) \
O(GreaterThanEquals, greater_than_equals) \
O(LeftShift, left_shift) \
O(LessThan, less_than) \
O(LessThanEquals, less_than_equals) \
O(Mul, mul) \
Expand All @@ -75,8 +76,7 @@ class Mov final : public Instruction {
O(LooselyInequals, loosely_inequals) \
O(LooselyEquals, loosely_equals) \
O(StrictlyInequals, strict_inequals) \
O(StrictlyEquals, strict_equals) \
O(LeftShift, left_shift)
O(StrictlyEquals, strict_equals)

#define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
class OpTitleCase final : public Instruction { \
Expand Down

0 comments on commit a5e1e66

Please sign in to comment.