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

[dataview] Move DataView floating point getters to Torque

This CL moves the DataViewGetFloat32 and DataViewGetFloat64
getters from runtime to Torque.

Change-Id: Ic85ec7bcb4e48f679c24e28121b7c543454e7cde
Reviewed-on: https://chromium-review.googlesource.com/1088919Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Théotime Grohens <theotime@google.com>
Cr-Commit-Position: refs/heads/master@{#53606}
parent a17041d0
......@@ -12,7 +12,9 @@ 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 int64 generates 'TNode<Int64T>' constexpr 'int64_t';
type intptr generates 'TNode<IntPtrT>' constexpr 'intptr_t';
type float32 generates 'TNode<Float32T>' constexpr 'float';
type float64 generates 'TNode<Float64T>' constexpr 'double';
type bool generates 'TNode<BoolT>' constexpr 'bool';
......@@ -319,6 +321,7 @@ extern operator 'convert<>' macro SmiFromInt32(int32): Smi;
extern operator 'convert<>' macro SmiUntag(Smi): intptr;
extern operator 'convert<>' macro SmiToInt32(Smi): int32;
extern operator 'convert<>' macro LoadHeapNumberValue(HeapNumber): float64;
extern operator 'convert<>' macro ChangeFloat32ToFloat64(float32): float64;
extern operator 'convert<>' macro ChangeNumberToFloat64(Number): float64;
extern macro BranchIfFastJSArray(Object, Context): never labels Taken, NotTaken;
......
......@@ -73,6 +73,10 @@ module data_view {
}
}
extern macro BitcastInt32ToFloat32(int32): float32;
extern macro Float64InsertLowWord32(float64, int32): float64;
extern macro Float64InsertHighWord32(float64, int32): float64;
extern macro LoadUint8(RawPtr, intptr): int32;
extern macro LoadInt8(RawPtr, intptr): int32;
......@@ -134,9 +138,57 @@ module data_view {
}
}
macro LoadDataViewFloat32(data_pointer: RawPtr, offset: intptr,
requested_little_endian: bool): Number {
let b0: int32 = LoadUint8(data_pointer, offset);
let b1: int32 = LoadUint8(data_pointer, offset + 1);
let b2: int32 = LoadUint8(data_pointer, offset + 2);
let b3: int32 = LoadUint8(data_pointer, offset + 3);
let result: int32;
if (requested_little_endian) {
let low_part: int32 = (b1 << 8) + b0;
let high_part: int32 = (b3 << 8) + b2;
result = (high_part << 16) + low_part;
} else {
let high_part: int32 = (b0 << 8) + b1;
let low_part: int32 = (b2 << 8) + b3;
result = (high_part << 16) + low_part;
}
let float_res: float64 = convert<float64>(BitcastInt32ToFloat32(result));
return AllocateHeapNumberWithValue(float_res);
}
macro LoadDataViewFloat64(data_pointer: RawPtr, offset: intptr,
requested_little_endian: bool): Number {
let b0: int32 = LoadUint8(data_pointer, offset);
let b1: int32 = LoadUint8(data_pointer, offset + 1);
let b2: int32 = LoadUint8(data_pointer, offset + 2);
let b3: int32 = LoadUint8(data_pointer, offset + 3);
let b4: int32 = LoadUint8(data_pointer, offset + 4);
let b5: int32 = LoadUint8(data_pointer, offset + 5);
let b6: int32 = LoadUint8(data_pointer, offset + 6);
let b7: int32 = LoadUint8(data_pointer, offset + 7);
let result: float64 = convert<float64>(0);
if (requested_little_endian) {
let low_part: int32 = (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
let high_part: int32 = (b7 << 24) + (b6 << 16) + (b5 << 8) + b4;
result = Float64InsertLowWord32(result, low_part);
result = Float64InsertHighWord32(result, high_part);
}
else {
let high_part: int32 = (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
let low_part: int32 = (b4 << 24) + (b5 << 16) + (b6 << 8) + b7;
result = Float64InsertLowWord32(result, low_part);
result = Float64InsertHighWord32(result, high_part);
}
return AllocateHeapNumberWithValue(result);
}
// Context, receiver, byteOffset, littleEndian
extern runtime DataViewGetFloat32(Context, Object, Object, Object): Number;
extern runtime DataViewGetFloat64(Context, Object, Object, Object): Number;
extern runtime DataViewGetBigInt64(Context, Object, Object, Object): Number;
extern runtime DataViewGetBigUint64(Context, Object, Object, Object): Number;
......@@ -194,6 +246,10 @@ module data_view {
return LoadDataView32(data_pointer, bufferIndex, littleEndian, false);
} else if constexpr (kind == INT32_ELEMENTS) {
return LoadDataView32(data_pointer, bufferIndex, littleEndian, true);
} else if constexpr (kind == FLOAT32_ELEMENTS) {
return LoadDataViewFloat32(data_pointer, bufferIndex, littleEndian);
} else if constexpr (kind == FLOAT64_ELEMENTS) {
return LoadDataViewFloat64(data_pointer, bufferIndex, littleEndian);
} else {
unreachable;
}
......@@ -271,7 +327,8 @@ module data_view {
let is_little_endian : Object = arguments.length > 1 ?
arguments[1] :
Undefined;
return DataViewGetFloat32(context, receiver, offset, is_little_endian);
return DataViewGet(context, receiver, offset, is_little_endian,
FLOAT32_ELEMENTS);
}
javascript builtin DataViewPrototypeGetFloat64(
......@@ -282,7 +339,8 @@ module data_view {
let is_little_endian : Object = arguments.length > 1 ?
arguments[1] :
Undefined;
return DataViewGetFloat64(context, receiver, offset, is_little_endian);
return DataViewGet(context, receiver, offset, is_little_endian,
FLOAT64_ELEMENTS);
}
javascript builtin DataViewPrototypeGetBigInt64(
......
......@@ -531,6 +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(RoundFloat64ToInt32, Int32T, Float64T) \
V(RoundInt32ToFloat32, Int32T, Float32T) \
V(Float64SilenceNaN, Float64T, Float64T) \
......
......@@ -253,6 +253,7 @@ class MachineRepresentationInferrer {
case IrOpcode::kRoundUint32ToFloat32:
case IrOpcode::kRoundInt64ToFloat32:
case IrOpcode::kRoundUint64ToFloat32:
case IrOpcode::kBitcastInt32ToFloat32:
case IrOpcode::kFloat32Constant:
case IrOpcode::kTruncateFloat64ToFloat32:
MACHINE_FLOAT32_BINOP_LIST(LABEL)
......@@ -266,6 +267,8 @@ class MachineRepresentationInferrer {
case IrOpcode::kChangeFloat32ToFloat64:
case IrOpcode::kChangeInt32ToFloat64:
case IrOpcode::kChangeUint32ToFloat64:
case IrOpcode::kFloat64InsertLowWord32:
case IrOpcode::kFloat64InsertHighWord32:
case IrOpcode::kFloat64Constant:
case IrOpcode::kFloat64SilenceNaN:
MACHINE_FLOAT64_BINOP_LIST(LABEL)
......@@ -407,6 +410,7 @@ class MachineRepresentationChecker {
case IrOpcode::kChangeUint32ToFloat64:
case IrOpcode::kRoundInt32ToFloat32:
case IrOpcode::kRoundUint32ToFloat32:
case IrOpcode::kBitcastInt32ToFloat32:
case IrOpcode::kChangeInt32ToInt64:
case IrOpcode::kChangeUint32ToUint64:
MACHINE_UNOP_32_LIST(LABEL) { CheckValueInputForInt32Op(node, 0); }
......@@ -470,6 +474,11 @@ class MachineRepresentationChecker {
}
break;
#undef LABEL
case IrOpcode::kFloat64InsertLowWord32:
case IrOpcode::kFloat64InsertHighWord32:
CheckValueInputForFloat64Op(node, 0);
CheckValueInputForInt32Op(node, 1);
break;
case IrOpcode::kParameter:
case IrOpcode::kProjection:
break;
......
......@@ -353,8 +353,6 @@ bool IntrinsicHasNoSideEffect(Runtime::FunctionId id) {
V(TrySliceSimpleNonFastElements) \
V(TypedArrayGetBuffer) \
/* DataView */ \
V(DataViewGetFloat32) \
V(DataViewGetFloat64) \
V(DataViewGetBigInt64) \
V(DataViewGetBigUint64) \
/* Errors */ \
......
......@@ -256,8 +256,6 @@ MaybeHandle<Object> SetViewValue(Isolate* isolate, Handle<JSDataView> data_view,
return *result; \
}
DATA_VIEW_PROTOTYPE_GET(Float32, float)
DATA_VIEW_PROTOTYPE_GET(Float64, double)
DATA_VIEW_PROTOTYPE_GET(BigInt64, int64_t)
DATA_VIEW_PROTOTYPE_GET(BigUint64, uint64_t)
#undef DATA_VIEW_PROTOTYPE_GET
......
......@@ -570,8 +570,6 @@ namespace internal {
F(TypedArraySortFast, 1, 1)
#define FOR_EACH_INTRINSIC_DATAVIEW(F) \
F(DataViewGetFloat32, 2, 1) \
F(DataViewGetFloat64, 2, 1) \
F(DataViewGetBigInt64, 2, 1) \
F(DataViewGetBigUint64, 2, 1) \
F(DataViewSetInt8, 2, 1) \
......
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