Optimize the emitted instruction of random function for X64

Review URL: https://codereview.chromium.org/11852007
Patch from Weiliang Lin <weiliang.lin@intel.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13393 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b5767291
...@@ -1646,6 +1646,15 @@ void Assembler::movzxwl(Register dst, const Operand& src) { ...@@ -1646,6 +1646,15 @@ void Assembler::movzxwl(Register dst, const Operand& src) {
} }
void Assembler::movzxwl(Register dst, Register src) {
EnsureSpace ensure_space(this);
emit_optional_rex_32(dst, src);
emit(0x0F);
emit(0xB7);
emit_modrm(dst, src);
}
void Assembler::repmovsb() { void Assembler::repmovsb() {
EnsureSpace ensure_space(this); EnsureSpace ensure_space(this);
emit(0xF3); emit(0xF3);
......
...@@ -732,6 +732,7 @@ class Assembler : public AssemblerBase { ...@@ -732,6 +732,7 @@ class Assembler : public AssemblerBase {
void movzxbl(Register dst, const Operand& src); void movzxbl(Register dst, const Operand& src);
void movzxwq(Register dst, const Operand& src); void movzxwq(Register dst, const Operand& src);
void movzxwl(Register dst, const Operand& src); void movzxwl(Register dst, const Operand& src);
void movzxwl(Register dst, Register src);
// Repeated moves. // Repeated moves.
......
...@@ -3594,45 +3594,43 @@ void LCodeGen::DoRandom(LRandom* instr) { ...@@ -3594,45 +3594,43 @@ void LCodeGen::DoRandom(LRandom* instr) {
// rbx: FixedArray of the native context's random seeds // rbx: FixedArray of the native context's random seeds
// Load state[0]. // Load state[0].
__ movl(rax, FieldOperand(rbx, ByteArray::kHeaderSize)); __ movl(rcx, FieldOperand(rbx, ByteArray::kHeaderSize));
// If state[0] == 0, call runtime to initialize seeds. // If state[0] == 0, call runtime to initialize seeds.
__ testl(rax, rax); __ testl(rcx, rcx);
__ j(zero, deferred->entry()); __ j(zero, deferred->entry());
// Load state[1]. // Load state[1].
__ movl(rcx, FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize)); __ movl(rax, FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize));
// state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
// Only operate on the lower 32 bit of rax. // Only operate on the lower 32 bit of rcx.
__ movl(rdx, rax); __ movzxwl(rdx, rcx);
__ andl(rdx, Immediate(0xFFFF));
__ imull(rdx, rdx, Immediate(18273)); __ imull(rdx, rdx, Immediate(18273));
__ shrl(rax, Immediate(16)); __ shrl(rcx, Immediate(16));
__ addl(rax, rdx); __ addl(rcx, rdx);
// Save state[0]. // Save state[0].
__ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rax); __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rcx);
// state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
__ movl(rdx, rcx); __ movzxwl(rdx, rax);
__ andl(rdx, Immediate(0xFFFF));
__ imull(rdx, rdx, Immediate(36969)); __ imull(rdx, rdx, Immediate(36969));
__ shrl(rcx, Immediate(16)); __ shrl(rax, Immediate(16));
__ addl(rcx, rdx); __ addl(rax, rdx);
// Save state[1]. // Save state[1].
__ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rcx); __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rax);
// Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
__ shll(rax, Immediate(14)); __ shll(rcx, Immediate(14));
__ andl(rcx, Immediate(0x3FFFF)); __ andl(rax, Immediate(0x3FFFF));
__ addl(rax, rcx); __ addl(rcx, rax);
__ bind(deferred->exit()); __ bind(deferred->exit());
// Convert 32 random bits in rax to 0.(32 random bits) in a double // Convert 32 random bits in rcx to 0.(32 random bits) in a double
// by computing: // by computing:
// ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
__ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. __ movq(rax, V8_INT64_C(0x4130000000000000),
__ movd(xmm2, rcx); RelocInfo::NONE64); // 1.0 x 2^20 as double
__ movd(xmm1, rax); __ movq(xmm2, rax);
__ cvtss2sd(xmm2, xmm2); __ movd(xmm1, rcx);
__ xorps(xmm1, xmm2); __ xorps(xmm1, xmm2);
__ subsd(xmm1, xmm2); __ subsd(xmm1, xmm2);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment