Commit 5b4e8db5 authored by Théotime Grohens's avatar Théotime Grohens Committed by Commit Bot

[dataview] Move DataView BigInt getters to Torque

This CL moves the remaining runtime DataView getters to Torque,
namely DataViewGetBigInt64/BigUint64, and removes the associated
runtime code that is now unneeded.

All of the DataView getters are now implemented in Torque, which brings
a nice performance improvement over the former C++ builtin code.

Change-Id: I35cf2eabce3c79cc0d3200e7f24dbe0c3e5c2804
Reviewed-on: https://chromium-review.googlesource.com/1092736
Commit-Queue: Théotime Grohens <theotime@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53765}
parent 082422c4
......@@ -10,10 +10,12 @@ type Tagged generates 'TNode<Object>';
type Smi extends Tagged generates 'TNode<Smi>';
type HeapObject extends Tagged generates 'TNode<HeapObject>';
type Object = Smi|HeapObject;
type int32 generates 'TNode<Int32T>' constexpr 'int32_t';
type uint32 generates 'TNode<Uint32T>' constexpr 'uint32_t';
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 int64 generates 'TNode<Int64T>' constexpr 'int64_t';
type intptr generates 'TNode<IntPtrT>' constexpr 'intptr_t';
type uintptr generates 'TNode<UintPtrT>' constexpr 'uintptr_t';
type float32 generates 'TNode<Float32T>' constexpr 'float';
type float64 generates 'TNode<Float64T>' constexpr 'double';
type bool generates 'TNode<BoolT>' constexpr 'bool';
......@@ -27,7 +29,9 @@ type Context extends HeapObject generates 'TNode<Context>';
type String extends HeapObject generates 'TNode<String>';
type Oddball extends HeapObject generates 'TNode<Oddball>';
type HeapNumber extends HeapObject generates 'TNode<HeapNumber>';
type Number = Smi|HeapNumber;
type Number = Smi | HeapNumber;
type BigInt extends HeapObject generates 'TNode<BigInt>';
type Numeric = Number | BigInt;
type Boolean extends Oddball generates 'TNode<Oddball>';
type JSProxy extends JSReceiver generates 'TNode<JSProxy>';
type JSObject extends JSReceiver generates 'TNode<JSObject>';
......@@ -137,6 +141,8 @@ const kSloppy: constexpr LanguageMode = 'LanguageMode::kSloppy';
const SMI_PARAMETERS: constexpr ParameterMode = 'SMI_PARAMETERS';
const INTPTR_PARAMETERS: constexpr ParameterMode = 'INTPTR_PARAMETERS';
extern macro Is64(): constexpr bool;
extern macro Print(Object);
extern macro DebugBreak();
extern macro ToInteger_Inline(Context, Object): Number;
......@@ -172,8 +178,6 @@ extern builtin StringLessThan(Context, String, String): Boolean;
extern macro StrictEqual(Object, Object): Boolean;
extern runtime SmiLexicographicCompare(Context, Object, Object): Number;
extern operator '==' macro Word32Equal(int32, int32): bool;
extern operator '!=' macro Word32NotEqual(int32, int32): bool;
extern operator '<' macro Int32LessThan(int32, int32): bool;
extern operator '>' macro Int32GreaterThan(int32, int32): bool;
extern operator '<=' macro Int32LessThanOrEqual(int32, int32): bool;
......@@ -227,12 +231,19 @@ 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 WordShl(intptr, intptr): intptr;
extern operator '&' macro WordAnd(intptr, intptr): intptr;
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(int32, int32): int32;
extern operator '<<' macro Word32Shl(int32, int32): int32;
extern operator '==' macro Word32Equal(word32, word32): bool;
extern operator '!=' macro Word32NotEqual(word32, word32): bool;
extern operator '<<' macro Word32Shl(word32, word32): word32;
extern operator '|' macro Word32Or(word32, word32): word32;
extern operator '+' macro NumberAdd(Number, Number): Number;
extern operator '-' macro NumberSub(Number, Number): Number;
......@@ -298,7 +309,10 @@ 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(int32): uint32;
extern macro Unsigned(word32): uint32;
extern macro Unsigned(intptr): uintptr;
extern macro Signed(word32): int32;
extern macro Signed(uintptr): intptr;
extern macro TruncateIntPtrToInt32(intptr): int32;
extern macro SmiTag(intptr): Smi;
extern macro SmiFromInt32(int32): Smi;
......@@ -307,6 +321,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 NumberConstant(constexpr float64): Number;
extern macro NumberConstant(constexpr int32): Number;
......@@ -326,6 +342,9 @@ 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<Smi>(i: constexpr int31): Smi {
return SmiConstant(i);
}
......@@ -339,6 +358,9 @@ from_constexpr<intptr>(i: constexpr int32): intptr {
from_constexpr<int32>(i: constexpr int32): int32 {
return Int32Constant(2);
}
from_constexpr<word32>(i: constexpr int32): word32 {
return from_constexpr<int32>(i);
}
from_constexpr<Number>(i: constexpr int32): Number {
return NumberConstant(i);
}
......@@ -366,6 +388,9 @@ convert<Number>(i: int32): Number {
convert<uint32>(i: int32): uint32 {
return Unsigned(i);
}
convert<intptr>(i: int32): intptr {
return ChangeInt32ToIntPtr(i);
}
convert<Smi>(i: int32): Smi {
return SmiFromInt32(i);
}
......@@ -373,13 +398,30 @@ 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<uint32>(word: word32): uint32 {
return Unsigned(word);
}
convert<uintptr>(word: word32): uintptr {
return ChangeUint32ToWord(word);
}
macro convert<A: type>(i: intptr): A;
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);
}
macro convert<A: type>(s: Smi): A;
convert<intptr>(s: Smi): intptr {
return SmiUntag(s);
......
......@@ -6,6 +6,7 @@
#define V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
#include "src/elements-kind.h"
#include "src/objects/bigint.h"
#include "torque-generated/builtins-base-from-dsl-gen.h"
namespace v8 {
......@@ -24,8 +25,8 @@ class DataViewBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
return LoadObjectField<Smi>(data_view, JSDataView::kByteLengthOffset);
}
TNode<Int32T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Int32T>(
TNode<Uint32T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<IntPtrT> offset) {
return UncheckedCast<Uint32T>(
Load(MachineType::Uint8(), data_pointer, offset));
}
......@@ -33,11 +34,16 @@ class DataViewBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler {
return UncheckedCast<Int32T>(
Load(MachineType::Int8(), data_pointer, offset));
}
};
int32_t DataViewElementSize(ElementsKind elements_kind) {
return ElementsKindToByteSize(elements_kind);
}
int32_t DataViewElementSize(ElementsKind elements_kind) {
return ElementsKindToByteSize(elements_kind);
}
TNode<IntPtrT> DataViewEncodeBigIntBits(bool sign, int32_t digits) {
return IntPtrConstant(BigInt::SignBits::encode(sign) |
BigInt::LengthBits::encode(digits));
}
};
} // namespace internal
} // namespace v8
......
This diff is collapsed.
......@@ -531,7 +531,7 @@ TNode<Float64T> Float64Add(TNode<Float64T> a, TNode<Float64T> b);
V(ChangeInt32ToInt64, Int64T, Int32T) \
V(ChangeUint32ToFloat64, Float64T, Word32T) \
V(ChangeUint32ToUint64, Uint64T, Word32T) \
V(BitcastInt32ToFloat32, Float32T, Int32T) \
V(BitcastInt32ToFloat32, Float32T, Word32T) \
V(RoundFloat64ToInt32, Int32T, Float64T) \
V(RoundInt32ToFloat32, Int32T, Float32T) \
V(Float64SilenceNaN, Float64T, Float64T) \
......
......@@ -352,9 +352,6 @@ bool IntrinsicHasNoSideEffect(Runtime::FunctionId id) {
V(PrepareElementsForSort) \
V(TrySliceSimpleNonFastElements) \
V(TypedArrayGetBuffer) \
/* DataView */ \
V(DataViewGetBigInt64) \
V(DataViewGetBigUint64) \
/* Errors */ \
V(NewTypeError) \
V(ReThrow) \
......
......@@ -39,70 +39,6 @@ void FlipBytes(uint8_t* target, uint8_t const* source) {
}
}
template <typename T>
MaybeHandle<Object> AllocateResult(Isolate* isolate, T value) {
return isolate->factory()->NewNumber(value);
}
template <>
MaybeHandle<Object> AllocateResult(Isolate* isolate, int64_t value) {
return BigInt::FromInt64(isolate, value);
}
template <>
MaybeHandle<Object> AllocateResult(Isolate* isolate, uint64_t value) {
return BigInt::FromUint64(isolate, value);
}
// ES6 section 24.2.1.1 GetViewValue (view, requestIndex, isLittleEndian, type)
template <typename T>
MaybeHandle<Object> GetViewValue(Isolate* isolate, Handle<JSDataView> data_view,
Handle<Object> request_index,
bool is_little_endian, const char* method) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, request_index,
Object::ToIndex(isolate, request_index,
MessageTemplate::kInvalidDataViewAccessorOffset),
Object);
size_t get_index = 0;
if (!TryNumberToSize(*request_index, &get_index)) {
THROW_NEW_ERROR(
isolate, NewRangeError(MessageTemplate::kInvalidDataViewAccessorOffset),
Object);
}
Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(data_view->buffer()),
isolate);
if (buffer->was_neutered()) {
Handle<String> operation =
isolate->factory()->NewStringFromAsciiChecked(method);
THROW_NEW_ERROR(
isolate, NewTypeError(MessageTemplate::kDetachedOperation, operation),
Object);
}
size_t const data_view_byte_offset = NumberToSize(data_view->byte_offset());
size_t const data_view_byte_length = NumberToSize(data_view->byte_length());
if (get_index + sizeof(T) > data_view_byte_length ||
get_index + sizeof(T) < get_index) { // overflow
THROW_NEW_ERROR(
isolate, NewRangeError(MessageTemplate::kInvalidDataViewAccessorOffset),
Object);
}
union {
T data;
uint8_t bytes[sizeof(T)];
} v;
size_t const buffer_offset = data_view_byte_offset + get_index;
DCHECK_GE(NumberToSize(buffer->byte_length()), buffer_offset + sizeof(T));
uint8_t const* const source =
static_cast<uint8_t*>(buffer->backing_store()) + buffer_offset;
if (NeedToFlipBytes(is_little_endian)) {
FlipBytes<sizeof(T)>(v.bytes, source);
} else {
CopyBytes<sizeof(T)>(v.bytes, source);
}
return AllocateResult<T>(isolate, v.data);
}
template <typename T>
MaybeHandle<Object> DataViewConvertInput(Isolate* isolate,
Handle<Object> input) {
......@@ -241,25 +177,6 @@ MaybeHandle<Object> SetViewValue(Isolate* isolate, Handle<JSDataView> data_view,
} \
Handle<JSDataView> data_view = Handle<JSDataView>::cast(receiver);
#define DATA_VIEW_PROTOTYPE_GET(Type, type) \
RUNTIME_FUNCTION(Runtime_DataViewGet##Type) { \
HandleScope scope(isolate); \
CHECK_RECEIVER_OBJECT("DataView.prototype.get" #Type); \
Handle<Object> byte_offset = args.at<Object>(1); \
Handle<Object> is_little_endian = args.at<Object>(2); \
Handle<Object> result; \
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \
isolate, result, \
GetViewValue<type>(isolate, data_view, byte_offset, \
is_little_endian->BooleanValue(isolate), \
"DataView.prototype.get" #Type)); \
return *result; \
}
DATA_VIEW_PROTOTYPE_GET(BigInt64, int64_t)
DATA_VIEW_PROTOTYPE_GET(BigUint64, uint64_t)
#undef DATA_VIEW_PROTOTYPE_GET
#define DATA_VIEW_PROTOTYPE_SET(Type, type) \
RUNTIME_FUNCTION(Runtime_DataViewSet##Type) { \
HandleScope scope(isolate); \
......
......@@ -570,8 +570,6 @@ namespace internal {
F(TypedArraySortFast, 1, 1)
#define FOR_EACH_INTRINSIC_DATAVIEW(F) \
F(DataViewGetBigInt64, 2, 1) \
F(DataViewGetBigUint64, 2, 1) \
F(DataViewSetInt8, 2, 1) \
F(DataViewSetUint8, 2, 1) \
F(DataViewSetInt16, 3, 1) \
......
......@@ -68,6 +68,16 @@ assertEquals(0x89, bytes[23]);
assertEquals(b2, dataview.getBigInt64(8, true));
assertEquals(0x89abcdef01234568n, dataview.getBigUint64(8, true));
var b3 = -0x8000000000000000n; // The int64_t minimum value.
dataview.setBigInt64(8, b3);
assertEquals(b3, dataview.getBigInt64(8));
assertEquals(-b3, dataview.getBigUint64(8));
var b4 = 0x8000000000000000n;
dataview.setBigInt64(8, b4);
assertEquals(-b4, dataview.getBigInt64(8));
assertEquals(b4, dataview.getBigUint64(8));
assertThrows(() => dataview.setBigInt64(0, 1), TypeError);
assertThrows(() => dataview.setBigUint64(0, 1), TypeError);
assertThrows(() => dataview.setInt32(0, 1n), TypeError);
......
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