| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 for (int i = 0; i < translation_size; ++i) { | 464 for (int i = 0; i < translation_size; ++i) { |
| 465 LOperand* value = environment->values()->at(i); | 465 LOperand* value = environment->values()->at(i); |
| 466 // spilled_registers_ and spilled_double_registers_ are either | 466 // spilled_registers_ and spilled_double_registers_ are either |
| 467 // both NULL or both set. | 467 // both NULL or both set. |
| 468 if (environment->spilled_registers() != NULL && value != NULL) { | 468 if (environment->spilled_registers() != NULL && value != NULL) { |
| 469 if (value->IsRegister() && | 469 if (value->IsRegister() && |
| 470 environment->spilled_registers()[value->index()] != NULL) { | 470 environment->spilled_registers()[value->index()] != NULL) { |
| 471 translation->MarkDuplicate(); | 471 translation->MarkDuplicate(); |
| 472 AddToTranslation(translation, | 472 AddToTranslation(translation, |
| 473 environment->spilled_registers()[value->index()], | 473 environment->spilled_registers()[value->index()], |
| 474 environment->HasTaggedValueAt(i)); | 474 environment->HasTaggedValueAt(i), |
| 475 environment->HasUint32ValueAt(i)); |
| 475 } else if ( | 476 } else if ( |
| 476 value->IsDoubleRegister() && | 477 value->IsDoubleRegister() && |
| 477 environment->spilled_double_registers()[value->index()] != NULL) { | 478 environment->spilled_double_registers()[value->index()] != NULL) { |
| 478 translation->MarkDuplicate(); | 479 translation->MarkDuplicate(); |
| 479 AddToTranslation( | 480 AddToTranslation( |
| 480 translation, | 481 translation, |
| 481 environment->spilled_double_registers()[value->index()], | 482 environment->spilled_double_registers()[value->index()], |
| 483 false, |
| 482 false); | 484 false); |
| 483 } | 485 } |
| 484 } | 486 } |
| 485 | 487 |
| 486 AddToTranslation(translation, value, environment->HasTaggedValueAt(i)); | 488 AddToTranslation(translation, |
| 489 value, |
| 490 environment->HasTaggedValueAt(i), |
| 491 environment->HasUint32ValueAt(i)); |
| 487 } | 492 } |
| 488 } | 493 } |
| 489 | 494 |
| 490 | 495 |
| 491 void LCodeGen::AddToTranslation(Translation* translation, | 496 void LCodeGen::AddToTranslation(Translation* translation, |
| 492 LOperand* op, | 497 LOperand* op, |
| 493 bool is_tagged) { | 498 bool is_tagged, |
| 499 bool is_uint32) { |
| 494 if (op == NULL) { | 500 if (op == NULL) { |
| 495 // TODO(twuerthinger): Introduce marker operands to indicate that this value | 501 // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 496 // is not present and must be reconstructed from the deoptimizer. Currently | 502 // is not present and must be reconstructed from the deoptimizer. Currently |
| 497 // this is only used for the arguments object. | 503 // this is only used for the arguments object. |
| 498 translation->StoreArgumentsObject(); | 504 translation->StoreArgumentsObject(); |
| 499 } else if (op->IsStackSlot()) { | 505 } else if (op->IsStackSlot()) { |
| 500 if (is_tagged) { | 506 if (is_tagged) { |
| 501 translation->StoreStackSlot(op->index()); | 507 translation->StoreStackSlot(op->index()); |
| 508 } else if (is_uint32) { |
| 509 translation->StoreUint32StackSlot(op->index()); |
| 502 } else { | 510 } else { |
| 503 translation->StoreInt32StackSlot(op->index()); | 511 translation->StoreInt32StackSlot(op->index()); |
| 504 } | 512 } |
| 505 } else if (op->IsDoubleStackSlot()) { | 513 } else if (op->IsDoubleStackSlot()) { |
| 506 translation->StoreDoubleStackSlot(op->index()); | 514 translation->StoreDoubleStackSlot(op->index()); |
| 507 } else if (op->IsArgument()) { | 515 } else if (op->IsArgument()) { |
| 508 ASSERT(is_tagged); | 516 ASSERT(is_tagged); |
| 509 int src_index = GetStackSlotCount() + op->index(); | 517 int src_index = GetStackSlotCount() + op->index(); |
| 510 translation->StoreStackSlot(src_index); | 518 translation->StoreStackSlot(src_index); |
| 511 } else if (op->IsRegister()) { | 519 } else if (op->IsRegister()) { |
| 512 Register reg = ToRegister(op); | 520 Register reg = ToRegister(op); |
| 513 if (is_tagged) { | 521 if (is_tagged) { |
| 514 translation->StoreRegister(reg); | 522 translation->StoreRegister(reg); |
| 523 } else if (is_uint32) { |
| 524 translation->StoreUint32Register(reg); |
| 515 } else { | 525 } else { |
| 516 translation->StoreInt32Register(reg); | 526 translation->StoreInt32Register(reg); |
| 517 } | 527 } |
| 518 } else if (op->IsDoubleRegister()) { | 528 } else if (op->IsDoubleRegister()) { |
| 519 DoubleRegister reg = ToDoubleRegister(op); | 529 DoubleRegister reg = ToDoubleRegister(op); |
| 520 translation->StoreDoubleRegister(reg); | 530 translation->StoreDoubleRegister(reg); |
| 521 } else if (op->IsConstantOperand()) { | 531 } else if (op->IsConstantOperand()) { |
| 522 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); | 532 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
| 523 int src_index = DefineDeoptimizationLiteral(constant->handle()); | 533 int src_index = DefineDeoptimizationLiteral(constant->handle()); |
| 524 translation->StoreLiteral(src_index); | 534 translation->StoreLiteral(src_index); |
| (...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2762 __ lh(result, mem_operand); | 2772 __ lh(result, mem_operand); |
| 2763 break; | 2773 break; |
| 2764 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 2774 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 2765 __ lhu(result, mem_operand); | 2775 __ lhu(result, mem_operand); |
| 2766 break; | 2776 break; |
| 2767 case EXTERNAL_INT_ELEMENTS: | 2777 case EXTERNAL_INT_ELEMENTS: |
| 2768 __ lw(result, mem_operand); | 2778 __ lw(result, mem_operand); |
| 2769 break; | 2779 break; |
| 2770 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | 2780 case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 2771 __ lw(result, mem_operand); | 2781 __ lw(result, mem_operand); |
| 2772 // TODO(danno): we could be more clever here, perhaps having a special | 2782 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 2773 // version of the stub that detects if the overflow case actually | 2783 DeoptimizeIf(Ugreater_equal, instr->environment(), |
| 2774 // happens, and generate code that returns a double rather than int. | 2784 result, Operand(0x80000000)); |
| 2775 DeoptimizeIf(Ugreater_equal, instr->environment(), | 2785 } |
| 2776 result, Operand(0x80000000)); | |
| 2777 break; | 2786 break; |
| 2778 case EXTERNAL_FLOAT_ELEMENTS: | 2787 case EXTERNAL_FLOAT_ELEMENTS: |
| 2779 case EXTERNAL_DOUBLE_ELEMENTS: | 2788 case EXTERNAL_DOUBLE_ELEMENTS: |
| 2780 case FAST_DOUBLE_ELEMENTS: | 2789 case FAST_DOUBLE_ELEMENTS: |
| 2781 case FAST_ELEMENTS: | 2790 case FAST_ELEMENTS: |
| 2782 case FAST_SMI_ELEMENTS: | 2791 case FAST_SMI_ELEMENTS: |
| 2783 case FAST_HOLEY_DOUBLE_ELEMENTS: | 2792 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 2784 case FAST_HOLEY_ELEMENTS: | 2793 case FAST_HOLEY_ELEMENTS: |
| 2785 case FAST_HOLEY_SMI_ELEMENTS: | 2794 case FAST_HOLEY_SMI_ELEMENTS: |
| 2786 case DICTIONARY_ELEMENTS: | 2795 case DICTIONARY_ELEMENTS: |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4052 Register scratch = scratch0(); | 4061 Register scratch = scratch0(); |
| 4053 __ lw(scratch, ToMemOperand(input)); | 4062 __ lw(scratch, ToMemOperand(input)); |
| 4054 __ mtc1(scratch, single_scratch); | 4063 __ mtc1(scratch, single_scratch); |
| 4055 } else { | 4064 } else { |
| 4056 __ mtc1(ToRegister(input), single_scratch); | 4065 __ mtc1(ToRegister(input), single_scratch); |
| 4057 } | 4066 } |
| 4058 __ cvt_d_w(ToDoubleRegister(output), single_scratch); | 4067 __ cvt_d_w(ToDoubleRegister(output), single_scratch); |
| 4059 } | 4068 } |
| 4060 | 4069 |
| 4061 | 4070 |
| 4071 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
| 4072 LOperand* input = instr->InputAt(0); |
| 4073 LOperand* output = instr->result(); |
| 4074 |
| 4075 FPURegister dbl_scratch = double_scratch0(); |
| 4076 __ mtc1(ToRegister(input), dbl_scratch); |
| 4077 __ Cvt_d_uw(ToDoubleRegister(output), dbl_scratch, f22); |
| 4078 } |
| 4079 |
| 4080 |
| 4062 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { | 4081 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 4063 class DeferredNumberTagI: public LDeferredCode { | 4082 class DeferredNumberTagI: public LDeferredCode { |
| 4064 public: | 4083 public: |
| 4065 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) | 4084 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4066 : LDeferredCode(codegen), instr_(instr) { } | 4085 : LDeferredCode(codegen), instr_(instr) { } |
| 4067 virtual void Generate() { codegen()->DoDeferredNumberTagI(instr_); } | 4086 virtual void Generate() { |
| 4087 codegen()->DoDeferredNumberTagI(instr_, SIGNED_INT32); |
| 4088 } |
| 4068 virtual LInstruction* instr() { return instr_; } | 4089 virtual LInstruction* instr() { return instr_; } |
| 4069 private: | 4090 private: |
| 4070 LNumberTagI* instr_; | 4091 LNumberTagI* instr_; |
| 4071 }; | 4092 }; |
| 4072 | 4093 |
| 4073 Register src = ToRegister(instr->InputAt(0)); | 4094 Register src = ToRegister(instr->InputAt(0)); |
| 4074 Register dst = ToRegister(instr->result()); | 4095 Register dst = ToRegister(instr->result()); |
| 4075 Register overflow = scratch0(); | 4096 Register overflow = scratch0(); |
| 4076 | 4097 |
| 4077 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); | 4098 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
| 4078 __ SmiTagCheckOverflow(dst, src, overflow); | 4099 __ SmiTagCheckOverflow(dst, src, overflow); |
| 4079 __ BranchOnOverflow(deferred->entry(), overflow); | 4100 __ BranchOnOverflow(deferred->entry(), overflow); |
| 4080 __ bind(deferred->exit()); | 4101 __ bind(deferred->exit()); |
| 4081 } | 4102 } |
| 4082 | 4103 |
| 4083 | 4104 |
| 4084 void LCodeGen::DoDeferredNumberTagI(LNumberTagI* instr) { | 4105 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
| 4106 class DeferredNumberTagU: public LDeferredCode { |
| 4107 public: |
| 4108 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4109 : LDeferredCode(codegen), instr_(instr) { } |
| 4110 virtual void Generate() { |
| 4111 codegen()->DoDeferredNumberTagI(instr_, UNSIGNED_INT32); |
| 4112 } |
| 4113 virtual LInstruction* instr() { return instr_; } |
| 4114 private: |
| 4115 LNumberTagU* instr_; |
| 4116 }; |
| 4117 |
| 4118 LOperand* input = instr->InputAt(0); |
| 4119 ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 4120 Register reg = ToRegister(input); |
| 4121 |
| 4122 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
| 4123 __ Branch(deferred->entry(), hi, reg, Operand(Smi::kMaxValue)); |
| 4124 __ SmiTag(reg, reg); |
| 4125 __ bind(deferred->exit()); |
| 4126 } |
| 4127 |
| 4128 |
| 4129 void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 4130 IntegerSignedness signedness) { |
| 4085 Label slow; | 4131 Label slow; |
| 4086 Register src = ToRegister(instr->InputAt(0)); | 4132 Register src = ToRegister(instr->InputAt(0)); |
| 4087 Register dst = ToRegister(instr->result()); | 4133 Register dst = ToRegister(instr->result()); |
| 4088 FPURegister dbl_scratch = double_scratch0(); | 4134 FPURegister dbl_scratch = double_scratch0(); |
| 4089 | 4135 |
| 4090 // Preserve the value of all registers. | 4136 // Preserve the value of all registers. |
| 4091 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); | 4137 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4092 | 4138 |
| 4093 // There was overflow, so bits 30 and 31 of the original integer | |
| 4094 // disagree. Try to allocate a heap number in new space and store | |
| 4095 // the value in there. If that fails, call the runtime system. | |
| 4096 Label done; | 4139 Label done; |
| 4097 if (dst.is(src)) { | 4140 if (signedness == SIGNED_INT32) { |
| 4098 __ SmiUntag(src, dst); | 4141 // There was overflow, so bits 30 and 31 of the original integer |
| 4099 __ Xor(src, src, Operand(0x80000000)); | 4142 // disagree. Try to allocate a heap number in new space and store |
| 4143 // the value in there. If that fails, call the runtime system. |
| 4144 if (dst.is(src)) { |
| 4145 __ SmiUntag(src, dst); |
| 4146 __ Xor(src, src, Operand(0x80000000)); |
| 4147 } |
| 4148 __ mtc1(src, dbl_scratch); |
| 4149 __ cvt_d_w(dbl_scratch, dbl_scratch); |
| 4150 } else { |
| 4151 __ mtc1(src, dbl_scratch); |
| 4152 __ Cvt_d_uw(dbl_scratch, dbl_scratch, f22); |
| 4100 } | 4153 } |
| 4101 __ mtc1(src, dbl_scratch); | 4154 |
| 4102 __ cvt_d_w(dbl_scratch, dbl_scratch); | |
| 4103 if (FLAG_inline_new) { | 4155 if (FLAG_inline_new) { |
| 4104 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex); | 4156 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex); |
| 4105 __ AllocateHeapNumber(t1, a3, t0, t2, &slow); | 4157 __ AllocateHeapNumber(t1, a3, t0, t2, &slow); |
| 4106 __ Move(dst, t1); | 4158 __ Move(dst, t1); |
| 4107 __ Branch(&done); | 4159 __ Branch(&done); |
| 4108 } | 4160 } |
| 4109 | 4161 |
| 4110 // Slow case: Call the runtime system to do the number allocation. | 4162 // Slow case: Call the runtime system to do the number allocation. |
| 4111 __ bind(&slow); | 4163 __ bind(&slow); |
| 4112 | 4164 |
| (...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5343 __ Subu(scratch, result, scratch); | 5395 __ Subu(scratch, result, scratch); |
| 5344 __ lw(result, FieldMemOperand(scratch, | 5396 __ lw(result, FieldMemOperand(scratch, |
| 5345 FixedArray::kHeaderSize - kPointerSize)); | 5397 FixedArray::kHeaderSize - kPointerSize)); |
| 5346 __ bind(&done); | 5398 __ bind(&done); |
| 5347 } | 5399 } |
| 5348 | 5400 |
| 5349 | 5401 |
| 5350 #undef __ | 5402 #undef __ |
| 5351 | 5403 |
| 5352 } } // namespace v8::internal | 5404 } } // namespace v8::internal |
| OLD | NEW |