| 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 3576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3587 STATIC_ASSERT(kPointerSize == 2 * kSeedSize); | 3587 STATIC_ASSERT(kPointerSize == 2 * kSeedSize); |
| 3588 | 3588 |
| 3589 __ movq(global_object, | 3589 __ movq(global_object, |
| 3590 FieldOperand(global_object, GlobalObject::kNativeContextOffset)); | 3590 FieldOperand(global_object, GlobalObject::kNativeContextOffset)); |
| 3591 static const int kRandomSeedOffset = | 3591 static const int kRandomSeedOffset = |
| 3592 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | 3592 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3593 __ movq(rbx, FieldOperand(global_object, kRandomSeedOffset)); | 3593 __ movq(rbx, FieldOperand(global_object, kRandomSeedOffset)); |
| 3594 // rbx: FixedArray of the native context's random seeds | 3594 // rbx: FixedArray of the native context's random seeds |
| 3595 | 3595 |
| 3596 // Load state[0]. | 3596 // Load state[0]. |
| 3597 __ movl(rcx, FieldOperand(rbx, ByteArray::kHeaderSize)); | 3597 __ movl(rax, FieldOperand(rbx, ByteArray::kHeaderSize)); |
| 3598 // If state[0] == 0, call runtime to initialize seeds. | 3598 // If state[0] == 0, call runtime to initialize seeds. |
| 3599 __ testl(rcx, rcx); | 3599 __ testl(rax, rax); |
| 3600 __ j(zero, deferred->entry()); | 3600 __ j(zero, deferred->entry()); |
| 3601 // Load state[1]. | 3601 // Load state[1]. |
| 3602 __ movl(rax, FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize)); | 3602 __ movl(rcx, FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize)); |
| 3603 | 3603 |
| 3604 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | 3604 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3605 // Only operate on the lower 32 bit of rcx. | 3605 // Only operate on the lower 32 bit of rax. |
| 3606 __ movzxwl(rdx, rcx); | 3606 __ movl(rdx, rax); |
| 3607 __ andl(rdx, Immediate(0xFFFF)); |
| 3607 __ imull(rdx, rdx, Immediate(18273)); | 3608 __ imull(rdx, rdx, Immediate(18273)); |
| 3609 __ shrl(rax, Immediate(16)); |
| 3610 __ addl(rax, rdx); |
| 3611 // Save state[0]. |
| 3612 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rax); |
| 3613 |
| 3614 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3615 __ movl(rdx, rcx); |
| 3616 __ andl(rdx, Immediate(0xFFFF)); |
| 3617 __ imull(rdx, rdx, Immediate(36969)); |
| 3608 __ shrl(rcx, Immediate(16)); | 3618 __ shrl(rcx, Immediate(16)); |
| 3609 __ addl(rcx, rdx); | 3619 __ addl(rcx, rdx); |
| 3610 // Save state[0]. | |
| 3611 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rcx); | |
| 3612 | |
| 3613 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | |
| 3614 __ movzxwl(rdx, rax); | |
| 3615 __ imull(rdx, rdx, Immediate(36969)); | |
| 3616 __ shrl(rax, Immediate(16)); | |
| 3617 __ addl(rax, rdx); | |
| 3618 // Save state[1]. | 3620 // Save state[1]. |
| 3619 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rax); | 3621 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rcx); |
| 3620 | 3622 |
| 3621 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | 3623 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3622 __ shll(rcx, Immediate(14)); | 3624 __ shll(rax, Immediate(14)); |
| 3623 __ andl(rax, Immediate(0x3FFFF)); | 3625 __ andl(rcx, Immediate(0x3FFFF)); |
| 3624 __ addl(rcx, rax); | 3626 __ addl(rax, rcx); |
| 3625 | 3627 |
| 3626 __ bind(deferred->exit()); | 3628 __ bind(deferred->exit()); |
| 3627 // Convert 32 random bits in rcx to 0.(32 random bits) in a double | 3629 // Convert 32 random bits in rax to 0.(32 random bits) in a double |
| 3628 // by computing: | 3630 // by computing: |
| 3629 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 3631 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 3630 __ movq(rax, V8_INT64_C(0x4130000000000000), | 3632 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
| 3631 RelocInfo::NONE64); // 1.0 x 2^20 as double | 3633 __ movd(xmm2, rcx); |
| 3632 __ movq(xmm2, rax); | 3634 __ movd(xmm1, rax); |
| 3633 __ movd(xmm1, rcx); | 3635 __ cvtss2sd(xmm2, xmm2); |
| 3634 __ xorps(xmm1, xmm2); | 3636 __ xorps(xmm1, xmm2); |
| 3635 __ subsd(xmm1, xmm2); | 3637 __ subsd(xmm1, xmm2); |
| 3636 } | 3638 } |
| 3637 | 3639 |
| 3638 | 3640 |
| 3639 void LCodeGen::DoDeferredRandom(LRandom* instr) { | 3641 void LCodeGen::DoDeferredRandom(LRandom* instr) { |
| 3640 __ PrepareCallCFunction(1); | 3642 __ PrepareCallCFunction(1); |
| 3641 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | 3643 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
| 3642 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3644 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3643 // Return value is in rax. | 3645 // Return value is in rax. |
| (...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5551 FixedArray::kHeaderSize - kPointerSize)); | 5553 FixedArray::kHeaderSize - kPointerSize)); |
| 5552 __ bind(&done); | 5554 __ bind(&done); |
| 5553 } | 5555 } |
| 5554 | 5556 |
| 5555 | 5557 |
| 5556 #undef __ | 5558 #undef __ |
| 5557 | 5559 |
| 5558 } } // namespace v8::internal | 5560 } } // namespace v8::internal |
| 5559 | 5561 |
| 5560 #endif // V8_TARGET_ARCH_X64 | 5562 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |