Skip to content

Commit

Permalink
Interpreter: add _RJS suffix to some functions
Browse files Browse the repository at this point in the history
Summary:
Some interpreter helpers were missing the _RJS suffix. I discovered this
while annotation IR instructions for it.

Reviewed By: neildhar

Differential Revision: D42297945

fbshipit-source-id: 817587cbfeeb23cd5ad096a48f7069b81f93f85d
  • Loading branch information
Tzvetan Mikov authored and facebook-github-bot committed Jan 10, 2023
1 parent 4ab8204 commit 504a4d4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 50 deletions.
14 changes: 8 additions & 6 deletions lib/VM/Interpreter-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,24 @@ inline double doDec(double d) {

template <auto Oper>
CallResult<HermesValue>
doOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template <auto Oper>
CallResult<HermesValue>
doBitOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doBitOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template <auto Oper>
CallResult<HermesValue>
doShiftOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doShiftOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template <auto Oper>
CallResult<HermesValue> doIncDecOperSlowPath(Runtime &runtime, Handle<> src);
CallResult<HermesValue> doIncDecOperSlowPath_RJS(
Runtime &runtime,
Handle<> src);

CallResult<HermesValue> doBitNotSlowPath(Runtime &runtime, Handle<> src);
CallResult<HermesValue> doBitNotSlowPath_RJS(Runtime &runtime, Handle<> src);

CallResult<HermesValue> doNegateSlowPath(Runtime &runtime, Handle<> src);
CallResult<HermesValue> doNegateSlowPath_RJS(Runtime &runtime, Handle<> src);

} // namespace vm
} // namespace hermes
Expand Down
42 changes: 23 additions & 19 deletions lib/VM/Interpreter-slowpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ constexpr auto &BigIntOper<doDec> = BigIntPrimitive::dec;

template <auto Oper>
CallResult<HermesValue>
doOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
doOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
CallResult<HermesValue> res =
toPrimitive_RJS(runtime, lhs, PreferredType::NUMBER);
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
Expand All @@ -398,20 +398,20 @@ doOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
}

template CallResult<HermesValue>
doOperSlowPath<doDiv>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doOperSlowPath_RJS<doDiv>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doOperSlowPath<doMod>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doOperSlowPath_RJS<doMod>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doOperSlowPath<doMul>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doOperSlowPath_RJS<doMul>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doOperSlowPath<doSub>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doOperSlowPath_RJS<doSub>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template <auto Oper>
CallResult<HermesValue>
doBitOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
doBitOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
CallResult<HermesValue> res =
toPrimitive_RJS(runtime, lhs, PreferredType::NUMBER);
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
Expand All @@ -435,13 +435,13 @@ doBitOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
}

template CallResult<HermesValue>
doBitOperSlowPath<doBitAnd>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doBitOperSlowPath_RJS<doBitAnd>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doBitOperSlowPath<doBitOr>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doBitOperSlowPath_RJS<doBitOr>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doBitOperSlowPath<doBitXor>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doBitOperSlowPath_RJS<doBitXor>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

