!2182 Refactor Class SubBuilder

Merge pull request !2182 from Gargoyle.h/wzfmaster-dev
This commit is contained in:
openharmony_ci 2022-08-25 11:28:23 +00:00 committed by Gitee
commit 19fb4a2d9c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 230 additions and 132 deletions

View File

@ -79,6 +79,95 @@ GateRef CircuitBuilder::ChangeTaggedPointerToInt64(GateRef x)
return UnaryArithmetic(OpCode(OpCode::TAGGED_TO_INT64), x);
}
GateRef CircuitBuilder::ChangeInt32ToFloat64(GateRef x)
{
return UnaryArithmetic(OpCode(OpCode::SIGNED_INT_TO_FLOAT), MachineType::F64, x);
}
GateRef CircuitBuilder::ChangeUInt32ToFloat64(GateRef x)
{
return UnaryArithmetic(OpCode(OpCode::UNSIGNED_INT_TO_FLOAT), MachineType::F64, x);
}
GateRef CircuitBuilder::PointerSub(GateRef x, GateRef y)
{
return BinaryArithmetic(OpCode(OpCode::SUB), MachineType::ARCH, x, y);
}
GateRef CircuitBuilder::Int8Equal(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::EQ), x, y);
}
GateRef CircuitBuilder::Int32NotEqual(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::NE), x, y);
}
GateRef CircuitBuilder::Int64NotEqual(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::NE), x, y);
}
GateRef CircuitBuilder::DoubleEqual(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::EQ), x, y);
}
GateRef CircuitBuilder::Int64Equal(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::EQ), x, y);
}
GateRef CircuitBuilder::Int32Equal(GateRef x, GateRef y)
{
return BinaryLogic(OpCode(OpCode::EQ), x, y);
}
template<OpCode::Op Op, MachineType Type>
GateRef CircuitBuilder::BinaryOp(GateRef x, GateRef y)
{
return BinaryArithmetic(OpCode(Op), Type, x, y);
}
GateRef CircuitBuilder::IntPtrLSR(GateRef x, GateRef y)
{
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return BinaryArithmetic(OpCode(OpCode::LSR), ptrSize, x, y);
}
GateRef CircuitBuilder::IntPtrLSL(GateRef x, GateRef y)
{
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return BinaryArithmetic(OpCode(OpCode::LSL), ptrSize, x, y);
}
GateRef CircuitBuilder::IntPtrOr(GateRef x, GateRef y)
{
auto ptrsize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return BinaryArithmetic(OpCode(OpCode::OR), ptrsize, x, y);
}
GateRef CircuitBuilder::IntPtrDiv(GateRef x, GateRef y)
{
return env_->Is32Bit() ? Int32Div(x, y) : Int64Div(x, y);
}
GateRef CircuitBuilder::ChangeFloat64ToInt32(GateRef x)
{
return UnaryArithmetic(OpCode(OpCode::FLOAT_TO_SIGNED_INT), MachineType::I32, x);
}
GateRef CircuitBuilder::SExtInt16ToInt64(GateRef x)
{
return UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
GateRef CircuitBuilder::SExtInt8ToInt64(GateRef x)
{
return UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
GateRef CircuitBuilder::ChangeInt64ToTagged(GateRef x)
{
return TaggedNumber(OpCode(OpCode::INT64_TO_TAGGED), x);

View File

@ -16,8 +16,6 @@
#ifndef ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_H
#define ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_H
#include <stack>
#include "ecmascript/base/number_helper.h"
#include "ecmascript/compiler/circuit.h"
#include "ecmascript/compiler/call_signature.h"
@ -342,12 +340,31 @@ public:
inline GateRef DoubleToTagged(GateRef x);
inline GateRef TaggedTrue();
inline GateRef TaggedFalse();
inline GateRef SExtInt8ToInt64(GateRef x);
inline GateRef SExtInt16ToInt64(GateRef x);
inline GateRef ChangeFloat64ToInt32(GateRef x);
inline GateRef ChangeUInt32ToFloat64(GateRef x);
inline GateRef ChangeInt32ToFloat64(GateRef x);
// Pointer/Arithmetic/Logic Operations
inline GateRef PointerSub(GateRef x, GateRef y);
inline GateRef IntPtrDiv(GateRef x, GateRef y);
inline GateRef IntPtrOr(GateRef x, GateRef y);
inline GateRef IntPtrLSL(GateRef x, GateRef y);
inline GateRef IntPtrLSR(GateRef x, GateRef y);
inline GateRef Int64NotEqual(GateRef x, GateRef y);
inline GateRef Int32NotEqual(GateRef x, GateRef y);
inline GateRef Int64Equal(GateRef x, GateRef y);
inline GateRef DoubleEqual(GateRef x, GateRef y);
inline GateRef Int8Equal(GateRef x, GateRef y);
inline GateRef Int32Equal(GateRef x, GateRef y);
template<OpCode::Op Op, MachineType Type>
inline GateRef BinaryOp(GateRef x, GateRef y);
inline GateRef GetValueFromTaggedArray(VariableType returnType, GateRef array, GateRef index);
inline void SetValueToTaggedArray(VariableType valType, GateRef glue, GateRef array, GateRef index, GateRef val);
GateRef TaggedIsString(GateRef obj);
GateRef TaggedIsStringOrSymbol(GateRef obj);
inline GateRef GetGlobalConstantString(ConstantIndex index);
// object operation
// Object Operations
inline GateRef LoadHClass(GateRef object);
inline GateRef IsJsType(GateRef object, JSType type);
inline GateRef GetObjectType(GateRef hClass);

View File

@ -13,8 +13,9 @@
* limitations under the License.
*/
#include "ecmascript/ark_stackmap_builder.h"
#include "ecmascript/compiler/file_generators.h"
#include "ecmascript/ark_stackmap_builder.h"
#include "ecmascript/compiler/llvm_ir_builder.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/llvm_stackmap_parser.h"

View File

@ -162,6 +162,13 @@ public:
BITCAST,
RESTORE_REGISTER,
SAVE_REGISTER,
COMMON_CIR_FIRST = NOP,
COMMON_CIR_LAST = DEPEND_AND,
HIGH_CIR_FIRST = JS_BYTECODE,
HIGH_CIR_LAST = GET_EXCEPTION,
MID_CIR_FIRST = RUNTIME_CALL,
MID_CIR_LAST = SAVE_REGISTER
};
OpCode() = default;

View File

@ -276,22 +276,22 @@ inline GateRef StubBuilder::Load(VariableType type, GateRef base)
// arithmetic
inline GateRef StubBuilder::Int16Add(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I16, x, y);
return env_->GetBuilder()->Int16Add(x, y);
}
inline GateRef StubBuilder::Int32Add(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Add(x, y);
}
inline GateRef StubBuilder::Int64Add(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Add(x, y);
}
inline GateRef StubBuilder::DoubleAdd(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::F64, x, y);
return env_->GetBuilder()->DoubleAdd(x, y);
}
inline GateRef StubBuilder::PtrAdd(GateRef x, GateRef y)
@ -330,103 +330,103 @@ inline GateRef StubBuilder::PtrSub(GateRef x, GateRef y)
inline GateRef StubBuilder::PointerSub(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::ARCH, x, y);
return env_->GetBuilder()->PointerSub(x, y);
}
inline GateRef StubBuilder::Int16Sub(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I16, x, y);
return env_->GetBuilder()->Int16Sub(x, y);
}
inline GateRef StubBuilder::Int32Sub(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Sub(x, y);
}
inline GateRef StubBuilder::Int64Sub(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Sub(x, y);
}
inline GateRef StubBuilder::DoubleSub(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::F64, x, y);
return env_->GetBuilder()->DoubleSub(x, y);
}
inline GateRef StubBuilder::Int32Mul(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Mul(x, y);
}
inline GateRef StubBuilder::Int64Mul(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Mul(x, y);
}
inline GateRef StubBuilder::DoubleMul(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::F64, x, y);
return env_->GetBuilder()->DoubleMul(x, y);
}
inline GateRef StubBuilder::DoubleDiv(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::FDIV), MachineType::F64, x, y);
return env_->GetBuilder()->DoubleDiv(x, y);
}
inline GateRef StubBuilder::Int32Div(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Div(x, y);
}
inline GateRef StubBuilder::Int64Div(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Div(x, y);
}
inline GateRef StubBuilder::IntPtrDiv(GateRef x, GateRef y)
{
return env_->Is32Bit() ? Int32Div(x, y) : Int64Div(x, y);
return env_->GetBuilder()->IntPtrDiv(x, y);
}
inline GateRef StubBuilder::Int32Mod(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Mod(x, y);
}
inline GateRef StubBuilder::DoubleMod(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::F64, x, y);
return env_->GetBuilder()->DoubleMod(x, y);
}
// bit operation
inline GateRef StubBuilder::Int32Or(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Or(x, y);
}
inline GateRef StubBuilder::Int8And(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I8, x, y);
return env_->GetBuilder()->Int8And(x, y);
}
inline GateRef StubBuilder::Int32And(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I32, x, y);
return env_->GetBuilder()->Int32And(x, y);
}
inline GateRef StubBuilder::BoolAnd(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I1, x, y);
return env_->GetBuilder()->BoolAnd(x, y);
}
inline GateRef StubBuilder::BoolOr(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I1, x, y);
return env_->GetBuilder()->BoolOr(x, y);
}
inline GateRef StubBuilder::Int32Not(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I32, x);
return env_->GetBuilder()->Int32Not(x);
}
inline GateRef StubBuilder::IntPtrNot(GateRef x)
@ -436,91 +436,88 @@ inline GateRef StubBuilder::IntPtrNot(GateRef x)
inline GateRef StubBuilder::BoolNot(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I1, x);
return env_->GetBuilder()->BoolNot(x);
}
inline GateRef StubBuilder::Int64Or(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Or(x, y);
}
inline GateRef StubBuilder::IntPtrOr(GateRef x, GateRef y)
{
auto ptrsize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), ptrsize, x, y);
return env_->GetBuilder()->IntPtrOr(x, y);
}
inline GateRef StubBuilder::Int64And(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I64, x, y);
return env_->GetBuilder()->Int64And(x, y);
}
inline GateRef StubBuilder::Int16LSL(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I16, x, y);
return env_->GetBuilder()->Int16LSL(x, y);
}
inline GateRef StubBuilder::Int64Xor(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I64, x, y);
return env_->GetBuilder()->Int64Xor(x, y);
}
inline GateRef StubBuilder::Int32Xor(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I32, x, y);
return env_->GetBuilder()->Int32Xor(x, y);
}
inline GateRef StubBuilder::Int8LSR(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I8, x, y);
return env_->GetBuilder()->Int8LSR(x, y);
}
inline GateRef StubBuilder::Int64Not(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I64, x);
return env_->GetBuilder()->Int64Not(x);
}
inline GateRef StubBuilder::Int32LSL(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I32, x, y);
return env_->GetBuilder()->Int32LSL(x, y);
}
inline GateRef StubBuilder::Int64LSL(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I64, x, y);
return env_->GetBuilder()->Int64LSL(x, y);
}
inline GateRef StubBuilder::IntPtrLSL(GateRef x, GateRef y)
{
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), ptrSize, x, y);
return env_->GetBuilder()->IntPtrLSL(x, y);
}
inline GateRef StubBuilder::Int32ASR(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ASR), MachineType::I32, x, y);
return env_->GetBuilder()->Int32ASR(x, y);
}
inline GateRef StubBuilder::Int32LSR(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I32, x, y);
return env_->GetBuilder()->Int32LSR(x, y);
}
inline GateRef StubBuilder::Int64LSR(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I64, x, y);
return env_->GetBuilder()->Int64LSR(x, y);
}
inline GateRef StubBuilder::IntPtrLSR(GateRef x, GateRef y)
{
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), ptrSize, x, y);
return env_->GetBuilder()->IntPtrLSR(x, y);
}
template<OpCode::Op Op, MachineType Type>
inline GateRef StubBuilder::BinaryOp(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryArithmetic(OpCode(Op), Type, x, y);
return env_->GetBuilder()->BinaryOp<Op, Type>(x, y);
}
inline GateRef StubBuilder::TaggedIsInt(GateRef x)
@ -726,7 +723,7 @@ inline GateRef StubBuilder::DoubleBuildTaggedTypeWithNoGC(GateRef x)
inline GateRef StubBuilder::CastDoubleToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::I64, x);
return env_->GetBuilder()->CastDoubleToInt64(x);
}
inline GateRef StubBuilder::TaggedTrue()
@ -742,112 +739,112 @@ inline GateRef StubBuilder::TaggedFalse()
// compare operation
inline GateRef StubBuilder::Int8Equal(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->Int8Equal(x, y);
}
inline GateRef StubBuilder::Int32Equal(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->Int32Equal(x, y);
}
inline GateRef StubBuilder::Int32NotEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::NE), x, y);
return env_->GetBuilder()->Int32NotEqual(x, y);
}
inline GateRef StubBuilder::Int64Equal(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->Int64Equal(x, y);
}
inline GateRef StubBuilder::DoubleEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->DoubleEqual(x, y);
}
inline GateRef StubBuilder::DoubleLessThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->DoubleLessThan(x, y);
}
inline GateRef StubBuilder::DoubleLessThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->DoubleLessThanOrEqual(x, y);
}
inline GateRef StubBuilder::DoubleGreaterThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->DoubleGreaterThan(x, y);
}
inline GateRef StubBuilder::DoubleGreaterThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->DoubleGreaterThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int64NotEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::NE), x, y);
return env_->GetBuilder()->Int64NotEqual(x, y);
}
inline GateRef StubBuilder::Int32GreaterThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->Int32GreaterThan(x, y);
}
inline GateRef StubBuilder::Int32LessThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->Int32LessThan(x, y);
}
inline GateRef StubBuilder::Int32GreaterThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->Int32GreaterThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int32LessThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->Int32LessThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int32UnsignedGreaterThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::UGT), x, y);
return env_->GetBuilder()->Int32UnsignedGreaterThan(x, y);
}
inline GateRef StubBuilder::Int32UnsignedLessThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::ULT), x, y);
return env_->GetBuilder()->Int32UnsignedLessThan(x, y);
}
inline GateRef StubBuilder::Int32UnsignedGreaterThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::UGE), x, y);
return env_->GetBuilder()->Int32UnsignedGreaterThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int64GreaterThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->Int64GreaterThan(x, y);
}
inline GateRef StubBuilder::Int64LessThan(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->Int64LessThan(x, y);
}
inline GateRef StubBuilder::Int64LessThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->Int64LessThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int64GreaterThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->Int64GreaterThanOrEqual(x, y);
}
inline GateRef StubBuilder::Int64UnsignedLessThanOrEqual(GateRef x, GateRef y)
{
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::ULE), x, y);
return env_->GetBuilder()->Int64UnsignedLessThanOrEqual(x, y);
}
inline GateRef StubBuilder::IntPtrGreaterThan(GateRef x, GateRef y)
@ -858,7 +855,7 @@ inline GateRef StubBuilder::IntPtrGreaterThan(GateRef x, GateRef y)
// cast operation
inline GateRef StubBuilder::ChangeInt64ToInt32(GateRef val)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), val);
return env_->GetBuilder()->ChangeInt64ToInt32(val);
}
inline GateRef StubBuilder::ChangeInt16ToInt8(GateRef val)
@ -1515,126 +1512,117 @@ inline GateRef StubBuilder::TaggedCastToWeakReferentUnChecked(GateRef x)
inline GateRef StubBuilder::ChangeInt32ToFloat64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SIGNED_INT_TO_FLOAT), MachineType::F64, x);
return env_->GetBuilder()->ChangeInt32ToFloat64(x);
}
inline GateRef StubBuilder::ChangeUInt32ToFloat64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::UNSIGNED_INT_TO_FLOAT), MachineType::F64, x);
return env_->GetBuilder()->ChangeUInt32ToFloat64(x);
}
inline GateRef StubBuilder::ChangeFloat64ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::FLOAT_TO_SIGNED_INT), MachineType::I32, x);
return env_->GetBuilder()->ChangeFloat64ToInt32(x);
}
inline GateRef StubBuilder::ChangeTaggedPointerToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TAGGED_TO_INT64), x);
return env_->GetBuilder()->ChangeTaggedPointerToInt64(x);
}
inline GateRef StubBuilder::ChangeInt64ToTagged(GateRef x)
{
return env_->GetBuilder()->TaggedNumber(OpCode(OpCode::INT64_TO_TAGGED), x);
return env_->GetBuilder()->ChangeInt64ToTagged(x);
}
inline GateRef StubBuilder::CastInt64ToFloat64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::F64, x);
return env_->GetBuilder()->CastInt64ToFloat64(x);
}
inline GateRef StubBuilder::SExtInt32ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->SExtInt32ToInt64(x);
}
inline GateRef StubBuilder::SExtInt16ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->SExtInt16ToInt64(x);
}
inline GateRef StubBuilder::SExtInt8ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->SExtInt8ToInt64(x);
}
inline GateRef StubBuilder::SExtInt1ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->SExtInt1ToInt64(x);
}
inline GateRef StubBuilder::SExtInt1ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
return env_->GetBuilder()->SExtInt1ToInt32(x);
}
inline GateRef StubBuilder::ZExtInt8ToInt16(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT16), x);
return env_->GetBuilder()->ZExtInt8ToInt16(x);
}
inline GateRef StubBuilder::ZExtInt32ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt32ToInt64(x);
}
inline GateRef StubBuilder::ZExtInt1ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt1ToInt64(x);
}
inline GateRef StubBuilder::ZExtInt1ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->ZExtInt1ToInt32(x);
}
inline GateRef StubBuilder::ZExtInt8ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->ZExtInt8ToInt32(x);
}
inline GateRef StubBuilder::ZExtInt8ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt8ToInt64(x);
}
inline GateRef StubBuilder::ZExtInt8ToPtr(GateRef x)
{
if (env_->IsArch32Bit()) {
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt8ToPtr(x);
}
inline GateRef StubBuilder::ZExtInt16ToPtr(GateRef x)
{
if (env_->IsArch32Bit()) {
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt16ToPtr(x);
}
inline GateRef StubBuilder::SExtInt32ToPtr(GateRef x)
{
if (env_->IsArch32Bit()) {
return x;
}
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->SExtInt32ToPtr(x);
}
inline GateRef StubBuilder::ZExtInt16ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->ZExtInt16ToInt32(x);
}
inline GateRef StubBuilder::ZExtInt16ToInt64(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->ZExtInt16ToInt64(x);
}
inline GateRef StubBuilder::TruncInt64ToInt32(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), x);
return env_->GetBuilder()->TruncInt64ToInt32(x);
}
inline GateRef StubBuilder::TruncPtrToInt32(GateRef x)
@ -1647,12 +1635,12 @@ inline GateRef StubBuilder::TruncPtrToInt32(GateRef x)
inline GateRef StubBuilder::TruncInt64ToInt1(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
return env_->GetBuilder()->TruncInt64ToInt1(x);
}
inline GateRef StubBuilder::TruncInt32ToInt1(GateRef x)
{
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
return env_->GetBuilder()->TruncInt32ToInt1(x);
}
inline GateRef StubBuilder::GetGlobalConstantAddr(GateRef index)

