diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index d11073fdc4..65177d876b 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -1519,7 +1519,7 @@ LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) { LInstruction* LChunkBuilder::DoGetCachedArrayIndex( HGetCachedArrayIndex* instr) { ASSERT(instr->value()->representation().IsTagged()); - LOperand* value = UseRegister(instr->value()); + LOperand* value = UseRegisterAtStart(instr->value()); return DefineAsRegister(new LGetCachedArrayIndex(value)); } diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 77d6b71a93..f036f76834 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -728,17 +728,6 @@ class LHasInstanceTypeAndBranch: public LControlInstruction<1, 0> { }; -class LHasCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { - public: - explicit LHasCachedArrayIndex(LOperand* value) { - inputs_[0] = value; - } - - DECLARE_CONCRETE_INSTRUCTION(HasCachedArrayIndex, "has-cached-array-index") - DECLARE_HYDROGEN_ACCESSOR(HasCachedArrayIndex) -}; - - class LGetCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { public: explicit LGetCachedArrayIndex(LOperand* value) { @@ -750,6 +739,17 @@ class LGetCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { }; +class LHasCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { + public: + explicit LHasCachedArrayIndex(LOperand* value) { + inputs_[0] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(HasCachedArrayIndex, "has-cached-array-index") + DECLARE_HYDROGEN_ACCESSOR(HasCachedArrayIndex) +}; + + class LHasCachedArrayIndexAndBranch: public LControlInstruction<1, 0> { public: explicit LHasCachedArrayIndexAndBranch(LOperand* value) { diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 6d4c7199df..9e046e74f7 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -1711,10 +1711,13 @@ void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { Register input = ToRegister(instr->InputAt(0)); Register result = ToRegister(instr->result()); - Register scratch = scratch0(); - __ ldr(scratch, FieldMemOperand(input, String::kHashFieldOffset)); - __ IndexFromHash(scratch, result); + if (FLAG_debug_code) { + __ AbortIfNotString(input); + } + + __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); + __ IndexFromHash(result, result); } diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 54b4801605..d84354f66c 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -1654,6 +1654,19 @@ void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { } +void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { + Register input = ToRegister(instr->InputAt(0)); + Register result = ToRegister(instr->result()); + + if (FLAG_debug_code) { + __ AbortIfNotString(input); + } + + __ mov(result, FieldOperand(input, String::kHashFieldOffset)); + __ IndexFromHash(result, result); +} + + void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { Register input = ToRegister(instr->InputAt(0)); Register result = ToRegister(instr->result()); @@ -1663,7 +1676,7 @@ void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { __ test(FieldOperand(input, String::kHashFieldOffset), Immediate(String::kContainsCachedArrayIndexMask)); NearLabel done; - __ j(not_zero, &done); + __ j(zero, &done); __ mov(result, Factory::false_value()); __ bind(&done); } @@ -1678,7 +1691,7 @@ void LCodeGen::DoHasCachedArrayIndexAndBranch( __ test(FieldOperand(input, String::kHashFieldOffset), Immediate(String::kContainsCachedArrayIndexMask)); - EmitBranch(true_block, false_block, not_equal); + EmitBranch(true_block, false_block, equal); } diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index e2fdf2c5ee..237ce55480 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -1541,8 +1541,10 @@ LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) { LInstruction* LChunkBuilder::DoGetCachedArrayIndex( HGetCachedArrayIndex* instr) { - Abort("Unimplemented: %s", "DoGetCachedArrayIndex"); - return NULL; + ASSERT(instr->value()->representation().IsTagged()); + LOperand* value = UseRegisterAtStart(instr->value()); + + return DefineAsRegister(new LGetCachedArrayIndex(value)); } diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index ad0b0ca059..b8cba44e27 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -92,6 +92,7 @@ class LCodeGen; V(FixedArrayLength) \ V(FunctionLiteral) \ V(Gap) \ + V(GetCachedArrayIndex) \ V(GlobalObject) \ V(GlobalReceiver) \ V(Goto) \ @@ -743,6 +744,17 @@ class LHasInstanceTypeAndBranch: public LControlInstruction<1, 1> { }; +class LGetCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { + public: + explicit LGetCachedArrayIndex(LOperand* value) { + inputs_[0] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(GetCachedArrayIndex, "get-cached-array-index") + DECLARE_HYDROGEN_ACCESSOR(GetCachedArrayIndex) +}; + + class LHasCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { public: explicit LHasCachedArrayIndex(LOperand* value) { diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 7e7ec987e6..2cbab4bf05 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -1637,6 +1637,20 @@ void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { } +void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { + Register input = ToRegister(instr->InputAt(0)); + Register result = ToRegister(instr->result()); + + if (FLAG_debug_code) { + __ AbortIfNotString(input); + } + + __ movl(result, FieldOperand(input, String::kHashFieldOffset)); + ASSERT(String::kHashShift >= kSmiTagSize); + __ IndexFromHash(result, result); +} + + void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { Register input = ToRegister(instr->InputAt(0)); Register result = ToRegister(instr->result()); @@ -1646,7 +1660,7 @@ void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { __ testl(FieldOperand(input, String::kHashFieldOffset), Immediate(String::kContainsCachedArrayIndexMask)); NearLabel done; - __ j(not_zero, &done); + __ j(zero, &done); __ LoadRoot(result, Heap::kFalseValueRootIndex); __ bind(&done); } @@ -1661,7 +1675,7 @@ void LCodeGen::DoHasCachedArrayIndexAndBranch( __ testl(FieldOperand(input, String::kHashFieldOffset), Immediate(String::kContainsCachedArrayIndexMask)); - EmitBranch(true_block, false_block, not_equal); + EmitBranch(true_block, false_block, equal); } diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index b73e7a995d..7c26468a38 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -1522,8 +1522,10 @@ LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) { LInstruction* LChunkBuilder::DoGetCachedArrayIndex( HGetCachedArrayIndex* instr) { - Abort("Unimplemented: %s", "DoGetCachedArrayIndex"); - return NULL; + ASSERT(instr->value()->representation().IsTagged()); + LOperand* value = UseRegisterAtStart(instr->value()); + + return DefineAsRegister(new LGetCachedArrayIndex(value)); } diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index fed5b8cb88..bdc5b2b5cb 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -89,6 +89,7 @@ class LCodeGen; V(DoubleToI) \ V(FunctionLiteral) \ V(Gap) \ + V(GetCachedArrayIndex) \ V(GlobalObject) \ V(GlobalReceiver) \ V(Goto) \ @@ -730,6 +731,17 @@ class LHasInstanceTypeAndBranch: public LControlInstruction<1, 0> { }; +class LGetCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { + public: + explicit LGetCachedArrayIndex(LOperand* value) { + inputs_[0] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(GetCachedArrayIndex, "get-cached-array-index") + DECLARE_HYDROGEN_ACCESSOR(GetCachedArrayIndex) +}; + + class LHasCachedArrayIndex: public LTemplateInstruction<1, 1, 0> { public: explicit LHasCachedArrayIndex(LOperand* value) {