LibJS: Add fast path for multiplying two Int32 values

We can avoid a lot of work here, as long as the result doesn't overflow
the Int32 range.

5% speed-up on Kraken/imaging-gaussian-blur.js :^)
This commit is contained in:
Andreas Kling 2023-10-04 15:48:29 +02:00
parent 14a9cfef4d
commit 111622a164

View file

@ -1818,6 +1818,14 @@ ThrowCompletionOr<Value> sub(VM& vm, Value lhs, Value rhs)
// MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression
ThrowCompletionOr<Value> mul(VM& vm, Value lhs, Value rhs)
{
// OPTIMIZATION: Fast path for multiplication of two Int32 values.
if (lhs.is_int32() && rhs.is_int32()) {
Checked<i32> result = lhs.as_i32();
result *= rhs.as_i32();
if (!result.has_overflow())
return result.value();
}
// 13.15.3 ApplyStringOrNumericBinaryOperator ( lval, opText, rval ), https://tc39.es/ecma262/#sec-applystringornumericbinaryoperator
// 1-2, 6. N/A.