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 29 matching lines...) Expand all Loading... |
40 | 40 |
41 #ifdef USE_SIMULATOR | 41 #ifdef USE_SIMULATOR |
42 #include "simulator.h" | 42 #include "simulator.h" |
43 #endif | 43 #endif |
44 | 44 |
45 using namespace v8::internal; | 45 using namespace v8::internal; |
46 | 46 |
47 | 47 |
48 typedef uint32_t (*HASH_FUNCTION)(); | 48 typedef uint32_t (*HASH_FUNCTION)(); |
49 | 49 |
| 50 static v8::Persistent<v8::Context> env; |
| 51 |
50 #define __ masm-> | 52 #define __ masm-> |
51 | 53 |
52 | 54 |
53 void generate(MacroAssembler* masm, i::Vector<const uint8_t> string) { | 55 void generate(MacroAssembler* masm, i::Vector<const uint8_t> string) { |
54 // GenerateHashInit takes the first character as an argument so it can't | 56 // GenerateHashInit takes the first character as an argument so it can't |
55 // handle the zero length string. | 57 // handle the zero length string. |
56 ASSERT(string.length() > 0); | 58 ASSERT(string.length() > 0); |
57 #ifdef V8_TARGET_ARCH_IA32 | 59 #ifdef V8_TARGET_ARCH_IA32 |
58 __ push(ebx); | 60 __ push(ebx); |
59 __ push(ecx); | 61 __ push(ecx); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 check(i::Vector<const uint8_t>(ab, 2)); | 228 check(i::Vector<const uint8_t>(ab, 2)); |
227 } | 229 } |
228 | 230 |
229 | 231 |
230 static uint32_t PseudoRandom(uint32_t i, uint32_t j) { | 232 static uint32_t PseudoRandom(uint32_t i, uint32_t j) { |
231 return ~(~((i * 781) ^ (j * 329))); | 233 return ~(~((i * 781) ^ (j * 329))); |
232 } | 234 } |
233 | 235 |
234 | 236 |
235 TEST(StringHash) { | 237 TEST(StringHash) { |
236 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 238 if (env.IsEmpty()) env = v8::Context::New(); |
237 v8::HandleScope handle_scope(isolate); | |
238 v8::Context::Scope context_scope(v8::Context::New(isolate)); | |
239 | |
240 for (uint8_t a = 0; a < String::kMaxOneByteCharCode; a++) { | 239 for (uint8_t a = 0; a < String::kMaxOneByteCharCode; a++) { |
241 // Numbers are hashed differently. | 240 // Numbers are hashed differently. |
242 if (a >= '0' && a <= '9') continue; | 241 if (a >= '0' && a <= '9') continue; |
243 for (uint8_t b = 0; b < String::kMaxOneByteCharCode; b++) { | 242 for (uint8_t b = 0; b < String::kMaxOneByteCharCode; b++) { |
244 if (b >= '0' && b <= '9') continue; | 243 if (b >= '0' && b <= '9') continue; |
245 check_twochars(a, b); | 244 check_twochars(a, b); |
246 } | 245 } |
247 } | 246 } |
248 check(i::Vector<const char>("*", 1)); | 247 check(i::Vector<const char>("*", 1)); |
249 check(i::Vector<const char>(".zZ", 3)); | 248 check(i::Vector<const char>(".zZ", 3)); |
250 check(i::Vector<const char>("muc", 3)); | 249 check(i::Vector<const char>("muc", 3)); |
251 check(i::Vector<const char>("(>'_')>", 7)); | 250 check(i::Vector<const char>("(>'_')>", 7)); |
252 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); | 251 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); |
253 } | 252 } |
254 | 253 |
255 | 254 |
256 TEST(NumberHash) { | 255 TEST(NumberHash) { |
257 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 256 if (env.IsEmpty()) env = v8::Context::New(); |
258 v8::HandleScope handle_scope(isolate); | |
259 v8::Context::Scope context_scope(v8::Context::New(isolate)); | |
260 | 257 |
261 // Some specific numbers | 258 // Some specific numbers |
262 for (uint32_t key = 0; key < 42; key += 7) { | 259 for (uint32_t key = 0; key < 42; key += 7) { |
263 check(key); | 260 check(key); |
264 } | 261 } |
265 | 262 |
266 // Some pseudo-random numbers | 263 // Some pseudo-random numbers |
267 static const uint32_t kLimit = 1000; | 264 static const uint32_t kLimit = 1000; |
268 for (uint32_t i = 0; i < 5; i++) { | 265 for (uint32_t i = 0; i < 5; i++) { |
269 for (uint32_t j = 0; j < 5; j++) { | 266 for (uint32_t j = 0; j < 5; j++) { |
270 check(PseudoRandom(i, j) % kLimit); | 267 check(PseudoRandom(i, j) % kLimit); |
271 } | 268 } |
272 } | 269 } |
273 } | 270 } |
274 | 271 |
275 #undef __ | 272 #undef __ |
OLD | NEW |