Commit e6f180b0 authored by Frank Emrich's avatar Frank Emrich Committed by Commit Bot

[csa][torque] Improve support for explicit 64 bit ints in CSA & Torque

This CL:

a) Adds an unsigned 64 bit type to Torque, called uint64.

b) Makes more operations on 64 bit integers from the raw machine
   assembler available in CSA and Torque.

Change-Id: I147501d65882892e4628ec22088c0940df79a974
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742204
Commit-Queue: Frank Emrich <emrich@google.com>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73403}
parent 3e689a7d
......@@ -104,6 +104,7 @@ type uint8 extends uint16
type char8 extends uint8 constexpr 'char';
type char16 extends uint16 constexpr 'char16_t';
type int64 generates 'TNode<Int64T>' constexpr 'int64_t';
type uint64 generates 'TNode<Uint64T>' constexpr 'uint64_t';
type intptr generates 'TNode<IntPtrT>' constexpr 'intptr_t';
type uintptr generates 'TNode<UintPtrT>' constexpr 'uintptr_t';
type float32 generates 'TNode<Float32T>' constexpr 'float';
......@@ -804,6 +805,8 @@ extern operator '>=' macro IntPtrGreaterThanOrEqual(intptr, intptr): bool;
extern operator '>=' macro UintPtrGreaterThanOrEqual(uintptr, uintptr): bool;
extern operator '~' macro WordNot(intptr): intptr;
extern operator '~' macro WordNot(uintptr): uintptr;
extern operator '~' macro Word64Not(uint64): uint64;
extern operator '~' macro Word64Not(int64): int64;
extern operator '~' macro ConstexprWordNot(constexpr intptr): constexpr intptr;
extern operator '~' macro ConstexprWordNot(constexpr uintptr):
constexpr uintptr;
......@@ -878,16 +881,23 @@ extern operator '+' macro ConstexprIntPtrAdd(
constexpr intptr, constexpr intptr): constexpr intptr;
extern operator '+' macro ConstexprUintPtrAdd(
constexpr uintptr, constexpr uintptr): constexpr intptr;
extern operator '+' macro Int64Add(int64, int64): int64;
extern operator '-' macro IntPtrSub(intptr, intptr): intptr;
extern operator '-' macro Int64Sub(int64, int64): int64;
extern operator '*' macro IntPtrMul(intptr, intptr): intptr;
extern operator '*' macro Int64Mul(int64, int64): int64;
extern operator '/' macro IntPtrDiv(intptr, intptr): intptr;
extern operator '/' macro Int64Div(int64, int64): int64;
extern operator '<<' macro WordShl(intptr, intptr): intptr;
extern operator '>>' macro WordSar(intptr, intptr): intptr;
extern operator '&' macro WordAnd(intptr, intptr): intptr;
extern operator '|' macro WordOr(intptr, intptr): intptr;
extern operator '+' macro UintPtrAdd(uintptr, uintptr): uintptr;
extern operator '+' macro Uint64Add(uint64, uint64): uint64;
extern operator '-' macro UintPtrSub(uintptr, uintptr): uintptr;
extern operator '-' macro Uint64Sub(uint64, uint64): uint64;
extern operator '*' macro Uint64Mul(uint64, uint64): uint64;
extern operator '<<' macro WordShl(uintptr, uintptr): uintptr;
extern operator '>>>' macro WordShr(uintptr, uintptr): uintptr;
extern operator '&' macro WordAnd(uintptr, uintptr): uintptr;
......@@ -941,6 +951,18 @@ extern operator '!=' macro Word32NotEqual(bool, bool): bool;
extern operator '|' macro ConstexprWord32Or(
constexpr int32, constexpr int32): constexpr int32;
extern operator '==' macro Word64Equal(int64, int64): bool;
extern operator '==' macro Word64Equal(uint64, uint64): bool;
extern operator '!=' macro Word64NotEqual(int64, int64): bool;
extern operator '!=' macro Word64NotEqual(uint64, uint64): bool;
extern operator '>>>' macro Word64Shr(uint64, uint64): uint64;
extern operator '>>' macro Word64Sar(int64, int64): int64;
extern operator '<<' macro Word64Shl(int64, int64): int64;
extern operator '<<' macro Word64Shl(uint64, uint64): uint64;
extern operator '|' macro Word64Or(int64, int64): int64;
extern operator '|' macro Word64Or(uint64, uint64): uint64;
extern operator '&' macro Word64And(uint64, uint64): uint64;
extern operator '+' macro Float64Add(float64, float64): float64;
extern operator '-' macro Float64Sub(float64, float64): float64;
extern operator '*' macro Float64Mul(float64, float64): float64;
......@@ -1028,17 +1050,20 @@ extern macro ChangeInt32ToTagged(int32): Number;
extern macro ChangeUint32ToTagged(uint32): Number;
extern macro ChangeUintPtrToFloat64(uintptr): float64;
extern macro ChangeUintPtrToTagged(uintptr): Number;
extern macro Unsigned(int64): uint64;
extern macro Unsigned(int32): uint32;
extern macro Unsigned(int16): uint16;
extern macro Unsigned(int8): uint8;
extern macro Unsigned(intptr): uintptr;
extern macro Unsigned(RawPtr): uintptr;
extern macro Signed(uint64): int64;
extern macro Signed(uint32): int32;
extern macro Signed(uint16): int16;
extern macro Signed(uint8): int8;
extern macro Signed(uintptr): intptr;
extern macro Signed(RawPtr): intptr;
extern macro TruncateIntPtrToInt32(intptr): int32;
extern macro TruncateInt64ToInt32(int64): int32;
extern macro SmiTag(intptr): Smi;
extern macro SmiFromInt32(int32): Smi;
extern macro SmiFromUint32(uint32): Smi;
......@@ -1067,8 +1092,10 @@ extern macro ChangeFloat64ToTagged(float64): Number;
extern macro ChangeFloat64ToUintPtr(float64): uintptr;
extern macro ChangeFloat64ToIntPtr(float64): intptr;
extern macro ChangeInt32ToFloat64(int32): float64;
extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
extern macro ChangeInt32ToInt64(int32): intptr; // Sign-extends.
extern macro ChangeUint32ToUint64(uint32): uint64; // Doesn't sign-extend.
extern macro LoadNativeContext(Context): NativeContext;
extern macro TruncateFloat64ToFloat32(float64): float32;
extern macro TruncateHeapNumberValueToWord32(HeapNumber): int32;
......@@ -1082,6 +1109,8 @@ extern macro IntPtrConstant(constexpr int32): intptr;
extern macro Uint16Constant(constexpr uint16): uint16;
extern macro Int32Constant(constexpr int31): int31;
extern macro Int32Constant(constexpr int32): int32;
extern macro Int64Constant(constexpr int64): int64;
extern macro Uint64Constant(constexpr uint64): uint64;
extern macro Float64Constant(constexpr int31): float64;
extern macro Float64Constant(constexpr float64): float64;
extern macro SmiConstant(constexpr int31): Smi;
......
......@@ -72,6 +72,12 @@ FromConstexpr<uint32, constexpr int31>(i: constexpr int31): uint32 {
FromConstexpr<uint32, constexpr uint32>(i: constexpr uint32): uint32 {
return Unsigned(%FromConstexpr<int32>(i));
}
FromConstexpr<uint64, constexpr uint64>(i: constexpr uint64): uint64 {
return Uint64Constant(i);
}
FromConstexpr<uint64, constexpr int31>(i: constexpr int31): uint64 {
return Convert<uint64>(Unsigned(Int32Constant(i)));
}
FromConstexpr<uintptr, constexpr int31>(i: constexpr int31): uintptr {
return ChangeUint32ToWord(i);
}
......@@ -152,6 +158,9 @@ Convert<Smi, uint32>(ui: uint32): Smi {
Convert<uintptr, uint32>(ui: uint32): uintptr {
return ChangeUint32ToWord(ui);
}
Convert<uint64, uint32>(ui: uint32): uint64 {
return ChangeUint32ToUint64(ui);
}
Convert<intptr, uint16>(ui: uint16): intptr {
return Signed(ChangeUint32ToWord(ui));
}
......@@ -179,6 +188,9 @@ Convert<int32, uint31>(i: uint31): int32 {
Convert<int32, intptr>(i: intptr): int32 {
return TruncateIntPtrToInt32(i);
}
Convert<int32, int64>(i: int64): int32 {
return TruncateInt64ToInt32(i);
}
Convert<int32, Number>(n: Number): int32 {
typeswitch (n) {
case (s: Smi): {
......
......@@ -284,6 +284,12 @@ class CodeAssemblerParameterizedLabel;
V(Int32MulWithOverflow, PAIR_TYPE(Int32T, BoolT), Int32T, Int32T) \
V(Int32Div, Int32T, Int32T, Int32T) \
V(Int32Mod, Int32T, Int32T, Int32T) \
V(Int64Add, Word64T, Word64T, Word64T) \
V(Int64Sub, Word64T, Word64T, Word64T) \
V(Int64SubWithOverflow, PAIR_TYPE(Int64T, BoolT), Int64T, Int64T) \
V(Int64Mul, Word64T, Word64T, Word64T) \
V(Int64Div, Int64T, Int64T, Int64T) \
V(Int64Mod, Int64T, Int64T, Int64T) \
V(WordOr, WordT, WordT, WordT) \
V(WordAnd, WordT, WordT, WordT) \
V(WordXor, WordT, WordT, WordT) \
......@@ -362,6 +368,7 @@ TNode<Float64T> Float64Add(TNode<Float64T> a, TNode<Float64T> b);
V(Word32Clz, Int32T, Word32T) \
V(Word32BitwiseNot, Word32T, Word32T) \
V(WordNot, WordT, WordT) \
V(Word64Not, Word64T, Word64T) \
V(Int32AbsWithOverflow, PAIR_TYPE(Int32T, BoolT), Int32T) \
V(Int64AbsWithOverflow, PAIR_TYPE(Int64T, BoolT), Int64T) \
V(IntPtrAbsWithOverflow, PAIR_TYPE(IntPtrT, BoolT), IntPtrT) \
......@@ -523,6 +530,9 @@ class V8_EXPORT_PRIVATE CodeAssembler {
// Constants.
TNode<Int32T> Int32Constant(int32_t value);
TNode<Int64T> Int64Constant(int64_t value);
TNode<Uint64T> Uint64Constant(uint64_t value) {
return Unsigned(Int64Constant(bit_cast<int64_t>(value)));
}
TNode<IntPtrT> IntPtrConstant(intptr_t value);
TNode<Uint32T> Uint32Constant(uint32_t value) {
return Unsigned(Int32Constant(bit_cast<int32_t>(value)));
......@@ -574,10 +584,14 @@ class V8_EXPORT_PRIVATE CodeAssembler {
bool IsNullConstant(TNode<Object> node);
TNode<Int32T> Signed(TNode<Word32T> x) { return UncheckedCast<Int32T>(x); }
TNode<Int64T> Signed(TNode<Word64T> x) { return UncheckedCast<Int64T>(x); }
TNode<IntPtrT> Signed(TNode<WordT> x) { return UncheckedCast<IntPtrT>(x); }
TNode<Uint32T> Unsigned(TNode<Word32T> x) {
return UncheckedCast<Uint32T>(x);
}
TNode<Uint64T> Unsigned(TNode<Word64T> x) {
return UncheckedCast<Uint64T>(x);
}
TNode<UintPtrT> Unsigned(TNode<WordT> x) {
return UncheckedCast<UintPtrT>(x);
}
......@@ -894,6 +908,40 @@ class V8_EXPORT_PRIVATE CodeAssembler {
return Signed(Word32Sar(static_cast<TNode<Word32T>>(left), right));
}
TNode<Int64T> Word64Shl(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Word64Shl(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Word64Shl(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Word64Shl(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Word64Shr(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Word64Shr(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Word64Sar(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Word64Sar(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Word64And(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Word64And(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Word64And(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Word64And(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Word64Xor(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Word64Xor(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Word64Xor(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Word64Xor(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Word64Not(TNode<Int64T> value) {
return Signed(Word64Not(static_cast<TNode<Word64T>>(value)));
}
TNode<Uint64T> Word64Not(TNode<Uint64T> value) {
return Unsigned(Word64Not(static_cast<TNode<Word64T>>(value)));
}
TNode<IntPtrT> WordAnd(TNode<IntPtrT> left, TNode<IntPtrT> right) {
return Signed(WordAnd(static_cast<TNode<WordT>>(left),
static_cast<TNode<WordT>>(right)));
......@@ -958,6 +1006,30 @@ class V8_EXPORT_PRIVATE CodeAssembler {
static_cast<TNode<Word32T>>(right)));
}
TNode<Int64T> Int64Add(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Int64Add(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Uint64Add(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Int64Add(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Int64Sub(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Int64Sub(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Uint64Sub(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Int64Sub(static_cast<TNode<Word64T>>(left), right));
}
TNode<Int64T> Int64Mul(TNode<Int64T> left, TNode<Int64T> right) {
return Signed(Int64Mul(static_cast<TNode<Word64T>>(left), right));
}
TNode<Uint64T> Uint64Mul(TNode<Uint64T> left, TNode<Uint64T> right) {
return Unsigned(Int64Mul(static_cast<TNode<Word64T>>(left), right));
}
TNode<IntPtrT> IntPtrAdd(TNode<IntPtrT> left, TNode<IntPtrT> right) {
return Signed(IntPtrAdd(static_cast<TNode<WordT>>(left),
static_cast<TNode<WordT>>(right)));
......
......@@ -49,6 +49,7 @@ static const char* const BUILTIN_POINTER_TYPE_STRING = "BuiltinPtr";
static const char* const INTPTR_TYPE_STRING = "intptr";
static const char* const UINTPTR_TYPE_STRING = "uintptr";
static const char* const INT64_TYPE_STRING = "int64";
static const char* const UINT64_TYPE_STRING = "uint64";
static const char* const INT31_TYPE_STRING = "int31";
static const char* const INT32_TYPE_STRING = "int32";
static const char* const UINT31_TYPE_STRING = "uint31";
......
......@@ -279,6 +279,10 @@ void CSAGenerator::EmitInstruction(const CallIntrinsicInstruction& instruction,
out() << "ca_.Int32Constant";
} else if (return_type->IsSubtypeOf(TypeOracle::GetUint32Type())) {
out() << "ca_.Uint32Constant";
} else if (return_type->IsSubtypeOf(TypeOracle::GetInt64Type())) {
out() << "ca_.Int64Constant";
} else if (return_type->IsSubtypeOf(TypeOracle::GetUint64Type())) {
out() << "ca_.Uint64Constant";
} else if (return_type->IsSubtypeOf(TypeOracle::GetBoolType())) {
out() << "ca_.BoolConstant";
} else {
......
......@@ -267,6 +267,14 @@ class TypeOracle : public ContextualClass<TypeOracle> {
return Get().GetBuiltinType(UINTPTR_TYPE_STRING);
}
static const Type* GetInt64Type() {
return Get().GetBuiltinType(INT64_TYPE_STRING);
}
static const Type* GetUint64Type() {
return Get().GetBuiltinType(UINT64_TYPE_STRING);
}
static const Type* GetInt32Type() {
return Get().GetBuiltinType(INT32_TYPE_STRING);
}
......
......@@ -192,19 +192,28 @@ bool IsKeywordLikeName(const std::string& s) {
// Untagged/MachineTypes like 'int32', 'intptr' etc. follow a 'all-lowercase'
// naming convention and are those exempt from the normal type convention.
bool IsMachineType(const std::string& s) {
static const char* const machine_types[]{
VOID_TYPE_STRING, NEVER_TYPE_STRING,
INT8_TYPE_STRING, UINT8_TYPE_STRING,
INT16_TYPE_STRING, UINT16_TYPE_STRING,
INT31_TYPE_STRING, UINT31_TYPE_STRING,
INT32_TYPE_STRING, UINT32_TYPE_STRING,
INT64_TYPE_STRING, INTPTR_TYPE_STRING,
UINTPTR_TYPE_STRING, FLOAT32_TYPE_STRING,
FLOAT64_TYPE_STRING, FLOAT64_OR_HOLE_TYPE_STRING,
BOOL_TYPE_STRING, "string",
BINT_TYPE_STRING, CHAR8_TYPE_STRING,
CHAR16_TYPE_STRING};
static const char* const machine_types[]{VOID_TYPE_STRING,
NEVER_TYPE_STRING,
INT8_TYPE_STRING,
UINT8_TYPE_STRING,
INT16_TYPE_STRING,
UINT16_TYPE_STRING,
INT31_TYPE_STRING,
UINT31_TYPE_STRING,
INT32_TYPE_STRING,
UINT32_TYPE_STRING,
INT64_TYPE_STRING,
UINT64_TYPE_STRING,
INTPTR_TYPE_STRING,
UINTPTR_TYPE_STRING,
FLOAT32_TYPE_STRING,
FLOAT64_TYPE_STRING,
FLOAT64_OR_HOLE_TYPE_STRING,
BOOL_TYPE_STRING,
"string",
BINT_TYPE_STRING,
CHAR8_TYPE_STRING,
CHAR16_TYPE_STRING};
return std::find(std::begin(machine_types), std::end(machine_types), s) !=
std::end(machine_types);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment