Skip to content

Commit

Permalink
Add GetByIndex
Browse files Browse the repository at this point in the history
Reviewed By: neildhar

Differential Revision: D61743976

fbshipit-source-id: b29f2bf5c0f7ae9a6b26f168e02da3d499f329d5
  • Loading branch information
avp authored and facebook-github-bot committed Aug 28, 2024
1 parent 63eb199 commit 63034eb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/VM/JIT/arm64/JIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ JITCompiledFunctionPtr JITContext::compileImpl(
ip = NEXTINST(PutByValStrict);
break;

case inst::OpCode::GetByIndex:
em.getByIndex(
FR(ip->iGetByIndex.op1),
FR(ip->iGetByIndex.op2),
ip->iGetByIndex.op3);
ip = NEXTINST(GetByIndex);
break;

case inst::OpCode::Ret:
em.ret(FR(ip->iRet.op1));
ip = NEXTINST(Ret);
Expand Down
17 changes: 17 additions & 0 deletions lib/VM/JIT/arm64/JitEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,23 @@ void Emitter::getByVal(FR frRes, FR frSource, FR frKey) {
frUpdatedWithHWReg(frRes, hwRes);
}

void Emitter::getByIndex(FR frRes, FR frSource, uint8_t key) {
comment("// getByIdx r%u, r%u, %u", frRes.index(), frSource.index(), key);

syncAllTempExcept(frRes != frSource ? frRes : FR());
syncToMem(frSource);
freeAllTempExcept({});

a.mov(a64::x0, xRuntime);
loadFrameAddr(a64::x1, frSource);
a.mov(a64::w2, key);
EMIT_RUNTIME_CALL(*this, _sh_ljs_get_by_index_rjs);

HWReg hwRes = getOrAllocFRInAnyReg(frRes, false, HWReg::gpX(0));
movHWReg<false>(hwRes, HWReg::gpX(0));
frUpdatedWithHWReg(frRes, hwRes);
}

void Emitter::putByIdImpl(
FR frTarget,
SHSymbolID symID,
Expand Down
1 change: 1 addition & 0 deletions lib/VM/JIT/arm64/JitEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class Emitter {
#undef DECL_JCOND

void getByVal(FR frRes, FR frSource, FR frKey);
void getByIndex(FR frRes, FR frSource, uint8_t key);

#define DECL_PUT_BY_VAL(methodName, commentStr, shFn) \
void methodName(FR frTarget, FR frKey, FR frValue) { \
Expand Down
13 changes: 13 additions & 0 deletions test/jit/objops.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function isIn(a, prop) {
return prop in a;
}

function getByIndex(o) {
return o[1];
}

print("foo", foo());
// CHECK: JIT successfully compiled FunctionID 1, 'foo'
// CHECK-NEXT: foo 30
Expand All @@ -43,3 +47,12 @@ print("isIn", isIn({}, "prop"));
// CHECK-NEXT: isIn false
print("isIn", isIn({prop: 1}, "prop"));
// CHECK-NEXT: isIn true
print("getByIndex", getByIndex(0));
// CHECK: JIT successfully compiled FunctionID 4, 'getByIndex'
// CHECK-NEXT: getByIndex undefined
print("getByIndex", getByIndex("abc"));
// CHECK-NEXT: getByIndex b
print("getByIndex", getByIndex([10, 20, 30]));
// CHECK-NEXT: getByIndex 20
print("getByIndex", getByIndex({0:11, 1: 21, 2: 31}));
// CHECK-NEXT: getByIndex 21

0 comments on commit 63034eb

Please sign in to comment.