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

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

Issue 1631008: Optimize the assembly code generated for Math.random() (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 8 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') | src/x64/disasm-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 4063 matching lines...) Expand 10 before | Expand all | Expand 10 after
4074 } 4074 }
4075 4075
4076 4076
4077 void CodeGenerator::GenerateRandomHeapNumber( 4077 void CodeGenerator::GenerateRandomHeapNumber(
4078 ZoneList<Expression*>* args) { 4078 ZoneList<Expression*>* args) {
4079 ASSERT(args->length() == 0); 4079 ASSERT(args->length() == 0);
4080 frame_->SpillAll(); 4080 frame_->SpillAll();
4081 4081
4082 Label slow_allocate_heapnumber; 4082 Label slow_allocate_heapnumber;
4083 Label heapnumber_allocated; 4083 Label heapnumber_allocated;
4084 __ AllocateHeapNumber(rdi, rbx, &slow_allocate_heapnumber); 4084 __ AllocateHeapNumber(rbx, rcx, &slow_allocate_heapnumber);
4085 __ jmp(&heapnumber_allocated); 4085 __ jmp(&heapnumber_allocated);
4086 4086
4087 __ bind(&slow_allocate_heapnumber); 4087 __ bind(&slow_allocate_heapnumber);
4088 // To allocate a heap number, and ensure that it is not a smi, we 4088 // To allocate a heap number, and ensure that it is not a smi, we
4089 // call the runtime function FUnaryMinus on 0, returning the double 4089 // call the runtime function FUnaryMinus on 0, returning the double
4090 // -0.0. A new, distinct heap number is returned each time. 4090 // -0.0. A new, distinct heap number is returned each time.
4091 __ Push(Smi::FromInt(0)); 4091 __ Push(Smi::FromInt(0));
4092 __ CallRuntime(Runtime::kNumberUnaryMinus, 1); 4092 __ CallRuntime(Runtime::kNumberUnaryMinus, 1);
4093 __ movq(rdi, rax); 4093 __ movq(rbx, rax);
4094 4094
4095 __ bind(&heapnumber_allocated); 4095 __ bind(&heapnumber_allocated);
4096 4096
4097 // Put a random number into the heap number rdi using a C++ function. 4097 // Return a random uint32 number in rax.
4098 // Return the heap number in rax. 4098 // The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs.
4099 #ifdef _WIN64 4099 __ PrepareCallCFunction(0);
4100 __ movq(rcx, rdi); 4100 __ CallCFunction(ExternalReference::random_uint32_function(), 0);
4101 #else 4101
4102 // Callee-save in Microsoft 64-bit ABI, but not in AMD64 ABI. 4102 // Convert 32 random bits in eax to 0.(32 random bits) in a double
4103 __ push(rsi); 4103 // by computing:
4104 #endif 4104 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
4105 __ PrepareCallCFunction(1); 4105 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
4106 __ CallCFunction(ExternalReference::fill_heap_number_with_random_function(), 4106 __ movd(xmm1, rcx);
4107 1); 4107 __ movd(xmm0, rax);
4108 #ifndef _WIN64 4108 __ cvtss2sd(xmm1, xmm1);
4109 // Callee-save in Microsoft 64-bit ABI, but not in AMD64 ABI. 4109 __ xorpd(xmm0, xmm1);
4110 __ pop(rsi); 4110 __ subsd(xmm0, xmm1);
4111 #endif 4111 __ movsd(FieldOperand(rbx, HeapNumber::kValueOffset), xmm0);
4112
4113 __ movq(rax, rbx);
4112 Result result = allocator_->Allocate(rax); 4114 Result result = allocator_->Allocate(rax);
4113 frame_->Push(&result); 4115 frame_->Push(&result);
4114 } 4116 }
4115 4117
4116 4118
4117 void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) { 4119 void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) {
4118 ASSERT_EQ(args->length(), 4); 4120 ASSERT_EQ(args->length(), 4);
4119 4121
4120 // Load the arguments on the stack and call the runtime system. 4122 // Load the arguments on the stack and call the runtime system.
4121 Load(args->at(0)); 4123 Load(args->at(0));
(...skipping 5951 matching lines...) Expand 10 before | Expand all | Expand 10 after
10073 // Call the function from C++. 10075 // Call the function from C++.
10074 return FUNCTION_CAST<ModuloFunction>(buffer); 10076 return FUNCTION_CAST<ModuloFunction>(buffer);
10075 } 10077 }
10076 10078
10077 #endif 10079 #endif
10078 10080
10079 10081
10080 #undef __ 10082 #undef __
10081 10083
10082 } } // namespace v8::internal 10084 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | src/x64/disasm-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698