| Index: src/arm/lithium-codegen-arm.cc
|
| diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
|
| index cf76a086720a7282487f2d59ddd09f6938c79759..059aa13322adb4dde769c9be9cf594fac8133cb4 100644
|
| --- a/src/arm/lithium-codegen-arm.cc
|
| +++ b/src/arm/lithium-codegen-arm.cc
|
| @@ -1383,7 +1383,8 @@ void LCodeGen::EmitSignedIntegerDivisionByConstant(
|
|
|
| void LCodeGen::DoDivI(LDivI* instr) {
|
| if (instr->hydrogen()->HasPowerOf2Divisor()) {
|
| - Register dividend = ToRegister(instr->left());
|
| + const Register dividend = ToRegister(instr->left());
|
| + const Register result = ToRegister(instr->result());
|
| int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant();
|
| int32_t test_value = 0;
|
| int32_t power = 0;
|
| @@ -1394,7 +1395,7 @@ void LCodeGen::DoDivI(LDivI* instr) {
|
| } else {
|
| // Check for (0 / -x) that will produce negative zero.
|
| if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
|
| - __ tst(dividend, Operand(dividend));
|
| + __ cmp(dividend, Operand::Zero());
|
| DeoptimizeIf(eq, instr->environment());
|
| }
|
| // Check for (kMinInt / -1).
|
| @@ -1409,20 +1410,26 @@ void LCodeGen::DoDivI(LDivI* instr) {
|
| if (test_value != 0) {
|
| if (instr->hydrogen()->CheckFlag(
|
| HInstruction::kAllUsesTruncatingToInt32)) {
|
| - __ cmp(dividend, Operand(0));
|
| - __ rsb(dividend, dividend, Operand(0), LeaveCC, lt);
|
| - __ mov(dividend, Operand(dividend, ASR, power));
|
| - if (divisor > 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, lt);
|
| - if (divisor < 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, gt);
|
| + __ sub(result, dividend, Operand::Zero(), SetCC);
|
| + __ rsb(result, result, Operand::Zero(), LeaveCC, lt);
|
| + __ mov(result, Operand(result, ASR, power));
|
| + if (divisor > 0) __ rsb(result, result, Operand::Zero(), LeaveCC, lt);
|
| + if (divisor < 0) __ rsb(result, result, Operand::Zero(), LeaveCC, gt);
|
| return; // Don't fall through to "__ rsb" below.
|
| } else {
|
| // Deoptimize if remainder is not 0.
|
| __ tst(dividend, Operand(test_value));
|
| DeoptimizeIf(ne, instr->environment());
|
| - __ mov(dividend, Operand(dividend, ASR, power));
|
| + __ mov(result, Operand(dividend, ASR, power));
|
| + if (divisor < 0) __ rsb(result, result, Operand(0));
|
| + }
|
| + } else {
|
| + if (divisor < 0) {
|
| + __ rsb(result, dividend, Operand(0));
|
| + } else {
|
| + __ Move(result, dividend);
|
| }
|
| }
|
| - if (divisor < 0) __ rsb(dividend, dividend, Operand(0));
|
|
|
| return;
|
| }
|
| @@ -1439,12 +1446,15 @@ void LCodeGen::DoDivI(LDivI* instr) {
|
|
|
| // Check for (0 / -x) that will produce negative zero.
|
| if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
|
| - Label left_not_zero;
|
| + Label positive;
|
| + if (!instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
|
| + // Do the test only if it hadn't be done above.
|
| + __ cmp(right, Operand::Zero());
|
| + }
|
| + __ b(pl, &positive);
|
| __ cmp(left, Operand::Zero());
|
| - __ b(ne, &left_not_zero);
|
| - __ cmp(right, Operand::Zero());
|
| - DeoptimizeIf(mi, instr->environment());
|
| - __ bind(&left_not_zero);
|
| + DeoptimizeIf(eq, instr->environment());
|
| + __ bind(&positive);
|
| }
|
|
|
| // Check for (kMinInt / -1).
|
| @@ -1975,32 +1985,42 @@ void LCodeGen::DoDateField(LDateField* instr) {
|
|
|
| void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
|
| Register string = ToRegister(instr->string());
|
| - Register index = ToRegister(instr->index());
|
| + LOperand* index_op = instr->index();
|
| Register value = ToRegister(instr->value());
|
| + Register scratch = scratch0();
|
| String::Encoding encoding = instr->encoding();
|
|
|
| if (FLAG_debug_code) {
|
| - __ ldr(ip, FieldMemOperand(string, HeapObject::kMapOffset));
|
| - __ ldrb(ip, FieldMemOperand(ip, Map::kInstanceTypeOffset));
|
| + __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset));
|
| + __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
|
|
|
| - __ and_(ip, ip, Operand(kStringRepresentationMask | kStringEncodingMask));
|
| + __ and_(scratch, scratch,
|
| + Operand(kStringRepresentationMask | kStringEncodingMask));
|
| static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
|
| static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
|
| - __ cmp(ip, Operand(encoding == String::ONE_BYTE_ENCODING
|
| - ? one_byte_seq_type : two_byte_seq_type));
|
| + __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING
|
| + ? one_byte_seq_type : two_byte_seq_type));
|
| __ Check(eq, kUnexpectedStringType);
|
| }
|
|
|
| - __ add(ip,
|
| - string,
|
| - Operand(SeqString::kHeaderSize - kHeapObjectTag));
|
| - if (encoding == String::ONE_BYTE_ENCODING) {
|
| - __ strb(value, MemOperand(ip, index));
|
| + if (index_op->IsConstantOperand()) {
|
| + int constant_index = ToInteger32(LConstantOperand::cast(index_op));
|
| + if (encoding == String::ONE_BYTE_ENCODING) {
|
| + __ strb(value,
|
| + FieldMemOperand(string, SeqString::kHeaderSize + constant_index));
|
| + } else {
|
| + __ strh(value,
|
| + FieldMemOperand(string, SeqString::kHeaderSize + constant_index * 2));
|
| + }
|
| } else {
|
| - // MemOperand with ip as the base register is not allowed for strh, so
|
| - // we do the address calculation explicitly.
|
| - __ add(ip, ip, Operand(index, LSL, 1));
|
| - __ strh(value, MemOperand(ip));
|
| + Register index = ToRegister(index_op);
|
| + if (encoding == String::ONE_BYTE_ENCODING) {
|
| + __ add(scratch, string, Operand(index));
|
| + __ strb(value, FieldMemOperand(scratch, SeqString::kHeaderSize));
|
| + } else {
|
| + __ add(scratch, string, Operand(index, LSL, 1));
|
| + __ strh(value, FieldMemOperand(scratch, SeqString::kHeaderSize));
|
| + }
|
| }
|
| }
|
|
|
| @@ -3891,80 +3911,64 @@ void LCodeGen::DoPower(LPower* instr) {
|
|
|
|
|
| void LCodeGen::DoRandom(LRandom* instr) {
|
| - class DeferredDoRandom V8_FINAL : public LDeferredCode {
|
| - public:
|
| - DeferredDoRandom(LCodeGen* codegen, LRandom* instr)
|
| - : LDeferredCode(codegen), instr_(instr) { }
|
| - virtual void Generate() V8_OVERRIDE { codegen()->DoDeferredRandom(instr_); }
|
| - virtual LInstruction* instr() V8_OVERRIDE { return instr_; }
|
| - private:
|
| - LRandom* instr_;
|
| - };
|
| -
|
| - DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr);
|
| -
|
| - // Having marked this instruction as a call we can use any
|
| - // registers.
|
| - ASSERT(ToDoubleRegister(instr->result()).is(d7));
|
| - ASSERT(ToRegister(instr->global_object()).is(r0));
|
| -
|
| + // Assert that the register size is indeed the size of each seed.
|
| static const int kSeedSize = sizeof(uint32_t);
|
| STATIC_ASSERT(kPointerSize == kSeedSize);
|
|
|
| - __ ldr(r0, FieldMemOperand(r0, GlobalObject::kNativeContextOffset));
|
| + // Load native context
|
| + Register global_object = ToRegister(instr->global_object());
|
| + Register native_context = global_object;
|
| + __ ldr(native_context, FieldMemOperand(
|
| + global_object, GlobalObject::kNativeContextOffset));
|
| +
|
| + // Load state (FixedArray of the native context's random seeds)
|
| static const int kRandomSeedOffset =
|
| FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
|
| - __ ldr(r2, FieldMemOperand(r0, kRandomSeedOffset));
|
| - // r2: FixedArray of the native context's random seeds
|
| + Register state = native_context;
|
| + __ ldr(state, FieldMemOperand(native_context, kRandomSeedOffset));
|
|
|
| // Load state[0].
|
| - __ ldr(r1, FieldMemOperand(r2, ByteArray::kHeaderSize));
|
| - __ cmp(r1, Operand::Zero());
|
| - __ b(eq, deferred->entry());
|
| + Register state0 = ToRegister(instr->scratch());
|
| + __ ldr(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
|
| // Load state[1].
|
| - __ ldr(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize));
|
| - // r1: state[0].
|
| - // r0: state[1].
|
| + Register state1 = ToRegister(instr->scratch2());
|
| + __ ldr(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
|
|
|
| // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
|
| - __ and_(r3, r1, Operand(0xFFFF));
|
| - __ mov(r4, Operand(18273));
|
| - __ mul(r3, r3, r4);
|
| - __ add(r1, r3, Operand(r1, LSR, 16));
|
| + Register scratch3 = ToRegister(instr->scratch3());
|
| + Register scratch4 = scratch0();
|
| + __ and_(scratch3, state0, Operand(0xFFFF));
|
| + __ mov(scratch4, Operand(18273));
|
| + __ mul(scratch3, scratch3, scratch4);
|
| + __ add(state0, scratch3, Operand(state0, LSR, 16));
|
| // Save state[0].
|
| - __ str(r1, FieldMemOperand(r2, ByteArray::kHeaderSize));
|
| + __ str(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
|
|
|
| // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
|
| - __ and_(r3, r0, Operand(0xFFFF));
|
| - __ mov(r4, Operand(36969));
|
| - __ mul(r3, r3, r4);
|
| - __ add(r0, r3, Operand(r0, LSR, 16));
|
| + __ and_(scratch3, state1, Operand(0xFFFF));
|
| + __ mov(scratch4, Operand(36969));
|
| + __ mul(scratch3, scratch3, scratch4);
|
| + __ add(state1, scratch3, Operand(state1, LSR, 16));
|
| // Save state[1].
|
| - __ str(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize));
|
| + __ str(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
|
|
|
| // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
|
| - __ and_(r0, r0, Operand(0x3FFFF));
|
| - __ add(r0, r0, Operand(r1, LSL, 14));
|
| + Register random = scratch4;
|
| + __ and_(random, state1, Operand(0x3FFFF));
|
| + __ add(random, random, Operand(state0, LSL, 14));
|
|
|
| - __ bind(deferred->exit());
|
| // 0x41300000 is the top half of 1.0 x 2^20 as a double.
|
| // Create this constant using mov/orr to avoid PC relative load.
|
| - __ mov(r1, Operand(0x41000000));
|
| - __ orr(r1, r1, Operand(0x300000));
|
| + __ mov(scratch3, Operand(0x41000000));
|
| + __ orr(scratch3, scratch3, Operand(0x300000));
|
| // Move 0x41300000xxxxxxxx (x = random bits) to VFP.
|
| - __ vmov(d7, r0, r1);
|
| + DwVfpRegister result = ToDoubleRegister(instr->result());
|
| + __ vmov(result, random, scratch3);
|
| // Move 0x4130000000000000 to VFP.
|
| - __ mov(r0, Operand::Zero());
|
| - __ vmov(d8, r0, r1);
|
| - // Subtract and store the result in the heap number.
|
| - __ vsub(d7, d7, d8);
|
| -}
|
| -
|
| -
|
| -void LCodeGen::DoDeferredRandom(LRandom* instr) {
|
| - __ PrepareCallCFunction(1, scratch0());
|
| - __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
|
| - // Return value is in r0.
|
| + __ mov(scratch4, Operand::Zero());
|
| + DwVfpRegister scratch5 = double_scratch0();
|
| + __ vmov(scratch5, scratch4, scratch3);
|
| + __ vsub(result, result, scratch5);
|
| }
|
|
|
|
|
| @@ -5003,15 +5007,19 @@ void LCodeGen::DoTaggedToI(LTaggedToI* instr) {
|
|
|
| Register input_reg = ToRegister(input);
|
|
|
| - DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr);
|
| + if (instr->hydrogen()->value()->representation().IsSmi()) {
|
| + __ SmiUntag(input_reg);
|
| + } else {
|
| + DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr);
|
|
|
| - // Optimistically untag the input.
|
| - // If the input is a HeapObject, SmiUntag will set the carry flag.
|
| - __ SmiUntag(input_reg, SetCC);
|
| - // Branch to deferred code if the input was tagged.
|
| - // The deferred code will take care of restoring the tag.
|
| - __ b(cs, deferred->entry());
|
| - __ bind(deferred->exit());
|
| + // Optimistically untag the input.
|
| + // If the input is a HeapObject, SmiUntag will set the carry flag.
|
| + __ SmiUntag(input_reg, SetCC);
|
| + // Branch to deferred code if the input was tagged.
|
| + // The deferred code will take care of restoring the tag.
|
| + __ b(cs, deferred->entry());
|
| + __ bind(deferred->exit());
|
| + }
|
| }
|
|
|
|
|
|
|