void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
- // TODO(all): Possible optimisations in this function:
- // 1. Merge CheckFastElements and CheckFastSmiElements, so that the map
- // bitfield is loaded only once.
- // 2. Refactor the Ldr/Add sequence at the start of fast_elements and
- // smi_element.
-
// x0 value element value to store
// x3 index_smi element index as smi
// sp[0] array_index_smi array literal index in function as smi
__ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
Label double_elements, smi_element, fast_elements, slow_elements;
- __ CheckFastElements(array_map, x10, &double_elements);
+ Register bitfield2 = x10;
+ __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
+
+ // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
+ // FAST_HOLEY_ELEMENTS.
+ STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
+ STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
+ STATIC_ASSERT(FAST_ELEMENTS == 2);
+ STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
+ __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
+ __ B(hi, &double_elements);
+
__ JumpIfSmi(value, &smi_element);
- __ CheckFastSmiElements(array_map, x10, &fast_elements);
+
+ // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
+ __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::kElementsKindShift),
+ &fast_elements);
// Store into the array literal requires an elements transition. Call into
// the runtime.
__ Ldr(x10, FieldMemOperand(constructor,
JSFunction::kPrototypeOrInitialMapOffset));
- // TODO(jbramley): Add a helper function to read elements kind from an
- // existing map.
- // Load the map's "bit field 2" into result.
- __ Ldr(kind, FieldMemOperand(x10, Map::kBitField2Offset));
- // Retrieve elements_kind from bit field 2.
- __ Ubfx(kind, kind, Map::kElementsKindShift, Map::kElementsKindBitCount);
+ // Retrieve elements_kind from map.
+ __ LoadElementsKindFromMap(kind, x10);
if (FLAG_debug_code) {
Label done;
LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
- // We only need a temp register if the target is in new space, but we can't
- // dereference the handle to test that here.
- // TODO(all): Check these constraints. The temp register is not always used.
- LOperand* value = UseRegister(instr->value());
- LOperand* temp = TempRegister();
- return AssignEnvironment(new(zone()) LCheckValue(value, temp));
+ LOperand* value = UseRegisterAtStart(instr->value());
+ return AssignEnvironment(new(zone()) LCheckValue(value));
}
LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
- // TODO(all) use at start and remove assert in codegen
LOperand* char_code = UseRegister(instr->value());
LOperand* context = UseAny(instr->context());
LStringCharFromCode* result =
ASSERT(instr->right()->representation().Equals(instr->representation()));
LOperand *left;
if (instr->left()->IsConstant() &&
- (HConstant::cast(instr->left())->Integer32Value() == 0)) {
+ (HConstant::cast(instr->left())->Integer32Value() == 0)) {
left = UseConstant(instr->left());
} else {
left = UseRegisterAtStart(instr->left());
};
-class LCheckValue V8_FINAL : public LTemplateInstruction<0, 1, 1> {
+class LCheckValue V8_FINAL : public LTemplateInstruction<0, 1, 0> {
public:
- LCheckValue(LOperand* value, LOperand* temp) {
+ explicit LCheckValue(LOperand* value) {
inputs_[0] = value;
- temps_[0] = temp;
}
LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(CheckValue, "check-value")
DECLARE_HYDROGEN_ACCESSOR(CheckValue)
Handle<HeapObject> object = instr->hydrogen()->object().handle();
AllowDeferredHandleDereference smi_check;
if (isolate()->heap()->InNewSpace(*object)) {
- Register temp = ToRegister(instr->temp());
+ UseScratchRegisterScope temps(masm());
+ Register temp = temps.AcquireX();
Handle<Cell> cell = isolate()->factory()->NewCell(object);
__ Mov(temp, Operand(Handle<Object>(cell)));
__ Ldr(temp, FieldMemOperand(temp, Cell::kValueOffset));
}
-void MacroAssembler::LoadElementsKind(Register result, Register object) {
- // Load map.
- __ Ldr(result, FieldMemOperand(object, HeapObject::kMapOffset));
+void MacroAssembler::LoadElementsKindFromMap(Register result, Register map) {
// Load the map's "bit field 2".
- __ Ldrb(result, FieldMemOperand(result, Map::kBitField2Offset));
+ __ Ldrb(result, FieldMemOperand(map, Map::kBitField2Offset));
// Retrieve elements_kind from bit field 2.
__ Ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount);
}
}
-void MacroAssembler::CheckFastSmiElements(Register map,
- Register scratch,
- Label* fail) {
- STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
- STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
- Ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
- Cmp(scratch, Map::kMaximumBitField2FastHoleySmiElementValue);
- B(hi, fail);
-}
-
-
// Note: The ARM version of this clobbers elements_reg, but this version does
// not. Some uses of this in A64 assume that elements_reg will be preserved.
void MacroAssembler::StoreNumberToDoubleElements(Register value_reg,
// flags. The object register is preserved.
void TestMapBitfield(Register object, uint64_t mask);
- // Load the elements kind field of an object, and return it in the result
+ // Load the elements kind field from a map, and return it in the result
// register.
- void LoadElementsKind(Register result, Register object);
+ void LoadElementsKindFromMap(Register result, Register map);
// Compare the object in a register to a value from the root list.
void CompareRoot(const Register& obj, Heap::RootListIndex index);
// Check if a map for a JSObject indicates that the object has fast elements.
// Jump to the specified label if it does not.
- void CheckFastElements(Register map,
- Register scratch,
- Label* fail);
+ void CheckFastElements(Register map, Register scratch, Label* fail);
// Check if a map for a JSObject indicates that the object can have both smi
// and HeapObject elements. Jump to the specified label if it does not.
- void CheckFastObjectElements(Register map,
- Register scratch,
- Label* fail);
-
- // Check if a map for a JSObject indicates that the object has fast smi only
- // elements. Jump to the specified label if it does not.
- void CheckFastSmiElements(Register map, Register scratch, Label* fail);
+ void CheckFastObjectElements(Register map, Register scratch, Label* fail);
// Check to see if number can be stored as a double in FastDoubleElements.
// If it can, store it at the index specified by key_reg in the array,