From: danno@chromium.org Date: Tue, 27 May 2014 09:38:01 +0000 (+0000) Subject: Convert ElementsKind into a BitField X-Git-Tag: upstream/4.7.83~8955 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=621c7eb6731ed599eccde7da7422161e3472be7c;p=platform%2Fupstream%2Fv8.git Convert ElementsKind into a BitField R=yangguo@chromium.org Review URL: https://codereview.chromium.org/306513002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21515 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 585108b..bd991e3 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -5134,7 +5134,7 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { // but the following bit field extraction takes care of that anyway. __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset)); // Retrieve elements_kind from bit field 2. - __ Ubfx(r3, r3, Map::kElementsKindShift, Map::kElementsKindBitCount); + __ DecodeField(r3); if (FLAG_debug_code) { Label done; diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index 28ce3de..d1bbe7e 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -3951,7 +3951,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( bind(&loop_again); ldr(current, FieldMemOperand(current, HeapObject::kMapOffset)); ldr(scratch1, FieldMemOperand(current, Map::kBitField2Offset)); - Ubfx(scratch1, scratch1, Map::kElementsKindShift, Map::kElementsKindBitCount); + DecodeField(scratch1); cmp(scratch1, Operand(DICTIONARY_ELEMENTS)); b(eq, found); ldr(current, FieldMemOperand(current, Map::kPrototypeOffset)); diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index d1185b2..7ab05f1 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -4687,7 +4687,7 @@ void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { __ JumpIfSmi(value, &smi_element); // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS. - __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::kElementsKindShift), + __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift), &fast_elements); // Store into the array literal requires an elements transition. Call into diff --git a/src/arm64/macro-assembler-arm64.cc b/src/arm64/macro-assembler-arm64.cc index 83c45a6..cd7f0ae 100644 --- a/src/arm64/macro-assembler-arm64.cc +++ b/src/arm64/macro-assembler-arm64.cc @@ -3769,7 +3769,7 @@ void MacroAssembler::LoadElementsKindFromMap(Register result, Register map) { // Load the map's "bit field 2". __ Ldrb(result, FieldMemOperand(map, Map::kBitField2Offset)); // Retrieve elements_kind from bit field 2. - __ Ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount); + DecodeField(result); } @@ -4544,7 +4544,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( Bind(&loop_again); Ldr(current, FieldMemOperand(current, HeapObject::kMapOffset)); Ldrb(scratch1, FieldMemOperand(current, Map::kBitField2Offset)); - Ubfx(scratch1, scratch1, Map::kElementsKindShift, Map::kElementsKindBitCount); + DecodeField(scratch1); CompareAndBranch(scratch1, DICTIONARY_ELEMENTS, eq, found); Ldr(current, FieldMemOperand(current, Map::kPrototypeOffset)); CompareAndBranch(current, Operand(factory->null_value()), ne, &loop_again); diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index 5547ba2..5695719 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -4952,8 +4952,7 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { // but the following masking takes care of that anyway. __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); // Retrieve elements_kind from bit field 2. - __ and_(ecx, Map::kElementsKindMask); - __ shr(ecx, Map::kElementsKindShift); + __ DecodeField(ecx); if (FLAG_debug_code) { Label done; diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index 9f10b82..a405c63 100644 --- a/src/ia32/macro-assembler-ia32.cc +++ b/src/ia32/macro-assembler-ia32.cc @@ -3422,8 +3422,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( bind(&loop_again); mov(current, FieldOperand(current, HeapObject::kMapOffset)); mov(scratch1, FieldOperand(current, Map::kBitField2Offset)); - and_(scratch1, Map::kElementsKindMask); - shr(scratch1, Map::kElementsKindShift); + DecodeField(scratch1); cmp(scratch1, Immediate(DICTIONARY_ELEMENTS)); j(equal, found); mov(current, FieldOperand(current, Map::kPrototypeOffset)); diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index f47ab38..f23d166 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -5349,7 +5349,7 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { // but the following bit field extraction takes care of that anyway. __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset)); // Retrieve elements_kind from bit field 2. - __ Ext(a3, a3, Map::kElementsKindShift, Map::kElementsKindBitCount); + __ DecodeField(a3); if (FLAG_debug_code) { Label done; diff --git a/src/mips/macro-assembler-mips.cc b/src/mips/macro-assembler-mips.cc index 13e67a3..02d798c 100644 --- a/src/mips/macro-assembler-mips.cc +++ b/src/mips/macro-assembler-mips.cc @@ -5627,7 +5627,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( bind(&loop_again); lw(current, FieldMemOperand(current, HeapObject::kMapOffset)); lb(scratch1, FieldMemOperand(current, Map::kBitField2Offset)); - Ext(scratch1, scratch1, Map::kElementsKindShift, Map::kElementsKindBitCount); + DecodeField(scratch1); Branch(found, eq, scratch1, Operand(DICTIONARY_ELEMENTS)); lw(current, FieldMemOperand(current, Map::kPrototypeOffset)); Branch(&loop_again, ne, current, Operand(factory->null_value())); diff --git a/src/objects.h b/src/objects.h index 8ef7f20..e89efdf 100644 --- a/src/objects.h +++ b/src/objects.h @@ -6084,15 +6084,13 @@ class Map: public HeapObject { inline void set_elements_kind(ElementsKind elements_kind) { ASSERT(elements_kind < kElementsKindCount); - ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount)); - set_bit_field2((bit_field2() & ~kElementsKindMask) | - (elements_kind << kElementsKindShift)); + ASSERT(kElementsKindCount <= (1 << Map::ElementsKindBits::kSize)); + set_bit_field2(Map::ElementsKindBits::update(bit_field2(), elements_kind)); ASSERT(this->elements_kind() == elements_kind); } inline ElementsKind elements_kind() { - return static_cast( - (bit_field2() & kElementsKindMask) >> kElementsKindShift); + return Map::ElementsKindBits::decode(bit_field2()); } // Tells whether the instance has fast elements that are only Smis. @@ -6573,25 +6571,20 @@ class Map: public HeapObject { static const int kIsExtensible = 0; static const int kStringWrapperSafeForDefaultValueOf = 1; // Currently bit 2 is not used. - // No bits can be used after kElementsKindFirstBit, they are all reserved for - // storing ElementKind. - static const int kElementsKindShift = 3; - static const int kElementsKindBitCount = 5; + class ElementsKindBits: public BitField {}; // Derived values from bit field 2 - static const int kElementsKindMask = (-1 << kElementsKindShift) & - ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); static const int8_t kMaximumBitField2FastElementValue = static_cast( - (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; + (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1; static const int8_t kMaximumBitField2FastSmiElementValue = static_cast((FAST_SMI_ELEMENTS + 1) << - Map::kElementsKindShift) - 1; + Map::ElementsKindBits::kShift) - 1; static const int8_t kMaximumBitField2FastHoleyElementValue = static_cast((FAST_HOLEY_ELEMENTS + 1) << - Map::kElementsKindShift) - 1; + Map::ElementsKindBits::kShift) - 1; static const int8_t kMaximumBitField2FastHoleySmiElementValue = static_cast((FAST_HOLEY_SMI_ELEMENTS + 1) << - Map::kElementsKindShift) - 1; + Map::ElementsKindBits::kShift) - 1; typedef FixedBodyDescriptor(rcx); if (FLAG_debug_code) { Label done; diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index f773a61..acff185 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -5197,8 +5197,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( bind(&loop_again); movp(current, FieldOperand(current, HeapObject::kMapOffset)); movp(scratch1, FieldOperand(current, Map::kBitField2Offset)); - andp(scratch1, Immediate(Map::kElementsKindMask)); - shrp(scratch1, Immediate(Map::kElementsKindShift)); + DecodeField(scratch1); cmpp(scratch1, Immediate(DICTIONARY_ELEMENTS)); j(equal, found); movp(current, FieldOperand(current, Map::kPrototypeOffset)); diff --git a/src/x87/code-stubs-x87.cc b/src/x87/code-stubs-x87.cc index 2c95ad1..bf1818c 100644 --- a/src/x87/code-stubs-x87.cc +++ b/src/x87/code-stubs-x87.cc @@ -4592,8 +4592,7 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { // but the following masking takes care of that anyway. __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); // Retrieve elements_kind from bit field 2. - __ and_(ecx, Map::kElementsKindMask); - __ shr(ecx, Map::kElementsKindShift); + DecodeField(ecx); if (FLAG_debug_code) { Label done; diff --git a/src/x87/macro-assembler-x87.cc b/src/x87/macro-assembler-x87.cc index 57fb53a..7baa659 100644 --- a/src/x87/macro-assembler-x87.cc +++ b/src/x87/macro-assembler-x87.cc @@ -3304,8 +3304,7 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain( bind(&loop_again); mov(current, FieldOperand(current, HeapObject::kMapOffset)); mov(scratch1, FieldOperand(current, Map::kBitField2Offset)); - and_(scratch1, Map::kElementsKindMask); - shr(scratch1, Map::kElementsKindShift); + DecodeField(scratch1); cmp(scratch1, Immediate(DICTIONARY_ELEMENTS)); j(equal, found); mov(current, FieldOperand(current, Map::kPrototypeOffset));