mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
!692 fix DoubleToInt overflow bug
Merge pull request !692 from 孙哲/master
This commit is contained in:
commit
8b1ad9e3ae
@ -158,6 +158,7 @@ namespace panda::ecmascript::kungfu {
|
||||
V(CallSpreadDyn, 4) \
|
||||
V(DefineGetterSetterByValue, 6) \
|
||||
V(SuperCall, 5) \
|
||||
I(DoubleToInt, 1) \
|
||||
I(CallRuntimeTrampoline, 4)
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
|
@ -3014,7 +3014,7 @@ DECLARE_ASM_HANDLER(HandleNotDynPrefV8)
|
||||
Bind(&numberIsDouble);
|
||||
{
|
||||
GateRef valueDouble = TaggedCastToDouble(value);
|
||||
number = ChangeFloat64ToInt32(valueDouble);
|
||||
number = DoubleToInt(glue, valueDouble);
|
||||
varAcc = IntBuildTaggedWithNoGC(Int32Not(*number));
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3078,7 +3078,7 @@ DECLARE_ASM_HANDLER(HandleAnd2DynPrefV8)
|
||||
{
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3090,7 +3090,7 @@ DECLARE_ASM_HANDLER(HandleAnd2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3098,8 +3098,8 @@ DECLARE_ASM_HANDLER(HandleAnd2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3170,7 +3170,7 @@ DECLARE_ASM_HANDLER(HandleOr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3182,7 +3182,7 @@ DECLARE_ASM_HANDLER(HandleOr2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3190,8 +3190,8 @@ DECLARE_ASM_HANDLER(HandleOr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3262,7 +3262,7 @@ DECLARE_ASM_HANDLER(HandleXOr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3274,7 +3274,7 @@ DECLARE_ASM_HANDLER(HandleXOr2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3282,8 +3282,8 @@ DECLARE_ASM_HANDLER(HandleXOr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3354,7 +3354,7 @@ DECLARE_ASM_HANDLER(HandleAshr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3366,7 +3366,7 @@ DECLARE_ASM_HANDLER(HandleAshr2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3374,8 +3374,8 @@ DECLARE_ASM_HANDLER(HandleAshr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3447,7 +3447,7 @@ DECLARE_ASM_HANDLER(HandleShr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3459,7 +3459,7 @@ DECLARE_ASM_HANDLER(HandleShr2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3467,8 +3467,8 @@ DECLARE_ASM_HANDLER(HandleShr2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3539,7 +3539,7 @@ DECLARE_ASM_HANDLER(HandleShl2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
opNumber0 = TaggedCastToInt32(left);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
@ -3551,7 +3551,7 @@ DECLARE_ASM_HANDLER(HandleShl2DynPrefV8)
|
||||
Bind(&rightIsInt);
|
||||
{
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = TaggedCastToInt32(right);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
@ -3559,8 +3559,8 @@ DECLARE_ASM_HANDLER(HandleShl2DynPrefV8)
|
||||
{
|
||||
GateRef rightDouble = TaggedCastToDouble(right);
|
||||
GateRef leftDouble = TaggedCastToDouble(left);
|
||||
opNumber0 = ChangeFloat64ToInt32(leftDouble);
|
||||
opNumber1 = ChangeFloat64ToInt32(rightDouble);
|
||||
opNumber0 = DoubleToInt(glue, leftDouble);
|
||||
opNumber1 = DoubleToInt(glue, rightDouble);
|
||||
Jump(&accDispatch);
|
||||
}
|
||||
}
|
||||
|
@ -3452,4 +3452,41 @@ GateRef Stub::JSArrayListGet(GateRef glue, GateRef receiver, GateRef index)
|
||||
env->PopCurrentLabel();
|
||||
return ret;
|
||||
}
|
||||
|
||||
GateRef Stub::DoubleToInt(GateRef glue, GateRef x)
|
||||
{
|
||||
auto env = GetEnvironment();
|
||||
Label entry(env);
|
||||
env->PushCurrentLabel(&entry);
|
||||
Label exit(env);
|
||||
Label overflow(env);
|
||||
|
||||
GateRef xInt = ChangeFloat64ToInt32(x);
|
||||
DEFVARIABLE(result, VariableType::INT32(), xInt);
|
||||
|
||||
if (env->IsAmd64()) {
|
||||
// 0x80000000: amd64 overflow return value
|
||||
Branch(Int32Equal(xInt, GetInt32Constant(0x80000000)), &overflow, &exit);
|
||||
} else {
|
||||
GateRef xInt64 = CastDoubleToInt64(x);
|
||||
// exp = (u64 & DOUBLE_EXPONENT_MASK) >> DOUBLE_SIGNIFICAND_SIZE - DOUBLE_EXPONENT_BIAS
|
||||
GateRef exp = Int64And(xInt64, GetInt64Constant(base::DOUBLE_EXPONENT_MASK));
|
||||
exp = ChangeInt64ToInt32(UInt64LSR(exp, GetInt64Constant(base::DOUBLE_SIGNIFICAND_SIZE)));
|
||||
exp = Int32Sub(exp, GetInt32Constant(base::DOUBLE_EXPONENT_BIAS));
|
||||
GateRef bits = GetInt32Constant(base::INT32_BITS - 1);
|
||||
// exp < 32 - 1
|
||||
Branch(Int32LessThan(exp, bits), &exit, &overflow);
|
||||
}
|
||||
Bind(&overflow);
|
||||
{
|
||||
StubDescriptor *doubleToInt = GET_STUBDESCRIPTOR(DoubleToInt);
|
||||
result = CallRuntime(doubleToInt, glue,
|
||||
GetIntPtrConstant(FAST_STUB_ID(DoubleToInt)), { x });
|
||||
Jump(&exit);
|
||||
}
|
||||
Bind(&exit);
|
||||
auto ret = *result;
|
||||
env->PopCurrentLabel();
|
||||
return ret;
|
||||
}
|
||||
} // namespace panda::ecmascript::kungfu
|
||||
|
@ -735,6 +735,7 @@ public:
|
||||
GateRef ICStoreElement(GateRef glue, GateRef receiver, GateRef key,
|
||||
GateRef value, GateRef handlerInfo);
|
||||
GateRef GetArrayLength(GateRef object);
|
||||
GateRef DoubleToInt(GateRef glue, GateRef x);
|
||||
void StoreField(GateRef glue, GateRef receiver, GateRef value, GateRef handler);
|
||||
void StoreWithTransition(GateRef glue, GateRef receiver, GateRef value, GateRef handler);
|
||||
GateRef StoreGlobal(GateRef glue, GateRef value, GateRef cell);
|
||||
|
@ -1000,6 +1000,19 @@ CALL_STUB_INIT_DESCRIPTOR(InsertOldToNewRememberedSet)
|
||||
descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB);
|
||||
}
|
||||
|
||||
CALL_STUB_INIT_DESCRIPTOR(DoubleToInt)
|
||||
{
|
||||
// 1 : 1 input parameters
|
||||
StubDescriptor index("DoubleToInt", 0, 1, ArgumentsOrder::DEFAULT_ORDER, VariableType::INT32());
|
||||
*descriptor = index;
|
||||
// 1 : 1 input parameters
|
||||
std::array<VariableType, 1> params = {
|
||||
VariableType::FLOAT64(),
|
||||
};
|
||||
descriptor->SetParameters(params.data());
|
||||
descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB);
|
||||
}
|
||||
|
||||
CALL_STUB_INIT_DESCRIPTOR(MarkingBarrier)
|
||||
{
|
||||
// 5 : 5 input parameters
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "runtime_trampolines.h"
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/base/number_helper.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/frames.h"
|
||||
#include "ecmascript/ic/ic_runtime.h"
|
||||
@ -1520,6 +1521,11 @@ DEF_RUNTIME_TRAMPOLINES(SuperCall)
|
||||
static_cast<uint16_t>(length.GetInt())).GetRawData();
|
||||
}
|
||||
|
||||
int32_t RuntimeTrampolines::DoubleToInt(double x)
|
||||
{
|
||||
return base::NumberHelper::DoubleToInt(x, base::INT32_BITS);
|
||||
}
|
||||
|
||||
void RuntimeTrampolines::InsertOldToNewRememberedSet([[maybe_unused]]uintptr_t argGlue, Region* region, uintptr_t addr)
|
||||
{
|
||||
return region->InsertOldToNewRememberedSet(addr);
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
static void MarkingBarrier([[maybe_unused]]uintptr_t argGlue, uintptr_t slotAddr,
|
||||
Region *objectRegion, TaggedObject *value, Region *valueRegion);
|
||||
static void InsertOldToNewRememberedSet([[maybe_unused]]uintptr_t argGlue, Region* region, uintptr_t addr);
|
||||
static int32_t DoubleToInt(double x);
|
||||
|
||||
private:
|
||||
static void PrintHeapReginInfo(uintptr_t argGlue);
|
||||
|
Loading…
Reference in New Issue
Block a user