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 3680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3691 MathPowStub stub(MathPowStub::INTEGER); | 3691 MathPowStub stub(MathPowStub::INTEGER); |
3692 __ CallStub(&stub); | 3692 __ CallStub(&stub); |
3693 } else { | 3693 } else { |
3694 ASSERT(exponent_type.IsDouble()); | 3694 ASSERT(exponent_type.IsDouble()); |
3695 MathPowStub stub(MathPowStub::DOUBLE); | 3695 MathPowStub stub(MathPowStub::DOUBLE); |
3696 __ CallStub(&stub); | 3696 __ CallStub(&stub); |
3697 } | 3697 } |
3698 } | 3698 } |
3699 | 3699 |
3700 | 3700 |
| 3701 void LCodeGen::DoRandom(LRandom* instr) { |
| 3702 // Assert that register size is twice the size of each seed. |
| 3703 static const int kSeedSize = sizeof(uint32_t); |
| 3704 STATIC_ASSERT(kPointerSize == 2 * kSeedSize); |
| 3705 |
| 3706 // Load native context |
| 3707 Register global_object = ToRegister(instr->global_object()); |
| 3708 Register native_context = global_object; |
| 3709 __ movq(native_context, FieldOperand( |
| 3710 global_object, GlobalObject::kNativeContextOffset)); |
| 3711 |
| 3712 // Load state (FixedArray of the native context's random seeds) |
| 3713 static const int kRandomSeedOffset = |
| 3714 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3715 Register state = native_context; |
| 3716 __ movq(state, FieldOperand(native_context, kRandomSeedOffset)); |
| 3717 |
| 3718 // Load state[0]. |
| 3719 Register state0 = ToRegister(instr->scratch()); |
| 3720 __ movl(state0, FieldOperand(state, ByteArray::kHeaderSize)); |
| 3721 // Load state[1]. |
| 3722 Register state1 = ToRegister(instr->scratch2()); |
| 3723 __ movl(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
| 3724 |
| 3725 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3726 Register scratch3 = ToRegister(instr->scratch3()); |
| 3727 __ movzxwl(scratch3, state0); |
| 3728 __ imull(scratch3, scratch3, Immediate(18273)); |
| 3729 __ shrl(state0, Immediate(16)); |
| 3730 __ addl(state0, scratch3); |
| 3731 // Save state[0]. |
| 3732 __ movl(FieldOperand(state, ByteArray::kHeaderSize), state0); |
| 3733 |
| 3734 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3735 __ movzxwl(scratch3, state1); |
| 3736 __ imull(scratch3, scratch3, Immediate(36969)); |
| 3737 __ shrl(state1, Immediate(16)); |
| 3738 __ addl(state1, scratch3); |
| 3739 // Save state[1]. |
| 3740 __ movl(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1); |
| 3741 |
| 3742 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3743 Register random = state0; |
| 3744 __ shll(random, Immediate(14)); |
| 3745 __ andl(state1, Immediate(0x3FFFF)); |
| 3746 __ addl(random, state1); |
| 3747 |
| 3748 // Convert 32 random bits in rax to 0.(32 random bits) in a double |
| 3749 // by computing: |
| 3750 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 3751 XMMRegister result = ToDoubleRegister(instr->result()); |
| 3752 XMMRegister scratch4 = double_scratch0(); |
| 3753 __ movq(scratch3, V8_INT64_C(0x4130000000000000)); // 1.0 x 2^20 as double |
| 3754 __ movq(scratch4, scratch3); |
| 3755 __ movd(result, random); |
| 3756 __ xorps(result, scratch4); |
| 3757 __ subsd(result, scratch4); |
| 3758 } |
| 3759 |
| 3760 |
3701 void LCodeGen::DoMathExp(LMathExp* instr) { | 3761 void LCodeGen::DoMathExp(LMathExp* instr) { |
3702 XMMRegister input = ToDoubleRegister(instr->value()); | 3762 XMMRegister input = ToDoubleRegister(instr->value()); |
3703 XMMRegister result = ToDoubleRegister(instr->result()); | 3763 XMMRegister result = ToDoubleRegister(instr->result()); |
3704 XMMRegister temp0 = double_scratch0(); | 3764 XMMRegister temp0 = double_scratch0(); |
3705 Register temp1 = ToRegister(instr->temp1()); | 3765 Register temp1 = ToRegister(instr->temp1()); |
3706 Register temp2 = ToRegister(instr->temp2()); | 3766 Register temp2 = ToRegister(instr->temp2()); |
3707 | 3767 |
3708 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); | 3768 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); |
3709 } | 3769 } |
3710 | 3770 |
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5604 FixedArray::kHeaderSize - kPointerSize)); | 5664 FixedArray::kHeaderSize - kPointerSize)); |
5605 __ bind(&done); | 5665 __ bind(&done); |
5606 } | 5666 } |
5607 | 5667 |
5608 | 5668 |
5609 #undef __ | 5669 #undef __ |
5610 | 5670 |
5611 } } // namespace v8::internal | 5671 } } // namespace v8::internal |
5612 | 5672 |
5613 #endif // V8_TARGET_ARCH_X64 | 5673 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |