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

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

Issue 11759008: Introduce ENABLE_LATIN_1 compile flag (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix FilterASCII Created 7 years, 11 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-api.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 __ masm-> 49 #define __ masm->
50 50
51 51
52 void generate(MacroAssembler* masm, i::Vector<const char> string) { 52 void generate(MacroAssembler* masm, i::Vector<const uint8_t> string) {
53 // GenerateHashInit takes the first character as an argument so it can't 53 // GenerateHashInit takes the first character as an argument so it can't
54 // handle the zero length string. 54 // handle the zero length string.
55 ASSERT(string.length() > 0); 55 ASSERT(string.length() > 0);
56 #ifdef V8_TARGET_ARCH_IA32 56 #ifdef V8_TARGET_ARCH_IA32
57 __ push(ebx); 57 __ push(ebx);
58 __ push(ecx); 58 __ push(ecx);
59 __ mov(eax, Immediate(0)); 59 __ mov(eax, Immediate(0));
60 __ mov(ebx, Immediate(string.at(0))); 60 __ mov(ebx, Immediate(string.at(0)));
61 StringHelper::GenerateHashInit(masm, eax, ebx, ecx); 61 StringHelper::GenerateHashInit(masm, eax, ebx, ecx);
62 for (int i = 1; i < string.length(); i++) { 62 for (int i = 1; i < string.length(); i++) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 __ InitializeRootRegister(); 145 __ InitializeRootRegister();
146 __ li(v0, Operand(key)); 146 __ li(v0, Operand(key));
147 __ GetNumberHash(v0, t1); 147 __ GetNumberHash(v0, t1);
148 __ pop(kRootRegister); 148 __ pop(kRootRegister);
149 __ jr(ra); 149 __ jr(ra);
150 __ nop(); 150 __ nop();
151 #endif 151 #endif
152 } 152 }
153 153
154 154
155 void check(i::Vector<const char> string) { 155 void check(i::Vector<const uint8_t> string) {
156 v8::HandleScope scope; 156 v8::HandleScope scope;
157 v8::internal::byte buffer[2048]; 157 v8::internal::byte buffer[2048];
158 MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer); 158 MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer);
159 159
160 generate(&masm, string); 160 generate(&masm, string);
161 161
162 CodeDesc desc; 162 CodeDesc desc;
163 masm.GetCode(&desc); 163 masm.GetCode(&desc);
164 Code* code = Code::cast(HEAP->CreateCode( 164 Code* code = Code::cast(HEAP->CreateCode(
165 desc, 165 desc,
166 Code::ComputeFlags(Code::STUB), 166 Code::ComputeFlags(Code::STUB),
167 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); 167 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked());
168 CHECK(code->IsCode()); 168 CHECK(code->IsCode());
169 169
170 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); 170 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry());
171 Handle<String> v8_string = FACTORY->NewStringFromAscii(string); 171 Handle<String> v8_string = FACTORY->NewStringFromOneByte(string);
172 v8_string->set_hash_field(String::kEmptyHashField); 172 v8_string->set_hash_field(String::kEmptyHashField);
173 #ifdef USE_SIMULATOR 173 #ifdef USE_SIMULATOR
174 uint32_t codegen_hash = 174 uint32_t codegen_hash =
175 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0)); 175 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0));
176 #else 176 #else
177 uint32_t codegen_hash = hash(); 177 uint32_t codegen_hash = hash();
178 #endif 178 #endif
179 uint32_t runtime_hash = v8_string->Hash(); 179 uint32_t runtime_hash = v8_string->Hash();
180 CHECK(runtime_hash == codegen_hash); 180 CHECK(runtime_hash == codegen_hash);
181 } 181 }
182 182
183 183
184 void check(i::Vector<const char> s) {
185 check(i::Vector<const uint8_t>::cast(s));
186 }
187
188
184 void check(uint32_t key) { 189 void check(uint32_t key) {
185 v8::HandleScope scope; 190 v8::HandleScope scope;
186 v8::internal::byte buffer[2048]; 191 v8::internal::byte buffer[2048];
187 MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer); 192 MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer);
188 193
189 generate(&masm, key); 194 generate(&masm, key);
190 195
191 CodeDesc desc; 196 CodeDesc desc;
192 masm.GetCode(&desc); 197 masm.GetCode(&desc);
193 Code* code = Code::cast(HEAP->CreateCode( 198 Code* code = Code::cast(HEAP->CreateCode(
(...skipping 10 matching lines...) Expand all
204 uint32_t codegen_hash = hash(); 209 uint32_t codegen_hash = hash();
205 #endif 210 #endif
206 211
207 uint32_t runtime_hash = ComputeIntegerHash( 212 uint32_t runtime_hash = ComputeIntegerHash(
208 key, 213 key,
209 Isolate::Current()->heap()->HashSeed()); 214 Isolate::Current()->heap()->HashSeed());
210 CHECK(runtime_hash == codegen_hash); 215 CHECK(runtime_hash == codegen_hash);
211 } 216 }
212 217
213 218
214 void check_twochars(char a, char b) { 219 void check_twochars(uint8_t a, uint8_t b) {
215 char ab[2] = {a, b}; 220 uint8_t ab[2] = {a, b};
216 check(i::Vector<const char>(ab, 2)); 221 check(i::Vector<const uint8_t>(ab, 2));
217 } 222 }
218 223
219 224
220 static uint32_t PseudoRandom(uint32_t i, uint32_t j) { 225 static uint32_t PseudoRandom(uint32_t i, uint32_t j) {
221 return ~(~((i * 781) ^ (j * 329))); 226 return ~(~((i * 781) ^ (j * 329)));
222 } 227 }
223 228
224 229
225 TEST(StringHash) { 230 TEST(StringHash) {
226 if (env.IsEmpty()) env = v8::Context::New(); 231 if (env.IsEmpty()) env = v8::Context::New();
227 for (int a = 0; a < String::kMaxAsciiCharCode; a++) { 232 for (int a = 0; a < String::kMaxOneByteCharCode; a++) {
228 // Numbers are hashed differently. 233 // Numbers are hashed differently.
229 if (a >= '0' && a <= '9') continue; 234 if (a >= '0' && a <= '9') continue;
230 for (int b = 0; b < String::kMaxAsciiCharCode; b++) { 235 for (int b = 0; b < String::kMaxOneByteCharCode; b++) {
231 if (b >= '0' && b <= '9') continue; 236 if (b >= '0' && b <= '9') continue;
232 check_twochars(static_cast<char>(a), static_cast<char>(b)); 237 check_twochars(static_cast<uint8_t>(a), static_cast<uint8_t>(b));
233 } 238 }
234 } 239 }
235 check(i::Vector<const char>("*", 1)); 240 check(i::Vector<const char>("*", 1));
236 check(i::Vector<const char>(".zZ", 3)); 241 check(i::Vector<const char>(".zZ", 3));
237 check(i::Vector<const char>("muc", 3)); 242 check(i::Vector<const char>("muc", 3));
238 check(i::Vector<const char>("(>'_')>", 7)); 243 check(i::Vector<const char>("(>'_')>", 7));
239 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); 244 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21));
240 } 245 }
241 246
242 247
243 TEST(NumberHash) { 248 TEST(NumberHash) {
244 if (env.IsEmpty()) env = v8::Context::New(); 249 if (env.IsEmpty()) env = v8::Context::New();
245 250
246 // Some specific numbers 251 // Some specific numbers
247 for (uint32_t key = 0; key < 42; key += 7) { 252 for (uint32_t key = 0; key < 42; key += 7) {
248 check(key); 253 check(key);
249 } 254 }
250 255
251 // Some pseudo-random numbers 256 // Some pseudo-random numbers
252 static const uint32_t kLimit = 1000; 257 static const uint32_t kLimit = 1000;
253 for (uint32_t i = 0; i < 5; i++) { 258 for (uint32_t i = 0; i < 5; i++) {
254 for (uint32_t j = 0; j < 5; j++) { 259 for (uint32_t j = 0; j < 5; j++) {
255 check(PseudoRandom(i, j) % kLimit); 260 check(PseudoRandom(i, j) % kLimit);
256 } 261 }
257 } 262 }
258 } 263 }
259 264
260 #undef __ 265 #undef __
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698