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 4687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4698 // hash: hash of two character string (32-bit int) | 4698 // hash: hash of two character string (32-bit int) |
4699 // symbol_table: symbol table | 4699 // symbol_table: symbol table |
4700 // mask: capacity mask (32-bit int) | 4700 // mask: capacity mask (32-bit int) |
4701 // map: - | 4701 // map: - |
4702 // scratch: - | 4702 // scratch: - |
4703 | 4703 |
4704 // Perform a number of probes in the symbol table. | 4704 // Perform a number of probes in the symbol table. |
4705 static const int kProbes = 4; | 4705 static const int kProbes = 4; |
4706 Label found_in_symbol_table; | 4706 Label found_in_symbol_table; |
4707 Label next_probe[kProbes]; | 4707 Label next_probe[kProbes]; |
| 4708 Register candidate = scratch; // Scratch register contains candidate. |
4708 for (int i = 0; i < kProbes; i++) { | 4709 for (int i = 0; i < kProbes; i++) { |
4709 // Calculate entry in symbol table. | 4710 // Calculate entry in symbol table. |
4710 __ movl(scratch, hash); | 4711 __ movl(scratch, hash); |
4711 if (i > 0) { | 4712 if (i > 0) { |
4712 __ addl(scratch, Immediate(SymbolTable::GetProbeOffset(i))); | 4713 __ addl(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
4713 } | 4714 } |
4714 __ andl(scratch, mask); | 4715 __ andl(scratch, mask); |
4715 | 4716 |
4716 // Load the entry from the symbol table. | 4717 // Load the entry from the symbol table. |
4717 Register candidate = scratch; // Scratch register contains candidate. | |
4718 STATIC_ASSERT(SymbolTable::kEntrySize == 1); | 4718 STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
4719 __ movq(candidate, | 4719 __ movq(candidate, |
4720 FieldOperand(symbol_table, | 4720 FieldOperand(symbol_table, |
4721 scratch, | 4721 scratch, |
4722 times_pointer_size, | 4722 times_pointer_size, |
4723 SymbolTable::kElementsStartOffset)); | 4723 SymbolTable::kElementsStartOffset)); |
4724 | 4724 |
4725 // If entry is undefined no string with this hash can be found. | 4725 // If entry is undefined no string with this hash can be found. |
4726 Label is_string; | 4726 Label is_string; |
4727 __ CmpObjectType(candidate, ODDBALL_TYPE, map); | 4727 __ CmpObjectType(candidate, ODDBALL_TYPE, map); |
4728 __ j(not_equal, &is_string, Label::kNear); | 4728 __ j(not_equal, &is_string, Label::kNear); |
4729 | 4729 |
4730 __ CompareRoot(candidate, Heap::kUndefinedValueRootIndex); | 4730 __ CompareRoot(candidate, Heap::kUndefinedValueRootIndex); |
4731 __ j(equal, not_found); | 4731 __ j(equal, not_found); |
4732 // Must be null (deleted entry). | 4732 // Must be the hole (deleted entry). |
| 4733 if (FLAG_debug_code) { |
| 4734 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
| 4735 __ cmpq(kScratchRegister, candidate); |
| 4736 __ Assert(equal, "oddball in symbol table is not undefined or the hole"); |
| 4737 } |
4733 __ jmp(&next_probe[i]); | 4738 __ jmp(&next_probe[i]); |
4734 | 4739 |
4735 __ bind(&is_string); | 4740 __ bind(&is_string); |
4736 | 4741 |
4737 // If length is not 2 the string is not a candidate. | 4742 // If length is not 2 the string is not a candidate. |
4738 __ SmiCompare(FieldOperand(candidate, String::kLengthOffset), | 4743 __ SmiCompare(FieldOperand(candidate, String::kLengthOffset), |
4739 Smi::FromInt(2)); | 4744 Smi::FromInt(2)); |
4740 __ j(not_equal, &next_probe[i]); | 4745 __ j(not_equal, &next_probe[i]); |
4741 | 4746 |
4742 // We use kScratchRegister as a temporary register in assumption that | 4747 // We use kScratchRegister as a temporary register in assumption that |
(...skipping 10 matching lines...) Expand all Loading... |
4753 __ andl(temp, Immediate(0x0000ffff)); | 4758 __ andl(temp, Immediate(0x0000ffff)); |
4754 __ cmpl(chars, temp); | 4759 __ cmpl(chars, temp); |
4755 __ j(equal, &found_in_symbol_table); | 4760 __ j(equal, &found_in_symbol_table); |
4756 __ bind(&next_probe[i]); | 4761 __ bind(&next_probe[i]); |
4757 } | 4762 } |
4758 | 4763 |
4759 // No matching 2 character string found by probing. | 4764 // No matching 2 character string found by probing. |
4760 __ jmp(not_found); | 4765 __ jmp(not_found); |
4761 | 4766 |
4762 // Scratch register contains result when we fall through to here. | 4767 // Scratch register contains result when we fall through to here. |
4763 Register result = scratch; | 4768 Register result = candidate; |
4764 __ bind(&found_in_symbol_table); | 4769 __ bind(&found_in_symbol_table); |
4765 if (!result.is(rax)) { | 4770 if (!result.is(rax)) { |
4766 __ movq(rax, result); | 4771 __ movq(rax, result); |
4767 } | 4772 } |
4768 } | 4773 } |
4769 | 4774 |
4770 | 4775 |
4771 void StringHelper::GenerateHashInit(MacroAssembler* masm, | 4776 void StringHelper::GenerateHashInit(MacroAssembler* masm, |
4772 Register hash, | 4777 Register hash, |
4773 Register character, | 4778 Register character, |
4774 Register scratch) { | 4779 Register scratch) { |
4775 // hash = character + (character << 10); | 4780 // hash = character + (character << 10); |
4776 __ movl(hash, character); | 4781 __ movl(hash, character); |
4777 __ shll(hash, Immediate(10)); | 4782 __ shll(hash, Immediate(10)); |
4778 __ addl(hash, character); | 4783 __ addl(hash, character); |
4779 // hash ^= hash >> 6; | 4784 // hash ^= hash >> 6; |
4780 __ movl(scratch, hash); | 4785 __ movl(scratch, hash); |
4781 __ sarl(scratch, Immediate(6)); | 4786 __ shrl(scratch, Immediate(6)); |
4782 __ xorl(hash, scratch); | 4787 __ xorl(hash, scratch); |
4783 } | 4788 } |
4784 | 4789 |
4785 | 4790 |
4786 void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, | 4791 void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
4787 Register hash, | 4792 Register hash, |
4788 Register character, | 4793 Register character, |
4789 Register scratch) { | 4794 Register scratch) { |
4790 // hash += character; | 4795 // hash += character; |
4791 __ addl(hash, character); | 4796 __ addl(hash, character); |
4792 // hash += hash << 10; | 4797 // hash += hash << 10; |
4793 __ movl(scratch, hash); | 4798 __ movl(scratch, hash); |
4794 __ shll(scratch, Immediate(10)); | 4799 __ shll(scratch, Immediate(10)); |
4795 __ addl(hash, scratch); | 4800 __ addl(hash, scratch); |
4796 // hash ^= hash >> 6; | 4801 // hash ^= hash >> 6; |
4797 __ movl(scratch, hash); | 4802 __ movl(scratch, hash); |
4798 __ sarl(scratch, Immediate(6)); | 4803 __ shrl(scratch, Immediate(6)); |
4799 __ xorl(hash, scratch); | 4804 __ xorl(hash, scratch); |
4800 } | 4805 } |
4801 | 4806 |
4802 | 4807 |
4803 void StringHelper::GenerateHashGetHash(MacroAssembler* masm, | 4808 void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
4804 Register hash, | 4809 Register hash, |
4805 Register scratch) { | 4810 Register scratch) { |
4806 // hash += hash << 3; | 4811 // hash += hash << 3; |
4807 __ leal(hash, Operand(hash, hash, times_8, 0)); | 4812 __ leal(hash, Operand(hash, hash, times_8, 0)); |
4808 // hash ^= hash >> 11; | 4813 // hash ^= hash >> 11; |
4809 __ movl(scratch, hash); | 4814 __ movl(scratch, hash); |
4810 __ sarl(scratch, Immediate(11)); | 4815 __ shrl(scratch, Immediate(11)); |
4811 __ xorl(hash, scratch); | 4816 __ xorl(hash, scratch); |
4812 // hash += hash << 15; | 4817 // hash += hash << 15; |
4813 __ movl(scratch, hash); | 4818 __ movl(scratch, hash); |
4814 __ shll(scratch, Immediate(15)); | 4819 __ shll(scratch, Immediate(15)); |
4815 __ addl(hash, scratch); | 4820 __ addl(hash, scratch); |
4816 | 4821 |
| 4822 uint32_t kHashShiftCutOffMask = (1 << (32 - String::kHashShift)) - 1; |
| 4823 __ andl(hash, Immediate(kHashShiftCutOffMask)); |
| 4824 |
4817 // if (hash == 0) hash = 27; | 4825 // if (hash == 0) hash = 27; |
4818 Label hash_not_zero; | 4826 Label hash_not_zero; |
4819 __ j(not_zero, &hash_not_zero); | 4827 __ j(not_zero, &hash_not_zero); |
4820 __ Set(hash, 27); | 4828 __ Set(hash, 27); |
4821 __ bind(&hash_not_zero); | 4829 __ bind(&hash_not_zero); |
4822 } | 4830 } |
4823 | 4831 |
4824 void SubStringStub::Generate(MacroAssembler* masm) { | 4832 void SubStringStub::Generate(MacroAssembler* masm) { |
4825 Label runtime; | 4833 Label runtime; |
4826 | 4834 |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6022 __ bind(&element_done); | 6030 __ bind(&element_done); |
6023 __ ret(0); | 6031 __ ret(0); |
6024 } | 6032 } |
6025 } | 6033 } |
6026 | 6034 |
6027 #undef __ | 6035 #undef __ |
6028 | 6036 |
6029 } } // namespace v8::internal | 6037 } } // namespace v8::internal |
6030 | 6038 |
6031 #endif // V8_TARGET_ARCH_X64 | 6039 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |