Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: src/x64/lithium-codegen-x64.cc

Issue 11852007: Optimize the emitted instruction of random function for X64 (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3585 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 // Load state[0]. 3596 // Load state[0].
3597 __ movl(rax, 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(rax, rax); 3599 __ testl(rax, rax);
3600 __ j(zero, deferred->entry()); 3600 __ j(zero, deferred->entry());
3601 // Load state[1]. 3601 // Load state[1].
3602 __ movl(rcx, 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 rax. 3605 // Only operate on the lower 32 bit of rax.
3606 __ movl(rdx, rax); 3606 __ movzxwl(rdx, rax);
3607 __ andl(rdx, Immediate(0xFFFF));
3608 __ imull(rdx, rdx, Immediate(18273)); 3607 __ imull(rdx, rdx, Immediate(18273));
3609 __ shrl(rax, Immediate(16)); 3608 __ shrl(rax, Immediate(16));
3610 __ addl(rax, rdx); 3609 __ addl(rax, rdx);
3611 // Save state[0]. 3610 // Save state[0].
3612 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rax); 3611 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rax);
3613 3612
3614 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) 3613 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3615 __ movl(rdx, rcx); 3614 __ movzxwl(rdx, rcx);
3616 __ andl(rdx, Immediate(0xFFFF));
3617 __ imull(rdx, rdx, Immediate(36969)); 3615 __ imull(rdx, rdx, Immediate(36969));
3618 __ shrl(rcx, Immediate(16)); 3616 __ shrl(rcx, Immediate(16));
3619 __ addl(rcx, rdx); 3617 __ addl(rcx, rdx);
3620 // Save state[1]. 3618 // Save state[1].
3621 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rcx); 3619 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rcx);
3622 3620
3623 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) 3621 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3624 __ shll(rax, Immediate(14)); 3622 __ shll(rax, Immediate(14));
3625 __ andl(rcx, Immediate(0x3FFFF)); 3623 __ andl(rcx, Immediate(0x3FFFF));
3626 __ addl(rax, rcx); 3624 __ addl(rax, rcx);
3627 3625
3628 __ bind(deferred->exit()); 3626 __ bind(deferred->exit());
3629 // Convert 32 random bits in rax to 0.(32 random bits) in a double 3627 // Convert 32 random bits in rax to 0.(32 random bits) in a double
3630 // by computing: 3628 // by computing:
3631 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). 3629 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
3632 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. 3630 __ movq(rcx, V8_INT64_C(0x4130000000000000),
3633 __ movd(xmm2, rcx); 3631 RelocInfo::NONE64); // 1.0 x 2^20 as double
3632 __ movq(xmm2, rcx);
3634 __ movd(xmm1, rax); 3633 __ movd(xmm1, rax);
3635 __ cvtss2sd(xmm2, xmm2);
3636 __ xorps(xmm1, xmm2); 3634 __ xorps(xmm1, xmm2);
3637 __ subsd(xmm1, xmm2); 3635 __ subsd(xmm1, xmm2);
3638 } 3636 }
3639 3637
3640 3638
3641 void LCodeGen::DoDeferredRandom(LRandom* instr) { 3639 void LCodeGen::DoDeferredRandom(LRandom* instr) {
3642 __ PrepareCallCFunction(1); 3640 __ PrepareCallCFunction(1);
3643 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); 3641 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3644 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 3642 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
3645 // Return value is in rax. 3643 // Return value is in rax.
(...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after
5574 FixedArray::kHeaderSize - kPointerSize)); 5572 FixedArray::kHeaderSize - kPointerSize));
5575 __ bind(&done); 5573 __ bind(&done);
5576 } 5574 }
5577 5575
5578 5576
5579 #undef __ 5577 #undef __
5580 5578
5581 } } // namespace v8::internal 5579 } } // namespace v8::internal
5582 5580
5583 #endif // V8_TARGET_ARCH_X64 5581 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698