diff --git a/src/arm/builtins-arm.cc b/src/arm/builtins-arm.cc index 69ef1872c7..c8a4b213fb 100644 --- a/src/arm/builtins-arm.cc +++ b/src/arm/builtins-arm.cc @@ -1082,10 +1082,7 @@ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, // Set up the context from the function argument. __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); - // Set up the roots register. - ExternalReference roots_array_start = - ExternalReference::roots_array_start(masm->isolate()); - __ mov(r10, Operand(roots_array_start)); + __ InitializeRootRegister(); // Push the function and the receiver onto the stack. __ push(r1); diff --git a/src/arm/deoptimizer-arm.cc b/src/arm/deoptimizer-arm.cc index 4b54b6dbc2..042cfe8d39 100644 --- a/src/arm/deoptimizer-arm.cc +++ b/src/arm/deoptimizer-arm.cc @@ -723,10 +723,7 @@ void Deoptimizer::EntryGenerator::Generate() { __ pop(ip); // remove sp __ pop(ip); // remove lr - // Set up the roots register. - ExternalReference roots_array_start = - ExternalReference::roots_array_start(isolate); - __ mov(r10, Operand(roots_array_start)); + __ InitializeRootRegister(); __ pop(ip); // remove pc __ pop(r7); // get continuation, leave pc on stack diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index 59a5e5ba79..470e322078 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -396,14 +396,14 @@ void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index, Condition cond) { - ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); + ldr(destination, MemOperand(kRootRegister, index << kPointerSizeLog2), cond); } void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index, Condition cond) { - str(source, MemOperand(roots, index << kPointerSizeLog2), cond); + str(source, MemOperand(kRootRegister, index << kPointerSizeLog2), cond); } diff --git a/src/arm/macro-assembler-arm.h b/src/arm/macro-assembler-arm.h index 392c2f7503..3c9ccfbdf2 100644 --- a/src/arm/macro-assembler-arm.h +++ b/src/arm/macro-assembler-arm.h @@ -52,7 +52,7 @@ inline Operand SmiUntagOperand(Register object) { // Give alias names to registers const Register cp = { 8 }; // JavaScript context pointer -const Register roots = { 10 }; // Roots array pointer. +const Register kRootRegister = { 10 }; // Roots array pointer. // Flags used for the AllocateInNewSpace functions. enum AllocationFlags { @@ -499,6 +499,12 @@ class MacroAssembler: public Assembler { Register map, Register scratch); + void InitializeRootRegister() { + ExternalReference roots_array_start = + ExternalReference::roots_array_start(isolate()); + mov(kRootRegister, Operand(roots_array_start)); + } + // --------------------------------------------------------------------------- // JavaScript invokes diff --git a/src/mips/builtins-mips.cc b/src/mips/builtins-mips.cc index 46a912bd59..754132e435 100644 --- a/src/mips/builtins-mips.cc +++ b/src/mips/builtins-mips.cc @@ -1114,10 +1114,7 @@ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, // Set up the context from the function argument. __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); - // Set up the roots register. - ExternalReference roots_array_start = - ExternalReference::roots_array_start(masm->isolate()); - __ li(s6, Operand(roots_array_start)); + __ InitializeRootRegister(); // Push the function and the receiver onto the stack. __ Push(a1, a2); diff --git a/src/mips/deoptimizer-mips.cc b/src/mips/deoptimizer-mips.cc index a27c61cb2d..8717f14c1c 100644 --- a/src/mips/deoptimizer-mips.cc +++ b/src/mips/deoptimizer-mips.cc @@ -733,10 +733,7 @@ void Deoptimizer::EntryGenerator::Generate() { } } - // Set up the roots register. - ExternalReference roots_array_start = - ExternalReference::roots_array_start(isolate); - __ li(roots, Operand(roots_array_start)); + __ InitializeRootRegister(); __ pop(at); // Get continuation, leave pc on stack. __ pop(ra); diff --git a/src/mips/lithium-codegen-mips.h b/src/mips/lithium-codegen-mips.h index 68a7c5b1aa..2bdb52782a 100644 --- a/src/mips/lithium-codegen-mips.h +++ b/src/mips/lithium-codegen-mips.h @@ -148,9 +148,9 @@ class LCodeGen BASE_EMBEDDED { Scope* scope() const { return scope_; } HGraph* graph() const { return chunk_->graph(); } - Register scratch0() { return lithiumScratchReg; } - Register scratch1() { return lithiumScratchReg2; } - DoubleRegister double_scratch0() { return lithiumScratchDouble; } + Register scratch0() { return kLithiumScratchReg; } + Register scratch1() { return kLithiumScratchReg2; } + DoubleRegister double_scratch0() { return kLithiumScratchDouble; } int GetNextEmittedBlock(int block); LInstruction* GetNextInstruction(); diff --git a/src/mips/lithium-gap-resolver-mips.cc b/src/mips/lithium-gap-resolver-mips.cc index 2e5c64e7a2..279a95ece4 100644 --- a/src/mips/lithium-gap-resolver-mips.cc +++ b/src/mips/lithium-gap-resolver-mips.cc @@ -33,8 +33,8 @@ namespace v8 { namespace internal { -static const Register kSavedValueRegister = lithiumScratchReg; -static const DoubleRegister kSavedDoubleValueRegister = lithiumScratchDouble; +static const Register kSavedValueRegister = kLithiumScratchReg; +static const DoubleRegister kSavedDoubleValueRegister = kLithiumScratchDouble; LGapResolver::LGapResolver(LCodeGen* owner) : cgen_(owner), diff --git a/src/mips/macro-assembler-mips.h b/src/mips/macro-assembler-mips.h index bd5b94f57c..cefd4acf1b 100644 --- a/src/mips/macro-assembler-mips.h +++ b/src/mips/macro-assembler-mips.h @@ -53,13 +53,13 @@ class JumpTarget; // Register aliases. // cp is assumed to be a callee saved register. -const Register lithiumScratchReg = s3; // Scratch register. -const Register lithiumScratchReg2 = s4; // Scratch register. -const Register condReg = s5; // Simulated (partial) condition code for mips. -const Register roots = s6; // Roots array pointer. +const Register kLithiumScratchReg = s3; // Scratch register. +const Register kLithiumScratchReg2 = s4; // Scratch register. +const Register kCondReg = s5; // Simulated (partial) condition code for mips. +const Register kRootRegister = s6; // Roots array pointer. const Register cp = s7; // JavaScript context pointer. const Register fp = s8_fp; // Alias for fp. -const DoubleRegister lithiumScratchDouble = f30; // Double scratch register. +const DoubleRegister kLithiumScratchDouble = f30; // Double scratch register. // Flags used for the AllocateInNewSpace functions. enum AllocationFlags { @@ -789,6 +789,11 @@ class MacroAssembler: public Assembler { Register map, Register scratch); + void InitializeRootRegister() { + ExternalReference roots_array_start = + ExternalReference::roots_array_start(isolate()); + li(kRootRegister, Operand(roots_array_start)); + } // ------------------------------------------------------------------------- // JavaScript invokes. diff --git a/test/cctest/SConscript b/test/cctest/SConscript index 5fc9188ee9..edb859e9cb 100644 --- a/test/cctest/SConscript +++ b/test/cctest/SConscript @@ -73,6 +73,7 @@ SOURCES = { 'test-fixed-dtoa.cc', 'test-flags.cc', 'test-func-name-inference.cc', + 'test-hashing.cc', 'test-hashmap.cc', 'test-heap-profiler.cc', 'test-heap.cc', diff --git a/test/cctest/test-hashing.cc b/test/cctest/test-hashing.cc index df1ab20013..9aa84614d6 100644 --- a/test/cctest/test-hashing.cc +++ b/test/cctest/test-hashing.cc @@ -46,65 +46,71 @@ typedef uint32_t (*HASH_FUNCTION)(); static v8::Persistent env; -#define __ assm-> +#define __ masm-> -void generate(MacroAssembler* assm, i::Vector string) { +void generate(MacroAssembler* masm, i::Vector string) { + // GenerateHashInit takes the first character as an argument so it can't + // handle the zero length string. + ASSERT(string.length() > 0); #ifdef V8_TARGET_ARCH_IA32 __ push(ebx); __ push(ecx); __ mov(eax, Immediate(0)); - if (string.length() > 0) { - __ mov(ebx, Immediate(string.at(0))); - StringHelper::GenerateHashInit(assm, eax, ebx, ecx); - } + __ mov(ebx, Immediate(string.at(0))); + StringHelper::GenerateHashInit(masm, eax, ebx, ecx); for (int i = 1; i < string.length(); i++) { __ mov(ebx, Immediate(string.at(i))); - StringHelper::GenerateHashAddCharacter(assm, eax, ebx, ecx); + StringHelper::GenerateHashAddCharacter(masm, eax, ebx, ecx); } - StringHelper::GenerateHashGetHash(assm, eax, ecx); + StringHelper::GenerateHashGetHash(masm, eax, ecx); __ pop(ecx); __ pop(ebx); __ Ret(); #elif V8_TARGET_ARCH_X64 + __ push(kRootRegister); + __ InitializeRootRegister(); __ push(rbx); __ push(rcx); __ movq(rax, Immediate(0)); - if (string.length() > 0) { - __ movq(rbx, Immediate(string.at(0))); - StringHelper::GenerateHashInit(assm, rax, rbx, rcx); - } + __ movq(rbx, Immediate(string.at(0))); + StringHelper::GenerateHashInit(masm, rax, rbx, rcx); for (int i = 1; i < string.length(); i++) { __ movq(rbx, Immediate(string.at(i))); - StringHelper::GenerateHashAddCharacter(assm, rax, rbx, rcx); + StringHelper::GenerateHashAddCharacter(masm, rax, rbx, rcx); } - StringHelper::GenerateHashGetHash(assm, rax, rcx); + StringHelper::GenerateHashGetHash(masm, rax, rcx); __ pop(rcx); __ pop(rbx); + __ pop(kRootRegister); __ Ret(); #elif V8_TARGET_ARCH_ARM + __ push(kRootRegister); + __ InitializeRootRegister(); + __ mov(r0, Operand(0)); - if (string.length() > 0) { - __ mov(ip, Operand(string.at(0))); - StringHelper::GenerateHashInit(assm, r0, ip); - } + __ mov(ip, Operand(string.at(0))); + StringHelper::GenerateHashInit(masm, r0, ip); for (int i = 1; i < string.length(); i++) { __ mov(ip, Operand(string.at(i))); - StringHelper::GenerateHashAddCharacter(assm, r0, ip); + StringHelper::GenerateHashAddCharacter(masm, r0, ip); } - StringHelper::GenerateHashGetHash(assm, r0); + StringHelper::GenerateHashGetHash(masm, r0); + __ pop(kRootRegister); __ mov(pc, Operand(lr)); #elif V8_TARGET_ARCH_MIPS + __ push(kRootRegister); + __ InitializeRootRegister(); + __ li(v0, Operand(0)); - if (string.length() > 0) { - __ li(t1, Operand(string.at(0))); - StringHelper::GenerateHashInit(assm, v0, t1); - } + __ li(t1, Operand(string.at(0))); + StringHelper::GenerateHashInit(masm, v0, t1); for (int i = 1; i < string.length(); i++) { __ li(t1, Operand(string.at(i))); - StringHelper::GenerateHashAddCharacter(assm, v0, t1); + StringHelper::GenerateHashAddCharacter(masm, v0, t1); } - StringHelper::GenerateHashGetHash(assm, v0); + StringHelper::GenerateHashGetHash(masm, v0); + __ pop(kRootRegister); __ jr(ra); __ nop(); #endif @@ -114,12 +120,12 @@ void generate(MacroAssembler* assm, i::Vector string) { void check(i::Vector string) { v8::HandleScope scope; v8::internal::byte buffer[2048]; - MacroAssembler assm(Isolate::Current(), buffer, sizeof buffer); + MacroAssembler masm(Isolate::Current(), buffer, sizeof buffer); - generate(&assm, string); + generate(&masm, string); CodeDesc desc; - assm.GetCode(&desc); + masm.GetCode(&desc); Code* code = Code::cast(HEAP->CreateCode( desc, Code::ComputeFlags(Code::STUB), @@ -156,7 +162,6 @@ TEST(StringHash) { check_twochars(static_cast(a), static_cast(b)); } } - check(i::Vector("", 0)); check(i::Vector("*", 1)); check(i::Vector(".zZ", 3)); check(i::Vector("muc", 3));