Commit e5ad1b1d authored by jochen's avatar jochen Committed by Commit bot

Make sure fixed typed array is always double aligned for doubles

Allows for getting rid of the special casing for float64 and is probably
faster.

BUG=v8:3996
R=verwaest@chromium.org,dslomov@chromium.org,plind44@gmail.com
LOG=n

Review URL: https://codereview.chromium.org/1128433006

Cr-Commit-Position: refs/heads/master@{#28281}
parent 537ed750
......@@ -640,6 +640,10 @@ struct AccessorDescriptor {
#define CODE_POINTER_ALIGN(value) \
(((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
#define DOUBLE_POINTER_ALIGN(value) \
(((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
// inside a C++ class and new and delete will be overloaded so logging is
// performed.
......
......@@ -2714,8 +2714,8 @@ bool Heap::CreateInitialMaps() {
ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array)
ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space)
#define ALLOCATE_EXTERNAL_ARRAY_MAP(Type, type, TYPE, ctype, size) \
ALLOCATE_MAP(EXTERNAL_##TYPE##_ARRAY_TYPE, ExternalArray::kAlignedSize, \
#define ALLOCATE_EXTERNAL_ARRAY_MAP(Type, type, TYPE, ctype, size) \
ALLOCATE_MAP(EXTERNAL_##TYPE##_ARRAY_TYPE, ExternalArray::kSize, \
external_##type##_array)
TYPED_ARRAYS(ALLOCATE_EXTERNAL_ARRAY_MAP)
......@@ -3619,7 +3619,7 @@ AllocationResult Heap::AllocateExternalArray(int length,
ExternalArrayType array_type,
void* external_pointer,
PretenureFlag pretenure) {
int size = ExternalArray::kAlignedSize;
int size = ExternalArray::kSize;
AllocationSpace space = SelectSpace(size, pretenure);
HeapObject* result;
{
......
......@@ -9835,11 +9835,8 @@ HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements(
// conversion after allocation but before the new object fields are set.
length = AddUncasted<HForceRepresentation>(length, Representation::Smi());
HValue* elements =
Add<HAllocate>(
Add<HConstant>(ExternalArray::kAlignedSize),
HType::HeapObject(),
NOT_TENURED,
external_array_map->instance_type());
Add<HAllocate>(Add<HConstant>(ExternalArray::kSize), HType::HeapObject(),
NOT_TENURED, external_array_map->instance_type());
AddStoreMapConstant(elements, external_array_map);
Add<HStoreNamedField>(elements,
......@@ -9892,9 +9889,16 @@ HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray(
length = AddUncasted<HForceRepresentation>(length, Representation::Smi());
Handle<Map> fixed_typed_array_map(
isolate()->heap()->MapForFixedTypedArray(array_type));
HValue* elements =
Add<HAllocate>(total_size, HType::HeapObject(),
NOT_TENURED, fixed_typed_array_map->instance_type());
HAllocate* elements =
Add<HAllocate>(total_size, HType::HeapObject(), NOT_TENURED,
fixed_typed_array_map->instance_type());
#ifndef V8_HOST_ARCH_64_BIT
if (array_type == kExternalFloat64Array) {
elements->MakeDoubleAligned();
}
#endif
AddStoreMapConstant(elements, fixed_typed_array_map);
Add<HStoreNamedField>(elements,
......
......@@ -4312,14 +4312,6 @@ typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) {
}
template<> inline
FixedTypedArray<Float64ArrayTraits>::ElementType
FixedTypedArray<Float64ArrayTraits>::get_scalar(int index) {
DCHECK((index >= 0) && (index < this->length()));
return READ_DOUBLE_FIELD(this, ElementOffset(index));
}
template <class Traits>
void FixedTypedArray<Traits>::set(int index, ElementType value) {
DCHECK((index >= 0) && (index < this->length()));
......@@ -4329,14 +4321,6 @@ void FixedTypedArray<Traits>::set(int index, ElementType value) {
}
template<> inline
void FixedTypedArray<Float64ArrayTraits>::set(
int index, Float64ArrayTraits::ElementType value) {
DCHECK((index >= 0) && (index < this->length()));
WRITE_DOUBLE_FIELD(this, ElementOffset(index), value);
}
template <class Traits>
typename Traits::ElementType FixedTypedArray<Traits>::from_int(int value) {
return static_cast<ElementType>(value);
......
......@@ -4645,8 +4645,7 @@ class ExternalArray: public FixedArrayBase {
// ExternalArray headers are not quadword aligned.
static const int kExternalPointerOffset =
POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize);
static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
static const int kSize = kExternalPointerOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
......@@ -4888,7 +4887,7 @@ class FixedTypedArrayBase: public FixedArrayBase {
public:
DECLARE_CAST(FixedTypedArrayBase)
static const int kDataOffset = kHeaderSize;
static const int kDataOffset = DOUBLE_POINTER_ALIGN(kHeaderSize);
inline int size();
......@@ -4917,14 +4916,6 @@ class FixedTypedArray: public FixedTypedArrayBase {
DECLARE_CAST(FixedTypedArray<Traits>)
static inline int ElementOffset(int index) {
return kDataOffset + index * sizeof(ElementType);
}
static inline int SizeFor(int length) {
return ElementOffset(length);
}
inline ElementType get_scalar(int index);
static inline Handle<Object> get(Handle<FixedTypedArray> array, int index);
inline void set(int index, ElementType value);
......
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