OLD | NEW |
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 5754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5765 // chars: two character string, char 1 in byte 0 and char 2 in byte 1. | 5765 // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
5766 // hash: hash of two character string | 5766 // hash: hash of two character string |
5767 // symbol_table: symbol table | 5767 // symbol_table: symbol table |
5768 // mask: capacity mask | 5768 // mask: capacity mask |
5769 // scratch: - | 5769 // scratch: - |
5770 | 5770 |
5771 // Perform a number of probes in the symbol table. | 5771 // Perform a number of probes in the symbol table. |
5772 static const int kProbes = 4; | 5772 static const int kProbes = 4; |
5773 Label found_in_symbol_table; | 5773 Label found_in_symbol_table; |
5774 Label next_probe[kProbes], next_probe_pop_mask[kProbes]; | 5774 Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
| 5775 Register candidate = scratch; // Scratch register contains candidate. |
5775 for (int i = 0; i < kProbes; i++) { | 5776 for (int i = 0; i < kProbes; i++) { |
5776 // Calculate entry in symbol table. | 5777 // Calculate entry in symbol table. |
5777 __ mov(scratch, hash); | 5778 __ mov(scratch, hash); |
5778 if (i > 0) { | 5779 if (i > 0) { |
5779 __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); | 5780 __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
5780 } | 5781 } |
5781 __ and_(scratch, mask); | 5782 __ and_(scratch, mask); |
5782 | 5783 |
5783 // Load the entry from the symbol table. | 5784 // Load the entry from the symbol table. |
5784 Register candidate = scratch; // Scratch register contains candidate. | |
5785 STATIC_ASSERT(SymbolTable::kEntrySize == 1); | 5785 STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
5786 __ mov(candidate, | 5786 __ mov(candidate, |
5787 FieldOperand(symbol_table, | 5787 FieldOperand(symbol_table, |
5788 scratch, | 5788 scratch, |
5789 times_pointer_size, | 5789 times_pointer_size, |
5790 SymbolTable::kElementsStartOffset)); | 5790 SymbolTable::kElementsStartOffset)); |
5791 | 5791 |
5792 // If entry is undefined no string with this hash can be found. | 5792 // If entry is undefined no string with this hash can be found. |
5793 Factory* factory = masm->isolate()->factory(); | 5793 Factory* factory = masm->isolate()->factory(); |
5794 __ cmp(candidate, factory->undefined_value()); | 5794 __ cmp(candidate, factory->undefined_value()); |
5795 __ j(equal, not_found); | 5795 __ j(equal, not_found); |
5796 __ cmp(candidate, factory->null_value()); | 5796 __ cmp(candidate, factory->the_hole_value()); |
5797 __ j(equal, &next_probe[i]); | 5797 __ j(equal, &next_probe[i]); |
5798 | 5798 |
5799 // If length is not 2 the string is not a candidate. | 5799 // If length is not 2 the string is not a candidate. |
5800 __ cmp(FieldOperand(candidate, String::kLengthOffset), | 5800 __ cmp(FieldOperand(candidate, String::kLengthOffset), |
5801 Immediate(Smi::FromInt(2))); | 5801 Immediate(Smi::FromInt(2))); |
5802 __ j(not_equal, &next_probe[i]); | 5802 __ j(not_equal, &next_probe[i]); |
5803 | 5803 |
5804 // As we are out of registers save the mask on the stack and use that | 5804 // As we are out of registers save the mask on the stack and use that |
5805 // register as a temporary. | 5805 // register as a temporary. |
5806 __ push(mask); | 5806 __ push(mask); |
(...skipping 12 matching lines...) Expand all Loading... |
5819 __ j(equal, &found_in_symbol_table); | 5819 __ j(equal, &found_in_symbol_table); |
5820 __ bind(&next_probe_pop_mask[i]); | 5820 __ bind(&next_probe_pop_mask[i]); |
5821 __ pop(mask); | 5821 __ pop(mask); |
5822 __ bind(&next_probe[i]); | 5822 __ bind(&next_probe[i]); |
5823 } | 5823 } |
5824 | 5824 |
5825 // No matching 2 character string found by probing. | 5825 // No matching 2 character string found by probing. |
5826 __ jmp(not_found); | 5826 __ jmp(not_found); |
5827 | 5827 |
5828 // Scratch register contains result when we fall through to here. | 5828 // Scratch register contains result when we fall through to here. |
5829 Register result = scratch; | 5829 Register result = candidate; |
5830 __ bind(&found_in_symbol_table); | 5830 __ bind(&found_in_symbol_table); |
5831 __ pop(mask); // Pop saved mask from the stack. | 5831 __ pop(mask); // Pop saved mask from the stack. |
5832 if (!result.is(eax)) { | 5832 if (!result.is(eax)) { |
5833 __ mov(eax, result); | 5833 __ mov(eax, result); |
5834 } | 5834 } |
5835 } | 5835 } |
5836 | 5836 |
5837 | 5837 |
5838 void StringHelper::GenerateHashInit(MacroAssembler* masm, | 5838 void StringHelper::GenerateHashInit(MacroAssembler* masm, |
5839 Register hash, | 5839 Register hash, |
5840 Register character, | 5840 Register character, |
5841 Register scratch) { | 5841 Register scratch) { |
5842 // hash = character + (character << 10); | 5842 // hash = character + (character << 10); |
5843 __ mov(hash, character); | 5843 __ mov(hash, character); |
5844 __ shl(hash, 10); | 5844 __ shl(hash, 10); |
5845 __ add(hash, character); | 5845 __ add(hash, character); |
5846 // hash ^= hash >> 6; | 5846 // hash ^= hash >> 6; |
5847 __ mov(scratch, hash); | 5847 __ mov(scratch, hash); |
5848 __ sar(scratch, 6); | 5848 __ shr(scratch, 6); |
5849 __ xor_(hash, scratch); | 5849 __ xor_(hash, scratch); |
5850 } | 5850 } |
5851 | 5851 |
5852 | 5852 |
5853 void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, | 5853 void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
5854 Register hash, | 5854 Register hash, |
5855 Register character, | 5855 Register character, |
5856 Register scratch) { | 5856 Register scratch) { |
5857 // hash += character; | 5857 // hash += character; |
5858 __ add(hash, character); | 5858 __ add(hash, character); |
5859 // hash += hash << 10; | 5859 // hash += hash << 10; |
5860 __ mov(scratch, hash); | 5860 __ mov(scratch, hash); |
5861 __ shl(scratch, 10); | 5861 __ shl(scratch, 10); |
5862 __ add(hash, scratch); | 5862 __ add(hash, scratch); |
5863 // hash ^= hash >> 6; | 5863 // hash ^= hash >> 6; |
5864 __ mov(scratch, hash); | 5864 __ mov(scratch, hash); |
5865 __ sar(scratch, 6); | 5865 __ shr(scratch, 6); |
5866 __ xor_(hash, scratch); | 5866 __ xor_(hash, scratch); |
5867 } | 5867 } |
5868 | 5868 |
5869 | 5869 |
5870 void StringHelper::GenerateHashGetHash(MacroAssembler* masm, | 5870 void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
5871 Register hash, | 5871 Register hash, |
5872 Register scratch) { | 5872 Register scratch) { |
5873 // hash += hash << 3; | 5873 // hash += hash << 3; |
5874 __ mov(scratch, hash); | 5874 __ mov(scratch, hash); |
5875 __ shl(scratch, 3); | 5875 __ shl(scratch, 3); |
5876 __ add(hash, scratch); | 5876 __ add(hash, scratch); |
5877 // hash ^= hash >> 11; | 5877 // hash ^= hash >> 11; |
5878 __ mov(scratch, hash); | 5878 __ mov(scratch, hash); |
5879 __ sar(scratch, 11); | 5879 __ shr(scratch, 11); |
5880 __ xor_(hash, scratch); | 5880 __ xor_(hash, scratch); |
5881 // hash += hash << 15; | 5881 // hash += hash << 15; |
5882 __ mov(scratch, hash); | 5882 __ mov(scratch, hash); |
5883 __ shl(scratch, 15); | 5883 __ shl(scratch, 15); |
5884 __ add(hash, scratch); | 5884 __ add(hash, scratch); |
5885 | 5885 |
| 5886 uint32_t kHashShiftCutOffMask = (1 << (32 - String::kHashShift)) - 1; |
| 5887 __ and_(hash, kHashShiftCutOffMask); |
| 5888 |
5886 // if (hash == 0) hash = 27; | 5889 // if (hash == 0) hash = 27; |
5887 Label hash_not_zero; | 5890 Label hash_not_zero; |
5888 __ test(hash, hash); | 5891 __ test(hash, hash); |
5889 __ j(not_zero, &hash_not_zero, Label::kNear); | 5892 __ j(not_zero, &hash_not_zero, Label::kNear); |
5890 __ mov(hash, Immediate(27)); | 5893 __ mov(hash, Immediate(27)); |
5891 __ bind(&hash_not_zero); | 5894 __ bind(&hash_not_zero); |
5892 } | 5895 } |
5893 | 5896 |
5894 | 5897 |
5895 void SubStringStub::Generate(MacroAssembler* masm) { | 5898 void SubStringStub::Generate(MacroAssembler* masm) { |
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7108 __ bind(&element_done); | 7111 __ bind(&element_done); |
7109 __ ret(0); | 7112 __ ret(0); |
7110 } | 7113 } |
7111 } | 7114 } |
7112 | 7115 |
7113 #undef __ | 7116 #undef __ |
7114 | 7117 |
7115 } } // namespace v8::internal | 7118 } } // namespace v8::internal |
7116 | 7119 |
7117 #endif // V8_TARGET_ARCH_IA32 | 7120 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |