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

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

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 3228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 VisitForStackValue(args->at(1)); 3239 VisitForStackValue(args->at(1));
3240 VisitForStackValue(args->at(2)); 3240 VisitForStackValue(args->at(2));
3241 __ CallRuntime(Runtime::kLog, 2); 3241 __ CallRuntime(Runtime::kLog, 2);
3242 } 3242 }
3243 // Finally, we're expected to leave a value on the top of the stack. 3243 // Finally, we're expected to leave a value on the top of the stack.
3244 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); 3244 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
3245 context()->Plug(rax); 3245 context()->Plug(rax);
3246 } 3246 }
3247 3247
3248 3248
3249 void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
3250 ASSERT(expr->arguments()->length() == 0);
3251
3252 Label slow_allocate_heapnumber;
3253 Label heapnumber_allocated;
3254
3255 __ AllocateHeapNumber(rbx, rcx, &slow_allocate_heapnumber);
3256 __ jmp(&heapnumber_allocated);
3257
3258 __ bind(&slow_allocate_heapnumber);
3259 // Allocate a heap number.
3260 __ CallRuntime(Runtime::kNumberAlloc, 0);
3261 __ movq(rbx, rax);
3262
3263 __ bind(&heapnumber_allocated);
3264
3265 // Return a random uint32 number in rax.
3266 // The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs.
3267 __ PrepareCallCFunction(1);
3268 __ movq(arg_reg_1,
3269 ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX));
3270 __ movq(arg_reg_1,
3271 FieldOperand(arg_reg_1, GlobalObject::kNativeContextOffset));
3272 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3273
3274 // Convert 32 random bits in rax to 0.(32 random bits) in a double
3275 // by computing:
3276 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
3277 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
3278 __ movd(xmm1, rcx);
3279 __ movd(xmm0, rax);
3280 __ cvtss2sd(xmm1, xmm1);
3281 __ xorps(xmm0, xmm1);
3282 __ subsd(xmm0, xmm1);
3283 __ movsd(FieldOperand(rbx, HeapNumber::kValueOffset), xmm0);
3284
3285 __ movq(rax, rbx);
3286 context()->Plug(rax);
3287 }
3288
3289
3290 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { 3249 void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
3291 // Load the arguments on the stack and call the stub. 3250 // Load the arguments on the stack and call the stub.
3292 SubStringStub stub; 3251 SubStringStub stub;
3293 ZoneList<Expression*>* args = expr->arguments(); 3252 ZoneList<Expression*>* args = expr->arguments();
3294 ASSERT(args->length() == 3); 3253 ASSERT(args->length() == 3);
3295 VisitForStackValue(args->at(0)); 3254 VisitForStackValue(args->at(0));
3296 VisitForStackValue(args->at(1)); 3255 VisitForStackValue(args->at(1));
3297 VisitForStackValue(args->at(2)); 3256 VisitForStackValue(args->at(2));
3298 __ CallStub(&stub); 3257 __ CallStub(&stub);
3299 context()->Plug(rax); 3258 context()->Plug(rax);
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after
4951 4910
4952 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4911 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4953 Assembler::target_address_at(call_target_address)); 4912 Assembler::target_address_at(call_target_address));
4954 return OSR_AFTER_STACK_CHECK; 4913 return OSR_AFTER_STACK_CHECK;
4955 } 4914 }
4956 4915
4957 4916
4958 } } // namespace v8::internal 4917 } } // namespace v8::internal
4959 4918
4960 #endif // V8_TARGET_ARCH_X64 4919 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/math.js ('K') | « src/v8.cc ('k') | src/x64/lithium-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698