Commit afd09062 authored by danno@chromium.org's avatar danno@chromium.org

Add custom typed ICs for pixel array loads.

Review URL: http://codereview.chromium.org/6323002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6526 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3d4c4951
...@@ -501,6 +501,66 @@ static void GenerateFastArrayLoad(MacroAssembler* masm, ...@@ -501,6 +501,66 @@ static void GenerateFastArrayLoad(MacroAssembler* masm,
} }
static void GenerateFastPixelArrayLoad(MacroAssembler* masm,
Register receiver,
Register key,
Register elements_map,
Register elements,
Register scratch1,
Register scratch2,
Register result,
Label* not_pixel_array,
Label* key_not_smi,
Label* out_of_range) {
// Register use:
//
// receiver - holds the receiver on entry.
// Unchanged unless 'result' is the same register.
//
// key - holds the smi key on entry.
// Unchanged unless 'result' is the same register.
//
// elements - set to be the receiver's elements on exit.
//
// elements_map - set to be the map of the receiver's elements
// on exit.
//
// result - holds the result of the pixel array load on exit,
// tagged as a smi if successful.
//
// Scratch registers:
//
// scratch1 - holds the receiver's elements, the length of the
// pixel array, the pointer to external elements and
// the untagged result.
//
// scratch2 - holds the untaged key.
// Verify that the receiver has pixel array elements.
__ ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
__ LoadRoot(scratch1, Heap::kPixelArrayMapRootIndex);
__ ldr(elements_map, FieldMemOperand(elements, JSObject::kMapOffset));
__ cmp(elements_map, scratch1);
__ b(ne, not_pixel_array);
// Key must be a smi that is in the range of the pixel array.
if (key_not_smi != NULL) {
__ JumpIfNotSmi(key, key_not_smi);
}
__ ldr(scratch1, FieldMemOperand(elements, PixelArray::kLengthOffset));
__ SmiUntag(scratch2, key);
__ cmp(scratch2, scratch1);
__ b(hs, out_of_range);
// Perform the indexed load and tag the result as a smi.
__ ldr(scratch1,
FieldMemOperand(elements, PixelArray::kExternalPointerOffset));
__ ldrb(scratch1, MemOperand(scratch1, scratch2));
__ SmiTag(r0, scratch1);
__ Ret();
}
// Checks whether a key is an array index string or a symbol string. // Checks whether a key is an array index string or a symbol string.
// Falls through if a key is a symbol. // Falls through if a key is a symbol.
static void GenerateKeyStringCheck(MacroAssembler* masm, static void GenerateKeyStringCheck(MacroAssembler* masm,
...@@ -1189,19 +1249,18 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) { ...@@ -1189,19 +1249,18 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) {
// r0: key // r0: key
// r1: receiver // r1: receiver
__ bind(&check_pixel_array); __ bind(&check_pixel_array);
__ ldr(r4, FieldMemOperand(r1, JSObject::kElementsOffset));
__ ldr(r3, FieldMemOperand(r4, HeapObject::kMapOffset)); GenerateFastPixelArrayLoad(masm,
__ LoadRoot(ip, Heap::kPixelArrayMapRootIndex); r1,
__ cmp(r3, ip); r0,
__ b(ne, &check_number_dictionary); r3,
__ ldr(ip, FieldMemOperand(r4, PixelArray::kLengthOffset)); r4,
__ mov(r2, Operand(key, ASR, kSmiTagSize)); r2,
__ cmp(r2, ip); r5,
__ b(hs, &slow); r0,
__ ldr(ip, FieldMemOperand(r4, PixelArray::kExternalPointerOffset)); &check_number_dictionary,
__ ldrb(r2, MemOperand(ip, r2)); NULL,
__ mov(r0, Operand(r2, LSL, kSmiTagSize)); // Tag result as smi. &slow);
__ Ret();
__ bind(&check_number_dictionary); __ bind(&check_number_dictionary);
// Check whether the elements is a number dictionary. // Check whether the elements is a number dictionary.
...@@ -1375,6 +1434,41 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) { ...@@ -1375,6 +1434,41 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) {
} }
void KeyedLoadIC::GeneratePixelArray(MacroAssembler* masm) {
// ---------- S t a t e --------------
// -- lr : return address
// -- r0 : key
// -- r1 : receiver
// -----------------------------------
// Register usage.
Register key = r0;
Register receiver = r1;
Label slow;
// Verify that it's safe to access the receiver's elements.
GenerateKeyedLoadReceiverCheck(
masm, receiver, r5, r6,
Map::kHasIndexedInterceptor, &slow);
GenerateFastPixelArrayLoad(masm,
receiver,
key,
r2,
r3,
r4,
r5,
r0,
&slow,
&slow,
&slow);
__ bind(&slow);
GenerateMiss(masm);
}
void KeyedStoreIC::GenerateMiss(MacroAssembler* masm) { void KeyedStoreIC::GenerateMiss(MacroAssembler* masm) {
// ---------- S t a t e -------------- // ---------- S t a t e --------------
// -- r0 : value // -- r0 : value
......
...@@ -1287,6 +1287,11 @@ static void Generate_KeyedLoadIC_String(MacroAssembler* masm) { ...@@ -1287,6 +1287,11 @@ static void Generate_KeyedLoadIC_String(MacroAssembler* masm) {
} }
static void Generate_KeyedLoadIC_PixelArray(MacroAssembler* masm) {
KeyedLoadIC::GeneratePixelArray(masm);
}
static void Generate_KeyedLoadIC_PreMonomorphic(MacroAssembler* masm) { static void Generate_KeyedLoadIC_PreMonomorphic(MacroAssembler* masm) {
KeyedLoadIC::GeneratePreMonomorphic(masm); KeyedLoadIC::GeneratePreMonomorphic(masm);
} }
......
...@@ -94,6 +94,7 @@ enum BuiltinExtraArguments { ...@@ -94,6 +94,7 @@ enum BuiltinExtraArguments {
V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC) \ V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC) \
V(KeyedLoadIC_Generic, KEYED_LOAD_IC, MEGAMORPHIC) \ V(KeyedLoadIC_Generic, KEYED_LOAD_IC, MEGAMORPHIC) \
V(KeyedLoadIC_String, KEYED_LOAD_IC, MEGAMORPHIC) \ V(KeyedLoadIC_String, KEYED_LOAD_IC, MEGAMORPHIC) \
V(KeyedLoadIC_PixelArray, KEYED_LOAD_IC, MONOMORPHIC) \
V(KeyedLoadIC_IndexedInterceptor, KEYED_LOAD_IC, MEGAMORPHIC) \ V(KeyedLoadIC_IndexedInterceptor, KEYED_LOAD_IC, MEGAMORPHIC) \
\ \
V(StoreIC_Initialize, STORE_IC, UNINITIALIZED) \ V(StoreIC_Initialize, STORE_IC, UNINITIALIZED) \
......
...@@ -491,6 +491,48 @@ static void GenerateFastArrayLoad(MacroAssembler* masm, ...@@ -491,6 +491,48 @@ static void GenerateFastArrayLoad(MacroAssembler* masm,
} }
} }
// Loads a indexed element from a pixel array.
static void GenerateFastPixelArrayLoad(MacroAssembler* masm,
Register receiver,
Register key,
Register elements,
Register untagged_key,
Register result,
Label* not_pixel_array,
Label* key_not_smi,
Label* out_of_range) {
// Register use:
// receiver - holds the receiver and is unchanged.
// key - holds the key and is unchanged (must be a smi).
// elements - is set to the the receiver's element if
// the receiver doesn't have a pixel array or the
// key is not a smi, otherwise it's the elements'
// external pointer.
// untagged_key - is set to the untagged key
// Key must be a smi.
if (key_not_smi != NULL) {
__ test(key, Immediate(kSmiTagMask));
__ j(not_zero, key_not_smi, not_taken);
}
__ mov(untagged_key, key);
__ SmiUntag(untagged_key);
// Verify that the receiver has pixel array elements.
__ mov(elements, FieldOperand(receiver, JSObject::kElementsOffset));
__ CheckMap(elements, Factory::pixel_array_map(), not_pixel_array, true);
// Key must be in range.
__ cmp(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset));
__ j(above_equal, out_of_range);
// Perform the indexed load and tag the result as a smi.
__ mov(elements, FieldOperand(elements, PixelArray::kExternalPointerOffset));
__ movzx_b(result, Operand(elements, untagged_key, times_1, 0));
__ SmiTag(result);
__ ret(0);
}
// Checks whether a key is an array index string or a symbol string. // Checks whether a key is an array index string or a symbol string.
// Falls through if the key is a symbol. // Falls through if the key is a symbol.
...@@ -556,19 +598,15 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) { ...@@ -556,19 +598,15 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) {
__ ret(0); __ ret(0);
__ bind(&check_pixel_array); __ bind(&check_pixel_array);
// Check whether the elements is a pixel array. GenerateFastPixelArrayLoad(masm,
// edx: receiver edx,
// eax: key eax,
__ mov(ecx, FieldOperand(edx, JSObject::kElementsOffset)); ecx,
__ mov(ebx, eax); ebx,
__ SmiUntag(ebx); eax,
__ CheckMap(ecx, Factory::pixel_array_map(), &check_number_dictionary, true); &check_number_dictionary,
__ cmp(ebx, FieldOperand(ecx, PixelArray::kLengthOffset)); NULL,
__ j(above_equal, &slow); &slow);
__ mov(eax, FieldOperand(ecx, PixelArray::kExternalPointerOffset));
__ movzx_b(eax, Operand(eax, ebx, times_1, 0));
__ SmiTag(eax);
__ ret(0);
__ bind(&check_number_dictionary); __ bind(&check_number_dictionary);
// Check whether the elements is a number dictionary. // Check whether the elements is a number dictionary.
...@@ -762,6 +800,33 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) { ...@@ -762,6 +800,33 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) {
} }
void KeyedLoadIC::GeneratePixelArray(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- eax : key
// -- edx : receiver
// -- esp[0] : return address
// -----------------------------------
Label slow;
// Verify that it's safe to access the receiver's elements.
GenerateKeyedLoadReceiverCheck(
masm, edx, ecx, Map::kHasNamedInterceptor, &slow);
GenerateFastPixelArrayLoad(masm,
edx,
eax,
ecx,
ebx,
eax,
&slow,
&slow,
&slow);
__ bind(&slow);
GenerateMiss(masm);
}
void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm) { void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : value // -- eax : value
......
...@@ -1204,23 +1204,27 @@ MaybeObject* KeyedLoadIC::Load(State state, ...@@ -1204,23 +1204,27 @@ MaybeObject* KeyedLoadIC::Load(State state,
if (use_ic) { if (use_ic) {
Code* stub = generic_stub(); Code* stub = generic_stub();
if (object->IsString() && key->IsNumber()) { if (state == UNINITIALIZED) {
stub = string_stub(); if (object->IsString() && key->IsNumber()) {
} else if (object->IsJSObject()) { stub = string_stub();
Handle<JSObject> receiver = Handle<JSObject>::cast(object); } else if (object->IsJSObject()) {
if (receiver->HasExternalArrayElements()) { Handle<JSObject> receiver = Handle<JSObject>::cast(object);
MaybeObject* probe = if (receiver->HasExternalArrayElements()) {
MaybeObject* probe =
StubCache::ComputeKeyedLoadOrStoreExternalArray(*receiver, false); StubCache::ComputeKeyedLoadOrStoreExternalArray(*receiver, false);
stub = stub =
probe->IsFailure() ? NULL : Code::cast(probe->ToObjectUnchecked()); probe->IsFailure() ? NULL : Code::cast(probe->ToObjectUnchecked());
} else if (receiver->HasIndexedInterceptor()) { } else if (receiver->HasPixelElements()) {
stub = indexed_interceptor_stub(); stub = pixel_array_stub();
} else if (state == UNINITIALIZED && } else if (receiver->HasIndexedInterceptor()) {
key->IsSmi() && stub = indexed_interceptor_stub();
receiver->map()->has_fast_elements()) { } else if (key->IsSmi() &&
MaybeObject* probe = StubCache::ComputeKeyedLoadSpecialized(*receiver); receiver->map()->has_fast_elements()) {
stub = MaybeObject* probe =
StubCache::ComputeKeyedLoadSpecialized(*receiver);
stub =
probe->IsFailure() ? NULL : Code::cast(probe->ToObjectUnchecked()); probe->IsFailure() ? NULL : Code::cast(probe->ToObjectUnchecked());
}
} }
} }
if (stub != NULL) set_target(stub); if (stub != NULL) set_target(stub);
......
...@@ -348,6 +348,9 @@ class KeyedLoadIC: public IC { ...@@ -348,6 +348,9 @@ class KeyedLoadIC: public IC {
static void GenerateIndexedInterceptor(MacroAssembler* masm); static void GenerateIndexedInterceptor(MacroAssembler* masm);
// Generator for loading bytes from a pixel array.
static void GeneratePixelArray(MacroAssembler* masm);
// Clear the use of the inlined version. // Clear the use of the inlined version.
static void ClearInlinedVersion(Address address); static void ClearInlinedVersion(Address address);
...@@ -382,6 +385,9 @@ class KeyedLoadIC: public IC { ...@@ -382,6 +385,9 @@ class KeyedLoadIC: public IC {
return Builtins::builtin(Builtins::KeyedLoadIC_String); return Builtins::builtin(Builtins::KeyedLoadIC_String);
} }
static Code* pixel_array_stub() {
return Builtins::builtin(Builtins::KeyedLoadIC_PixelArray);
}
static Code* indexed_interceptor_stub() { static Code* indexed_interceptor_stub() {
return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor); return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor);
} }
......
...@@ -515,6 +515,49 @@ static void GenerateFastArrayLoad(MacroAssembler* masm, ...@@ -515,6 +515,49 @@ static void GenerateFastArrayLoad(MacroAssembler* masm,
} }
// Loads a indexed element from a pixel array.
static void GenerateFastPixelArrayLoad(MacroAssembler* masm,
Register receiver,
Register key,
Register elements,
Register untagged_key,
Register result,
Label* not_pixel_array,
Label* key_not_smi,
Label* out_of_range) {
// Register use:
// receiver - holds the receiver and is unchanged.
// key - holds the key and is unchanged (must be a smi).
// elements - is set to the the receiver's element if
// the receiver doesn't have a pixel array or the
// key is not a smi, otherwise it's the elements'
// external pointer.
// untagged_key - is set to the untagged key
// Check that the key is a smi.
if (key_not_smi != NULL) {
__ JumpIfNotSmi(key, key_not_smi);
}
__ SmiToInteger32(untagged_key, key);
// Verify that the receiver has pixel array elements.
__ movq(elements, FieldOperand(receiver, JSObject::kElementsOffset));
__ CompareRoot(FieldOperand(elements, HeapObject::kMapOffset),
Heap::kPixelArrayMapRootIndex);
__ j(not_equal, not_pixel_array);
// Check that the smi is in range.
__ cmpl(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset));
__ j(above_equal, out_of_range);
// Load and tag the element as a smi.
__ movq(elements, FieldOperand(elements, PixelArray::kExternalPointerOffset));
__ movzxbq(result, Operand(elements, untagged_key, times_1, 0));
__ Integer32ToSmi(result, result);
__ ret(0);
}
// Checks whether a key is an array index string or a symbol string. // Checks whether a key is an array index string or a symbol string.
// Falls through if the key is a symbol. // Falls through if the key is a symbol.
static void GenerateKeyStringCheck(MacroAssembler* masm, static void GenerateKeyStringCheck(MacroAssembler* masm,
...@@ -580,20 +623,15 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) { ...@@ -580,20 +623,15 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) {
__ ret(0); __ ret(0);
__ bind(&check_pixel_array); __ bind(&check_pixel_array);
// Check whether the elements object is a pixel array. GenerateFastPixelArrayLoad(masm,
// rdx: receiver rdx,
// rax: key rax,
__ movq(rcx, FieldOperand(rdx, JSObject::kElementsOffset)); rcx,
__ SmiToInteger32(rbx, rax); // Used on both directions of next branch. rbx,
__ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset), rax,
Heap::kPixelArrayMapRootIndex); &check_number_dictionary,
__ j(not_equal, &check_number_dictionary); NULL,
__ cmpl(rbx, FieldOperand(rcx, PixelArray::kLengthOffset)); &slow);
__ j(above_equal, &slow);
__ movq(rax, FieldOperand(rcx, PixelArray::kExternalPointerOffset));
__ movzxbq(rax, Operand(rax, rbx, times_1, 0));
__ Integer32ToSmi(rax, rax);
__ ret(0);
__ bind(&check_number_dictionary); __ bind(&check_number_dictionary);
// Check whether the elements is a number dictionary. // Check whether the elements is a number dictionary.
...@@ -767,6 +805,33 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) { ...@@ -767,6 +805,33 @@ void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) {
GenerateMiss(masm); GenerateMiss(masm);
} }
void KeyedLoadIC::GeneratePixelArray(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- rax : key
// -- rdx : receiver
// -- rsp[0] : return address
// -----------------------------------
Label slow;
// Verify that it's safe to access the receiver's elements.
GenerateKeyedLoadReceiverCheck(
masm, rdx, rcx, Map::kHasNamedInterceptor, &slow);
// Generate the indexed load from the pixel array.
GenerateFastPixelArrayLoad(masm,
rdx,
rax,
rcx,
rbx,
rax,
&slow,
&slow,
&slow);
__ bind(&slow);
GenerateMiss(masm);
}
void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm) { void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
......
...@@ -10344,6 +10344,93 @@ THREADED_TEST(PixelArray) { ...@@ -10344,6 +10344,93 @@ THREADED_TEST(PixelArray) {
"i"); "i");
CHECK_EQ(255, result->Int32Value()); CHECK_EQ(255, result->Int32Value());
// Make sure that pixel array ICs recognize when a non-pixel array
// is passed to it.
result = CompileRun("function pa_load(p) {"
" var sum = 0;"
" for (var j = 0; j < 256; j++) { sum += p[j]; }"
" return sum;"
"}"
"for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
"for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
"just_ints = new Object();"
"for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
"for (var i = 0; i < 10; ++i) {"
" result = pa_load(just_ints);"
"}"
"result");
CHECK_EQ(32640, result->Int32Value());
// Make sure that pixel array ICs recognize out-of-bound accesses.
result = CompileRun("function pa_load(p, start) {"
" var sum = 0;"
" for (var j = start; j < 256; j++) { sum += p[j]; }"
" return sum;"
"}"
"for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
"for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
"for (var i = 0; i < 10; ++i) {"
" result = pa_load(pixels,-10);"
"}"
"result");
CHECK_EQ(0, result->Int32Value());
// Make sure that generic ICs properly handles a pixel array.
result = CompileRun("function pa_load(p) {"
" var sum = 0;"
" for (var j = 0; j < 256; j++) { sum += p[j]; }"
" return sum;"
"}"
"for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
"just_ints = new Object();"
"for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
"for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
"for (var i = 0; i < 10; ++i) {"
" result = pa_load(pixels);"
"}"
"result");
CHECK_EQ(32640, result->Int32Value());
// Make sure that generic load ICs recognize out-of-bound accesses in
// pixel arrays.
result = CompileRun("function pa_load(p, start) {"
" var sum = 0;"
" for (var j = start; j < 256; j++) { sum += p[j]; }"
" return sum;"
"}"
"for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
"just_ints = new Object();"
"for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
"for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
"for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
"for (var i = 0; i < 10; ++i) {"
" result = pa_load(pixels,-10);"
"}"
"result");
CHECK_EQ(0, result->Int32Value());
// Make sure that generic ICs properly handles other types than pixel
// arrays (that the inlined fast pixel array test leaves the right information
// in the right registers).
result = CompileRun("function pa_load(p) {"
" var sum = 0;"
" for (var j = 0; j < 256; j++) { sum += p[j]; }"
" return sum;"
"}"
"for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
"just_ints = new Object();"
"for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
"for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
"for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
"sparse_array = new Object();"
"for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
"sparse_array[1000000] = 3;"
"for (var i = 0; i < 10; ++i) {"
" result = pa_load(sparse_array);"
"}"
"result");
CHECK_EQ(32640, result->Int32Value());
free(pixel_data); free(pixel_data);
} }
......
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