Index: src/mips/lithium-codegen-mips.cc |
diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc |
index 8fa397bccdc52fb6b387a5ad7ab83595ff70e1d9..5d09a302aece1186d3808a785768633a1ff30420 100644 |
--- a/src/mips/lithium-codegen-mips.cc |
+++ b/src/mips/lithium-codegen-mips.cc |
@@ -1731,14 +1731,38 @@ void LCodeGen::DoDateField(LDateField* instr) { |
} |
+MemOperand LCodeGen::BuildSeqStringOperand(Register string, |
+ LOperand* index, |
+ String::Encoding encoding) { |
+ if (index->IsConstantOperand()) { |
+ int offset = ToInteger32(LConstantOperand::cast(index)); |
+ if (encoding == String::TWO_BYTE_ENCODING) { |
+ offset *= kUC16Size; |
+ } |
+ STATIC_ASSERT(kCharSize == 1); |
+ return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
+ } |
+ Register scratch = scratch0(); |
+ ASSERT(!scratch.is(string)); |
+ ASSERT(!scratch.is(ToRegister(index))); |
+ if (encoding == String::ONE_BYTE_ENCODING) { |
+ __ Addu(scratch, string, ToRegister(index)); |
+ } else { |
+ STATIC_ASSERT(kUC16Size == 2); |
+ __ sll(scratch, ToRegister(index), 1); |
+ __ Addu(scratch, string, scratch); |
+ } |
+ return FieldMemOperand(scratch, SeqString::kHeaderSize); |
+} |
+ |
+ |
void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
+ String::Encoding encoding = instr->hydrogen()->encoding(); |
Register string = ToRegister(instr->string()); |
- LOperand* index_op = instr->index(); |
Register value = ToRegister(instr->value()); |
- Register scratch = scratch0(); |
- String::Encoding encoding = instr->encoding(); |
if (FLAG_debug_code) { |
+ Register scratch = scratch0(); |
__ lw(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
__ lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
@@ -1751,25 +1775,11 @@ void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
__ Check(eq, kUnexpectedStringType, at, Operand(zero_reg)); |
} |
- if (index_op->IsConstantOperand()) { |
- int constant_index = ToInteger32(LConstantOperand::cast(index_op)); |
- if (encoding == String::ONE_BYTE_ENCODING) { |
- __ sb(value, |
- FieldMemOperand(string, SeqString::kHeaderSize + constant_index)); |
- } else { |
- __ sh(value, |
- FieldMemOperand(string, SeqString::kHeaderSize + constant_index * 2)); |
- } |
+ MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
+ if (encoding == String::ONE_BYTE_ENCODING) { |
+ __ sb(value, operand); |
} else { |
- Register index = ToRegister(index_op); |
- if (encoding == String::ONE_BYTE_ENCODING) { |
- __ Addu(scratch, string, Operand(index)); |
- __ sb(value, FieldMemOperand(scratch, SeqString::kHeaderSize)); |
- } else { |
- __ sll(scratch, index, 1); |
- __ Addu(scratch, string, scratch); |
- __ sh(value, FieldMemOperand(scratch, SeqString::kHeaderSize)); |
- } |
+ __ sh(value, operand); |
} |
} |