From 6c4e4e44061252c8a3ec9e62ba29ccf3e0197107 Mon Sep 17 00:00:00 2001 From: wanghuan Date: Sat, 2 Apr 2022 17:04:17 +0800 Subject: [PATCH] fix expdyn stub handle error in bigint desc: fix expdyn stub handle error in bigint solution: 1. Slowruntime expdyn need adaption to bigint, but stub's slowruntime doesn't modify. So fill up modification. issue: https://gitee.com/openharmony/ark_js_runtime/issues/I50ZRS Signed-off-by: wanghuan Change-Id: I46e4b11f3ed54239becdb3f80b5cea94d93f505b --- ecmascript/compiler/interpreter_stub.cpp | 2 +- ecmascript/stubs/runtime_stubs-inl.h | 21 ++++++++++++++------- ecmascript/stubs/runtime_stubs.cpp | 3 +-- ecmascript/stubs/runtime_stubs.h | 3 +-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index d751c0e8..13ed66e1 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -41,7 +41,7 @@ void name##Stub::GenerateCircuit(const CompilationConfig *cfg) GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is value */ \ GateRef acc = TaggedArgument(5); /* 5: 6th parameter is value */ \ GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is value */ \ - DebugPrint(glue, { Int32(GET_MESSAGE_STRING_ID(name)) }); \ + DebugPrint(glue, { Int32(GET_MESSAGE_STRING_ID(name)) }); \ GenerateCircuitImpl(glue, pc, sp, constpool, profileTypeInfo, acc, hotnessCounter); \ } \ void name##Stub::GenerateCircuitImpl(GateRef glue, GateRef pc, GateRef sp, \ diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 520e8307..3134f741 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -58,19 +58,26 @@ JSTaggedValue RuntimeStubs::RuntimeDecDyn(JSThread *thread, const JSHandle &base, - const JSHandle &exponent) +JSTaggedValue RuntimeStubs::RuntimeExpDyn(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent) { - JSTaggedNumber baseNumber = JSTaggedValue::ToNumber(thread, base); + JSHandle valBase = JSTaggedValue::ToNumeric(thread, base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double doubleBase = baseNumber.GetNumber(); - JSTaggedNumber exponentNumber = JSTaggedValue::ToNumber(thread, exponent); + JSHandle valExponent = JSTaggedValue::ToNumeric(thread, exponent); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double doubleExponent = exponentNumber.GetNumber(); + if (valBase->IsBigInt() || valExponent->IsBigInt()) { + if (valBase->IsBigInt() && valExponent->IsBigInt()) { + JSHandle bigBaseVale(valBase); + JSHandle bigExponentValue(valExponent); + return BigInt::Exponentiate(thread, bigBaseVale, bigExponentValue).GetTaggedValue(); + } + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot mix BigInt and other types, use explicit conversions", + JSTaggedValue::Exception()); + } + double doubleBase = valBase->GetNumber(); + double doubleExponent = valExponent->GetNumber(); if (std::abs(doubleBase) == 1 && std::isinf(doubleExponent)) { return JSTaggedValue(base::NAN_VALUE); } - if (((doubleBase == 0) && ((bit_cast(doubleBase)) & base::DOUBLE_SIGN_MASK) == base::DOUBLE_SIGN_MASK) && std::isfinite(doubleExponent) && base::NumberHelper::TruncateDouble(doubleExponent) == doubleExponent && base::NumberHelper::TruncateDouble(doubleExponent / 2) + base::HALF == (doubleExponent / 2)) { // 2: half diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index c6b91a3a..54760717 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -468,8 +468,7 @@ DEF_RUNTIME_STUBS(ExpDyn) return JSTaggedValue(std::pow(doubleBase, doubleExponent)).GetRawData(); } // Slow path - JSTaggedValue res = RuntimeExpDyn(thread, JSHandle(thread, baseValue), - JSHandle(thread, exponentValue)); + JSTaggedValue res = RuntimeExpDyn(thread, baseValue, exponentValue); return res.GetRawData(); } diff --git a/ecmascript/stubs/runtime_stubs.h b/ecmascript/stubs/runtime_stubs.h index 7977e21f..d7af5c6b 100644 --- a/ecmascript/stubs/runtime_stubs.h +++ b/ecmascript/stubs/runtime_stubs.h @@ -222,8 +222,7 @@ private: static inline JSTaggedValue RuntimeIncDyn(JSThread *thread, const JSHandle &value); static inline JSTaggedValue RuntimeDecDyn(JSThread *thread, const JSHandle &value); - static inline JSTaggedValue RuntimeExpDyn(JSThread *thread, const JSHandle &base, - const JSHandle &exponent); + static inline JSTaggedValue RuntimeExpDyn(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent); static inline JSTaggedValue RuntimeIsInDyn(JSThread *thread, const JSHandle &prop, const JSHandle &obj); static inline JSTaggedValue RuntimeInstanceofDyn(JSThread *thread, const JSHandle &obj,