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

Side by Side Diff: test/cctest/test-hashing.cc

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-fuzz-a64.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 __ mov(r0, Operand(0)); 89 __ mov(r0, Operand(0));
90 __ mov(ip, Operand(string.at(0))); 90 __ mov(ip, Operand(string.at(0)));
91 StringHelper::GenerateHashInit(masm, r0, ip); 91 StringHelper::GenerateHashInit(masm, r0, ip);
92 for (int i = 1; i < string.length(); i++) { 92 for (int i = 1; i < string.length(); i++) {
93 __ mov(ip, Operand(string.at(i))); 93 __ mov(ip, Operand(string.at(i)));
94 StringHelper::GenerateHashAddCharacter(masm, r0, ip); 94 StringHelper::GenerateHashAddCharacter(masm, r0, ip);
95 } 95 }
96 StringHelper::GenerateHashGetHash(masm, r0); 96 StringHelper::GenerateHashGetHash(masm, r0);
97 __ pop(kRootRegister); 97 __ pop(kRootRegister);
98 __ mov(pc, Operand(lr)); 98 __ mov(pc, Operand(lr));
99 #elif V8_TARGET_ARCH_A64
100 // The A64 assembler usually uses jssp (x28) as a stack pointer, but only csp
101 // is initialized by the calling (C++) code.
102 Register old_stack_pointer = __ StackPointer();
103 __ SetStackPointer(csp);
104 __ Push(root, xzr);
105 __ InitializeRootRegister();
106 __ Mov(x0, 0);
107 __ Mov(x10, Operand(string.at(0)));
108 StringHelper::GenerateHashInit(masm, x0, x10);
109 for (int i = 1; i < string.length(); i++) {
110 __ Mov(x10, Operand(string.at(i)));
111 StringHelper::GenerateHashAddCharacter(masm, x0, x10);
112 }
113 StringHelper::GenerateHashGetHash(masm, x0, x10);
114 __ Pop(xzr, root);
115 __ Ret();
116 __ SetStackPointer(old_stack_pointer);
117 #elif V8_TARGET_ARCH_MIPS 99 #elif V8_TARGET_ARCH_MIPS
118 __ push(kRootRegister); 100 __ push(kRootRegister);
119 __ InitializeRootRegister(); 101 __ InitializeRootRegister();
120 102
121 __ li(v0, Operand(0)); 103 __ li(v0, Operand(0));
122 __ li(t1, Operand(string.at(0))); 104 __ li(t1, Operand(string.at(0)));
123 StringHelper::GenerateHashInit(masm, v0, t1); 105 StringHelper::GenerateHashInit(masm, v0, t1);
124 for (int i = 1; i < string.length(); i++) { 106 for (int i = 1; i < string.length(); i++) {
125 __ li(t1, Operand(string.at(i))); 107 __ li(t1, Operand(string.at(i)));
126 StringHelper::GenerateHashAddCharacter(masm, v0, t1); 108 StringHelper::GenerateHashAddCharacter(masm, v0, t1);
127 } 109 }
128 StringHelper::GenerateHashGetHash(masm, v0); 110 StringHelper::GenerateHashGetHash(masm, v0);
129 __ pop(kRootRegister); 111 __ pop(kRootRegister);
130 __ jr(ra); 112 __ jr(ra);
131 __ nop(); 113 __ nop();
132 #else
133 #error Unsupported architecture.
134 #endif 114 #endif
135 } 115 }
136 116
137 117
138 void generate(MacroAssembler* masm, uint32_t key) { 118 void generate(MacroAssembler* masm, uint32_t key) {
139 #if V8_TARGET_ARCH_IA32 119 #if V8_TARGET_ARCH_IA32
140 __ push(ebx); 120 __ push(ebx);
141 __ mov(eax, Immediate(key)); 121 __ mov(eax, Immediate(key));
142 __ GetNumberHash(eax, ebx); 122 __ GetNumberHash(eax, ebx);
143 __ pop(ebx); 123 __ pop(ebx);
144 __ Ret(); 124 __ Ret();
145 #elif V8_TARGET_ARCH_X64 125 #elif V8_TARGET_ARCH_X64
146 __ push(kRootRegister); 126 __ push(kRootRegister);
147 __ InitializeRootRegister(); 127 __ InitializeRootRegister();
148 __ push(rbx); 128 __ push(rbx);
149 __ movq(rax, Immediate(key)); 129 __ movq(rax, Immediate(key));
150 __ GetNumberHash(rax, rbx); 130 __ GetNumberHash(rax, rbx);
151 __ pop(rbx); 131 __ pop(rbx);
152 __ pop(kRootRegister); 132 __ pop(kRootRegister);
153 __ Ret(); 133 __ Ret();
154 #elif V8_TARGET_ARCH_ARM 134 #elif V8_TARGET_ARCH_ARM
155 __ push(kRootRegister); 135 __ push(kRootRegister);
156 __ InitializeRootRegister(); 136 __ InitializeRootRegister();
157 __ mov(r0, Operand(key)); 137 __ mov(r0, Operand(key));
158 __ GetNumberHash(r0, ip); 138 __ GetNumberHash(r0, ip);
159 __ pop(kRootRegister); 139 __ pop(kRootRegister);
160 __ mov(pc, Operand(lr)); 140 __ mov(pc, Operand(lr));
161 #elif V8_TARGET_ARCH_A64
162 // The A64 assembler usually uses jssp (x28) as a stack pointer, but only csp
163 // is initialized by the calling (C++) code.
164 Register old_stack_pointer = __ StackPointer();
165 __ SetStackPointer(csp);
166 __ Push(root, xzr);
167 __ InitializeRootRegister();
168 __ Mov(x0, key);
169 __ GetNumberHash(x0, x10);
170 __ Pop(xzr, root);
171 __ Ret();
172 __ SetStackPointer(old_stack_pointer);
173 #elif V8_TARGET_ARCH_MIPS 141 #elif V8_TARGET_ARCH_MIPS
174 __ push(kRootRegister); 142 __ push(kRootRegister);
175 __ InitializeRootRegister(); 143 __ InitializeRootRegister();
176 __ li(v0, Operand(key)); 144 __ li(v0, Operand(key));
177 __ GetNumberHash(v0, t1); 145 __ GetNumberHash(v0, t1);
178 __ pop(kRootRegister); 146 __ pop(kRootRegister);
179 __ jr(ra); 147 __ jr(ra);
180 __ nop(); 148 __ nop();
181 #else
182 #error Unsupported architecture.
183 #endif 149 #endif
184 } 150 }
185 151
186 152
187 void check(i::Vector<const uint8_t> string) { 153 void check(i::Vector<const uint8_t> string) {
188 Isolate* isolate = CcTest::i_isolate(); 154 Isolate* isolate = CcTest::i_isolate();
189 Factory* factory = isolate->factory(); 155 Factory* factory = isolate->factory();
190 HandleScope scope(isolate); 156 HandleScope scope(isolate);
191 157
192 v8::internal::byte buffer[2048]; 158 v8::internal::byte buffer[2048];
193 MacroAssembler masm(isolate, buffer, sizeof buffer); 159 MacroAssembler masm(isolate, buffer, sizeof buffer);
194 160
195 generate(&masm, string); 161 generate(&masm, string);
196 162
197 CodeDesc desc; 163 CodeDesc desc;
198 masm.GetCode(&desc); 164 masm.GetCode(&desc);
199 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); 165 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate);
200 Handle<Code> code = factory->NewCode(desc, 166 Handle<Code> code = factory->NewCode(desc,
201 Code::ComputeFlags(Code::STUB), 167 Code::ComputeFlags(Code::STUB),
202 undefined); 168 undefined);
203 CHECK(code->IsCode()); 169 CHECK(code->IsCode());
204 170
205 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); 171 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry());
206 Handle<String> v8_string = factory->NewStringFromOneByte(string); 172 Handle<String> v8_string = factory->NewStringFromOneByte(string);
207 v8_string->set_hash_field(String::kEmptyHashField); 173 v8_string->set_hash_field(String::kEmptyHashField);
208 #ifdef USE_SIMULATOR 174 #ifdef USE_SIMULATOR
209 uint32_t codegen_hash = static_cast<uint32_t>( 175 uint32_t codegen_hash =
210 reinterpret_cast<uintptr_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0))); 176 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0));
211 #else 177 #else
212 uint32_t codegen_hash = hash(); 178 uint32_t codegen_hash = hash();
213 #endif 179 #endif
214 uint32_t runtime_hash = v8_string->Hash(); 180 uint32_t runtime_hash = v8_string->Hash();
215 CHECK(runtime_hash == codegen_hash); 181 CHECK(runtime_hash == codegen_hash);
216 } 182 }
217 183
218 184
219 void check(i::Vector<const char> s) { 185 void check(i::Vector<const char> s) {
220 check(i::Vector<const uint8_t>::cast(s)); 186 check(i::Vector<const uint8_t>::cast(s));
(...skipping 13 matching lines...) Expand all
234 CodeDesc desc; 200 CodeDesc desc;
235 masm.GetCode(&desc); 201 masm.GetCode(&desc);
236 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); 202 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate);
237 Handle<Code> code = factory->NewCode(desc, 203 Handle<Code> code = factory->NewCode(desc,
238 Code::ComputeFlags(Code::STUB), 204 Code::ComputeFlags(Code::STUB),
239 undefined); 205 undefined);
240 CHECK(code->IsCode()); 206 CHECK(code->IsCode());
241 207
242 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); 208 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry());
243 #ifdef USE_SIMULATOR 209 #ifdef USE_SIMULATOR
244 uint32_t codegen_hash = static_cast<uint32_t>( 210 uint32_t codegen_hash =
245 reinterpret_cast<uintptr_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0))); 211 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0));
246 #else 212 #else
247 uint32_t codegen_hash = hash(); 213 uint32_t codegen_hash = hash();
248 #endif 214 #endif
249 215
250 uint32_t runtime_hash = ComputeIntegerHash(key, isolate->heap()->HashSeed()); 216 uint32_t runtime_hash = ComputeIntegerHash(key, isolate->heap()->HashSeed());
251 CHECK(runtime_hash == codegen_hash); 217 CHECK(runtime_hash == codegen_hash);
252 } 218 }
253 219
254 220
255 void check_twochars(uint8_t a, uint8_t b) { 221 void check_twochars(uint8_t a, uint8_t b) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // Some pseudo-random numbers 263 // Some pseudo-random numbers
298 static const uint32_t kLimit = 1000; 264 static const uint32_t kLimit = 1000;
299 for (uint32_t i = 0; i < 5; i++) { 265 for (uint32_t i = 0; i < 5; i++) {
300 for (uint32_t j = 0; j < 5; j++) { 266 for (uint32_t j = 0; j < 5; j++) {
301 check(PseudoRandom(i, j) % kLimit); 267 check(PseudoRandom(i, j) % kLimit);
302 } 268 }
303 } 269 }
304 } 270 }
305 271
306 #undef __ 272 #undef __
OLDNEW
« no previous file with comments | « test/cctest/test-fuzz-a64.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698