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 3795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3806 __ CallStub(&stub); | 3806 __ CallStub(&stub); |
3807 } else { | 3807 } else { |
3808 ASSERT(exponent_type.IsDouble()); | 3808 ASSERT(exponent_type.IsDouble()); |
3809 MathPowStub stub(MathPowStub::DOUBLE); | 3809 MathPowStub stub(MathPowStub::DOUBLE); |
3810 __ CallStub(&stub); | 3810 __ CallStub(&stub); |
3811 } | 3811 } |
3812 } | 3812 } |
3813 | 3813 |
3814 | 3814 |
3815 void LCodeGen::DoRandom(LRandom* instr) { | 3815 void LCodeGen::DoRandom(LRandom* instr) { |
3816 class DeferredDoRandom V8_FINAL : public LDeferredCode { | 3816 // Assert that the register size is indeed the size of each seed. |
3817 public: | |
3818 DeferredDoRandom(LCodeGen* codegen, LRandom* instr) | |
3819 : LDeferredCode(codegen), instr_(instr) { } | |
3820 virtual void Generate() V8_OVERRIDE { codegen()->DoDeferredRandom(instr_); } | |
3821 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | |
3822 private: | |
3823 LRandom* instr_; | |
3824 }; | |
3825 | |
3826 DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr); | |
3827 // Having marked this instruction as a call we can use any | |
3828 // registers. | |
3829 ASSERT(ToDoubleRegister(instr->result()).is(f0)); | |
3830 ASSERT(ToRegister(instr->global_object()).is(a0)); | |
3831 | |
3832 static const int kSeedSize = sizeof(uint32_t); | 3817 static const int kSeedSize = sizeof(uint32_t); |
3833 STATIC_ASSERT(kPointerSize == kSeedSize); | 3818 STATIC_ASSERT(kPointerSize == kSeedSize); |
3834 | 3819 |
3835 __ lw(a0, FieldMemOperand(a0, GlobalObject::kNativeContextOffset)); | 3820 // Load native context. |
| 3821 Register global_object = ToRegister(instr->global_object()); |
| 3822 Register native_context = global_object; |
| 3823 __ lw(native_context, FieldMemOperand( |
| 3824 global_object, GlobalObject::kNativeContextOffset)); |
| 3825 |
| 3826 // Load state (FixedArray of the native context's random seeds). |
3836 static const int kRandomSeedOffset = | 3827 static const int kRandomSeedOffset = |
3837 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | 3828 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
3838 __ lw(a2, FieldMemOperand(a0, kRandomSeedOffset)); | 3829 Register state = native_context; |
3839 // a2: FixedArray of the native context's random seeds | 3830 __ lw(state, FieldMemOperand(native_context, kRandomSeedOffset)); |
3840 | 3831 |
3841 // Load state[0]. | 3832 // Load state[0]. |
3842 __ lw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); | 3833 Register state0 = ToRegister(instr->scratch()); |
3843 __ Branch(deferred->entry(), eq, a1, Operand(zero_reg)); | 3834 __ lw(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
3844 // Load state[1]. | 3835 // Load state[1]. |
3845 __ lw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); | 3836 Register state1 = ToRegister(instr->scratch2()); |
3846 // a1: state[0]. | 3837 __ lw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
3847 // a0: state[1]. | |
3848 | 3838 |
3849 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | 3839 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
3850 __ And(a3, a1, Operand(0xFFFF)); | 3840 Register scratch3 = ToRegister(instr->scratch3()); |
3851 __ li(t0, Operand(18273)); | 3841 Register scratch4 = scratch0(); |
3852 __ Mul(a3, a3, t0); | 3842 __ And(scratch3, state0, Operand(0xFFFF)); |
3853 __ srl(a1, a1, 16); | 3843 __ li(scratch4, Operand(18273)); |
3854 __ Addu(a1, a3, a1); | 3844 __ Mul(scratch3, scratch3, scratch4); |
| 3845 __ srl(state0, state0, 16); |
| 3846 __ Addu(state0, scratch3, state0); |
3855 // Save state[0]. | 3847 // Save state[0]. |
3856 __ sw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); | 3848 __ sw(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
3857 | 3849 |
3858 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | 3850 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
3859 __ And(a3, a0, Operand(0xFFFF)); | 3851 __ And(scratch3, state1, Operand(0xFFFF)); |
3860 __ li(t0, Operand(36969)); | 3852 __ li(scratch4, Operand(36969)); |
3861 __ Mul(a3, a3, t0); | 3853 __ Mul(scratch3, scratch3, scratch4); |
3862 __ srl(a0, a0, 16), | 3854 __ srl(state1, state1, 16), |
3863 __ Addu(a0, a3, a0); | 3855 __ Addu(state1, scratch3, state1); |
3864 // Save state[1]. | 3856 // Save state[1]. |
3865 __ sw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); | 3857 __ sw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
3866 | 3858 |
3867 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | 3859 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
3868 __ And(a0, a0, Operand(0x3FFFF)); | 3860 Register random = scratch4; |
3869 __ sll(a1, a1, 14); | 3861 __ And(random, state1, Operand(0x3FFFF)); |
3870 __ Addu(v0, a0, a1); | 3862 __ sll(state0, state0, 14); |
3871 | 3863 __ Addu(random, random, state0); |
3872 __ bind(deferred->exit()); | |
3873 | 3864 |
3874 // 0x41300000 is the top half of 1.0 x 2^20 as a double. | 3865 // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
3875 __ li(a2, Operand(0x41300000)); | 3866 __ li(scratch3, Operand(0x41300000)); |
3876 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. | 3867 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. |
3877 __ Move(f12, v0, a2); | 3868 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3869 __ Move(result, random, scratch3); |
3878 // Move 0x4130000000000000 to FPU. | 3870 // Move 0x4130000000000000 to FPU. |
3879 __ Move(f14, zero_reg, a2); | 3871 DoubleRegister scratch5 = double_scratch0(); |
3880 // Subtract to get the result. | 3872 __ Move(scratch5, zero_reg, scratch3); |
3881 __ sub_d(f0, f12, f14); | 3873 __ sub_d(result, result, scratch5); |
3882 } | 3874 } |
3883 | 3875 |
3884 | 3876 |
3885 void LCodeGen::DoDeferredRandom(LRandom* instr) { | |
3886 __ PrepareCallCFunction(1, scratch0()); | |
3887 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | |
3888 // Return value is in v0. | |
3889 } | |
3890 | |
3891 | |
3892 void LCodeGen::DoMathExp(LMathExp* instr) { | 3877 void LCodeGen::DoMathExp(LMathExp* instr) { |
3893 DoubleRegister input = ToDoubleRegister(instr->value()); | 3878 DoubleRegister input = ToDoubleRegister(instr->value()); |
3894 DoubleRegister result = ToDoubleRegister(instr->result()); | 3879 DoubleRegister result = ToDoubleRegister(instr->result()); |
3895 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); | 3880 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
3896 DoubleRegister double_scratch2 = double_scratch0(); | 3881 DoubleRegister double_scratch2 = double_scratch0(); |
3897 Register temp1 = ToRegister(instr->temp1()); | 3882 Register temp1 = ToRegister(instr->temp1()); |
3898 Register temp2 = ToRegister(instr->temp2()); | 3883 Register temp2 = ToRegister(instr->temp2()); |
3899 | 3884 |
3900 MathExpGenerator::EmitMathExp( | 3885 MathExpGenerator::EmitMathExp( |
3901 masm(), input, result, double_scratch1, double_scratch2, | 3886 masm(), input, result, double_scratch1, double_scratch2, |
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5788 __ Subu(scratch, result, scratch); | 5773 __ Subu(scratch, result, scratch); |
5789 __ lw(result, FieldMemOperand(scratch, | 5774 __ lw(result, FieldMemOperand(scratch, |
5790 FixedArray::kHeaderSize - kPointerSize)); | 5775 FixedArray::kHeaderSize - kPointerSize)); |
5791 __ bind(&done); | 5776 __ bind(&done); |
5792 } | 5777 } |
5793 | 5778 |
5794 | 5779 |
5795 #undef __ | 5780 #undef __ |
5796 | 5781 |
5797 } } // namespace v8::internal | 5782 } } // namespace v8::internal |
OLD | NEW |