1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

LibJS: Avoid roundtrip through Value for comparison bytecode evaluation

1.1x speedup on strictly-equals-object.js
This commit is contained in:
Shannon Booth 2025-05-08 15:19:35 +12:00 committed by Andreas Kling
parent 90d466e7e9
commit 19bf897116
Notes: github-actions[bot] 2025-05-08 18:40:23 +00:00
4 changed files with 42 additions and 42 deletions

View file

@ -142,40 +142,40 @@ static ByteString format_value_list(StringView name, ReadonlySpan<Value> values)
return builder.to_byte_string();
}
ALWAYS_INLINE static ThrowCompletionOr<Value> loosely_inequals(VM& vm, Value src1, Value src2)
ALWAYS_INLINE static ThrowCompletionOr<bool> loosely_inequals(VM& vm, Value src1, Value src2)
{
if (src1.tag() == src2.tag()) {
if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
return Value(src1.encoded() != src2.encoded());
return src1.encoded() != src2.encoded();
}
return Value(!TRY(is_loosely_equal(vm, src1, src2)));
return !TRY(is_loosely_equal(vm, src1, src2));
}
ALWAYS_INLINE static ThrowCompletionOr<Value> loosely_equals(VM& vm, Value src1, Value src2)
ALWAYS_INLINE static ThrowCompletionOr<bool> loosely_equals(VM& vm, Value src1, Value src2)
{
if (src1.tag() == src2.tag()) {
if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
return Value(src1.encoded() == src2.encoded());
return src1.encoded() == src2.encoded();
}
return Value(TRY(is_loosely_equal(vm, src1, src2)));
return TRY(is_loosely_equal(vm, src1, src2));
}
ALWAYS_INLINE static ThrowCompletionOr<Value> strict_inequals(VM&, Value src1, Value src2)
ALWAYS_INLINE static ThrowCompletionOr<bool> strict_inequals(VM&, Value src1, Value src2)
{
if (src1.tag() == src2.tag()) {
if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
return Value(src1.encoded() != src2.encoded());
return src1.encoded() != src2.encoded();
}
return Value(!is_strictly_equal(src1, src2));
return !is_strictly_equal(src1, src2);
}
ALWAYS_INLINE static ThrowCompletionOr<Value> strict_equals(VM&, Value src1, Value src2)
ALWAYS_INLINE static ThrowCompletionOr<bool> strict_equals(VM&, Value src1, Value src2)
{
if (src1.tag() == src2.tag()) {
if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
return Value(src1.encoded() == src2.encoded());
return src1.encoded() == src2.encoded();
}
return Value(is_strictly_equal(src1, src2));
return is_strictly_equal(src1, src2);
}
Interpreter::Interpreter(VM& vm)
@ -486,7 +486,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
return; \
goto start; \
} \
if (result.value().to_boolean()) \
if (result.value()) \
program_counter = instruction.true_target().address(); \
else \
program_counter = instruction.false_target().address(); \
@ -1932,7 +1932,7 @@ void Dump::execute_impl(Bytecode::Interpreter& interpreter) const
auto& vm = interpreter.vm(); \
auto lhs = interpreter.get(m_lhs); \
auto rhs = interpreter.get(m_rhs); \
interpreter.set(m_dst, TRY(op_snake_case(vm, lhs, rhs))); \
interpreter.set(m_dst, Value { TRY(op_snake_case(vm, lhs, rhs)) }); \
return {}; \
}
@ -2106,7 +2106,7 @@ ThrowCompletionOr<void> LessThan::execute_impl(Bytecode::Interpreter& interprete
interpreter.set(m_dst, Value(lhs.as_double() < rhs.as_double()));
return {};
}
interpreter.set(m_dst, TRY(less_than(vm, lhs, rhs)));
interpreter.set(m_dst, Value { TRY(less_than(vm, lhs, rhs)) });
return {};
}
@ -2123,7 +2123,7 @@ ThrowCompletionOr<void> LessThanEquals::execute_impl(Bytecode::Interpreter& inte
interpreter.set(m_dst, Value(lhs.as_double() <= rhs.as_double()));
return {};
}
interpreter.set(m_dst, TRY(less_than_equals(vm, lhs, rhs)));
interpreter.set(m_dst, Value { TRY(less_than_equals(vm, lhs, rhs)) });
return {};
}
@ -2140,7 +2140,7 @@ ThrowCompletionOr<void> GreaterThan::execute_impl(Bytecode::Interpreter& interpr
interpreter.set(m_dst, Value(lhs.as_double() > rhs.as_double()));
return {};
}
interpreter.set(m_dst, TRY(greater_than(vm, lhs, rhs)));
interpreter.set(m_dst, Value { TRY(greater_than(vm, lhs, rhs)) });
return {};
}
@ -2157,7 +2157,7 @@ ThrowCompletionOr<void> GreaterThanEquals::execute_impl(Bytecode::Interpreter& i
interpreter.set(m_dst, Value(lhs.as_double() >= rhs.as_double()));
return {};
}
interpreter.set(m_dst, TRY(greater_than_equals(vm, lhs, rhs)));
interpreter.set(m_dst, Value { TRY(greater_than_equals(vm, lhs, rhs)) });
return {};
}