X87: Simplify string copy in SubStringStub.

port r21756.

original commit message:
  The optimizations are unnecessary since the maximum
  string length they operate on is currently 12.

R=yangguo@chromium.org, bmeurer@chromium.org
  BUG=352155
  LOG=N

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

Patch from Chunyang Dai <chunyang.dai@intel.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21772 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 15f719df
...@@ -2855,18 +2855,12 @@ void StringCharFromCodeGenerator::GenerateSlow( ...@@ -2855,18 +2855,12 @@ void StringCharFromCodeGenerator::GenerateSlow(
} }
void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
Register dest, Register dest,
Register src, Register src,
Register count, Register count,
Register scratch, Register scratch,
bool ascii) { String::Encoding encoding) {
// Copy characters using rep movs of doublewords.
// The destination is aligned on a 4 byte boundary because we are
// copying to the beginning of a newly allocated string.
ASSERT(dest.is(edi)); // rep movs destination
ASSERT(src.is(esi)); // rep movs source
ASSERT(count.is(ecx)); // rep movs count
ASSERT(!scratch.is(dest)); ASSERT(!scratch.is(dest));
ASSERT(!scratch.is(src)); ASSERT(!scratch.is(src));
ASSERT(!scratch.is(count)); ASSERT(!scratch.is(count));
...@@ -2877,38 +2871,17 @@ void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, ...@@ -2877,38 +2871,17 @@ void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm,
__ j(zero, &done); __ j(zero, &done);
// Make count the number of bytes to copy. // Make count the number of bytes to copy.
if (!ascii) { if (encoding == String::TWO_BYTE_ENCODING) {
__ shl(count, 1); __ shl(count, 1);
} }
// Don't enter the rep movs if there are less than 4 bytes to copy.
Label last_bytes;
__ test(count, Immediate(~3));
__ j(zero, &last_bytes, Label::kNear);
// Copy from edi to esi using rep movs instruction.
__ mov(scratch, count);
__ sar(count, 2); // Number of doublewords to copy.
__ cld();
__ rep_movs();
// Find number of bytes left.
__ mov(count, scratch);
__ and_(count, 3);
// Check if there are more bytes to copy.
__ bind(&last_bytes);
__ test(count, count);
__ j(zero, &done);
// Copy remaining characters.
Label loop; Label loop;
__ bind(&loop); __ bind(&loop);
__ mov_b(scratch, Operand(src, 0)); __ mov_b(scratch, Operand(src, 0));
__ mov_b(Operand(dest, 0), scratch); __ mov_b(Operand(dest, 0), scratch);
__ add(src, Immediate(1)); __ inc(src);
__ add(dest, Immediate(1)); __ inc(dest);
__ sub(count, Immediate(1)); __ dec(count);
__ j(not_zero, &loop); __ j(not_zero, &loop);
__ bind(&done); __ bind(&done);
...@@ -3137,23 +3110,21 @@ void SubStringStub::Generate(MacroAssembler* masm) { ...@@ -3137,23 +3110,21 @@ void SubStringStub::Generate(MacroAssembler* masm) {
// eax: result string // eax: result string
// ecx: result string length // ecx: result string length
__ mov(edx, esi); // esi used by following code.
// Locate first character of result. // Locate first character of result.
__ mov(edi, eax); __ mov(edi, eax);
__ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag));
// Load string argument and locate character of sub string start. // Load string argument and locate character of sub string start.
__ pop(esi); __ pop(edx);
__ pop(ebx); __ pop(ebx);
__ SmiUntag(ebx); __ SmiUntag(ebx);
__ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); __ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize));
// eax: result string // eax: result string
// ecx: result length // ecx: result length
// edx: original value of esi
// edi: first character of result // edi: first character of result
// esi: character of sub string start // edx: character of sub string start
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); StringHelper::GenerateCopyCharacters(
__ mov(esi, edx); // Restore esi. masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING);
__ IncrementCounter(counters->sub_string_native(), 1); __ IncrementCounter(counters->sub_string_native(), 1);
__ ret(3 * kPointerSize); __ ret(3 * kPointerSize);
...@@ -3163,27 +3134,25 @@ void SubStringStub::Generate(MacroAssembler* masm) { ...@@ -3163,27 +3134,25 @@ void SubStringStub::Generate(MacroAssembler* masm) {
// eax: result string // eax: result string
// ecx: result string length // ecx: result string length
__ mov(edx, esi); // esi used by following code.
// Locate first character of result. // Locate first character of result.
__ mov(edi, eax); __ mov(edi, eax);
__ add(edi, __ add(edi,
Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
// Load string argument and locate character of sub string start. // Load string argument and locate character of sub string start.
__ pop(esi); __ pop(edx);
__ pop(ebx); __ pop(ebx);
// As from is a smi it is 2 times the value which matches the size of a two // As from is a smi it is 2 times the value which matches the size of a two
// byte character. // byte character.
STATIC_ASSERT(kSmiTag == 0); STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
__ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); __ lea(edx, FieldOperand(edx, ebx, times_1, SeqTwoByteString::kHeaderSize));
// eax: result string // eax: result string
// ecx: result length // ecx: result length
// edx: original value of esi
// edi: first character of result // edi: first character of result
// esi: character of sub string start // edx: character of sub string start
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); StringHelper::GenerateCopyCharacters(
__ mov(esi, edx); // Restore esi. masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING);
__ IncrementCounter(counters->sub_string_native(), 1); __ IncrementCounter(counters->sub_string_native(), 1);
__ ret(3 * kPointerSize); __ ret(3 * kPointerSize);
......
...@@ -38,12 +38,12 @@ class StringHelper : public AllStatic { ...@@ -38,12 +38,12 @@ class StringHelper : public AllStatic {
// Generate code for copying characters using the rep movs instruction. // Generate code for copying characters using the rep movs instruction.
// Copies ecx characters from esi to edi. Copying of overlapping regions is // Copies ecx characters from esi to edi. Copying of overlapping regions is
// not supported. // not supported.
static void GenerateCopyCharactersREP(MacroAssembler* masm, static void GenerateCopyCharacters(MacroAssembler* masm,
Register dest, // Must be edi. Register dest,
Register src, // Must be esi. Register src,
Register count, // Must be ecx. Register count,
Register scratch, // Neither of above. Register scratch,
bool ascii); String::Encoding encoding);
// Generate string hash. // Generate string hash.
static void GenerateHashInit(MacroAssembler* masm, static void GenerateHashInit(MacroAssembler* masm,
......
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