Revision: 4348
Author: [email protected]
Date: Tue Apr 6 07:16:39 2010
Log: Land patch by Pavel Podivilov ([email protected]).
Port string stub for keyed loads to x64 and ARM.
BUG=566
[email protected]
TEST=test/mjsunit/string-index.js
Original code review: http://codereview.chromium.org/1628003
Review URL: http://codereview.chromium.org/1567024
http://code.google.com/p/v8/source/detail?r=4348
Modified:
/branches/bleeding_edge/src/arm/ic-arm.cc
/branches/bleeding_edge/src/x64/ic-x64.cc
/branches/bleeding_edge/test/mjsunit/string-index.js
=======================================
--- /branches/bleeding_edge/src/arm/ic-arm.cc Fri Mar 26 02:05:22 2010
+++ /branches/bleeding_edge/src/arm/ic-arm.cc Tue Apr 6 07:16:39 2010
@@ -706,6 +706,29 @@
// -- sp[4] : receiver
// -----------------------------------
+ Label miss, index_ok;
+
+ // Get the key and receiver object from the stack.
+ __ ldm(ia, sp, r0.bit() | r1.bit());
+
+ // Check that the receiver isn't a smi.
+ __ BranchOnSmi(r1, &miss);
+
+ // Check that the receiver is a string.
+ Condition is_string = masm->IsObjectStringType(r1, r2);
+ __ b(NegateCondition(is_string), &miss);
+
+ // Check if key is a smi or a heap number.
+ __ BranchOnSmi(r0, &index_ok);
+ __ CheckMap(r0, r2, Factory::heap_number_map(), &miss, false);
+
+ __ bind(&index_ok);
+ // Duplicate receiver and key since they are expected on the stack after
+ // the KeyedLoadIC call.
+ __ stm(db_w, sp, r0.bit() | r1.bit());
+ __ InvokeBuiltin(Builtins::STRING_CHAR_AT, JUMP_JS);
+
+ __ bind(&miss);
GenerateGeneric(masm);
}
=======================================
--- /branches/bleeding_edge/src/x64/ic-x64.cc Fri Mar 26 02:05:22 2010
+++ /branches/bleeding_edge/src/x64/ic-x64.cc Tue Apr 6 07:16:39 2010
@@ -524,7 +524,32 @@
// -- rsp[16] : receiver
// -----------------------------------
- GenerateGeneric(masm);
+ Label miss, index_ok;
+
+ // Check that the receiver isn't a smi.
+ __ movq(rcx, Operand(rsp, 2 * kPointerSize));
+ __ JumpIfSmi(rcx, &miss);
+
+ // Check that the receiver is a string.
+ Condition is_string = masm->IsObjectStringType(rcx, rax, rbx);
+ __ j(NegateCondition(is_string), &miss);
+
+ // Check if key is a smi or a heap number.
+ __ movq(rax, Operand(rsp, kPointerSize));
+ __ JumpIfSmi(rax, &index_ok);
+ __ CheckMap(rax, Factory::heap_number_map(), &miss, false);
+
+ __ bind(&index_ok);
+ // Duplicate receiver and key since they are expected on the stack after
+ // the KeyedLoadIC call.
+ __ pop(rbx); // return address
+ __ push(rcx); // receiver
+ __ push(rax); // key
+ __ push(rbx); // return address
+ __ InvokeBuiltin(Builtins::STRING_CHAR_AT, JUMP_FUNCTION);
+
+ __ bind(&miss);
+ GenerateMiss(masm);
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/string-index.js Fri Feb 26
12:14:20 2010
+++ /branches/bleeding_edge/test/mjsunit/string-index.js Tue Apr 6
07:16:39 2010
@@ -166,3 +166,24 @@
assertEquals(alpha[i], alphaStr[i]);
assertEquals(String.fromCharCode(i), alphaStr[i]);
}
+
+// Test for keyed ic.
+var foo = ['a12', ['a', 2, 'c'], 'a31', 42];
+var results = [1, 2, 3, NaN];
+for (var i = 0; i < 200; ++i) {
+ var index = Math.floor(i / 50);
+ var receiver = foo[index];
+ var expected = results[index];
+ var actual = +(receiver[1]);
+ assertEquals(expected, actual);
+}
+
+var keys = [0, '1', 2, 3.0];
+var str = 'abcd', arr = ['a', 'b', 'c', 'd'];
+for (var i = 0; i < 200; ++i) {
+ var index = Math.floor(i / 50);
+ var key = keys[index];
+ var expected = arr[index];
+ var actual = str[key];
+ assertEquals(expected, actual);
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
To unsubscribe, reply using "remove me" as the subject.