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 28 matching lines...) Expand all Loading... |
39 #include "simulator.h" | 39 #include "simulator.h" |
40 #endif | 40 #endif |
41 | 41 |
42 using namespace v8::internal; | 42 using namespace v8::internal; |
43 | 43 |
44 | 44 |
45 typedef uint32_t (*HASH_FUNCTION)(); | 45 typedef uint32_t (*HASH_FUNCTION)(); |
46 | 46 |
47 static v8::Persistent<v8::Context> env; | 47 static v8::Persistent<v8::Context> env; |
48 | 48 |
49 #define __ assm-> | 49 #define __ masm-> |
50 | 50 |
51 | 51 |
52 void generate(MacroAssembler* assm, i::Vector<const char> string) { | 52 void generate(MacroAssembler* masm, i::Vector<const char> string) { |
| 53 // GenerateHashInit takes the first character as an argument so it can't |
| 54 // handle the zero length string. |
| 55 ASSERT(string.length() > 0); |
53 #ifdef V8_TARGET_ARCH_IA32 | 56 #ifdef V8_TARGET_ARCH_IA32 |
54 __ push(ebx); | 57 __ push(ebx); |
55 __ push(ecx); | 58 __ push(ecx); |
56 __ mov(eax, Immediate(0)); | 59 __ mov(eax, Immediate(0)); |
57 if (string.length() > 0) { | 60 __ mov(ebx, Immediate(string.at(0))); |
58 __ mov(ebx, Immediate(string.at(0))); | 61 StringHelper::GenerateHashInit(masm, eax, ebx, ecx); |
59 StringHelper::GenerateHashInit(assm, eax, ebx, ecx); | |
60 } | |
61 for (int i = 1; i < string.length(); i++) { | 62 for (int i = 1; i < string.length(); i++) { |
62 __ mov(ebx, Immediate(string.at(i))); | 63 __ mov(ebx, Immediate(string.at(i))); |
63 StringHelper::GenerateHashAddCharacter(assm, eax, ebx, ecx); | 64 StringHelper::GenerateHashAddCharacter(masm, eax, ebx, ecx); |
64 } | 65 } |
65 StringHelper::GenerateHashGetHash(assm, eax, ecx); | 66 StringHelper::GenerateHashGetHash(masm, eax, ecx); |
66 __ pop(ecx); | 67 __ pop(ecx); |
67 __ pop(ebx); | 68 __ pop(ebx); |
68 __ Ret(); | 69 __ Ret(); |
69 #elif V8_TARGET_ARCH_X64 | 70 #elif V8_TARGET_ARCH_X64 |
| 71 __ push(kRootRegister); |
| 72 __ InitializeRootRegister(); |
70 __ push(rbx); | 73 __ push(rbx); |
71 __ push(rcx); | 74 __ push(rcx); |
72 __ movq(rax, Immediate(0)); | 75 __ movq(rax, Immediate(0)); |
73 if (string.length() > 0) { | 76 __ movq(rbx, Immediate(string.at(0))); |
74 __ movq(rbx, Immediate(string.at(0))); | 77 StringHelper::GenerateHashInit(masm, rax, rbx, rcx); |
75 StringHelper::GenerateHashInit(assm, rax, rbx, rcx); | |
76 } | |
77 for (int i = 1; i < string.length(); i++) { | 78 for (int i = 1; i < string.length(); i++) { |
78 __ movq(rbx, Immediate(string.at(i))); | 79 __ movq(rbx, Immediate(string.at(i))); |
79 StringHelper::GenerateHashAddCharacter(assm, rax, rbx, rcx); | 80 StringHelper::GenerateHashAddCharacter(masm, rax, rbx, rcx); |
80 } | 81 } |
81 StringHelper::GenerateHashGetHash(assm, rax, rcx); | 82 StringHelper::GenerateHashGetHash(masm, rax, rcx); |
82 __ pop(rcx); | 83 __ pop(rcx); |
83 __ pop(rbx); | 84 __ pop(rbx); |
| 85 __ pop(kRootRegister); |
84 __ Ret(); | 86 __ Ret(); |
85 #elif V8_TARGET_ARCH_ARM | 87 #elif V8_TARGET_ARCH_ARM |
| 88 __ push(kRootRegister); |
| 89 __ InitializeRootRegister(); |
| 90 |
86 __ mov(r0, Operand(0)); | 91 __ mov(r0, Operand(0)); |
87 if (string.length() > 0) { | 92 __ mov(ip, Operand(string.at(0))); |
88 __ mov(ip, Operand(string.at(0))); | 93 StringHelper::GenerateHashInit(masm, r0, ip); |
89 StringHelper::GenerateHashInit(assm, r0, ip); | |
90 } | |
91 for (int i = 1; i < string.length(); i++) { | 94 for (int i = 1; i < string.length(); i++) { |
92 __ mov(ip, Operand(string.at(i))); | 95 __ mov(ip, Operand(string.at(i))); |
93 StringHelper::GenerateHashAddCharacter(assm, r0, ip); | 96 StringHelper::GenerateHashAddCharacter(masm, r0, ip); |
94 } | 97 } |
95 StringHelper::GenerateHashGetHash(assm, r0); | 98 StringHelper::GenerateHashGetHash(masm, r0); |
| 99 __ pop(kRootRegister); |
96 __ mov(pc, Operand(lr)); | 100 __ mov(pc, Operand(lr)); |
97 #elif V8_TARGET_ARCH_MIPS | 101 #elif V8_TARGET_ARCH_MIPS |
| 102 __ push(kRootRegister); |
| 103 __ InitializeRootRegister(); |
| 104 |
98 __ li(v0, Operand(0)); | 105 __ li(v0, Operand(0)); |
99 if (string.length() > 0) { | 106 __ li(t1, Operand(string.at(0))); |
100 __ li(t1, Operand(string.at(0))); | 107 StringHelper::GenerateHashInit(masm, v0, t1); |
101 StringHelper::GenerateHashInit(assm, v0, t1); | |
102 } | |
103 for (int i = 1; i < string.length(); i++) { | 108 for (int i = 1; i < string.length(); i++) { |
104 __ li(t1, Operand(string.at(i))); | 109 __ li(t1, Operand(string.at(i))); |
105 StringHelper::GenerateHashAddCharacter(assm, v0, t1); | 110 StringHelper::GenerateHashAddCharacter(masm, v0, t1); |
106 } | 111 } |
107 StringHelper::GenerateHashGetHash(assm, v0); | 112 StringHelper::GenerateHashGetHash(masm, v0); |
| 113 __ pop(kRootRegister); |
108 __ jr(ra); | 114 __ jr(ra); |
109 __ nop(); | 115 __ nop(); |
110 #endif | 116 #endif |
111 } | 117 } |
112 | 118 |
113 | 119 |
114 void check(i::Vector<const char> string) { | 120 void check(i::Vector<const char> string) { |
115 v8::HandleScope scope; | 121 v8::HandleScope scope; |
116 v8::internal::byte buffer[2048]; | 122 v8::internal::byte buffer[2048]; |
117 MacroAssembler assm(Isolate::Current(), buffer, sizeof buffer); | 123 MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer); |
118 | 124 |
119 generate(&assm, string); | 125 generate(&masm, string); |
120 | 126 |
121 CodeDesc desc; | 127 CodeDesc desc; |
122 assm.GetCode(&desc); | 128 masm.GetCode(&desc); |
123 Code* code = Code::cast(HEAP->CreateCode( | 129 Code* code = Code::cast(HEAP->CreateCode( |
124 desc, | 130 desc, |
125 Code::ComputeFlags(Code::STUB), | 131 Code::ComputeFlags(Code::STUB), |
126 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); | 132 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); |
127 CHECK(code->IsCode()); | 133 CHECK(code->IsCode()); |
128 | 134 |
129 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); | 135 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); |
130 Handle<String> v8_string = FACTORY->NewStringFromAscii(string); | 136 Handle<String> v8_string = FACTORY->NewStringFromAscii(string); |
131 v8_string->set_hash_field(String::kEmptyHashField); | 137 v8_string->set_hash_field(String::kEmptyHashField); |
132 #ifdef USE_SIMULATOR | 138 #ifdef USE_SIMULATOR |
(...skipping 16 matching lines...) Expand all Loading... |
149 TEST(StringHash) { | 155 TEST(StringHash) { |
150 if (env.IsEmpty()) env = v8::Context::New(); | 156 if (env.IsEmpty()) env = v8::Context::New(); |
151 for (int a = 0; a < String::kMaxAsciiCharCode; a++) { | 157 for (int a = 0; a < String::kMaxAsciiCharCode; a++) { |
152 // Numbers are hashed differently. | 158 // Numbers are hashed differently. |
153 if (a >= '0' && a <= '9') continue; | 159 if (a >= '0' && a <= '9') continue; |
154 for (int b = 0; b < String::kMaxAsciiCharCode; b++) { | 160 for (int b = 0; b < String::kMaxAsciiCharCode; b++) { |
155 if (b >= '0' && b <= '9') continue; | 161 if (b >= '0' && b <= '9') continue; |
156 check_twochars(static_cast<char>(a), static_cast<char>(b)); | 162 check_twochars(static_cast<char>(a), static_cast<char>(b)); |
157 } | 163 } |
158 } | 164 } |
159 check(i::Vector<const char>("", 0)); | |
160 check(i::Vector<const char>("*", 1)); | 165 check(i::Vector<const char>("*", 1)); |
161 check(i::Vector<const char>(".zZ", 3)); | 166 check(i::Vector<const char>(".zZ", 3)); |
162 check(i::Vector<const char>("muc", 3)); | 167 check(i::Vector<const char>("muc", 3)); |
163 check(i::Vector<const char>("(>'_')>", 7)); | 168 check(i::Vector<const char>("(>'_')>", 7)); |
164 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); | 169 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); |
165 } | 170 } |
166 | 171 |
167 #undef __ | 172 #undef __ |
OLD | NEW |