Skip to content

Commit

Permalink
Add a fast path for ToInt32
Browse files Browse the repository at this point in the history
Summary:
Like other operations that need an int32, we can add a fast path for
ToInt32 that performs the conversion inline.

Reviewed By: lavenzg

Differential Revision: D65826733

fbshipit-source-id: 6b689e84de3123e8ea25081f26baf997767ebb1c
  • Loading branch information
neildhar authored and facebook-github-bot committed Nov 23, 2024
1 parent 089f7d5 commit 0308342
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/VM/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2729,11 +2729,18 @@ CallResult<HermesValue> Interpreter::interpretFunction(
}

CASE(ToInt32) {
CAPTURE_IP(res = toInt32_RJS(runtime, Handle<>(&O2REG(ToInt32))));
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION))
goto exception;
gcScope.flushToSmallCount(KEEP_HANDLES);
O1REG(ToInt32) = res.getValue();
int32_t argInt;
if (LLVM_LIKELY(
_sh_ljs_tryfast_truncate_to_int32(O2REG(ToInt32), &argInt))) {
/* Fast-path. */
O1REG(ToInt32) = HermesValue::encodeTrustedNumberValue(argInt);
} else {
CAPTURE_IP(res = toInt32_RJS(runtime, Handle<>(&O2REG(ToInt32))));
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION))
goto exception;
gcScope.flushToSmallCount(KEEP_HANDLES);
O1REG(ToInt32) = res.getValue();
}
ip = NEXTINST(ToInt32);
DISPATCH;
}
Expand Down

0 comments on commit 0308342

Please sign in to comment.