Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1330)

Unified Diff: src/x64/ic-x64.cc

Issue 294022: Add optimized ICs for new CanvasArray types. This is a follow-on CL to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/x64/ic-x64.cc
===================================================================
--- src/x64/ic-x64.cc (revision 3112)
+++ src/x64/ic-x64.cc (working copy)
@@ -362,7 +362,142 @@
void KeyedLoadIC::GenerateExternalArray(MacroAssembler* masm,
ExternalArrayType array_type) {
- GenerateGeneric(masm);
+ // ----------- S t a t e -------------
+ // -- rsp[0] : return address
+ // -- rsp[8] : name
+ // -- rsp[16] : receiver
+ // -----------------------------------
+ Label slow, failed_allocation;
+
+ // Load name and receiver.
+ __ movq(rax, Operand(rsp, kPointerSize));
+ __ movq(rcx, Operand(rsp, 2 * kPointerSize));
+
+ // Check that the object isn't a smi.
+ __ JumpIfSmi(rcx, &slow);
+
+ // Check that the key is a smi.
+ __ JumpIfNotSmi(rax, &slow);
+
+ // Check that the object is a JS object.
+ __ CmpObjectType(rcx, JS_OBJECT_TYPE, rdx);
+ __ j(not_equal, &slow);
+ // Check that the receiver does not require access checks. We need
+ // to check this explicitly since this generic stub does not perform
+ // map checks. The map is already in rdx.
+ __ testb(FieldOperand(rdx, Map::kBitFieldOffset),
+ Immediate(1 << Map::kIsAccessCheckNeeded));
+ __ j(not_zero, &slow);
+
+ // Check that the elements array is the appropriate type of
+ // ExternalArray.
+ // rax: index (as a smi)
+ // rcx: JSObject
+ __ movq(rcx, FieldOperand(rdx, JSObject::kElementsOffset));
+ __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset),
+ Heap::RootIndexForExternalArrayType(array_type));
+ __ j(not_equal, &slow);
+
+ // Check that the index is in range.
+ __ SmiToInteger32(rax, rax);
+ __ cmpl(rax, FieldOperand(rcx, ExternalArray::kLengthOffset));
+ // Unsigned comparison catches both negative and too-large values.
+ __ j(above_equal, &slow);
+
+ // rax: untagged index
+ // rcx: elements array
+ __ movq(rcx, FieldOperand(rcx, ExternalArray::kExternalPointerOffset));
+ // rcx: base pointer of external storage
+ switch (array_type) {
+ case kExternalByteArray:
+ __ movsxbq(rax, Operand(rcx, rax, times_1, 0));
+ break;
+ case kExternalUnsignedByteArray:
+ __ movb(rax, Operand(rcx, rax, times_1, 0));
+ break;
+ case kExternalShortArray:
+ __ movsxwq(rax, Operand(rcx, rax, times_2, 0));
+ break;
+ case kExternalUnsignedShortArray:
+ __ movzxwq(rax, Operand(rcx, rax, times_2, 0));
+ break;
+ case kExternalIntArray:
+ __ movsxlq(rax, Operand(rcx, rax, times_4, 0));
+ break;
+ case kExternalUnsignedIntArray:
+ __ movl(rax, Operand(rcx, rax, times_4, 0));
+ break;
+ case kExternalFloatArray:
+ __ fld_s(Operand(rcx, rax, times_4, 0));
+ break;
+ default:
+ UNREACHABLE();
+ break;
+ }
+
+ // For integer array types:
+ // rax: value
+ // For floating-point array type:
+ // FP(0): value
+
+ if (array_type == kExternalIntArray ||
+ array_type == kExternalUnsignedIntArray) {
+
+ // For the Int and UnsignedInt array types, we need to see whether
+ // the value can be represented in a Smi. If not, we need to convert
+ // it to a HeapNumber.
+ Label box_int;
+ if (array_type == kExternalIntArray) {
+ __ JumpIfNotValidSmiValue(rax, &box_int);
+ } else {
+ ASSERT_EQ(array_type, kExternalUnsignedIntArray);
+ __ JumpIfUIntNotValidSmiValue(rax, &box_int);
+ }
+
+ __ Integer32ToSmi(rax, rax);
+ __ ret(0);
+
+ __ bind(&box_int);
+
+ // Allocate a HeapNumber for the int and perform int-to-double
+ // conversion.
+ __ push(rax);
+ if (array_type == kExternalIntArray) {
+ __ fild_s(Operand(rsp, 0));
+ } else {
+ ASSERT(array_type == kExternalUnsignedIntArray);
+ // Need to zero-extend the value.
+ __ fild_d(Operand(rsp, 0));
+ }
+ __ pop(rax);
+ // FP(0): value
+ __ AllocateHeapNumber(rax, rbx, &failed_allocation);
+ // Set the value.
+ __ fstp_d(FieldOperand(rax, HeapNumber::kValueOffset));
+ __ ret(0);
+ } else if (array_type == kExternalFloatArray) {
+ // For the floating-point array type, we need to always allocate a
+ // HeapNumber.
+ __ AllocateHeapNumber(rax, rbx, &failed_allocation);
+ // Set the value.
+ __ fstp_d(FieldOperand(rax, HeapNumber::kValueOffset));
+ __ ret(0);
+ } else {
+ __ Integer32ToSmi(rax, rax);
+ __ ret(0);
+ }
+
+ // If we fail allocation of the HeapNumber, we still have a value on
+ // top of the FPU stack. Remove it.
+ __ bind(&failed_allocation);
+ __ ffree();
+ __ fincstp();
+ // Fall through to slow case.
+
+ // Slow case: Load name and receiver from stack and jump to runtime.
+ __ bind(&slow);
+ __ IncrementCounter(&Counters::keyed_load_external_array_slow, 1);
+ Generate(masm, ExternalReference(Runtime::kKeyedGetProperty));
}
@@ -560,7 +695,175 @@
void KeyedStoreIC::GenerateExternalArray(MacroAssembler* masm,
ExternalArrayType array_type) {
- GenerateGeneric(masm);
+ // ----------- S t a t e -------------
+ // -- rax : value
+ // -- rsp[0] : return address
+ // -- rsp[8] : key
+ // -- rsp[16] : receiver
+ // -----------------------------------
+ Label slow, check_heap_number;
+
+ // Get the receiver from the stack.
+ __ movq(rdx, Operand(rsp, 2 * kPointerSize));
+ // Check that the object isn't a smi.
+ __ JumpIfSmi(rdx, &slow);
+ // Get the map from the receiver.
+ __ movq(rcx, FieldOperand(rdx, HeapObject::kMapOffset));
+ // Check that the receiver does not require access checks. We need
+ // to do this because this generic stub does not perform map checks.
+ __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
+ Immediate(1 << Map::kIsAccessCheckNeeded));
+ __ j(not_zero, &slow);
+ // Get the key from the stack.
+ __ movq(rbx, Operand(rsp, 1 * kPointerSize)); // 1 ~ return address
+ // Check that the key is a smi.
+ __ JumpIfNotSmi(rbx, &slow);
+
+ // Check that the object is a JS object.
+ __ CmpInstanceType(rcx, JS_OBJECT_TYPE);
+ __ j(not_equal, &slow);
+
+ // Check that the elements array is the appropriate type of
+ // ExternalArray.
+ // rax: value
+ // rdx: JSObject
+ // rbx: index (as a smi)
+ __ movq(rcx, FieldOperand(rdx, JSObject::kElementsOffset));
+ __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset),
+ Heap::RootIndexForExternalArrayType(array_type));
+ __ j(not_equal, &slow);
+
+ // Check that the index is in range.
+ __ SmiToInteger32(rbx, rbx); // Untag the index.
+ __ cmpl(rbx, FieldOperand(rcx, ExternalArray::kLengthOffset));
+ // Unsigned comparison catches both negative and too-large values.
+ __ j(above_equal, &slow);
+
+ // Handle both smis and HeapNumbers in the fast path. Go to the
+ // runtime for all other kinds of values.
+ // rax: value
+ // rcx: elements array
+ // rbx: untagged index
+ __ JumpIfNotSmi(rax, &check_heap_number);
+ __ movq(rdx, rax); // Save the value.
+ __ SmiToInteger32(rax, rax);
+ __ movq(rcx, FieldOperand(rcx, ExternalArray::kExternalPointerOffset));
+ // rcx: base pointer of external storage
+ switch (array_type) {
+ case kExternalByteArray:
+ case kExternalUnsignedByteArray:
+ __ movb(Operand(rcx, rbx, times_1, 0), rax);
+ break;
+ case kExternalShortArray:
+ case kExternalUnsignedShortArray:
+ __ movw(Operand(rcx, rbx, times_2, 0), rax);
+ break;
+ case kExternalIntArray:
+ case kExternalUnsignedIntArray:
+ __ movl(Operand(rcx, rbx, times_4, 0), rax);
+ break;
+ case kExternalFloatArray:
+ // Need to perform int-to-float conversion.
+ __ push(rax);
+ __ fild_s(Operand(rsp, 0));
+ __ pop(rax);
+ __ fstp_s(Operand(rcx, rbx, times_4, 0));
+ break;
+ default:
+ UNREACHABLE();
+ break;
+ }
+ __ movq(rax, rdx); // Return the original value.
+ __ ret(0);
+
+ __ bind(&check_heap_number);
+ __ CmpObjectType(rax, HEAP_NUMBER_TYPE, rdx);
+ __ j(not_equal, &slow);
+
+ // The WebGL specification leaves the behavior of storing NaN and
+ // +/-Infinity into integer arrays basically undefined. For more
+ // reproducible behavior, convert these to zero.
+ __ fld_d(FieldOperand(rax, HeapNumber::kValueOffset));
+ __ movq(rdx, rax); // Save the value.
+ __ movq(rcx, FieldOperand(rcx, ExternalArray::kExternalPointerOffset));
+ // rbx: untagged index
+ // rcx: base pointer of external storage
+ // top of FPU stack: value
+ if (array_type == kExternalFloatArray) {
+ __ fstp_s(Operand(rcx, rbx, times_4, 0));
+ } else {
+ // Need to perform float-to-int conversion.
+ // Test the top of the FP stack for NaN.
+ Label is_nan;
+ __ fucomi(0);
+ __ j(parity_even, &is_nan);
+
+ __ push(rax); // Make room on stack
+ __ fistp_d(Operand(rsp, 0));
+ __ pop(rax);
+ // rax: untagged integer value
+ switch (array_type) {
+ case kExternalByteArray:
+ case kExternalUnsignedByteArray:
+ __ movb(Operand(rcx, rbx, times_1, 0), rax);
+ break;
+ case kExternalShortArray:
+ case kExternalUnsignedShortArray:
+ __ movw(Operand(rcx, rbx, times_2, 0), rax);
+ break;
+ case kExternalIntArray:
+ case kExternalUnsignedIntArray: {
+ // We also need to explicitly check for +/-Infinity. These are
+ // converted to MIN_INT, but we need to be careful not to
+ // confuse with legal uses of MIN_INT.
+ Label not_infinity;
+ // This test would apparently detect both NaN and Infinity,
+ // but we've already checked for NaN using the FPU hardware
+ // above.
+ __ movzxwq(rdi, FieldOperand(rdx, HeapNumber::kValueOffset + 6));
+ __ and_(rdi, Immediate(0x7FF0));
+ __ cmpw(rdi, Immediate(0x7FF0));
+ __ j(not_equal, &not_infinity);
+ __ movq(rax, Immediate(0));
+ __ bind(&not_infinity);
+ __ movl(Operand(rcx, rbx, times_4, 0), rax);
+ break;
+ }
+ default:
+ UNREACHABLE();
+ break;
+ }
+ __ movq(rax, rdx); // Return the original value.
+ __ ret(0);
+
+ __ bind(&is_nan);
+ __ ffree();
+ __ fincstp();
+ __ movq(rax, Immediate(0));
+ switch (array_type) {
+ case kExternalByteArray:
+ case kExternalUnsignedByteArray:
+ __ movb(Operand(rcx, rbx, times_1, 0), rax);
+ break;
+ case kExternalShortArray:
+ case kExternalUnsignedShortArray:
+ __ movw(Operand(rcx, rbx, times_2, 0), rax);
+ break;
+ case kExternalIntArray:
+ case kExternalUnsignedIntArray:
+ __ movl(Operand(rcx, rbx, times_4, 0), rax);
+ break;
+ default:
+ UNREACHABLE();
+ break;
+ }
+ __ movq(rax, rdx); // Return the original value.
+ __ ret(0);
+ }
+
+ // Slow case: call runtime.
+ __ bind(&slow);
+ Generate(masm, ExternalReference(Runtime::kSetProperty));
}
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698