Commit 31080249 authored by palfia@homejinni.com's avatar palfia@homejinni.com

MIPS: Improve SeqStringSetChar implementation.

Port r14769 (f0000b20)

BUG=

Review URL: https://codereview.chromium.org/15949002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14785 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6aef61b5
...@@ -514,50 +514,6 @@ void StringCharLoadGenerator::Generate(MacroAssembler* masm, ...@@ -514,50 +514,6 @@ void StringCharLoadGenerator::Generate(MacroAssembler* masm,
} }
void SeqStringSetCharGenerator::Generate(MacroAssembler* masm,
String::Encoding encoding,
Register string,
Register index,
Register value) {
if (FLAG_debug_code) {
__ And(at, index, Operand(kSmiTagMask));
__ Check(eq, "Non-smi index", at, Operand(zero_reg));
__ And(at, value, Operand(kSmiTagMask));
__ Check(eq, "Non-smi value", at, Operand(zero_reg));
__ lw(at, FieldMemOperand(string, String::kLengthOffset));
__ Check(lt, "Index is too large", index, Operand(at));
__ Check(ge, "Index is negative", index, Operand(zero_reg));
__ lw(at, FieldMemOperand(string, HeapObject::kMapOffset));
__ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset));
__ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask));
static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
__ Subu(at, at, Operand(encoding == String::ONE_BYTE_ENCODING
? one_byte_seq_type : two_byte_seq_type));
__ Check(eq, "Unexpected string type", at, Operand(zero_reg));
}
__ Addu(at,
string,
Operand(SeqString::kHeaderSize - kHeapObjectTag));
__ SmiUntag(value);
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
if (encoding == String::ONE_BYTE_ENCODING) {
__ SmiUntag(index);
__ Addu(at, at, index);
__ sb(value, MemOperand(at));
} else {
// No need to untag a smi for two-byte addressing.
__ Addu(at, at, index);
__ sh(value, MemOperand(at));
}
}
static MemOperand ExpConstant(int index, Register base) { static MemOperand ExpConstant(int index, Register base) {
return MemOperand(base, index * kDoubleSize); return MemOperand(base, index * kDoubleSize);
} }
......
...@@ -3445,19 +3445,56 @@ void FullCodeGenerator::EmitDateField(CallRuntime* expr) { ...@@ -3445,19 +3445,56 @@ void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
} }
void FullCodeGenerator::EmitSeqStringSetCharCheck(Register string,
Register index,
Register value,
uint32_t encoding_mask) {
__ And(at, index, Operand(kSmiTagMask));
__ Check(eq, "Non-smi index", at, Operand(zero_reg));
__ And(at, value, Operand(kSmiTagMask));
__ Check(eq, "Non-smi value", at, Operand(zero_reg));
__ lw(at, FieldMemOperand(string, String::kLengthOffset));
__ Check(lt, "Index is too large", index, Operand(at));
__ Check(ge, "Index is negative", index, Operand(zero_reg));
__ lw(at, FieldMemOperand(string, HeapObject::kMapOffset));
__ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset));
__ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask));
__ Subu(at, at, Operand(encoding_mask));
__ Check(eq, "Unexpected string type", at, Operand(zero_reg));
}
void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments(); ZoneList<Expression*>* args = expr->arguments();
ASSERT_EQ(3, args->length()); ASSERT_EQ(3, args->length());
Register string = v0;
Register index = a1;
Register value = a2;
VisitForStackValue(args->at(1)); // index VisitForStackValue(args->at(1)); // index
VisitForStackValue(args->at(2)); // value VisitForStackValue(args->at(2)); // value
__ pop(a2); __ pop(value);
__ pop(a1); __ pop(index);
VisitForAccumulatorValue(args->at(0)); // string VisitForAccumulatorValue(args->at(0)); // string
static const String::Encoding encoding = String::ONE_BYTE_ENCODING; if (FLAG_debug_code) {
SeqStringSetCharGenerator::Generate(masm_, encoding, v0, a1, a2); static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
context()->Plug(v0); EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type);
}
__ SmiUntag(value, value);
__ Addu(at,
string,
Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
__ SmiUntag(index);
__ Addu(at, at, index);
__ sb(value, MemOperand(at));
context()->Plug(string);
} }
...@@ -3465,15 +3502,29 @@ void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { ...@@ -3465,15 +3502,29 @@ void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments(); ZoneList<Expression*>* args = expr->arguments();
ASSERT_EQ(3, args->length()); ASSERT_EQ(3, args->length());
Register string = v0;
Register index = a1;
Register value = a2;
VisitForStackValue(args->at(1)); // index VisitForStackValue(args->at(1)); // index
VisitForStackValue(args->at(2)); // value VisitForStackValue(args->at(2)); // value
__ pop(a2); __ pop(value);
__ pop(a1); __ pop(index);
VisitForAccumulatorValue(args->at(0)); // string VisitForAccumulatorValue(args->at(0)); // string
static const String::Encoding encoding = String::TWO_BYTE_ENCODING; if (FLAG_debug_code) {
SeqStringSetCharGenerator::Generate(masm_, encoding, v0, a1, a2); static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
context()->Plug(v0); EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type);
}
__ SmiUntag(value, value);
__ Addu(at,
string,
Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
__ Addu(at, at, index);
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
__ sh(value, MemOperand(at));
context()->Plug(string);
} }
......
...@@ -1605,11 +1605,35 @@ void LCodeGen::DoDateField(LDateField* instr) { ...@@ -1605,11 +1605,35 @@ void LCodeGen::DoDateField(LDateField* instr) {
void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
SeqStringSetCharGenerator::Generate(masm(), Register string = ToRegister(instr->string());
instr->encoding(), Register index = ToRegister(instr->index());
ToRegister(instr->string()), Register value = ToRegister(instr->value());
ToRegister(instr->index()), Register scratch = scratch0();
ToRegister(instr->value())); String::Encoding encoding = instr->encoding();
if (FLAG_debug_code) {
__ lw(at, FieldMemOperand(string, HeapObject::kMapOffset));
__ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset));
__ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask));
static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
__ Subu(at, at, Operand(encoding == String::ONE_BYTE_ENCODING
? one_byte_seq_type : two_byte_seq_type));
__ Check(eq, "Unexpected string type", at, Operand(zero_reg));
}
__ Addu(scratch,
string,
Operand(SeqString::kHeaderSize - kHeapObjectTag));
if (encoding == String::ONE_BYTE_ENCODING) {
__ Addu(at, scratch, index);
__ sb(value, MemOperand(at));
} else {
__ sll(at, index, 1);
__ Addu(at, scratch, at);
__ sh(value, MemOperand(at));
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment