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,23 +541,26 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) {
Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
ExternalArrayType type = array->type();
uint32_t length;
CHECK(array->length()->ToUint32(&length));
uint32_t byte_length;
if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start());
Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements);
Node* length = jsgraph()->Uint32Constant(
static_cast<uint32_t>(byte_length / array->element_size()));
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
Node* load = graph()->NewNode(
simplified()->LoadElement(
AccessBuilder::ForTypedArrayElement(type, true)),
pointer, key, jsgraph()->Uint32Constant(length), effect, control);
pointer, key, length, effect, control);
return ReplaceEagerly(node, load);
}
}
}
return NoChange();
}
......@@ -577,24 +580,26 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
ExternalArrayType type = array->type();
uint32_t length;
CHECK(array->length()->ToUint32(&length));
uint32_t byte_length;
if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start());
Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements);
Node* length = jsgraph()->Uint32Constant(
static_cast<uint32_t>(byte_length / array->element_size()));
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
Node* store =
graph()->NewNode(simplified()->StoreElement(
Node* store = graph()->NewNode(
simplified()->StoreElement(
AccessBuilder::ForTypedArrayElement(type, true)),
pointer, key, jsgraph()->Uint32Constant(length),
value, effect, control);
pointer, key, length, value, effect, control);
return ReplaceEagerly(node, store);
}
}
}
return NoChange();
}
......
......@@ -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) {
Context* native_context = isolate->context()->native_context();
switch (type) {
......@@ -1769,7 +1782,9 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
array->set_weak_next(buffer->weak_first_view());
buffer->set_weak_first_view(*array);
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);
array->set_length(*length_handle);
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