View File

@ -24,7 +24,6 @@
#include "ecmascript/message_string.h"
#include "ecmascript/tagged_dictionary.h"
#include "ecmascript/tagged_hash_table.h"
#include "libpandabase/macros.h"
namespace panda::ecmascript::kungfu {
void StubBuilder::Jump(Label *label)

View File

@ -20,7 +20,7 @@
#include "ecmascript/mem/barriers.h"
#include "ecmascript/mem/tagged_object-inl.h"
#define INVALID_OBJECT ((FreeObject *)NULL_POINTER)
#define INVALID_OBJECT ((FreeObject *) JSTaggedValue::NULL_POINTER)
namespace panda::ecmascript {
class FreeObject : public TaggedObject {

View File

@ -16,8 +16,6 @@
#ifndef ECMASCRIPT_JS_TAGGED_VALUE_H
#define ECMASCRIPT_JS_TAGGED_VALUE_H
#include <limits.h>
#include "ecmascript/base/bit_helper.h"
#include "ecmascript/mem/c_string.h"
#include "ecmascript/mem/mem_common.h"
@ -47,23 +45,8 @@ enum class ComparisonResult {
UNDEFINED // at least one of x or y was undefined or NaN
};
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define RETURN_TAGGED_VALUE_IF_ABRUPT(thread) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined());
using JSTaggedType = uint64_t;
static const JSTaggedType NULL_POINTER = 0x05ULL;
static const JSTaggedType INVALID_VALUE_LIMIT = 0x40000ULL;
static inline JSTaggedType ReinterpretDoubleToTaggedType(double value)
{
return base::bit_cast<JSTaggedType>(value);
}
static inline double ReinterpretTaggedTypeToDouble(JSTaggedType value)
{
return base::bit_cast<double>(value);
}
// Every double with all of its exponent bits set and its highest mantissa bit set is a quiet NaN.
// That leaves 51 bits unaccounted for. Well avoid one of those so that we dont step on Intels
// “QNaN Floating-Point Indefinite” value, leaving us 50 bits. Those remaining bits can be anything.
@ -87,9 +70,10 @@ static inline double ReinterpretTaggedTypeToDouble(JSTaggedType value)
class JSTaggedValue {
public:
static constexpr size_t BIT_PER_BYTE = 8;
static constexpr size_t TAG_BITS_SIZE = 16; // 16 means bit numbers of 0xFFFF
static constexpr size_t TAG_BITS_SHIFT = base::BitNumbers<JSTaggedType>() - TAG_BITS_SIZE;
static_assert((TAG_BITS_SHIFT + TAG_BITS_SIZE) == sizeof(JSTaggedType) * CHAR_BIT, "Insufficient bits!");
static_assert((TAG_BITS_SHIFT + TAG_BITS_SIZE) == sizeof(JSTaggedType) * BIT_PER_BYTE, "Insufficient bits!");
static constexpr JSTaggedType TAG_MARK = 0xFFFFULL << TAG_BITS_SHIFT;
// int tag
static constexpr JSTaggedType TAG_INT = TAG_MARK;
@ -124,6 +108,19 @@ public:
return JSTaggedValue(object);
}
static const JSTaggedType NULL_POINTER = VALUE_HOLE;
static const JSTaggedType INVALID_VALUE_LIMIT = 0x40000ULL;
static inline JSTaggedType CastDoubleToTagged(double value)
{
return base::bit_cast<JSTaggedType>(value);
}
static inline double CastTaggedToDouble(JSTaggedType value)
{
return base::bit_cast<double>(value);
}
static inline constexpr size_t TaggedTypeSize()
{
return sizeof(JSTaggedType);
@ -135,7 +132,7 @@ public:
explicit JSTaggedValue(void *) = delete;
constexpr JSTaggedValue() : value_(NULL_POINTER) {}
constexpr JSTaggedValue() : value_(JSTaggedValue::NULL_POINTER) {}
constexpr explicit JSTaggedValue(JSTaggedType v) : value_(v) {}
@ -156,8 +153,8 @@ public:
explicit JSTaggedValue(double v)
{
ASSERT_PRINT(!IsImpureNaN(v), "pureNaN will break the encoding of tagged double: "
<< std::hex << ReinterpretDoubleToTaggedType(v));
value_ = ReinterpretDoubleToTaggedType(v) + DOUBLE_ENCODE_OFFSET;
<< std::hex << CastDoubleToTagged(v));
value_ = CastDoubleToTagged(v) + DOUBLE_ENCODE_OFFSET;
}
explicit JSTaggedValue(const TaggedObject *v) : value_(static_cast<JSTaggedType>(ToUintPtr(v))) {}
@ -238,7 +235,7 @@ public:
inline double GetDouble() const
{
ASSERT_PRINT(IsDouble(), "can not convert JSTaggedValue to Double : " << std::hex << value_);
return ReinterpretTaggedTypeToDouble(value_ - DOUBLE_ENCODE_OFFSET);
return CastTaggedToDouble(value_ - DOUBLE_ENCODE_OFFSET);
}
inline int GetInt() const

View File

@ -71,9 +71,9 @@ HWTEST_F_L0(JSTaggedValueTest, Double)
EXPECT_EQ(true, tNan.IsDouble());
EXPECT_EQ(false, tNan.IsInt());
EXPECT_EQ(false, tNan.IsObject());
EXPECT_EQ(ReinterpretDoubleToTaggedType(tNan.GetDouble()), ReinterpretDoubleToTaggedType(nan));
EXPECT_EQ(JSTaggedValue::CastDoubleToTagged(tNan.GetDouble()), JSTaggedValue::CastDoubleToTagged(nan));
double pureNaN = ReinterpretTaggedTypeToDouble(JSTaggedValue::TAG_INT - JSTaggedValue::DOUBLE_ENCODE_OFFSET);
double pureNaN = JSTaggedValue::CastTaggedToDouble(JSTaggedValue::TAG_INT - JSTaggedValue::DOUBLE_ENCODE_OFFSET);
EXPECT_EQ(true, JSTaggedValue::IsImpureNaN(pureNaN));
}