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

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

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments only 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
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.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 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 3280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 VisitForStackValue(args->at(1)); 3291 VisitForStackValue(args->at(1));
3292 VisitForStackValue(args->at(2)); 3292 VisitForStackValue(args->at(2));
3293 __ CallRuntime(Runtime::kLog, 2); 3293 __ CallRuntime(Runtime::kLog, 2);
3294 } 3294 }
3295 // Finally, we're expected to leave a value on the top of the stack. 3295 // Finally, we're expected to leave a value on the top of the stack.
3296 __ mov(eax, isolate()->factory()->undefined_value()); 3296 __ mov(eax, isolate()->factory()->undefined_value());
3297 context()->Plug(eax); 3297 context()->Plug(eax);
3298 } 3298 }
3299 3299
3300 3300
3301 void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
3302 ASSERT(expr->arguments()->length() == 0);
3303
3304 Label slow_allocate_heapnumber;
3305 Label heapnumber_allocated;
3306
3307 __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber);
3308 __ jmp(&heapnumber_allocated);
3309
3310 __ bind(&slow_allocate_heapnumber);
3311 // Allocate a heap number.
3312 __ CallRuntime(Runtime::kNumberAlloc, 0);
3313 __ mov(edi, eax);
3314
3315 __ bind(&heapnumber_allocated);
3316
3317 __ PrepareCallCFunction(1, ebx);
3318 __ mov(eax, ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX));
3319 __ mov(eax, FieldOperand(eax, GlobalObject::kNativeContextOffset));
3320 __ mov(Operand(esp, 0), eax);
3321 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3322
3323 // Convert 32 random bits in eax to 0.(32 random bits) in a double
3324 // by computing:
3325 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
3326 // This is implemented on both SSE2 and FPU.
3327 if (CpuFeatures::IsSupported(SSE2)) {
3328 CpuFeatureScope fscope(masm(), SSE2);
3329 __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
3330 __ movd(xmm1, ebx);
3331 __ movd(xmm0, eax);
3332 __ cvtss2sd(xmm1, xmm1);
3333 __ xorps(xmm0, xmm1);
3334 __ subsd(xmm0, xmm1);
3335 __ movsd(FieldOperand(edi, HeapNumber::kValueOffset), xmm0);
3336 } else {
3337 // 0x4130000000000000 is 1.0 x 2^20 as a double.
3338 __ mov(FieldOperand(edi, HeapNumber::kExponentOffset),
3339 Immediate(0x41300000));
3340 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax);
3341 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
3342 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0));
3343 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
3344 __ fsubp(1);
3345 __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset));
3346 }
3347 __ mov(eax, edi);
3348 context()->Plug(eax);
3349 }
3350
3351
3352 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { 3301 void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
3353 // Load the arguments on the stack and call the stub. 3302 // Load the arguments on the stack and call the stub.
3354 SubStringStub stub; 3303 SubStringStub stub;
3355 ZoneList<Expression*>* args = expr->arguments(); 3304 ZoneList<Expression*>* args = expr->arguments();
3356 ASSERT(args->length() == 3); 3305 ASSERT(args->length() == 3);
3357 VisitForStackValue(args->at(0)); 3306 VisitForStackValue(args->at(0));
3358 VisitForStackValue(args->at(1)); 3307 VisitForStackValue(args->at(1));
3359 VisitForStackValue(args->at(2)); 3308 VisitForStackValue(args->at(2));
3360 __ CallStub(&stub); 3309 __ CallStub(&stub);
3361 context()->Plug(eax); 3310 context()->Plug(eax);
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
4968 4917
4969 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4918 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4970 Assembler::target_address_at(call_target_address)); 4919 Assembler::target_address_at(call_target_address));
4971 return OSR_AFTER_STACK_CHECK; 4920 return OSR_AFTER_STACK_CHECK;
4972 } 4921 }
4973 4922
4974 4923
4975 } } // namespace v8::internal 4924 } } // namespace v8::internal
4976 4925
4977 #endif // V8_TARGET_ARCH_IA32 4926 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698