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
This commit is contained in:
weiliang.lin@intel.com 2014-06-11 14:09:05 +00:00
parent 15f719df65
commit 38d1b5c71e
2 changed files with 26 additions and 57 deletions

View File

@ -2855,18 +2855,12 @@ void StringCharFromCodeGenerator::GenerateSlow(
}
void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm,
Register dest,
Register src,
Register count,
Register scratch,
bool ascii) {
// 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
void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
Register dest,
Register src,
Register count,
Register scratch,
String::Encoding encoding) {
ASSERT(!scratch.is(dest));
ASSERT(!scratch.is(src));
ASSERT(!scratch.is(count));
@ -2877,38 +2871,17 @@ void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm,
__ j(zero, &done);
// Make count the number of bytes to copy.
if (!ascii) {
if (encoding == String::TWO_BYTE_ENCODING) {
__ 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;
__ bind(&loop);
__ mov_b(scratch, Operand(src, 0));
__ mov_b(Operand(dest, 0), scratch);
__ add(src, Immediate(1));
__ add(dest, Immediate(1));
__ sub(count, Immediate(1));
__ inc(src);
__ inc(dest);
__ dec(count);
__ j(not_zero, &loop);
__ bind(&done);
@ -3137,23 +3110,21 @@ void SubStringStub::Generate(MacroAssembler* masm) {
// eax: result string
// ecx: result string length
__ mov(edx, esi); // esi used by following code.
// Locate first character of result.
__ mov(edi, eax);
__ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag));
// Load string argument and locate character of sub string start.
__ pop(esi);
__ pop(edx);
__ pop(ebx);
__ SmiUntag(ebx);
__ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize));
__ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize));
// eax: result string
// ecx: result length
// edx: original value of esi
// edi: first character of result
// esi: character of sub string start
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true);
__ mov(esi, edx); // Restore esi.
// edx: character of sub string start
StringHelper::GenerateCopyCharacters(
masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING);
__ IncrementCounter(counters->sub_string_native(), 1);
__ ret(3 * kPointerSize);
@ -3163,27 +3134,25 @@ void SubStringStub::Generate(MacroAssembler* masm) {
// eax: result string
// ecx: result string length
__ mov(edx, esi); // esi used by following code.
// Locate first character of result.
__ mov(edi, eax);
__ add(edi,
Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
// Load string argument and locate character of sub string start.
__ pop(esi);
__ pop(edx);
__ pop(ebx);
// As from is a smi it is 2 times the value which matches the size of a two
// byte character.
STATIC_ASSERT(kSmiTag == 0);
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
// ecx: result length
// edx: original value of esi
// edi: first character of result
// esi: character of sub string start
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false);
__ mov(esi, edx); // Restore esi.
// edx: character of sub string start
StringHelper::GenerateCopyCharacters(
masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING);
__ IncrementCounter(counters->sub_string_native(), 1);
__ ret(3 * kPointerSize);

View File

@ -38,12 +38,12 @@ class StringHelper : public AllStatic {
// Generate code for copying characters using the rep movs instruction.
// Copies ecx characters from esi to edi. Copying of overlapping regions is
// not supported.
static void GenerateCopyCharactersREP(MacroAssembler* masm,
Register dest, // Must be edi.
Register src, // Must be esi.
Register count, // Must be ecx.
Register scratch, // Neither of above.
bool ascii);
static void GenerateCopyCharacters(MacroAssembler* masm,
Register dest,
Register src,
Register count,
Register scratch,
String::Encoding encoding);
// Generate string hash.
static void GenerateHashInit(MacroAssembler* masm,