LibJS: Fast path for Increment of Int32 value in bytecode interpreter
5% speed-up on Kraken/ai-astar.js in interpreter mode. :^)
This commit is contained in:
parent
9fcd6776cf
commit
9326ded5a4
Notes:
sideshowbarker
2024-07-17 06:46:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9326ded5a4 Pull-request: https://github.com/SerenityOS/serenity/pull/22969
1 changed files with 13 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -1045,7 +1045,18 @@ ThrowCompletionOr<void> Return::execute_impl(Bytecode::Interpreter& interpreter)
|
|||
ThrowCompletionOr<void> Increment::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto old_value = TRY(interpreter.accumulator().to_numeric(vm));
|
||||
auto old_value = interpreter.accumulator();
|
||||
|
||||
// OPTIMIZATION: Fast path for Int32 values.
|
||||
if (old_value.is_int32()) {
|
||||
auto integer_value = old_value.as_i32();
|
||||
if (integer_value != NumericLimits<i32>::max()) [[likely]] {
|
||||
interpreter.accumulator() = Value { integer_value + 1 };
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
old_value = TRY(old_value.to_numeric(vm));
|
||||
|
||||
if (old_value.is_number())
|
||||
interpreter.accumulator() = Value(old_value.as_double() + 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue