Index: src/x64/full-codegen-x64.cc |
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc |
index a62fde0ee901f4c464f2aab4bc090d61f9c2bf84..71b54680f2035d352122fe631018cdd09b8590cc 100644 |
--- a/src/x64/full-codegen-x64.cc |
+++ b/src/x64/full-codegen-x64.cc |
@@ -3271,6 +3271,47 @@ void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
} |
+void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) { |
+ ASSERT(expr->arguments()->length() == 0); |
+ |
+ Label slow_allocate_heapnumber; |
+ Label heapnumber_allocated; |
+ |
+ __ AllocateHeapNumber(rbx, rcx, &slow_allocate_heapnumber); |
+ __ jmp(&heapnumber_allocated); |
+ |
+ __ bind(&slow_allocate_heapnumber); |
+ // Allocate a heap number. |
+ __ CallRuntime(Runtime::kNumberAlloc, 0); |
+ __ movq(rbx, rax); |
+ |
+ __ bind(&heapnumber_allocated); |
+ |
+ // Return a random uint32 number in rax. |
+ // The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs. |
+ __ PrepareCallCFunction(1); |
+ __ movq(arg_reg_1, |
+ ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX)); |
+ __ movq(arg_reg_1, |
+ FieldOperand(arg_reg_1, GlobalObject::kNativeContextOffset)); |
+ __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
+ |
+ // Convert 32 random bits in rax to 0.(32 random bits) in a double |
+ // by computing: |
+ // ( 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. |
+ __ movd(xmm1, rcx); |
+ __ movd(xmm0, rax); |
+ __ cvtss2sd(xmm1, xmm1); |
+ __ xorps(xmm0, xmm1); |
+ __ subsd(xmm0, xmm1); |
+ __ movsd(FieldOperand(rbx, HeapNumber::kValueOffset), xmm0); |
+ |
+ __ movq(rax, rbx); |
+ context()->Plug(rax); |
+} |
+ |
+ |
void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
// Load the arguments on the stack and call the stub. |
SubStringStub stub; |