| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 99 #elif V8_TARGET_ARCH_MIPS | 117 #elif V8_TARGET_ARCH_MIPS |
| 100 __ push(kRootRegister); | 118 __ push(kRootRegister); |
| 101 __ InitializeRootRegister(); | 119 __ InitializeRootRegister(); |
| 102 | 120 |
| 103 __ li(v0, Operand(0)); | 121 __ li(v0, Operand(0)); |
| 104 __ li(t1, Operand(string.at(0))); | 122 __ li(t1, Operand(string.at(0))); |
| 105 StringHelper::GenerateHashInit(masm, v0, t1); | 123 StringHelper::GenerateHashInit(masm, v0, t1); |
| 106 for (int i = 1; i < string.length(); i++) { | 124 for (int i = 1; i < string.length(); i++) { |
| 107 __ li(t1, Operand(string.at(i))); | 125 __ li(t1, Operand(string.at(i))); |
| 108 StringHelper::GenerateHashAddCharacter(masm, v0, t1); | 126 StringHelper::GenerateHashAddCharacter(masm, v0, t1); |
| 109 } | 127 } |
| 110 StringHelper::GenerateHashGetHash(masm, v0); | 128 StringHelper::GenerateHashGetHash(masm, v0); |
| 111 __ pop(kRootRegister); | 129 __ pop(kRootRegister); |
| 112 __ jr(ra); | 130 __ jr(ra); |
| 113 __ nop(); | 131 __ nop(); |
| 132 #else |
| 133 #error Unsupported architecture. |
| 114 #endif | 134 #endif |
| 115 } | 135 } |
| 116 | 136 |
| 117 | 137 |
| 118 void generate(MacroAssembler* masm, uint32_t key) { | 138 void generate(MacroAssembler* masm, uint32_t key) { |
| 119 #if V8_TARGET_ARCH_IA32 | 139 #if V8_TARGET_ARCH_IA32 |
| 120 __ push(ebx); | 140 __ push(ebx); |
| 121 __ mov(eax, Immediate(key)); | 141 __ mov(eax, Immediate(key)); |
| 122 __ GetNumberHash(eax, ebx); | 142 __ GetNumberHash(eax, ebx); |
| 123 __ pop(ebx); | 143 __ pop(ebx); |
| 124 __ Ret(); | 144 __ Ret(); |
| 125 #elif V8_TARGET_ARCH_X64 | 145 #elif V8_TARGET_ARCH_X64 |
| 126 __ push(kRootRegister); | 146 __ push(kRootRegister); |
| 127 __ InitializeRootRegister(); | 147 __ InitializeRootRegister(); |
| 128 __ push(rbx); | 148 __ push(rbx); |
| 129 __ movq(rax, Immediate(key)); | 149 __ movq(rax, Immediate(key)); |
| 130 __ GetNumberHash(rax, rbx); | 150 __ GetNumberHash(rax, rbx); |
| 131 __ pop(rbx); | 151 __ pop(rbx); |
| 132 __ pop(kRootRegister); | 152 __ pop(kRootRegister); |
| 133 __ Ret(); | 153 __ Ret(); |
| 134 #elif V8_TARGET_ARCH_ARM | 154 #elif V8_TARGET_ARCH_ARM |
| 135 __ push(kRootRegister); | 155 __ push(kRootRegister); |
| 136 __ InitializeRootRegister(); | 156 __ InitializeRootRegister(); |
| 137 __ mov(r0, Operand(key)); | 157 __ mov(r0, Operand(key)); |
| 138 __ GetNumberHash(r0, ip); | 158 __ GetNumberHash(r0, ip); |
| 139 __ pop(kRootRegister); | 159 __ pop(kRootRegister); |
| 140 __ mov(pc, Operand(lr)); | 160 __ 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); |
| 141 #elif V8_TARGET_ARCH_MIPS | 173 #elif V8_TARGET_ARCH_MIPS |
| 142 __ push(kRootRegister); | 174 __ push(kRootRegister); |
| 143 __ InitializeRootRegister(); | 175 __ InitializeRootRegister(); |
| 144 __ li(v0, Operand(key)); | 176 __ li(v0, Operand(key)); |
| 145 __ GetNumberHash(v0, t1); | 177 __ GetNumberHash(v0, t1); |
| 146 __ pop(kRootRegister); | 178 __ pop(kRootRegister); |
| 147 __ jr(ra); | 179 __ jr(ra); |
| 148 __ nop(); | 180 __ nop(); |
| 181 #else |
| 182 #error Unsupported architecture. |
| 149 #endif | 183 #endif |
| 150 } | 184 } |
| 151 | 185 |
| 152 | 186 |
| 153 void check(i::Vector<const uint8_t> string) { | 187 void check(i::Vector<const uint8_t> string) { |
| 154 Isolate* isolate = CcTest::i_isolate(); | 188 Isolate* isolate = CcTest::i_isolate(); |
| 155 Factory* factory = isolate->factory(); | 189 Factory* factory = isolate->factory(); |
| 156 HandleScope scope(isolate); | 190 HandleScope scope(isolate); |
| 157 | 191 |
| 158 v8::internal::byte buffer[2048]; | 192 v8::internal::byte buffer[2048]; |
| 159 MacroAssembler masm(isolate, buffer, sizeof buffer); | 193 MacroAssembler masm(isolate, buffer, sizeof buffer); |
| 160 | 194 |
| 161 generate(&masm, string); | 195 generate(&masm, string); |
| 162 | 196 |
| 163 CodeDesc desc; | 197 CodeDesc desc; |
| 164 masm.GetCode(&desc); | 198 masm.GetCode(&desc); |
| 165 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); | 199 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); |
| 166 Handle<Code> code = factory->NewCode(desc, | 200 Handle<Code> code = factory->NewCode(desc, |
| 167 Code::ComputeFlags(Code::STUB), | 201 Code::ComputeFlags(Code::STUB), |
| 168 undefined); | 202 undefined); |
| 169 CHECK(code->IsCode()); | 203 CHECK(code->IsCode()); |
| 170 | 204 |
| 171 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); | 205 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); |
| 172 Handle<String> v8_string = factory->NewStringFromOneByte(string); | 206 Handle<String> v8_string = factory->NewStringFromOneByte(string); |
| 173 v8_string->set_hash_field(String::kEmptyHashField); | 207 v8_string->set_hash_field(String::kEmptyHashField); |
| 174 #ifdef USE_SIMULATOR | 208 #ifdef USE_SIMULATOR |
| 175 uint32_t codegen_hash = | 209 uint32_t codegen_hash = static_cast<uint32_t>( |
| 176 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0)); | 210 reinterpret_cast<uintptr_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0))); |
| 177 #else | 211 #else |
| 178 uint32_t codegen_hash = hash(); | 212 uint32_t codegen_hash = hash(); |
| 179 #endif | 213 #endif |
| 180 uint32_t runtime_hash = v8_string->Hash(); | 214 uint32_t runtime_hash = v8_string->Hash(); |
| 181 CHECK(runtime_hash == codegen_hash); | 215 CHECK(runtime_hash == codegen_hash); |
| 182 } | 216 } |
| 183 | 217 |
| 184 | 218 |
| 185 void check(i::Vector<const char> s) { | 219 void check(i::Vector<const char> s) { |
| 186 check(i::Vector<const uint8_t>::cast(s)); | 220 check(i::Vector<const uint8_t>::cast(s)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 200 CodeDesc desc; | 234 CodeDesc desc; |
| 201 masm.GetCode(&desc); | 235 masm.GetCode(&desc); |
| 202 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); | 236 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); |
| 203 Handle<Code> code = factory->NewCode(desc, | 237 Handle<Code> code = factory->NewCode(desc, |
| 204 Code::ComputeFlags(Code::STUB), | 238 Code::ComputeFlags(Code::STUB), |
| 205 undefined); | 239 undefined); |
| 206 CHECK(code->IsCode()); | 240 CHECK(code->IsCode()); |
| 207 | 241 |
| 208 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); | 242 HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry()); |
| 209 #ifdef USE_SIMULATOR | 243 #ifdef USE_SIMULATOR |
| 210 uint32_t codegen_hash = | 244 uint32_t codegen_hash = static_cast<uint32_t>( |
| 211 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0)); | 245 reinterpret_cast<uintptr_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0))); |
| 212 #else | 246 #else |
| 213 uint32_t codegen_hash = hash(); | 247 uint32_t codegen_hash = hash(); |
| 214 #endif | 248 #endif |
| 215 | 249 |
| 216 uint32_t runtime_hash = ComputeIntegerHash(key, isolate->heap()->HashSeed()); | 250 uint32_t runtime_hash = ComputeIntegerHash(key, isolate->heap()->HashSeed()); |
| 217 CHECK(runtime_hash == codegen_hash); | 251 CHECK(runtime_hash == codegen_hash); |
| 218 } | 252 } |
| 219 | 253 |
| 220 | 254 |
| 221 void check_twochars(uint8_t a, uint8_t b) { | 255 void check_twochars(uint8_t a, uint8_t b) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // Some pseudo-random numbers | 297 // Some pseudo-random numbers |
| 264 static const uint32_t kLimit = 1000; | 298 static const uint32_t kLimit = 1000; |
| 265 for (uint32_t i = 0; i < 5; i++) { | 299 for (uint32_t i = 0; i < 5; i++) { |
| 266 for (uint32_t j = 0; j < 5; j++) { | 300 for (uint32_t j = 0; j < 5; j++) { |
| 267 check(PseudoRandom(i, j) % kLimit); | 301 check(PseudoRandom(i, j) % kLimit); |
| 268 } | 302 } |
| 269 } | 303 } |
| 270 } | 304 } |
| 271 | 305 |
| 272 #undef __ | 306 #undef __ |
| OLD | NEW |