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

Unified Diff: src/arm/lithium-codegen-arm.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Patched RegExp for string slices. Created 9 years, 4 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
Index: src/arm/lithium-codegen-arm.cc
diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
index 54ad4581c5ce632e7c74d7f193e5a627fcdff88f..9754c95eca95831797414d367a63c88223a53fb0 100644
--- a/src/arm/lithium-codegen-arm.cc
+++ b/src/arm/lithium-codegen-arm.cc
@@ -3424,7 +3424,7 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
Register scratch = scratch0();
Register string = ToRegister(instr->string());
Register index = no_reg;
- int const_index = -1;
+ int const_index = 0;
if (instr->index()->IsConstantOperand()) {
const_index = ToInteger32(LConstantOperand::cast(instr->index()));
STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
@@ -3446,7 +3446,7 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
DeferredStringCharCodeAt* deferred =
new DeferredStringCharCodeAt(this, instr);
- Label flat_string, ascii_string, done;
+ Label flat_string, ascii_string, cons_string, sliced_ascii_string, done;
// Fetch the instance type of the receiver into result register.
__ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
@@ -3458,14 +3458,52 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
__ b(eq, &flat_string);
// Handle non-flat strings.
- __ tst(result, Operand(kIsConsStringMask));
+ __ and_(result, result, Operand(kStringRepresentationMask));
+ __ cmp(result, Operand(kConsStringTag));
+ __ b(eq, &cons_string);
+ __ cmp(result, Operand(kExternalStringTag));
__ b(eq, deferred->entry());
+ // SlicedString.
+ // Unpack slice, add offset and retrieve the result char.
+ __ ldr(scratch, FieldMemOperand(string, SlicedString::kOffsetOffset));
+ __ ldr(string, FieldMemOperand(string, SlicedString::kParentOffset));
+ __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
+ __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
+ // Check for 1-byte or 2-byte string.
+ STATIC_ASSERT(kAsciiStringTag != 0);
+ __ tst(result, Operand(kStringEncodingMask));
+ __ b(ne, &sliced_ascii_string);
+ if (!instr->index()->IsConstantOperand()) {
+ // Double the index before adding to the smi-tagged offset.
+ STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
+ __ add(scratch, scratch, Operand(index, LSL, 1));
+ }
+ __ add(result,
+ string,
+ Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag
antonm 2011/08/04 12:18:48 nit: apparently v8 style is not to start continuat
+ + 2 * const_index));
+ __ ldrh(result, MemOperand(result, scratch));
+ __ jmp(&done);
+ __ bind(&sliced_ascii_string);
+ if (!instr->index()->IsConstantOperand()) {
+ // Smi-untag the offset before adding to the index.
+ __ add(scratch, index, Operand(scratch, LSR, kSmiTagSize));
+ } else {
+ __ SmiUntag(scratch, scratch);
+ }
+ __ add(result,
+ string,
+ Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag + const_index));
+ __ ldrb(result, MemOperand(result, scratch));
+ __ jmp(&done);
+
// ConsString.
// Check whether the right hand side is the empty string (i.e. if
// this is really a flat string in a cons string). If that is not
// the case we would rather go to the runtime system now to flatten
// the string.
+ __ bind(&cons_string);
__ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset));
__ LoadRoot(ip, Heap::kEmptyStringRootIndex);
__ cmp(scratch, ip);

Powered by Google App Engine
This is Rietveld 408576698