OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 3702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3713 MathPowStub stub(MathPowStub::INTEGER); | 3713 MathPowStub stub(MathPowStub::INTEGER); |
3714 __ CallStub(&stub); | 3714 __ CallStub(&stub); |
3715 } else { | 3715 } else { |
3716 ASSERT(exponent_type.IsDouble()); | 3716 ASSERT(exponent_type.IsDouble()); |
3717 MathPowStub stub(MathPowStub::DOUBLE); | 3717 MathPowStub stub(MathPowStub::DOUBLE); |
3718 __ CallStub(&stub); | 3718 __ CallStub(&stub); |
3719 } | 3719 } |
3720 } | 3720 } |
3721 | 3721 |
3722 | 3722 |
3723 void LCodeGen::DoRandom(LRandom* instr) { | |
3724 // Assert that register size is twice the size of each seed. | |
3725 static const int kSeedSize = sizeof(uint32_t); | |
3726 STATIC_ASSERT(kPointerSize == 2 * kSeedSize); | |
3727 | |
3728 // Load native context | |
3729 Register global_object = ToRegister(instr->global_object()); | |
3730 Register native_context = global_object; | |
3731 __ movq(native_context, FieldOperand( | |
3732 global_object, GlobalObject::kNativeContextOffset)); | |
3733 | |
3734 // Load state (FixedArray of the native context's random seeds) | |
3735 static const int kRandomSeedOffset = | |
3736 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | |
3737 Register state = native_context; | |
3738 __ movq(state, FieldOperand(native_context, kRandomSeedOffset)); | |
3739 | |
3740 // Load state[0]. | |
3741 Register state0 = ToRegister(instr->scratch()); | |
3742 __ movl(state0, FieldOperand(state, ByteArray::kHeaderSize)); | |
3743 // Load state[1]. | |
3744 Register state1 = ToRegister(instr->scratch2()); | |
3745 __ movl(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize)); | |
3746 | |
3747 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | |
3748 Register scratch3 = ToRegister(instr->scratch3()); | |
3749 __ movzxwl(scratch3, state0); | |
3750 __ imull(scratch3, scratch3, Immediate(18273)); | |
3751 __ shrl(state0, Immediate(16)); | |
3752 __ addl(state0, scratch3); | |
3753 // Save state[0]. | |
3754 __ movl(FieldOperand(state, ByteArray::kHeaderSize), state0); | |
3755 | |
3756 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | |
3757 __ movzxwl(scratch3, state1); | |
3758 __ imull(scratch3, scratch3, Immediate(36969)); | |
3759 __ shrl(state1, Immediate(16)); | |
3760 __ addl(state1, scratch3); | |
3761 // Save state[1]. | |
3762 __ movl(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1); | |
3763 | |
3764 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | |
3765 Register random = state0; | |
3766 __ shll(random, Immediate(14)); | |
3767 __ andl(state1, Immediate(0x3FFFF)); | |
3768 __ addl(random, state1); | |
3769 | |
3770 // Convert 32 random bits in rax to 0.(32 random bits) in a double | |
3771 // by computing: | |
3772 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | |
3773 XMMRegister result = ToDoubleRegister(instr->result()); | |
3774 XMMRegister scratch4 = double_scratch0(); | |
3775 __ movq(scratch3, V8_INT64_C(0x4130000000000000)); // 1.0 x 2^20 as double | |
3776 __ movq(scratch4, scratch3); | |
3777 __ movd(result, random); | |
3778 __ xorps(result, scratch4); | |
3779 __ subsd(result, scratch4); | |
3780 } | |
3781 | |
3782 | |
3783 void LCodeGen::DoMathExp(LMathExp* instr) { | 3723 void LCodeGen::DoMathExp(LMathExp* instr) { |
3784 XMMRegister input = ToDoubleRegister(instr->value()); | 3724 XMMRegister input = ToDoubleRegister(instr->value()); |
3785 XMMRegister result = ToDoubleRegister(instr->result()); | 3725 XMMRegister result = ToDoubleRegister(instr->result()); |
3786 XMMRegister temp0 = double_scratch0(); | 3726 XMMRegister temp0 = double_scratch0(); |
3787 Register temp1 = ToRegister(instr->temp1()); | 3727 Register temp1 = ToRegister(instr->temp1()); |
3788 Register temp2 = ToRegister(instr->temp2()); | 3728 Register temp2 = ToRegister(instr->temp2()); |
3789 | 3729 |
3790 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); | 3730 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); |
3791 } | 3731 } |
3792 | 3732 |
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5686 FixedArray::kHeaderSize - kPointerSize)); | 5626 FixedArray::kHeaderSize - kPointerSize)); |
5687 __ bind(&done); | 5627 __ bind(&done); |
5688 } | 5628 } |
5689 | 5629 |
5690 | 5630 |
5691 #undef __ | 5631 #undef __ |
5692 | 5632 |
5693 } } // namespace v8::internal | 5633 } } // namespace v8::internal |
5694 | 5634 |
5695 #endif // V8_TARGET_ARCH_X64 | 5635 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |