Commit cb37b6c5 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Fix typed lowering of typed array loads/stores.

R=jarin@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24514 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 889d1e54
...@@ -541,21 +541,24 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { ...@@ -541,21 +541,24 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) {
Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
if (IsExternalArrayElementsKind(array->map()->elements_kind())) { if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
ExternalArrayType type = array->type(); ExternalArrayType type = array->type();
uint32_t length; uint32_t byte_length;
CHECK(array->length()->ToUint32(&length)); if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode( Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start()); graph()->start());
Node* pointer = graph()->NewNode( Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements); elements, elements);
Node* effect = NodeProperties::GetEffectInput(node); Node* length = jsgraph()->Uint32Constant(
Node* control = NodeProperties::GetControlInput(node); static_cast<uint32_t>(byte_length / array->element_size()));
Node* load = graph()->NewNode( Node* effect = NodeProperties::GetEffectInput(node);
simplified()->LoadElement( Node* control = NodeProperties::GetControlInput(node);
AccessBuilder::ForTypedArrayElement(type, true)), Node* load = graph()->NewNode(
pointer, key, jsgraph()->Uint32Constant(length), effect, control); simplified()->LoadElement(
return ReplaceEagerly(node, load); AccessBuilder::ForTypedArrayElement(type, true)),
pointer, key, length, effect, control);
return ReplaceEagerly(node, load);
}
} }
} }
return NoChange(); return NoChange();
...@@ -577,22 +580,24 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { ...@@ -577,22 +580,24 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
Handle<JSTypedArray>::cast(base_type->AsConstant()->Value()); Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
if (IsExternalArrayElementsKind(array->map()->elements_kind())) { if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
ExternalArrayType type = array->type(); ExternalArrayType type = array->type();
uint32_t length; uint32_t byte_length;
CHECK(array->length()->ToUint32(&length)); if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode( Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start()); graph()->start());
Node* pointer = graph()->NewNode( Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements); elements, elements);
Node* effect = NodeProperties::GetEffectInput(node); Node* length = jsgraph()->Uint32Constant(
Node* control = NodeProperties::GetControlInput(node); static_cast<uint32_t>(byte_length / array->element_size()));
Node* store = Node* effect = NodeProperties::GetEffectInput(node);
graph()->NewNode(simplified()->StoreElement( Node* control = NodeProperties::GetControlInput(node);
AccessBuilder::ForTypedArrayElement(type, true)), Node* store = graph()->NewNode(
pointer, key, jsgraph()->Uint32Constant(length), simplified()->StoreElement(
value, effect, control); AccessBuilder::ForTypedArrayElement(type, true)),
return ReplaceEagerly(node, store); pointer, key, length, value, effect, control);
return ReplaceEagerly(node, store);
}
} }
} }
return NoChange(); return NoChange();
......
...@@ -1731,6 +1731,19 @@ ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) { ...@@ -1731,6 +1731,19 @@ ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) {
} }
size_t GetExternalArrayElementSize(ExternalArrayType type) {
switch (type) {
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case kExternal##Type##Array: \
return size;
TYPED_ARRAYS(TYPED_ARRAY_CASE)
}
UNREACHABLE();
return 0;
#undef TYPED_ARRAY_CASE
}
JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
Context* native_context = isolate->context()->native_context(); Context* native_context = isolate->context()->native_context();
switch (type) { switch (type) {
...@@ -1769,7 +1782,9 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, ...@@ -1769,7 +1782,9 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
array->set_weak_next(buffer->weak_first_view()); array->set_weak_next(buffer->weak_first_view());
buffer->set_weak_first_view(*array); buffer->set_weak_first_view(*array);
array->set_byte_offset(Smi::FromInt(0)); array->set_byte_offset(Smi::FromInt(0));
array->set_byte_length(buffer->byte_length()); Handle<Object> byte_length_handle =
NewNumberFromSize(length * GetExternalArrayElementSize(type));
array->set_byte_length(*byte_length_handle);
Handle<Object> length_handle = NewNumberFromSize(length); Handle<Object> length_handle = NewNumberFromSize(length);
array->set_length(*length_handle); array->set_length(*length_handle);
Handle<ExternalArray> elements = Handle<ExternalArray> elements =
......
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