namespace {
/// ToIntegral maps the \param Oper shift operation (on Number) to the function
Expand All @@ -463,7 +463,7 @@ inline constexpr auto &ToIntegral<doURshift> = toUInt32_RJS;

template <auto Oper>
CallResult<HermesValue>
doShiftOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
doShiftOperSlowPath_RJS(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
CallResult<HermesValue> res =
toPrimitive_RJS(runtime, std::move(lhs), PreferredType::NUMBER);

Expand Down Expand Up @@ -492,16 +492,20 @@ doShiftOperSlowPath(Runtime &runtime, Handle<> lhs, Handle<> rhs) {
}

template CallResult<HermesValue>
doShiftOperSlowPath<doLShift>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doShiftOperSlowPath_RJS<doLShift>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doShiftOperSlowPath<doRShift>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
doShiftOperSlowPath_RJS<doRShift>(Runtime &runtime, Handle<> lhs, Handle<> rhs);

template CallResult<HermesValue>
doShiftOperSlowPath<doURshift>(Runtime &runtime, Handle<> lhs, Handle<> rhs);
template CallResult<HermesValue> doShiftOperSlowPath_RJS<doURshift>(
Runtime &runtime,
Handle<> lhs,
Handle<> rhs);

template <auto Oper>
CallResult<HermesValue> doIncDecOperSlowPath(Runtime &runtime, Handle<> src) {
CallResult<HermesValue> doIncDecOperSlowPath_RJS(
Runtime &runtime,
Handle<> src) {
CallResult<HermesValue> res =
toPrimitive_RJS(runtime, std::move(src), PreferredType::NUMBER);
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
Expand All @@ -519,15 +523,15 @@ CallResult<HermesValue> doIncDecOperSlowPath(Runtime &runtime, Handle<> src) {
return BigIntOper<Oper>(runtime, runtime.makeHandle(res->getBigInt()));
}

template CallResult<HermesValue> doIncDecOperSlowPath<doInc>(
template CallResult<HermesValue> doIncDecOperSlowPath_RJS<doInc>(
Runtime &runtime,
Handle<> src);

template CallResult<HermesValue> doIncDecOperSlowPath<doDec>(
template CallResult<HermesValue> doIncDecOperSlowPath_RJS<doDec>(
Runtime &runtime,
Handle<> src);

CallResult<HermesValue> doBitNotSlowPath(Runtime &runtime, Handle<> src) {
CallResult<HermesValue> doBitNotSlowPath_RJS(Runtime &runtime, Handle<> src) {
// Try converting src to a numeric.
auto numRes = toNumeric_RJS(runtime, src);
if (LLVM_UNLIKELY(numRes == ExecutionStatus::EXCEPTION))
Expand All @@ -543,7 +547,7 @@ CallResult<HermesValue> doBitNotSlowPath(Runtime &runtime, Handle<> src) {
return BigIntPrimitive::unaryNOT(runtime, bigint);
}

CallResult<HermesValue> doNegateSlowPath(Runtime &runtime, Handle<> src) {
CallResult<HermesValue> doNegateSlowPath_RJS(Runtime &runtime, Handle<> src) {
// Try converting src to a numeric.
auto numRes = toNumeric_RJS(runtime, src);
if (LLVM_UNLIKELY(numRes == ExecutionStatus::EXCEPTION))
Expand Down
52 changes: 27 additions & 25 deletions lib/VM/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ CallResult<HermesValue> Interpreter::interpretFunction(
} \
} \
CAPTURE_IP( \
res = doOperSlowPath<do##name>( \
res = doOperSlowPath_RJS<do##name>( \
runtime, Handle<>(&O2REG(name)), Handle<>(&O3REG(name)))); \
if (res == ExecutionStatus::EXCEPTION) \
goto exception; \
Expand All @@ -1174,25 +1174,25 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH; \
}

#define INCDECOP(name) \
CASE(name) { \
if (LLVM_LIKELY(O2REG(name).isNumber())) { \
O1REG(name) = \
HermesValue::encodeDoubleValue(do##name(O2REG(name).getNumber())); \
gcScope.flushToSmallCount(KEEP_HANDLES); \
ip = NEXTINST(name); \
DISPATCH; \
} \
CAPTURE_IP( \
res = \
doIncDecOperSlowPath<do##name>(runtime, Handle<>(&O2REG(name)))); \
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) { \
goto exception; \
} \
O1REG(name) = *res; \
gcScope.flushToSmallCount(KEEP_HANDLES); \
ip = NEXTINST(name); \
DISPATCH; \
#define INCDECOP(name) \
CASE(name) { \
if (LLVM_LIKELY(O2REG(name).isNumber())) { \
O1REG(name) = \
HermesValue::encodeDoubleValue(do##name(O2REG(name).getNumber())); \
gcScope.flushToSmallCount(KEEP_HANDLES); \
ip = NEXTINST(name); \
DISPATCH; \
} \
CAPTURE_IP( \
res = doIncDecOperSlowPath_RJS<do##name>( \
runtime, Handle<>(&O2REG(name)))); \
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) { \
goto exception; \
} \
O1REG(name) = *res; \
gcScope.flushToSmallCount(KEEP_HANDLES); \
ip = NEXTINST(name); \
DISPATCH; \
}

/// Implement a shift instruction with a fast path where both
Expand All @@ -1210,7 +1210,7 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH; \
} \
CAPTURE_IP( \
res = doShiftOperSlowPath<do##name>( \
res = doShiftOperSlowPath_RJS<do##name>( \
runtime, Handle<>(&O2REG(name)), Handle<>(&O3REG(name)))); \
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) { \
goto exception; \
Expand All @@ -1235,7 +1235,7 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH; \
} \
CAPTURE_IP( \
res = doBitOperSlowPath<do##name>( \
res = doBitOperSlowPath_RJS<do##name>( \
runtime, Handle<>(&O2REG(name)), Handle<>(&O3REG(name)))); \
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) { \
goto exception; \
Expand Down Expand Up @@ -2813,7 +2813,8 @@ CallResult<HermesValue> Interpreter::interpretFunction(
ip = NEXTINST(BitNot);
DISPATCH;
}
CAPTURE_IP(res = doBitNotSlowPath(runtime, Handle<>(&O2REG(BitNot))));
CAPTURE_IP(
res = doBitNotSlowPath_RJS(runtime, Handle<>(&O2REG(BitNot))));
if (res == ExecutionStatus::EXCEPTION) {
goto exception;
}
Expand Down Expand Up @@ -3096,7 +3097,8 @@ CallResult<HermesValue> Interpreter::interpretFunction(
ip = NEXTINST(Negate);
DISPATCH;
}
CAPTURE_IP(res = doNegateSlowPath(runtime, Handle<>(&O2REG(Negate))));
CAPTURE_IP(
res = doNegateSlowPath_RJS(runtime, Handle<>(&O2REG(Negate))));
if (res == ExecutionStatus::EXCEPTION)
goto exception;
O1REG(Negate) = *res;
Expand All @@ -3118,7 +3120,7 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH;
}
CAPTURE_IP(
res = doOperSlowPath<doMod>(
res = doOperSlowPath_RJS<doMod>(
runtime, Handle<>(&O2REG(Mod)), Handle<>(&O3REG(Mod))));
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
goto exception;
Expand Down

0 comments on commit 504a4d4

Please sign in to comment.