OLD | NEW |
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 6420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6431 | 6431 |
6432 | 6432 |
6433 void CodeGenerator::GenerateRandomHeapNumber( | 6433 void CodeGenerator::GenerateRandomHeapNumber( |
6434 ZoneList<Expression*>* args) { | 6434 ZoneList<Expression*>* args) { |
6435 ASSERT(args->length() == 0); | 6435 ASSERT(args->length() == 0); |
6436 frame_->SpillAll(); | 6436 frame_->SpillAll(); |
6437 | 6437 |
6438 Label slow_allocate_heapnumber; | 6438 Label slow_allocate_heapnumber; |
6439 Label heapnumber_allocated; | 6439 Label heapnumber_allocated; |
6440 | 6440 |
6441 __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); | 6441 __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber); |
6442 __ jmp(&heapnumber_allocated); | 6442 __ jmp(&heapnumber_allocated); |
6443 | 6443 |
6444 __ bind(&slow_allocate_heapnumber); | 6444 __ bind(&slow_allocate_heapnumber); |
6445 // To allocate a heap number, and ensure that it is not a smi, we | 6445 // To allocate a heap number, and ensure that it is not a smi, we |
6446 // call the runtime function FUnaryMinus on 0, returning the double | 6446 // call the runtime function FUnaryMinus on 0, returning the double |
6447 // -0.0. A new, distinct heap number is returned each time. | 6447 // -0.0. A new, distinct heap number is returned each time. |
6448 __ push(Immediate(Smi::FromInt(0))); | 6448 __ push(Immediate(Smi::FromInt(0))); |
6449 __ CallRuntime(Runtime::kNumberUnaryMinus, 1); | 6449 __ CallRuntime(Runtime::kNumberUnaryMinus, 1); |
| 6450 __ mov(edi, eax); |
6450 | 6451 |
6451 __ bind(&heapnumber_allocated); | 6452 __ bind(&heapnumber_allocated); |
6452 | 6453 |
6453 __ PrepareCallCFunction(1, ebx); | 6454 __ PrepareCallCFunction(0, ebx); |
6454 __ mov(Operand(esp, 0), eax); | 6455 __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
6455 __ CallCFunction(ExternalReference::fill_heap_number_with_random_function(), | 6456 |
6456 1); | 6457 // Convert 32 random bits in eax to 0.(32 random bits) in a double |
| 6458 // by computing: |
| 6459 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 6460 // This is implemented on both SSE2 and FPU. |
| 6461 if (CpuFeatures::IsSupported(SSE2)) { |
| 6462 CpuFeatures::Scope fscope(SSE2); |
| 6463 __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
| 6464 __ movd(xmm1, Operand(ebx)); |
| 6465 __ movd(xmm0, Operand(eax)); |
| 6466 __ cvtss2sd(xmm1, xmm1); |
| 6467 __ pxor(xmm0, xmm1); |
| 6468 __ subsd(xmm0, xmm1); |
| 6469 __ movdbl(FieldOperand(edi, HeapNumber::kValueOffset), xmm0); |
| 6470 } else { |
| 6471 // 0x4130000000000000 is 1.0 x 2^20 as a double. |
| 6472 __ mov(FieldOperand(edi, HeapNumber::kExponentOffset), |
| 6473 Immediate(0x41300000)); |
| 6474 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax); |
| 6475 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 6476 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0)); |
| 6477 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 6478 __ fsubp(1); |
| 6479 __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 6480 } |
| 6481 __ mov(eax, edi); |
6457 | 6482 |
6458 Result result = allocator_->Allocate(eax); | 6483 Result result = allocator_->Allocate(eax); |
6459 frame_->Push(&result); | 6484 frame_->Push(&result); |
6460 } | 6485 } |
6461 | 6486 |
6462 | 6487 |
6463 void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { | 6488 void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { |
6464 ASSERT_EQ(2, args->length()); | 6489 ASSERT_EQ(2, args->length()); |
6465 | 6490 |
6466 Load(args->at(0)); | 6491 Load(args->at(0)); |
(...skipping 6194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12661 | 12686 |
12662 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) | 12687 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
12663 // tagged as a small integer. | 12688 // tagged as a small integer. |
12664 __ bind(&runtime); | 12689 __ bind(&runtime); |
12665 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); | 12690 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
12666 } | 12691 } |
12667 | 12692 |
12668 #undef __ | 12693 #undef __ |
12669 | 12694 |
12670 } } // namespace v8::internal | 12695 } } // namespace v8::internal |
OLD | NEW |