Commit 8a5ab573 authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque] Simplify Convert<>

Bug: v8:7793
Change-Id: I31cae67edfce6a0ba925df34d496d3d62bc7d5ef
Reviewed-on: https://chromium-review.googlesource.com/c/1358519
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58114}
parent e98c72a1
...@@ -21,8 +21,8 @@ namespace array { ...@@ -21,8 +21,8 @@ namespace array {
const newElements: FixedArray = const newElements: FixedArray =
Cast<FixedArray>(result.elements) otherwise Bailout; Cast<FixedArray>(result.elements) otherwise Bailout;
CopyElements( CopyElements(
PACKED_ELEMENTS, newElements, Convert<intptr>(0), sourceElements, PACKED_ELEMENTS, newElements, 0, sourceElements, Convert<intptr>(start),
Convert<intptr>(start), Convert<intptr>(count)); Convert<intptr>(count));
return result; return result;
} }
......
...@@ -815,7 +815,6 @@ FromConstexpr<Number, constexpr Smi>(s: constexpr Smi): Number { ...@@ -815,7 +815,6 @@ FromConstexpr<Number, constexpr Smi>(s: constexpr Smi): Number {
FromConstexpr<Smi, constexpr Smi>(s: constexpr Smi): Smi { FromConstexpr<Smi, constexpr Smi>(s: constexpr Smi): Smi {
return SmiConstant(s); return SmiConstant(s);
} }
FromConstexpr<uint32, constexpr int31>(i: constexpr int31): uint32 { FromConstexpr<uint32, constexpr int31>(i: constexpr int31): uint32 {
return Unsigned(Int32Constant(i)); return Unsigned(Int32Constant(i));
} }
...@@ -844,90 +843,78 @@ FromConstexpr<NativeContextSlot, constexpr NativeContextSlot>( ...@@ -844,90 +843,78 @@ FromConstexpr<NativeContextSlot, constexpr NativeContextSlot>(
return IntPtrConstant(c); return IntPtrConstant(c);
} }
macro Convert<A: type>(i: constexpr int31): A { macro Convert<To: type, From: type>(i: From): To {
return i; return i;
} }
extern macro ConvertElementsKindToInt(ElementsKind): int32;
macro Convert<A: type>(elementsKind: ElementsKind): A; extern macro ConvertElementsKindToInt(ElementsKind): int32;
Convert<int32>(elementsKind: ElementsKind): int32 { Convert<int32, ElementsKind>(elementsKind: ElementsKind): int32 {
return ConvertElementsKindToInt(elementsKind); return ConvertElementsKindToInt(elementsKind);
} }
Convert<Number, int32>(i: int32): Number {
macro Convert<A: type>(i: int32): A;
Convert<Number>(i: int32): Number {
return ChangeInt32ToTagged(i); return ChangeInt32ToTagged(i);
} }
Convert<intptr>(i: int32): intptr { Convert<intptr, int32>(i: int32): intptr {
return ChangeInt32ToIntPtr(i); return ChangeInt32ToIntPtr(i);
} }
Convert<Smi>(i: int32): Smi { Convert<Smi, int32>(i: int32): Smi {
return SmiFromInt32(i); return SmiFromInt32(i);
} }
macro Convert<A: type>(ui: uint32): A; Convert<Number, uint32>(ui: uint32): Number {
Convert<Number>(ui: uint32): Number {
return ChangeUint32ToTagged(ui); return ChangeUint32ToTagged(ui);
} }
Convert<Smi>(ui: uint32): Smi { Convert<Smi, uint32>(ui: uint32): Smi {
return SmiFromInt32(Signed(ui)); return SmiFromInt32(Signed(ui));
} }
Convert<uintptr>(ui: uint32): uintptr { Convert<uintptr, uint32>(ui: uint32): uintptr {
return ChangeUint32ToWord(ui); return ChangeUint32ToWord(ui);
} }
macro Convert<A: type>(i: intptr): A; Convert<int32, intptr>(i: intptr): int32 {
Convert<int32>(i: intptr): int32 {
return TruncateIntPtrToInt32(i); return TruncateIntPtrToInt32(i);
} }
Convert<Smi>(i: intptr): Smi { Convert<Smi, intptr>(i: intptr): Smi {
return SmiTag(i); return SmiTag(i);
} }
macro Convert<A: type>(ui: uintptr): A; Convert<uint32, uintptr>(ui: uintptr): uint32 {
Convert<uint32>(ui: uintptr): uint32 {
return Unsigned(TruncateIntPtrToInt32(Signed(ui))); return Unsigned(TruncateIntPtrToInt32(Signed(ui)));
} }
macro Convert<A: type>(s: Smi): A; Convert<intptr, Smi>(s: Smi): intptr {
Convert<intptr>(s: Smi): intptr {
return SmiUntag(s); return SmiUntag(s);
} }
Convert<int32>(s: Smi): int32 { Convert<int32, Smi>(s: Smi): int32 {
return SmiToInt32(s); return SmiToInt32(s);
} }
macro Convert<A: type>(h: HeapNumber): A; Convert<float64, HeapNumber>(h: HeapNumber): float64 {
Convert<float64>(h: HeapNumber): float64 {
return LoadHeapNumberValue(h); return LoadHeapNumberValue(h);
} }
macro Convert<A: type>(n: Number): A; Convert<float64, Number>(n: Number): float64 {
Convert<float64>(n: Number): float64 {
return ChangeNumberToFloat64(n); return ChangeNumberToFloat64(n);
} }
Convert<uintptr>(n: Number): uintptr { Convert<uintptr, Number>(n: Number): uintptr {
return ChangeNonnegativeNumberToUintPtr(n); return ChangeNonnegativeNumberToUintPtr(n);
} }
macro Convert<A: type>(f: float32): A; Convert<float64, float32>(f: float32): float64 {
Convert<float64>(f: float32): float64 {
return ChangeFloat32ToFloat64(f); return ChangeFloat32ToFloat64(f);
} }
macro Convert<A: type>(d: float64): A; Convert<Number, float64>(d: float64): Number {
Convert<Number>(d: float64): Number {
return AllocateHeapNumberWithValue(d); return AllocateHeapNumberWithValue(d);
} }
Convert<float64>(ui: uintptr): float64 { Convert<float64, uintptr>(ui: uintptr): float64 {
return ChangeUintPtrToFloat64(ui); return ChangeUintPtrToFloat64(ui);
} }
Convert<Number>(ui: uintptr): Number { Convert<Number, uintptr>(ui: uintptr): Number {
return ChangeUintPtrToTagged(ui); return ChangeUintPtrToTagged(ui);
} }
Convert<uintptr>(d: float64): uintptr { Convert<uintptr, float64>(d: float64): uintptr {
return ChangeFloat64ToUintPtr(d); return ChangeFloat64ToUintPtr(d);
} }
Convert<uintptr>(i: intptr): uintptr { Convert<uintptr, intptr>(i: intptr): uintptr {
return Unsigned(i); return Unsigned(i);
} }
macro Convert<A: type>(r: RawPtr): A; Convert<uintptr, RawPtr>(r: RawPtr): uintptr {
Convert<uintptr>(r: RawPtr): uintptr {
return Unsigned(r); return Unsigned(r);
} }
Convert<intptr>(r: RawPtr): intptr { Convert<intptr, RawPtr>(r: RawPtr): intptr {
return Signed(r); return Signed(r);
} }
......
...@@ -417,7 +417,7 @@ namespace data_view { ...@@ -417,7 +417,7 @@ namespace data_view {
let viewOffsetWord: uintptr = dataView.byte_offset; let viewOffsetWord: uintptr = dataView.byte_offset;
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length); let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
let elementSizeFloat: float64 = Convert<float64>(DataViewElementSize(kind)); let elementSizeFloat: float64 = DataViewElementSize(kind);
if (getIndexFloat + elementSizeFloat > viewSizeFloat) { if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
ThrowRangeError(context, kInvalidDataViewAccessorOffset); ThrowRangeError(context, kInvalidDataViewAccessorOffset);
...@@ -700,8 +700,7 @@ namespace data_view { ...@@ -700,8 +700,7 @@ namespace data_view {
let viewOffsetWord: uintptr = dataView.byte_offset; let viewOffsetWord: uintptr = dataView.byte_offset;
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length); let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
let elementSizeFloat: float64 = let elementSizeFloat: float64 = DataViewElementSize(kind);
Convert<float64>(DataViewElementSize(kind));
if (getIndexFloat + elementSizeFloat > viewSizeFloat) { if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
ThrowRangeError(context, kInvalidDataViewAccessorOffset); ThrowRangeError(context, kInvalidDataViewAccessorOffset);
...@@ -722,8 +721,7 @@ namespace data_view { ...@@ -722,8 +721,7 @@ namespace data_view {
let viewOffsetWord: uintptr = dataView.byte_offset; let viewOffsetWord: uintptr = dataView.byte_offset;
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length); let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
let elementSizeFloat: float64 = let elementSizeFloat: float64 = DataViewElementSize(kind);
Convert<float64>(DataViewElementSize(kind));
if (getIndexFloat + elementSizeFloat > viewSizeFloat) { if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
ThrowRangeError(context, kInvalidDataViewAccessorOffset); ThrowRangeError(context, kInvalidDataViewAccessorOffset);
......
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