Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 6928020: Faster string equals in generated code. (Closed)
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3894 // non-zero value, which indicates not equal, so just return. 3894 // non-zero value, which indicates not equal, so just return.
3895 __ ret(0); 3895 __ ret(0);
3896 } 3896 }
3897 3897
3898 __ bind(&check_for_strings); 3898 __ bind(&check_for_strings);
3899 3899
3900 __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, 3900 __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx,
3901 &check_unequal_objects); 3901 &check_unequal_objects);
3902 3902
3903 // Inline comparison of ascii strings. 3903 // Inline comparison of ascii strings.
3904 StringCompareStub::GenerateCompareFlatAsciiStrings(masm, 3904 if (cc_ == equal) {
3905 StringCompareStub::GenerateFlatAsciiStringEquals(masm,
3905 edx, 3906 edx,
3906 eax, 3907 eax,
3907 ecx, 3908 ecx,
3908 ebx, 3909 ebx);
3909 edi); 3910 } else {
3911 StringCompareStub::GenerateCompareFlatAsciiStrings(masm,
3912 edx,
3913 eax,
3914 ecx,
3915 ebx,
3916 edi);
3917 }
3910 #ifdef DEBUG 3918 #ifdef DEBUG
3911 __ Abort("Unexpected fall-through from string comparison"); 3919 __ Abort("Unexpected fall-through from string comparison");
3912 #endif 3920 #endif
3913 3921
3914 __ bind(&check_unequal_objects); 3922 __ bind(&check_unequal_objects);
3915 if (cc_ == equal && !strict_) { 3923 if (cc_ == equal && !strict_) {
3916 // Non-strict equality. Objects are unequal if 3924 // Non-strict equality. Objects are unequal if
3917 // they are both JSObjects and not undetectable, 3925 // they are both JSObjects and not undetectable,
3918 // and their pointers are different. 3926 // and their pointers are different.
3919 NearLabel not_both_objects; 3927 NearLabel not_both_objects;
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after
5595 __ bind(&return_eax); 5603 __ bind(&return_eax);
5596 __ IncrementCounter(counters->sub_string_native(), 1); 5604 __ IncrementCounter(counters->sub_string_native(), 1);
5597 __ ret(3 * kPointerSize); 5605 __ ret(3 * kPointerSize);
5598 5606
5599 // Just jump to runtime to create the sub string. 5607 // Just jump to runtime to create the sub string.
5600 __ bind(&runtime); 5608 __ bind(&runtime);
5601 __ TailCallRuntime(Runtime::kSubString, 3, 1); 5609 __ TailCallRuntime(Runtime::kSubString, 3, 1);
5602 } 5610 }
5603 5611
5604 5612
5613 void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm,
5614 Register left,
5615 Register right,
5616 Register scratch1,
5617 Register scratch2) {
5618 Register length = scratch1;
5619
5620 // Compare lengths.
5621 NearLabel strings_not_equal, check_zero_length;
5622 __ mov(length, FieldOperand(left, String::kLengthOffset));
5623 __ cmp(length, FieldOperand(right, String::kLengthOffset));
5624 __ j(equal, &check_zero_length);
5625 __ bind(&strings_not_equal);
5626 __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL)));
5627 __ ret(0);
5628
5629 // Check if the length is zero.
5630 NearLabel compare_chars;
5631 __ bind(&check_zero_length);
5632 STATIC_ASSERT(kSmiTag == 0);
5633 __ test(length, Operand(length));
5634 __ j(not_zero, &compare_chars);
5635 __ Set(eax, Immediate(Smi::FromInt(EQUAL)));
5636 __ ret(0);
5637
5638 // Compare characters.
5639 __ bind(&compare_chars);
5640
5641 // Change index to run from -length to -1 by adding length to string
5642 // start. This means that loop ends when index reaches zero, which
5643 // doesn't need an additional compare.
5644 __ SmiUntag(length);
5645 __ lea(left,
5646 FieldOperand(left, length, times_1, SeqAsciiString::kHeaderSize));
5647 __ lea(right,
5648 FieldOperand(right, length, times_1, SeqAsciiString::kHeaderSize));
5649 __ neg(length);
5650 Register index = length; // index = -length;
5651
5652 // Compare loop.
5653 NearLabel loop;
5654 __ bind(&loop);
5655 __ mov_b(scratch2, Operand(left, index, times_1, 0));
Mads Ager (chromium) 2011/05/05 07:42:24 Do you need "times_1, 0" here?
Vitaly Repeshko 2011/05/05 11:40:18 There's no Operand(reg, reg), only Operand(reg, im
5656 __ cmpb(scratch2, Operand(right, index, times_1, 0));
5657 __ j(not_equal, &strings_not_equal);
5658 __ add(Operand(index), Immediate(1));
5659 __ j(not_zero, &loop);
5660
5661 // Characters are equal.
5662 __ Set(eax, Immediate(Smi::FromInt(EQUAL)));
5663 __ ret(0);
5664 }
5665
5666
5605 void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, 5667 void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
5606 Register left, 5668 Register left,
5607 Register right, 5669 Register right,
5608 Register scratch1, 5670 Register scratch1,
5609 Register scratch2, 5671 Register scratch2,
5610 Register scratch3) { 5672 Register scratch3) {
5611 Label result_not_equal; 5673 Label result_not_equal;
5612 Label result_greater; 5674 Label result_greater;
5613 Label compare_lengths; 5675 Label compare_lengths;
5614 5676
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
5801 __ bind(&generic_stub); 5863 __ bind(&generic_stub);
5802 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); 5864 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
5803 5865
5804 __ bind(&miss); 5866 __ bind(&miss);
5805 GenerateMiss(masm); 5867 GenerateMiss(masm);
5806 } 5868 }
5807 5869
5808 5870
5809 void ICCompareStub::GenerateStrings(MacroAssembler* masm) { 5871 void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
5810 ASSERT(state_ == CompareIC::STRINGS); 5872 ASSERT(state_ == CompareIC::STRINGS);
5873 ASSERT(GetCondition() == equal);
5811 Label miss; 5874 Label miss;
5812 5875
5813 // Registers containing left and right operands respectively. 5876 // Registers containing left and right operands respectively.
5814 Register left = edx; 5877 Register left = edx;
5815 Register right = eax; 5878 Register right = eax;
5816 Register tmp1 = ecx; 5879 Register tmp1 = ecx;
5817 Register tmp2 = ebx; 5880 Register tmp2 = ebx;
5818 Register tmp3 = edi; 5881 Register tmp3 = edi;
5819 5882
5820 // Check that both operands are heap objects. 5883 // Check that both operands are heap objects.
(...skipping 23 matching lines...) Expand all
5844 STATIC_ASSERT(kSmiTag == 0); 5907 STATIC_ASSERT(kSmiTag == 0);
5845 __ Set(eax, Immediate(Smi::FromInt(EQUAL))); 5908 __ Set(eax, Immediate(Smi::FromInt(EQUAL)));
5846 __ ret(0); 5909 __ ret(0);
5847 5910
5848 // Handle not identical strings. 5911 // Handle not identical strings.
5849 __ bind(&not_same); 5912 __ bind(&not_same);
5850 5913
5851 // Check that both strings are symbols. If they are, we're done 5914 // Check that both strings are symbols. If they are, we're done
5852 // because we already know they are not identical. 5915 // because we already know they are not identical.
5853 NearLabel do_compare; 5916 NearLabel do_compare;
5854 ASSERT(GetCondition() == equal);
5855 STATIC_ASSERT(kSymbolTag != 0); 5917 STATIC_ASSERT(kSymbolTag != 0);
5856 __ and_(tmp1, Operand(tmp2)); 5918 __ and_(tmp1, Operand(tmp2));
5857 __ test(tmp1, Immediate(kIsSymbolMask)); 5919 __ test(tmp1, Immediate(kIsSymbolMask));
5858 __ j(zero, &do_compare); 5920 __ j(zero, &do_compare);
5859 // Make sure eax is non-zero. At this point input operands are 5921 // Make sure eax is non-zero. At this point input operands are
5860 // guaranteed to be non-zero. 5922 // guaranteed to be non-zero.
5861 ASSERT(right.is(eax)); 5923 ASSERT(right.is(eax));
5862 __ ret(0); 5924 __ ret(0);
5863 5925
5864 // Check that both strings are sequential ASCII. 5926 // Check that both strings are sequential ASCII.
5865 Label runtime; 5927 Label runtime;
5866 __ bind(&do_compare); 5928 __ bind(&do_compare);
5867 __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); 5929 __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime);
5868 5930
5869 // Compare flat ASCII strings. Returns when done. 5931 // Compare flat ASCII strings. Returns when done.
5870 StringCompareStub::GenerateCompareFlatAsciiStrings( 5932 StringCompareStub::GenerateFlatAsciiStringEquals(
5871 masm, left, right, tmp1, tmp2, tmp3); 5933 masm, left, right, tmp1, tmp2);
5872 5934
5873 // Handle more complex cases in runtime. 5935 // Handle more complex cases in runtime.
5874 __ bind(&runtime); 5936 __ bind(&runtime);
5875 __ pop(tmp1); // Return address. 5937 __ pop(tmp1); // Return address.
5876 __ push(left); 5938 __ push(left);
5877 __ push(right); 5939 __ push(right);
5878 __ push(tmp1); 5940 __ push(tmp1);
5879 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); 5941 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
5880 5942
5881 __ bind(&miss); 5943 __ bind(&miss);
5882 GenerateMiss(masm); 5944 GenerateMiss(masm);
5883 } 5945 }
5884 5946
5885 5947
5886 void ICCompareStub::GenerateObjects(MacroAssembler* masm) { 5948 void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
5887 ASSERT(state_ == CompareIC::OBJECTS); 5949 ASSERT(state_ == CompareIC::OBJECTS);
5888 NearLabel miss; 5950 NearLabel miss;
5889 __ mov(ecx, Operand(edx)); 5951 __ mov(ecx, Operand(edx));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5934 // Do a tail call to the rewritten stub. 5996 // Do a tail call to the rewritten stub.
5935 __ jmp(Operand(edi)); 5997 __ jmp(Operand(edi));
5936 } 5998 }
5937 5999
5938 6000
5939 #undef __ 6001 #undef __
5940 6002
5941 } } // namespace v8::internal 6003 } } // namespace v8::internal
5942 6004
5943 #endif // V8_TARGET_ARCH_IA32 6005 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/code-stubs-ia32.h ('k') | src/x64/code-stubs-x64.h » ('j') | src/x64/code-stubs-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698