| Index: src/ia32/lithium-codegen-ia32.cc
|
| diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc
|
| index 1797d2e17050820ff4a97b88402564e05ff6ab8a..f316e850f8e7d676123995d833f36f3bd49e4bcf 100644
|
| --- a/src/ia32/lithium-codegen-ia32.cc
|
| +++ b/src/ia32/lithium-codegen-ia32.cc
|
| @@ -4167,6 +4167,69 @@ void LCodeGen::DoPower(LPower* instr) {
|
| }
|
|
|
|
|
| +void LCodeGen::DoRandom(LRandom* instr) {
|
| + CpuFeatureScope scope(masm(), SSE2);
|
| +
|
| + // Assert that the register size is indeed the size of each seed.
|
| + static const int kSeedSize = sizeof(uint32_t);
|
| + STATIC_ASSERT(kPointerSize == kSeedSize);
|
| +
|
| + // Load native context
|
| + Register global_object = ToRegister(instr->global_object());
|
| + Register native_context = global_object;
|
| + __ mov(native_context, FieldOperand(
|
| + global_object, GlobalObject::kNativeContextOffset));
|
| +
|
| + // Load state (FixedArray of the native context's random seeds)
|
| + static const int kRandomSeedOffset =
|
| + FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
|
| + Register state = native_context;
|
| + __ mov(state, FieldOperand(native_context, kRandomSeedOffset));
|
| +
|
| + // Load state[0].
|
| + Register state0 = ToRegister(instr->scratch());
|
| + __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize));
|
| + // Load state[1].
|
| + Register state1 = ToRegister(instr->scratch2());
|
| + __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize));
|
| +
|
| + // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
|
| + Register scratch3 = ToRegister(instr->scratch3());
|
| + __ movzx_w(scratch3, state0);
|
| + __ imul(scratch3, scratch3, 18273);
|
| + __ shr(state0, 16);
|
| + __ add(state0, scratch3);
|
| + // Save state[0].
|
| + __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0);
|
| +
|
| + // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
|
| + __ movzx_w(scratch3, state1);
|
| + __ imul(scratch3, scratch3, 36969);
|
| + __ shr(state1, 16);
|
| + __ add(state1, scratch3);
|
| + // Save state[1].
|
| + __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1);
|
| +
|
| + // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
|
| + Register random = state0;
|
| + __ shl(random, 14);
|
| + __ and_(state1, Immediate(0x3FFFF));
|
| + __ add(random, state1);
|
| +
|
| + // Convert 32 random bits in random to 0.(32 random bits) in a double
|
| + // by computing:
|
| + // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
|
| + XMMRegister result = ToDoubleRegister(instr->result());
|
| + XMMRegister scratch4 = double_scratch0();
|
| + __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single.
|
| + __ movd(scratch4, scratch3);
|
| + __ movd(result, random);
|
| + __ cvtss2sd(scratch4, scratch4);
|
| + __ xorps(result, scratch4);
|
| + __ subsd(result, scratch4);
|
| +}
|
| +
|
| +
|
| void LCodeGen::DoMathLog(LMathLog* instr) {
|
| CpuFeatureScope scope(masm(), SSE2);
|
| ASSERT(instr->value()->Equals(instr->result()));
|
|
|