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..a60999ba4fb5b86a829856327f930a8c21767422 100644 |
--- a/src/arm/lithium-codegen-arm.cc |
+++ b/src/arm/lithium-codegen-arm.cc |
@@ -3424,6 +3424,7 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
Register scratch = scratch0(); |
Register string = ToRegister(instr->string()); |
Register index = no_reg; |
+ Register offset = ToRegister(instr->TempAt(0)); |
int const_index = -1; |
if (instr->index()->IsConstantOperand()) { |
const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
@@ -3446,7 +3447,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 +3459,46 @@ 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(result, FieldMemOperand(string, SlicedString::kOffsetOffset)); |
+ if (instr->index()->IsConstantOperand()) { |
+ __ mov(offset, Operand(result, LSR, kSmiTagSize)); |
+ __ add(offset, offset, Operand(const_index)); |
+ } else { |
+ __ add(offset, index, Operand(result, LSR, kSmiTagSize)); |
+ } |
+ __ 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); |
+ __ add(scratch, |
+ string, |
+ Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
+ __ ldrh(result, MemOperand(scratch, offset, LSL, 1)); |
+ __ jmp(&done); |
+ __ bind(&sliced_ascii_string); |
+ __ add(scratch, |
+ string, |
+ Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
+ __ ldrb(result, MemOperand(scratch, offset)); |
+ __ 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); |