From 9478ed5f7245d2b1aaf4edde95e688e3d8ebe8d2 Mon Sep 17 00:00:00 2001 From: lichenshuai Date: Tue, 11 Jan 2022 15:09:47 +0800 Subject: [PATCH] Add DECDYN stub. Signed-off-by: lichenshuai --- ecmascript/compiler/fast_stub_define.h | 3 +- ecmascript/compiler/interpreter_stub.cpp | 62 ++++++++++++++++++- ecmascript/compiler/interpreter_stub_define.h | 1 + ecmascript/compiler/stub_descriptor.cpp | 15 +++++ ecmascript/js_thread.cpp | 1 + ecmascript/runtime_trampolines.cpp | 10 +++ ecmascript/runtime_trampolines.h | 1 + 7 files changed, 91 insertions(+), 2 deletions(-) diff --git a/ecmascript/compiler/fast_stub_define.h b/ecmascript/compiler/fast_stub_define.h index fe352198b5..597b2109ea 100644 --- a/ecmascript/compiler/fast_stub_define.h +++ b/ecmascript/compiler/fast_stub_define.h @@ -48,7 +48,8 @@ namespace panda::ecmascript::kungfu { V(JumpToCInterpreter, 7) \ V(DebugPrint, 1) \ V(StGlobalRecord, 4) \ - V(IncDyn, 2) + V(IncDyn, 2) \ + V(DecDyn, 2) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define FAST_RUNTIME_STUB_LIST(V) \ diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index a974ece6b8..e1014c46a1 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -471,7 +471,67 @@ void HandleIncdynPrefV8Stub::GenerateCircuit(const CompilationConfig *cfg) // slow path StubDescriptor *incDyn = GET_STUBDESCRIPTOR(IncDyn); acc = CallRuntime(incDyn, glue, GetWord64Constant(FAST_STUB_ID(IncDyn)), - {glue, value}); + {glue, value}); + Jump(&accDispatch); + } + + Bind(&accDispatch); + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, + GetArchRelateConstant(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_V8))); +} + +void HandleDecdynPrefV8Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is value */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is value */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is value */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is value */ + + GateRef v0 = ReadInst8_1(pc); + GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0)); + Label valueIsInt(env); + Label valueNotInt(env); + Label accDispatch(env); + Branch(TaggedIsInt(value), &valueIsInt, &valueNotInt); + Bind(&valueIsInt); + { + GateRef valueInt = TaggedCastToInt32(value); + Label valueOverflow(env); + Label valueNoOverflow(env); + Branch(Word32Equal(valueInt, GetInt32Constant(INT32_MIN)), &valueOverflow, &valueNoOverflow); + Bind(&valueOverflow); + { + GateRef valueDoubleFromInt = ChangeInt32ToFloat64(valueInt); + acc = DoubleBuildTaggedWithNoGC(DoubleSub(valueDoubleFromInt, GetDoubleConstant(1.0))); + Jump(&accDispatch); + } + Bind(&valueNoOverflow); + { + acc = IntBuildTaggedWithNoGC(Int32Sub(valueInt, GetInt32Constant(1))); + Jump(&accDispatch); + } + } + Bind(&valueNotInt); + Label valueIsDouble(env); + Label valueNotDouble(env); + Branch(TaggedIsDouble(value), &valueIsDouble, &valueNotDouble); + Bind(&valueIsDouble); + { + GateRef valueDouble = TaggedCastToDouble(value); + acc = DoubleBuildTaggedWithNoGC(DoubleSub(valueDouble, GetDoubleConstant(1.0))); + Jump(&accDispatch); + } + Bind(&valueNotDouble); + { + // slow path + StubDescriptor *decDyn = GET_STUBDESCRIPTOR(DecDyn); + acc = CallRuntime(decDyn, glue, GetWord64Constant(FAST_STUB_ID(DecDyn)), + {glue, value}); Jump(&accDispatch); } diff --git a/ecmascript/compiler/interpreter_stub_define.h b/ecmascript/compiler/interpreter_stub_define.h index 0d8c88ac9b..67a2e3230e 100644 --- a/ecmascript/compiler/interpreter_stub_define.h +++ b/ecmascript/compiler/interpreter_stub_define.h @@ -23,6 +23,7 @@ namespace panda::ecmascript::kungfu { V(HandleStLexVarDynPrefImm8Imm8V8, 7) \ V(HandleStLexVarDynPrefImm16Imm16V8, 7) \ V(HandleIncdynPrefV8, 7) \ + V(HandleDecdynPrefV8, 7) \ V(HandleStConstToGlobalRecordPrefId32, 7) \ V(HandleStLetToGlobalRecordPrefId32, 7) \ V(HandleStClassToGlobalRecordPrefId32, 7) diff --git a/ecmascript/compiler/stub_descriptor.cpp b/ecmascript/compiler/stub_descriptor.cpp index 4d478b62d9..1523c10b1e 100644 --- a/ecmascript/compiler/stub_descriptor.cpp +++ b/ecmascript/compiler/stub_descriptor.cpp @@ -741,6 +741,21 @@ CALL_STUB_INIT_DESCRIPTOR(IncDyn) descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); } +CALL_STUB_INIT_DESCRIPTOR(DecDyn) +{ + // 2 : 2 input parameters + StubDescriptor decDyn("DecDyn", 0, 2, + ArgumentsOrder::DEFAULT_ORDER, MachineType::TAGGED); + *descriptor = decDyn; + // 2 : 2 input parameters + std::array params = { + MachineType::NATIVE_POINTER, + MachineType::TAGGED, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + CALL_STUB_INIT_DESCRIPTOR(StGlobalRecord) { // 4 : 4 input parameters diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index 6b0d374d61..24e9c2cf1e 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -252,6 +252,7 @@ void JSThread::LoadStubModule(const char *moduleFile) bytecodeHandlers_[EcmaOpcode::STLEXVARDYN_PREF_IMM16_IMM16_V8] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStLexVarDynPrefImm16Imm16V8); bytecodeHandlers_[EcmaOpcode::INCDYN_PREF_V8] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleIncdynPrefV8); + bytecodeHandlers_[EcmaOpcode::DECDYN_PREF_V8] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleDecdynPrefV8); bytecodeHandlers_[EcmaOpcode::STCONSTTOGLOBALRECORD_PREF_ID32] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStConstToGlobalRecordPrefId32); bytecodeHandlers_[EcmaOpcode::STLETTOGLOBALRECORD_PREF_ID32] = diff --git a/ecmascript/runtime_trampolines.cpp b/ecmascript/runtime_trampolines.cpp index 8002a3e881..188ed3849a 100644 --- a/ecmascript/runtime_trampolines.cpp +++ b/ecmascript/runtime_trampolines.cpp @@ -399,6 +399,16 @@ JSTaggedType RuntimeTrampolines::IncDyn(uintptr_t argGlue, JSTaggedType value) return (++number).GetRawData(); } +JSTaggedType RuntimeTrampolines::DecDyn(uintptr_t argGlue, JSTaggedType value) +{ + auto thread = JSThread::GlueToJSThread(argGlue); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + + JSHandle valueHandle(thread, JSTaggedValue(value)); + JSTaggedNumber number = JSTaggedValue::ToNumber(thread, valueHandle); + return (--number).GetRawData(); +} + JSTaggedType RuntimeTrampolines::StGlobalRecord(uintptr_t argGlue, JSTaggedType prop, JSTaggedType value, bool isConst) { auto thread = JSThread::GlueToJSThread(argGlue); diff --git a/ecmascript/runtime_trampolines.h b/ecmascript/runtime_trampolines.h index 4887e28a1b..f2852e4904 100644 --- a/ecmascript/runtime_trampolines.h +++ b/ecmascript/runtime_trampolines.h @@ -80,6 +80,7 @@ public: uint64_t constpool, uint64_t profileTypeInfo, uint64_t acc, int32_t hotnessCounter); static JSTaggedType IncDyn(uintptr_t argGlue, JSTaggedType value); + static JSTaggedType DecDyn(uintptr_t argGlue, JSTaggedType value); static JSTaggedType StGlobalRecord(uintptr_t argGlue, JSTaggedType prop, JSTaggedType value, bool isConst); }; } // namespace panda::ecmascript -- Gitee