Index: src/arm/lithium-codegen-arm.cc |
diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc |
index cd9c712d3eaf46c3d125e03bbac205612d960707..0aa8197ce1fe128098ef6f5c742592eb976f5653 100644 |
--- a/src/arm/lithium-codegen-arm.cc |
+++ b/src/arm/lithium-codegen-arm.cc |
@@ -3934,6 +3934,68 @@ void LCodeGen::DoPower(LPower* instr) { |
} |
+void LCodeGen::DoRandom(LRandom* instr) { |
+ // 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; |
+ __ ldr(native_context, FieldMemOperand( |
+ 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; |
+ __ ldr(state, FieldMemOperand(native_context, kRandomSeedOffset)); |
+ |
+ // Load state[0]. |
+ Register state0 = ToRegister(instr->scratch()); |
+ __ ldr(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
+ // Load state[1]. |
+ Register state1 = ToRegister(instr->scratch2()); |
+ __ ldr(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
+ |
+ // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
+ Register scratch3 = ToRegister(instr->scratch3()); |
+ Register scratch4 = scratch0(); |
+ __ and_(scratch3, state0, Operand(0xFFFF)); |
+ __ mov(scratch4, Operand(18273)); |
+ __ mul(scratch3, scratch3, scratch4); |
+ __ add(state0, scratch3, Operand(state0, LSR, 16)); |
+ // Save state[0]. |
+ __ str(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
+ |
+ // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
+ __ and_(scratch3, state1, Operand(0xFFFF)); |
+ __ mov(scratch4, Operand(36969)); |
+ __ mul(scratch3, scratch3, scratch4); |
+ __ add(state1, scratch3, Operand(state1, LSR, 16)); |
+ // Save state[1]. |
+ __ str(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
+ |
+ // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
+ Register random = scratch4; |
+ __ and_(random, state1, Operand(0x3FFFF)); |
+ __ add(random, random, Operand(state0, LSL, 14)); |
+ |
+ // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
+ // Create this constant using mov/orr to avoid PC relative load. |
+ __ mov(scratch3, Operand(0x41000000)); |
+ __ orr(scratch3, scratch3, Operand(0x300000)); |
+ // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
+ DwVfpRegister result = ToDoubleRegister(instr->result()); |
+ __ vmov(result, random, scratch3); |
+ // Move 0x4130000000000000 to VFP. |
+ __ mov(scratch4, Operand::Zero()); |
+ DwVfpRegister scratch5 = double_scratch0(); |
+ __ vmov(scratch5, scratch4, scratch3); |
+ __ vsub(result, result, scratch5); |
+} |
+ |
+ |
void LCodeGen::DoMathExp(LMathExp* instr) { |
DwVfpRegister input = ToDoubleRegister(instr->value()); |
DwVfpRegister result = ToDoubleRegister(instr->result()); |