Commit 3e78711c authored by Théotime Grohens's avatar Théotime Grohens Committed by Commit Bot

[dataview] Add fast path for DataView methods

This CL adds a fast path for DataView getters and setters when the
load or store to be performed is aligned and when the requested
endianness matches the platform endianness.

In that case, we can just emit the right load/store instruction
instead of having to read and write data byte by byte.

Change-Id: I10bd95a7fe8d23f695899eb8173bc654fb38fbb0
Reviewed-on: https://chromium-review.googlesource.com/1106168
Commit-Queue: Théotime Grohens <theotime@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54005}
parent 541a0b75
......@@ -10,9 +10,8 @@ type Tagged generates 'TNode<Object>';
type Smi extends Tagged generates 'TNode<Smi>';
type HeapObject extends Tagged generates 'TNode<HeapObject>';
type Object = Smi|HeapObject;
type word32 generates 'TNode<Word32T>' constexpr 'uint32_t';
type int32 extends word32 generates 'TNode<Int32T>' constexpr 'int32_t';
type uint32 extends word32 generates 'TNode<Uint32T>' constexpr 'uint32_t';
type int32 generates 'TNode<Int32T>' constexpr 'int32_t';
type uint32 generates 'TNode<Uint32T>' constexpr 'uint32_t';
type int64 generates 'TNode<Int64T>' constexpr 'int64_t';
type intptr generates 'TNode<IntPtrT>' constexpr 'intptr_t';
type uintptr generates 'TNode<UintPtrT>' constexpr 'uintptr_t';
......@@ -243,24 +242,29 @@ extern operator '>>>' macro SmiShr(Smi, constexpr int31): Smi;
extern operator '+' macro IntPtrAdd(intptr, intptr): intptr;
extern operator '-' macro IntPtrSub(intptr, intptr): intptr;
extern operator '>>>' macro WordShr(intptr, intptr): intptr;
extern operator '>>>' macro WordShr(uintptr, uintptr): uintptr;
extern operator '<<' macro WordShl(intptr, intptr): intptr;
extern operator '&' macro WordAnd(intptr, intptr): intptr;
extern operator '&' macro WordAnd(uintptr, uintptr): uintptr;
extern operator '+' macro Int32Add(int32, int32): int32;
extern operator '-' macro Int32Sub(int32, int32): int32;
extern operator '*' macro Int32Mul(int32, int32): int32;
extern operator '%' macro Int32Mod(int32, int32): int32;
extern operator '&' macro Word32And(word32, word32): int32;
extern operator '&' macro Word32And(int32, int32): int32;
extern operator '&' macro Word32And(uint32, uint32): uint32;
extern operator '==' macro
ConstexprInt31Equal(constexpr int31, constexpr int31): constexpr bool;
extern operator '==' macro Word32Equal(word32, word32): bool;
extern operator '!=' macro Word32NotEqual(word32, word32): bool;
extern operator '>>>' macro Word32Shr(word32, word32): word32;
extern operator '<<' macro Word32Shl(word32, word32): word32;
extern operator '|' macro Word32Or(word32, word32): word32;
extern operator '==' macro Word32Equal(int32, int32): bool;
extern operator '==' macro Word32Equal(uint32, uint32): bool;
extern operator '!=' macro Word32NotEqual(int32, int32): bool;
extern operator '!=' macro Word32NotEqual(uint32, uint32): bool;
extern operator '>>>' macro Word32Shr(uint32, uint32): uint32;
extern operator '<<' macro Word32Shl(int32, int32): int32;
extern operator '<<' macro Word32Shl(uint32, uint32): uint32;
extern operator '|' macro Word32Or(int32, int32): int32;
extern operator '|' macro Word32Or(uint32, uint32): uint32;
extern operator '+' macro NumberAdd(Number, Number): Number;
extern operator '-' macro NumberSub(Number, Number): Number;
......@@ -326,10 +330,12 @@ cast<FixedDoubleArray>(o: FixedArrayBase): FixedDoubleArray labels CastError {
extern macro AllocateHeapNumberWithValue(float64): HeapNumber;
extern macro ChangeInt32ToTagged(int32): Number;
extern macro ChangeUint32ToTagged(uint32): Number;
extern macro Unsigned(word32): uint32;
extern macro Unsigned(int32): uint32;
extern macro Unsigned(intptr): uintptr;
extern macro Signed(word32): int32;
extern macro Unsigned(RawPtr): uintptr;
extern macro Signed(uint32): int32;
extern macro Signed(uintptr): intptr;
extern macro Signed(RawPtr): intptr;
extern macro TruncateIntPtrToInt32(intptr): int32;
extern macro SmiTag(intptr): Smi;
extern macro SmiFromInt32(int32): Smi;
......@@ -338,8 +344,8 @@ extern macro SmiToInt32(Smi): int32;
extern macro LoadHeapNumberValue(HeapNumber): float64;
extern macro ChangeFloat32ToFloat64(float32): float64;
extern macro ChangeNumberToFloat64(Number): float64;
extern macro ChangeInt32ToIntPtr(word32): intptr; // Sign-extends.
extern macro ChangeUint32ToWord(word32): uintptr; // Doesn't sign-extend.
extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
extern macro NumberConstant(constexpr float64): Number;
extern macro NumberConstant(constexpr int32): Number;
......@@ -360,8 +366,8 @@ from_constexpr<intptr>(i: constexpr int31): intptr {
from_constexpr<int32>(i: constexpr int31): int32 {
return Int32Constant(i);
}
from_constexpr<word32>(i: constexpr int31): word32 {
return from_constexpr<int32>(i);
from_constexpr<uint32>(i: constexpr int31): uint32 {
return Unsigned(Int32Constant(i));
}
from_constexpr<uintptr>(i: constexpr int31): uintptr {
return ChangeUint32ToWord(i);
......@@ -379,9 +385,6 @@ from_constexpr<intptr>(i: constexpr int32): intptr {
from_constexpr<int32>(i: constexpr int32): int32 {
return Int32Constant(i);
}
from_constexpr<word32>(i: constexpr int32): word32 {
return from_constexpr<int32>(i);
}
from_constexpr<Number>(i: constexpr int32): Number {
return NumberConstant(i);
}
......@@ -413,9 +416,6 @@ macro convert<A : type>(i: int32): A;
convert<Number>(i: int32): Number {
return ChangeInt32ToTagged(i);
}
convert<uint32>(i: int32): uint32 {
return Unsigned(i);
}
convert<intptr>(i: int32): intptr {
return ChangeInt32ToIntPtr(i);
}
......@@ -426,32 +426,22 @@ macro convert<A : type>(ui: uint32): A;
convert<Number>(ui: uint32): Number {
return ChangeUint32ToTagged(ui);
}
macro convert<A : type>(word: word32): A;
convert<int32>(word: word32): int32 {
return Signed(word);
convert<Smi>(ui: uint32): Smi {
return SmiFromInt32(Signed(ui));
}
convert<uint32>(word: word32): uint32 {
return Unsigned(word);
}
convert<uintptr>(word: word32): uintptr {
return ChangeUint32ToWord(word);
convert<uintptr>(ui: uint32): uintptr {
return ChangeUint32ToWord(ui);
}
macro convert<A : type>(i: intptr): A;
convert<word32>(i: intptr): word32 {
convert<int32>(i: intptr): int32 {
return TruncateIntPtrToInt32(i);
}
convert<uintptr>(i: intptr): uintptr {
return Unsigned(i);
}
convert<Smi>(i: intptr): Smi {
return SmiTag(i);
}
macro convert<A : type>(ui: uintptr): A;
convert<intptr>(ui: uintptr): intptr {
return Signed(ui);
}
convert<word32>(ui: uintptr): word32 {
return TruncateIntPtrToInt32(Signed(ui));
convert<uint32>(ui: uintptr): uint32 {
return Unsigned(TruncateIntPtrToInt32(Signed(ui)));
}
macro convert<A : type>(s: Smi): A;
convert<intptr>(s: Smi): intptr {
......@@ -472,6 +462,17 @@ macro convert<A : type>(f: float32): A;
convert<float64>(f: float32): float64 {
return ChangeFloat32ToFloat64(f);
}
macro convert<A : type>(d: float64): A;
convert<Number>(d: float64): Number {
return AllocateHeapNumberWithValue(d);
}
macro convert<A : type>(r: RawPtr): A;
convert<uintptr>(r: RawPtr): uintptr {
return Unsigned(r);
}
convert<intptr>(r: RawPtr): intptr {
return Signed(r);
}
extern macro UnsafeCastNumberToHeapNumber(Number): HeapNumber;
extern macro UnsafeCastObjectToFixedArray(Object): FixedArray;
......
......@@ -25,6 +25,14 @@ class DataViewBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
return CAST(LoadObjectField(data_view, JSDataView::kByteLengthOffset));
}
bool IsTargetLittleEndian() {
#ifdef V8_TARGET_LITTLE_ENDIAN
return true;
#else
return false;
#endif
}
TNode<Int32T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Int32T>(
Load(MachineType::Uint8(), data_pointer, offset));
......@@ -35,12 +43,57 @@ class DataViewBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
Load(MachineType::Int8(), data_pointer, offset));
}
TNode<Int32T> LoadUint16(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Int32T>(
Load(MachineType::Uint16(), data_pointer, offset));
}
TNode<Int32T> LoadInt16(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Int32T>(
Load(MachineType::Int16(), data_pointer, offset));
}
TNode<Uint32T> LoadUint32(TNode<RawPtrT> data_pointer,
TNode<IntPtrT> offset) {
return UncheckedCast<Uint32T>(
Load(MachineType::Uint32(), data_pointer, offset));
}
TNode<Int32T> LoadInt32(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Int32T>(
Load(MachineType::Int32(), data_pointer, offset));
}
TNode<Float32T> LoadFloat32(TNode<RawPtrT> data_pointer,
TNode<IntPtrT> offset) {
return UncheckedCast<Float32T>(
Load(MachineType::Float32(), data_pointer, offset));
}
TNode<Float64T> LoadFloat64(TNode<RawPtrT> data_pointer,
TNode<IntPtrT> offset) {
return UncheckedCast<Float64T>(
Load(MachineType::Float64(), data_pointer, offset));
}
void StoreWord8(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset,
TNode<Word32T> value) {
StoreNoWriteBarrier(MachineRepresentation::kWord8, data_pointer, offset,
value);
}
void StoreWord16(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset,
TNode<Word32T> value) {
StoreNoWriteBarrier(MachineRepresentation::kWord16, data_pointer, offset,
value);
}
void StoreWord32(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset,
TNode<Word32T> value) {
StoreNoWriteBarrier(MachineRepresentation::kWord32, data_pointer, offset,
value);
}
int32_t DataViewElementSize(ElementsKind elements_kind) {
return ElementsKindToByteSize(elements_kind);
}
......
This diff is collapsed.
......@@ -174,8 +174,8 @@ module test {
}
macro TestVariableRedeclaration(context : Context) : Boolean {
let var1 : Number = 42 == 0 ? 0 : 1;
let var2 : Number = 42 == 0 ? 1 : 0;
let var1 : Number = from_constexpr<bool>(42 == 0) ? 0 : 1;
let var2 : Number = from_constexpr<bool>(42 == 0) ? 1 : 0;
return True;
}
......
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