ARM: Implement Math.abs in lithium code generator for the integer and
tagged case. I couldn't find a way to test the double case yet so I'm leaving that unimplemented for now. Review URL: http://codereview.chromium.org/6347007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6411 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
b4ff318e4b
commit
1c2fddb4c8
@ -66,8 +66,7 @@ static const RegList kCalleeSaved =
|
||||
1 << 6 | // r6 v3
|
||||
1 << 7 | // r7 v4
|
||||
1 << 8 | // r8 v5 (cp in JavaScript code)
|
||||
kR9Available
|
||||
<< 9 | // r9 v6
|
||||
kR9Available << 9 | // r9 v6
|
||||
1 << 10 | // r10 v7
|
||||
1 << 11; // r11 v8 (fp in JavaScript code)
|
||||
|
||||
|
@ -2451,12 +2451,112 @@ void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
|
||||
|
||||
|
||||
void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
|
||||
Abort("DoDeferredMathAbsTaggedHeapNumber unimplemented.");
|
||||
Register input = ToRegister(instr->input());
|
||||
Register scratch = scratch0();
|
||||
|
||||
// Deoptimize if not a heap number.
|
||||
__ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
|
||||
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
|
||||
__ cmp(scratch, Operand(ip));
|
||||
DeoptimizeIf(ne, instr->environment());
|
||||
|
||||
Label done;
|
||||
Register tmp = input.is(r0) ? r1 : r0;
|
||||
Register tmp2 = r2;
|
||||
Register tmp3 = r3;
|
||||
|
||||
Label negative;
|
||||
__ ldr(scratch, FieldMemOperand(input, HeapNumber::kExponentOffset));
|
||||
// Check the sign of the argument. If the argument is positive, just
|
||||
// return it. We do not need to patch the stack since |input| and
|
||||
// |result| are the same register and |input| will be restored
|
||||
// unchanged by popping safepoint registers.
|
||||
__ tst(scratch, Operand(HeapNumber::kSignMask));
|
||||
__ b(ne, &negative);
|
||||
__ jmp(&done);
|
||||
|
||||
__ bind(&negative);
|
||||
// Preserve the value of all registers.
|
||||
__ PushSafepointRegisters();
|
||||
|
||||
Label allocated, slow;
|
||||
__ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex);
|
||||
__ AllocateHeapNumber(tmp, tmp2, tmp3, scratch, &slow);
|
||||
__ b(&allocated);
|
||||
|
||||
// Slow case: Call the runtime system to do the number allocation.
|
||||
__ bind(&slow);
|
||||
|
||||
__ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
|
||||
RecordSafepointWithRegisters(
|
||||
instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex);
|
||||
// Set the pointer to the new heap number in tmp.
|
||||
if (!tmp.is(r0)) __ mov(tmp, Operand(r0));
|
||||
|
||||
// Restore input_reg after call to runtime.
|
||||
MemOperand input_register_slot = masm()->SafepointRegisterSlot(input);
|
||||
__ ldr(input, input_register_slot);
|
||||
|
||||
__ bind(&allocated);
|
||||
__ ldr(tmp2, FieldMemOperand(input, HeapNumber::kExponentOffset));
|
||||
__ bic(tmp2, tmp2, Operand(HeapNumber::kSignMask));
|
||||
__ str(tmp2, FieldMemOperand(tmp, HeapNumber::kExponentOffset));
|
||||
__ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset));
|
||||
__ str(tmp2, FieldMemOperand(tmp, HeapNumber::kMantissaOffset));
|
||||
|
||||
__ str(tmp, input_register_slot);
|
||||
__ PopSafepointRegisters();
|
||||
|
||||
__ bind(&done);
|
||||
}
|
||||
|
||||
|
||||
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
|
||||
Label is_positive;
|
||||
uint32_t kSignMask = 0x80000000u;
|
||||
Register input = ToRegister(instr->input());
|
||||
__ tst(input, Operand(kSignMask));
|
||||
__ b(eq, &is_positive);
|
||||
__ rsb(input, input, Operand(0), SetCC);
|
||||
// Deoptimize on overflow.
|
||||
DeoptimizeIf(vs, instr->environment());
|
||||
__ bind(&is_positive);
|
||||
}
|
||||
|
||||
|
||||
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
|
||||
Abort("DoMathAbs unimplemented.");
|
||||
// Class for deferred case.
|
||||
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
|
||||
public:
|
||||
DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen,
|
||||
LUnaryMathOperation* instr)
|
||||
: LDeferredCode(codegen), instr_(instr) { }
|
||||
virtual void Generate() {
|
||||
codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
|
||||
}
|
||||
private:
|
||||
LUnaryMathOperation* instr_;
|
||||
};
|
||||
|
||||
ASSERT(instr->input()->Equals(instr->result()));
|
||||
Representation r = instr->hydrogen()->value()->representation();
|
||||
if (r.IsDouble()) {
|
||||
DwVfpRegister input = ToDoubleRegister(instr->input());
|
||||
// __ vabs(input, input);
|
||||
Abort("Double DoMathAbs unimplemented");
|
||||
} else if (r.IsInteger32()) {
|
||||
EmitIntegerMathAbs(instr);
|
||||
} else {
|
||||
// Representation is tagged.
|
||||
DeferredMathAbsTaggedHeapNumber* deferred =
|
||||
new DeferredMathAbsTaggedHeapNumber(this, instr);
|
||||
Register input = ToRegister(instr->input());
|
||||
// Smi check.
|
||||
__ BranchOnNotSmi(input, deferred->entry());
|
||||
// If smi, handle it directly.
|
||||
EmitIntegerMathAbs(instr);
|
||||
__ bind(deferred->exit());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -214,6 +214,7 @@ class LCodeGen BASE_EMBEDDED {
|
||||
MemOperand ToMemOperand(LOperand* op) const;
|
||||
|
||||
// Specific math operations - used from DoUnaryMathOperation.
|
||||
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
|
||||
void DoMathAbs(LUnaryMathOperation* instr);
|
||||
void DoMathFloor(LUnaryMathOperation* instr);
|
||||
void DoMathSqrt(LUnaryMathOperation* instr);
|
||||
|
@ -499,7 +499,7 @@ int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
|
||||
|
||||
|
||||
MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
|
||||
return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kInstrSize);
|
||||
return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2220,11 +2220,12 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
|
||||
|
||||
Label negative;
|
||||
__ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset));
|
||||
// Check the sign of the argument. If the argument is positive,
|
||||
// just return it.
|
||||
// Check the sign of the argument. If the argument is positive, just
|
||||
// return it. We do not need to patch the stack since |input| and
|
||||
// |result| are the same register and |input| will be restored
|
||||
// unchanged by popping safepoint registers.
|
||||
__ test(tmp, Immediate(HeapNumber::kSignMask));
|
||||
__ j(not_zero, &negative);
|
||||
__ mov(tmp, input_reg);
|
||||
__ jmp(&done);
|
||||
|
||||
__ bind(&negative);
|
||||
@ -2251,14 +2252,25 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
|
||||
__ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2);
|
||||
__ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset));
|
||||
__ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2);
|
||||
|
||||
__ bind(&done);
|
||||
__ mov(Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize), tmp);
|
||||
|
||||
__ bind(&done);
|
||||
__ PopSafepointRegisters();
|
||||
}
|
||||
|
||||
|
||||
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
|
||||
Register input_reg = ToRegister(instr->InputAt(0));
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
Label is_positive;
|
||||
__ j(not_sign, &is_positive);
|
||||
__ neg(input_reg);
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
DeoptimizeIf(negative, instr->environment());
|
||||
__ bind(&is_positive);
|
||||
}
|
||||
|
||||
|
||||
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
|
||||
// Class for deferred case.
|
||||
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
|
||||
@ -2283,31 +2295,15 @@ void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
|
||||
__ subsd(scratch, input_reg);
|
||||
__ pand(input_reg, scratch);
|
||||
} else if (r.IsInteger32()) {
|
||||
Register input_reg = ToRegister(instr->InputAt(0));
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
Label is_positive;
|
||||
__ j(not_sign, &is_positive);
|
||||
__ neg(input_reg);
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
DeoptimizeIf(negative, instr->environment());
|
||||
__ bind(&is_positive);
|
||||
EmitIntegerMathAbs(instr);
|
||||
} else { // Tagged case.
|
||||
DeferredMathAbsTaggedHeapNumber* deferred =
|
||||
new DeferredMathAbsTaggedHeapNumber(this, instr);
|
||||
Label not_smi;
|
||||
Register input_reg = ToRegister(instr->InputAt(0));
|
||||
// Smi check.
|
||||
__ test(input_reg, Immediate(kSmiTagMask));
|
||||
__ j(not_zero, deferred->entry());
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
Label is_positive;
|
||||
__ j(not_sign, &is_positive);
|
||||
__ neg(input_reg);
|
||||
|
||||
__ test(input_reg, Operand(input_reg));
|
||||
DeoptimizeIf(negative, instr->environment());
|
||||
|
||||
__ bind(&is_positive);
|
||||
EmitIntegerMathAbs(instr);
|
||||
__ bind(deferred->exit());
|
||||
}
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ class LCodeGen BASE_EMBEDDED {
|
||||
int ToInteger32(LConstantOperand* op) const;
|
||||
|
||||
// Specific math operations - used from DoUnaryMathOperation.
|
||||
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
|
||||
void DoMathAbs(LUnaryMathOperation* instr);
|
||||
void DoMathFloor(LUnaryMathOperation* instr);
|
||||
void DoMathRound(LUnaryMathOperation* instr);
|
||||
|
Loading…
Reference in New Issue
Block a user