| 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 3873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3884 __ CallStub(&stub); | 3884 __ CallStub(&stub); |
| 3885 } else { | 3885 } else { |
| 3886 ASSERT(exponent_type.IsDouble()); | 3886 ASSERT(exponent_type.IsDouble()); |
| 3887 MathPowStub stub(MathPowStub::DOUBLE); | 3887 MathPowStub stub(MathPowStub::DOUBLE); |
| 3888 __ CallStub(&stub); | 3888 __ CallStub(&stub); |
| 3889 } | 3889 } |
| 3890 } | 3890 } |
| 3891 | 3891 |
| 3892 | 3892 |
| 3893 void LCodeGen::DoRandom(LRandom* instr) { | 3893 void LCodeGen::DoRandom(LRandom* instr) { |
| 3894 class DeferredDoRandom V8_FINAL : public LDeferredCode { | 3894 // Assert that the register size is indeed the size of each seed. |
| 3895 public: | |
| 3896 DeferredDoRandom(LCodeGen* codegen, LRandom* instr) | |
| 3897 : LDeferredCode(codegen), instr_(instr) { } | |
| 3898 virtual void Generate() V8_OVERRIDE { codegen()->DoDeferredRandom(instr_); } | |
| 3899 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | |
| 3900 private: | |
| 3901 LRandom* instr_; | |
| 3902 }; | |
| 3903 | |
| 3904 DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr); | |
| 3905 | |
| 3906 // Having marked this instruction as a call we can use any | |
| 3907 // registers. | |
| 3908 ASSERT(ToDoubleRegister(instr->result()).is(d7)); | |
| 3909 ASSERT(ToRegister(instr->global_object()).is(r0)); | |
| 3910 | |
| 3911 static const int kSeedSize = sizeof(uint32_t); | 3895 static const int kSeedSize = sizeof(uint32_t); |
| 3912 STATIC_ASSERT(kPointerSize == kSeedSize); | 3896 STATIC_ASSERT(kPointerSize == kSeedSize); |
| 3913 | 3897 |
| 3914 __ ldr(r0, FieldMemOperand(r0, GlobalObject::kNativeContextOffset)); | 3898 // Load native context |
| 3899 Register global_object = ToRegister(instr->global_object()); |
| 3900 Register native_context = global_object; |
| 3901 __ ldr(native_context, FieldMemOperand( |
| 3902 global_object, GlobalObject::kNativeContextOffset)); |
| 3903 |
| 3904 // Load state (FixedArray of the native context's random seeds) |
| 3915 static const int kRandomSeedOffset = | 3905 static const int kRandomSeedOffset = |
| 3916 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | 3906 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3917 __ ldr(r2, FieldMemOperand(r0, kRandomSeedOffset)); | 3907 Register state = native_context; |
| 3918 // r2: FixedArray of the native context's random seeds | 3908 __ ldr(state, FieldMemOperand(native_context, kRandomSeedOffset)); |
| 3919 | 3909 |
| 3920 // Load state[0]. | 3910 // Load state[0]. |
| 3921 __ ldr(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); | 3911 Register state0 = ToRegister(instr->scratch()); |
| 3922 __ cmp(r1, Operand::Zero()); | 3912 __ ldr(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
| 3923 __ b(eq, deferred->entry()); | |
| 3924 // Load state[1]. | 3913 // Load state[1]. |
| 3925 __ ldr(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); | 3914 Register state1 = ToRegister(instr->scratch2()); |
| 3926 // r1: state[0]. | 3915 __ ldr(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
| 3927 // r0: state[1]. | |
| 3928 | 3916 |
| 3929 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | 3917 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3930 __ and_(r3, r1, Operand(0xFFFF)); | 3918 Register scratch3 = ToRegister(instr->scratch3()); |
| 3931 __ mov(r4, Operand(18273)); | 3919 Register scratch4 = scratch0(); |
| 3932 __ mul(r3, r3, r4); | 3920 __ and_(scratch3, state0, Operand(0xFFFF)); |
| 3933 __ add(r1, r3, Operand(r1, LSR, 16)); | 3921 __ mov(scratch4, Operand(18273)); |
| 3922 __ mul(scratch3, scratch3, scratch4); |
| 3923 __ add(state0, scratch3, Operand(state0, LSR, 16)); |
| 3934 // Save state[0]. | 3924 // Save state[0]. |
| 3935 __ str(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); | 3925 __ str(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
| 3936 | 3926 |
| 3937 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | 3927 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3938 __ and_(r3, r0, Operand(0xFFFF)); | 3928 __ and_(scratch3, state1, Operand(0xFFFF)); |
| 3939 __ mov(r4, Operand(36969)); | 3929 __ mov(scratch4, Operand(36969)); |
| 3940 __ mul(r3, r3, r4); | 3930 __ mul(scratch3, scratch3, scratch4); |
| 3941 __ add(r0, r3, Operand(r0, LSR, 16)); | 3931 __ add(state1, scratch3, Operand(state1, LSR, 16)); |
| 3942 // Save state[1]. | 3932 // Save state[1]. |
| 3943 __ str(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); | 3933 __ str(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
| 3944 | 3934 |
| 3945 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | 3935 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3946 __ and_(r0, r0, Operand(0x3FFFF)); | 3936 Register random = scratch4; |
| 3947 __ add(r0, r0, Operand(r1, LSL, 14)); | 3937 __ and_(random, state1, Operand(0x3FFFF)); |
| 3938 __ add(random, random, Operand(state0, LSL, 14)); |
| 3948 | 3939 |
| 3949 __ bind(deferred->exit()); | |
| 3950 // 0x41300000 is the top half of 1.0 x 2^20 as a double. | 3940 // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 3951 // Create this constant using mov/orr to avoid PC relative load. | 3941 // Create this constant using mov/orr to avoid PC relative load. |
| 3952 __ mov(r1, Operand(0x41000000)); | 3942 __ mov(scratch3, Operand(0x41000000)); |
| 3953 __ orr(r1, r1, Operand(0x300000)); | 3943 __ orr(scratch3, scratch3, Operand(0x300000)); |
| 3954 // Move 0x41300000xxxxxxxx (x = random bits) to VFP. | 3944 // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 3955 __ vmov(d7, r0, r1); | 3945 DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3946 __ vmov(result, random, scratch3); |
| 3956 // Move 0x4130000000000000 to VFP. | 3947 // Move 0x4130000000000000 to VFP. |
| 3957 __ mov(r0, Operand::Zero()); | 3948 __ mov(scratch4, Operand::Zero()); |
| 3958 __ vmov(d8, r0, r1); | 3949 DwVfpRegister scratch5 = double_scratch0(); |
| 3959 // Subtract and store the result in the heap number. | 3950 __ vmov(scratch5, scratch4, scratch3); |
| 3960 __ vsub(d7, d7, d8); | 3951 __ vsub(result, result, scratch5); |
| 3961 } | 3952 } |
| 3962 | 3953 |
| 3963 | 3954 |
| 3964 void LCodeGen::DoDeferredRandom(LRandom* instr) { | |
| 3965 __ PrepareCallCFunction(1, scratch0()); | |
| 3966 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | |
| 3967 // Return value is in r0. | |
| 3968 } | |
| 3969 | |
| 3970 | |
| 3971 void LCodeGen::DoMathExp(LMathExp* instr) { | 3955 void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3972 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3956 DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3973 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3957 DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3974 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); | 3958 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3975 DwVfpRegister double_scratch2 = double_scratch0(); | 3959 DwVfpRegister double_scratch2 = double_scratch0(); |
| 3976 Register temp1 = ToRegister(instr->temp1()); | 3960 Register temp1 = ToRegister(instr->temp1()); |
| 3977 Register temp2 = ToRegister(instr->temp2()); | 3961 Register temp2 = ToRegister(instr->temp2()); |
| 3978 | 3962 |
| 3979 MathExpGenerator::EmitMathExp( | 3963 MathExpGenerator::EmitMathExp( |
| 3980 masm(), input, result, double_scratch1, double_scratch2, | 3964 masm(), input, result, double_scratch1, double_scratch2, |
| (...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5793 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 5777 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
| 5794 __ ldr(result, FieldMemOperand(scratch, | 5778 __ ldr(result, FieldMemOperand(scratch, |
| 5795 FixedArray::kHeaderSize - kPointerSize)); | 5779 FixedArray::kHeaderSize - kPointerSize)); |
| 5796 __ bind(&done); | 5780 __ bind(&done); |
| 5797 } | 5781 } |
| 5798 | 5782 |
| 5799 | 5783 |
| 5800 #undef __ | 5784 #undef __ |
| 5801 | 5785 |
| 5802 } } // namespace v8::internal | 5786 } } // namespace v8::internal |
| OLD | NEW |