Fix Multiplication -0 Bug

Fix the case when a negative number multiplies with 0.

Issue: #I79Y5V

Signed-off-by: lichenshuai <lichenshuai@huawei.com>
Change-Id: Icbbd9dad0402441d281301b9bff6bfa1e4771ea1
This commit is contained in:
lichenshuai 2023-06-01 11:40:27 +08:00
parent f261ee7c22
commit 754a47b63b
4 changed files with 27 additions and 3 deletions

View File

@ -4201,9 +4201,28 @@ GateRef StubBuilder::FastAddSubAndMul(GateRef left, GateRef right, ProfileOperat
}
Bind(&notOverflow);
{
result = IntToTaggedPtr(TruncInt64ToInt32(res));
TYPE_CALL_BACK(PGOSampleType::Type::INT)
Jump(&exit);
if (Op == OpCode::MUL) {
Label resultIsZero(env);
Label returnNegativeZero(env);
Label returnResult(env);
Branch(Int64Equal(res, Int64(0)), &resultIsZero, &returnResult);
Bind(&resultIsZero);
GateRef leftNegative = Int32LessThan(GetInt32OfTInt(left), Int32(0));
GateRef rightNegative = Int32LessThan(GetInt32OfTInt(right), Int32(0));
Branch(BoolOr(leftNegative, rightNegative), &returnNegativeZero, &returnResult);
Bind(&returnNegativeZero);
result = DoubleToTaggedDoublePtr(Double(-0.0));
TYPE_CALL_BACK(PGOSampleType::Type::DOUBLE)
Jump(&exit);
Bind(&returnResult);
result = IntToTaggedPtr(TruncInt64ToInt32(res));
TYPE_CALL_BACK(PGOSampleType::Type::INT)
Jump(&exit);
} else {
result = IntToTaggedPtr(TruncInt64ToInt32(res));
TYPE_CALL_BACK(PGOSampleType::Type::INT)
Jump(&exit);
}
}
Bind(&exit);
auto ret = *result;

View File

@ -112,6 +112,9 @@ public:
if (res > INT32_MAX || res < INT32_MIN) {
return JSTaggedNumber(static_cast<double>(res));
}
if (res == 0 && (intA < 0 || intB < 0)) {
return JSTaggedNumber(-0.0);
}
return JSTaggedNumber(static_cast<int>(res));
}
return JSTaggedNumber(GetNumber() * number.GetNumber());

View File

@ -23,4 +23,5 @@ let result = Number.parseInt("16947500000");
print("builtins number start");
print("parseInt result = " + result);
print(1 / 0.75 * 0.6);
print(1 / (-1 * 0));
print("builtins number end");

View File

@ -36,6 +36,7 @@ builtins ir end
builtins number start
parseInt result = 16947500000
0.7999999999999999
-Infinity
builtins number end
builtins regexp start
20210608_5V0J5lVh4xVNYx0AUE.jpg,.jpg