| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 8 | 8 |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/heap.h" | 10 #include "src/heap.h" |
| 11 #include "src/macro-assembler.h" | 11 #include "src/macro-assembler.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 | 16 |
| 17 // ------------------------------------------------------------------------- | 17 // ------------------------------------------------------------------------- |
| 18 // Platform-specific RuntimeCallHelper functions. | 18 // Platform-specific RuntimeCallHelper functions. |
| 19 | 19 |
| 20 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { | 20 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 21 masm->EnterFrame(StackFrame::INTERNAL); | 21 masm->EnterFrame(StackFrame::INTERNAL); |
| 22 ASSERT(!masm->has_frame()); | 22 DCHECK(!masm->has_frame()); |
| 23 masm->set_has_frame(true); | 23 masm->set_has_frame(true); |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | 27 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 28 masm->LeaveFrame(StackFrame::INTERNAL); | 28 masm->LeaveFrame(StackFrame::INTERNAL); |
| 29 ASSERT(masm->has_frame()); | 29 DCHECK(masm->has_frame()); |
| 30 masm->set_has_frame(false); | 30 masm->set_has_frame(false); |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 #define __ masm. | 34 #define __ masm. |
| 35 | 35 |
| 36 | 36 |
| 37 UnaryMathFunction CreateExpFunction() { | 37 UnaryMathFunction CreateExpFunction() { |
| 38 if (!FLAG_fast_math) return &std::exp; | 38 if (!FLAG_fast_math) return &std::exp; |
| 39 size_t actual_size; | 39 size_t actual_size; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 __ pop(ebx); | 57 __ pop(ebx); |
| 58 __ pop(eax); | 58 __ pop(eax); |
| 59 __ movsd(Operand(esp, 1 * kPointerSize), result); | 59 __ movsd(Operand(esp, 1 * kPointerSize), result); |
| 60 __ fld_d(Operand(esp, 1 * kPointerSize)); | 60 __ fld_d(Operand(esp, 1 * kPointerSize)); |
| 61 __ Ret(); | 61 __ Ret(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 CodeDesc desc; | 64 CodeDesc desc; |
| 65 masm.GetCode(&desc); | 65 masm.GetCode(&desc); |
| 66 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 66 DCHECK(!RelocInfo::RequiresRelocation(desc)); |
| 67 | 67 |
| 68 CpuFeatures::FlushICache(buffer, actual_size); | 68 CpuFeatures::FlushICache(buffer, actual_size); |
| 69 base::OS::ProtectCode(buffer, actual_size); | 69 base::OS::ProtectCode(buffer, actual_size); |
| 70 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 70 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 UnaryMathFunction CreateSqrtFunction() { | 74 UnaryMathFunction CreateSqrtFunction() { |
| 75 size_t actual_size; | 75 size_t actual_size; |
| 76 // Allocate buffer in executable space. | 76 // Allocate buffer in executable space. |
| 77 byte* buffer = | 77 byte* buffer = |
| 78 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | 78 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 79 if (buffer == NULL) return &std::sqrt; | 79 if (buffer == NULL) return &std::sqrt; |
| 80 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 80 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 81 // esp[1 * kPointerSize]: raw double input | 81 // esp[1 * kPointerSize]: raw double input |
| 82 // esp[0 * kPointerSize]: return address | 82 // esp[0 * kPointerSize]: return address |
| 83 // Move double input into registers. | 83 // Move double input into registers. |
| 84 { | 84 { |
| 85 __ movsd(xmm0, Operand(esp, 1 * kPointerSize)); | 85 __ movsd(xmm0, Operand(esp, 1 * kPointerSize)); |
| 86 __ sqrtsd(xmm0, xmm0); | 86 __ sqrtsd(xmm0, xmm0); |
| 87 __ movsd(Operand(esp, 1 * kPointerSize), xmm0); | 87 __ movsd(Operand(esp, 1 * kPointerSize), xmm0); |
| 88 // Load result into floating point register as return value. | 88 // Load result into floating point register as return value. |
| 89 __ fld_d(Operand(esp, 1 * kPointerSize)); | 89 __ fld_d(Operand(esp, 1 * kPointerSize)); |
| 90 __ Ret(); | 90 __ Ret(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 CodeDesc desc; | 93 CodeDesc desc; |
| 94 masm.GetCode(&desc); | 94 masm.GetCode(&desc); |
| 95 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 95 DCHECK(!RelocInfo::RequiresRelocation(desc)); |
| 96 | 96 |
| 97 CpuFeatures::FlushICache(buffer, actual_size); | 97 CpuFeatures::FlushICache(buffer, actual_size); |
| 98 base::OS::ProtectCode(buffer, actual_size); | 98 base::OS::ProtectCode(buffer, actual_size); |
| 99 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 99 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 // Helper functions for CreateMemMoveFunction. | 103 // Helper functions for CreateMemMoveFunction. |
| 104 #undef __ | 104 #undef __ |
| 105 #define __ ACCESS_MASM(masm) | 105 #define __ ACCESS_MASM(masm) |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 497 } |
| 498 __ mov(eax, Operand(count, times_4, conv.address(&small_handlers))); | 498 __ mov(eax, Operand(count, times_4, conv.address(&small_handlers))); |
| 499 __ jmp(eax); | 499 __ jmp(eax); |
| 500 } | 500 } |
| 501 | 501 |
| 502 __ bind(&pop_and_return); | 502 __ bind(&pop_and_return); |
| 503 MemMoveEmitPopAndReturn(&masm); | 503 MemMoveEmitPopAndReturn(&masm); |
| 504 | 504 |
| 505 CodeDesc desc; | 505 CodeDesc desc; |
| 506 masm.GetCode(&desc); | 506 masm.GetCode(&desc); |
| 507 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 507 DCHECK(!RelocInfo::RequiresRelocation(desc)); |
| 508 CpuFeatures::FlushICache(buffer, actual_size); | 508 CpuFeatures::FlushICache(buffer, actual_size); |
| 509 base::OS::ProtectCode(buffer, actual_size); | 509 base::OS::ProtectCode(buffer, actual_size); |
| 510 // TODO(jkummerow): It would be nice to register this code creation event | 510 // TODO(jkummerow): It would be nice to register this code creation event |
| 511 // with the PROFILE / GDBJIT system. | 511 // with the PROFILE / GDBJIT system. |
| 512 return FUNCTION_CAST<MemMoveFunction>(buffer); | 512 return FUNCTION_CAST<MemMoveFunction>(buffer); |
| 513 } | 513 } |
| 514 | 514 |
| 515 | 515 |
| 516 #undef __ | 516 #undef __ |
| 517 | 517 |
| 518 // ------------------------------------------------------------------------- | 518 // ------------------------------------------------------------------------- |
| 519 // Code generators | 519 // Code generators |
| 520 | 520 |
| 521 #define __ ACCESS_MASM(masm) | 521 #define __ ACCESS_MASM(masm) |
| 522 | 522 |
| 523 | 523 |
| 524 void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( | 524 void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 525 MacroAssembler* masm, | 525 MacroAssembler* masm, |
| 526 Register receiver, | 526 Register receiver, |
| 527 Register key, | 527 Register key, |
| 528 Register value, | 528 Register value, |
| 529 Register target_map, | 529 Register target_map, |
| 530 AllocationSiteMode mode, | 530 AllocationSiteMode mode, |
| 531 Label* allocation_memento_found) { | 531 Label* allocation_memento_found) { |
| 532 Register scratch = edi; | 532 Register scratch = edi; |
| 533 ASSERT(!AreAliased(receiver, key, value, target_map, scratch)); | 533 DCHECK(!AreAliased(receiver, key, value, target_map, scratch)); |
| 534 | 534 |
| 535 if (mode == TRACK_ALLOCATION_SITE) { | 535 if (mode == TRACK_ALLOCATION_SITE) { |
| 536 ASSERT(allocation_memento_found != NULL); | 536 DCHECK(allocation_memento_found != NULL); |
| 537 __ JumpIfJSArrayHasAllocationMemento( | 537 __ JumpIfJSArrayHasAllocationMemento( |
| 538 receiver, scratch, allocation_memento_found); | 538 receiver, scratch, allocation_memento_found); |
| 539 } | 539 } |
| 540 | 540 |
| 541 // Set transitioned map. | 541 // Set transitioned map. |
| 542 __ mov(FieldOperand(receiver, HeapObject::kMapOffset), target_map); | 542 __ mov(FieldOperand(receiver, HeapObject::kMapOffset), target_map); |
| 543 __ RecordWriteField(receiver, | 543 __ RecordWriteField(receiver, |
| 544 HeapObject::kMapOffset, | 544 HeapObject::kMapOffset, |
| 545 target_map, | 545 target_map, |
| 546 scratch, | 546 scratch, |
| 547 kDontSaveFPRegs, | 547 kDontSaveFPRegs, |
| 548 EMIT_REMEMBERED_SET, | 548 EMIT_REMEMBERED_SET, |
| 549 OMIT_SMI_CHECK); | 549 OMIT_SMI_CHECK); |
| 550 } | 550 } |
| 551 | 551 |
| 552 | 552 |
| 553 void ElementsTransitionGenerator::GenerateSmiToDouble( | 553 void ElementsTransitionGenerator::GenerateSmiToDouble( |
| 554 MacroAssembler* masm, | 554 MacroAssembler* masm, |
| 555 Register receiver, | 555 Register receiver, |
| 556 Register key, | 556 Register key, |
| 557 Register value, | 557 Register value, |
| 558 Register target_map, | 558 Register target_map, |
| 559 AllocationSiteMode mode, | 559 AllocationSiteMode mode, |
| 560 Label* fail) { | 560 Label* fail) { |
| 561 // Return address is on the stack. | 561 // Return address is on the stack. |
| 562 ASSERT(receiver.is(edx)); | 562 DCHECK(receiver.is(edx)); |
| 563 ASSERT(key.is(ecx)); | 563 DCHECK(key.is(ecx)); |
| 564 ASSERT(value.is(eax)); | 564 DCHECK(value.is(eax)); |
| 565 ASSERT(target_map.is(ebx)); | 565 DCHECK(target_map.is(ebx)); |
| 566 | 566 |
| 567 Label loop, entry, convert_hole, gc_required, only_change_map; | 567 Label loop, entry, convert_hole, gc_required, only_change_map; |
| 568 | 568 |
| 569 if (mode == TRACK_ALLOCATION_SITE) { | 569 if (mode == TRACK_ALLOCATION_SITE) { |
| 570 __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); | 570 __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); |
| 571 } | 571 } |
| 572 | 572 |
| 573 // Check for empty arrays, which only require a map transition and no changes | 573 // Check for empty arrays, which only require a map transition and no changes |
| 574 // to the backing store. | 574 // to the backing store. |
| 575 __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); | 575 __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 678 |
| 679 void ElementsTransitionGenerator::GenerateDoubleToObject( | 679 void ElementsTransitionGenerator::GenerateDoubleToObject( |
| 680 MacroAssembler* masm, | 680 MacroAssembler* masm, |
| 681 Register receiver, | 681 Register receiver, |
| 682 Register key, | 682 Register key, |
| 683 Register value, | 683 Register value, |
| 684 Register target_map, | 684 Register target_map, |
| 685 AllocationSiteMode mode, | 685 AllocationSiteMode mode, |
| 686 Label* fail) { | 686 Label* fail) { |
| 687 // Return address is on the stack. | 687 // Return address is on the stack. |
| 688 ASSERT(receiver.is(edx)); | 688 DCHECK(receiver.is(edx)); |
| 689 ASSERT(key.is(ecx)); | 689 DCHECK(key.is(ecx)); |
| 690 ASSERT(value.is(eax)); | 690 DCHECK(value.is(eax)); |
| 691 ASSERT(target_map.is(ebx)); | 691 DCHECK(target_map.is(ebx)); |
| 692 | 692 |
| 693 Label loop, entry, convert_hole, gc_required, only_change_map, success; | 693 Label loop, entry, convert_hole, gc_required, only_change_map, success; |
| 694 | 694 |
| 695 if (mode == TRACK_ALLOCATION_SITE) { | 695 if (mode == TRACK_ALLOCATION_SITE) { |
| 696 __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); | 696 __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); |
| 697 } | 697 } |
| 698 | 698 |
| 699 // Check for empty arrays, which only require a map transition and no changes | 699 // Check for empty arrays, which only require a map transition and no changes |
| 700 // to the backing store. | 700 // to the backing store. |
| 701 __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); | 701 __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 return Operand::StaticVariable(ExternalReference::math_exp_constants(index)); | 917 return Operand::StaticVariable(ExternalReference::math_exp_constants(index)); |
| 918 } | 918 } |
| 919 | 919 |
| 920 | 920 |
| 921 void MathExpGenerator::EmitMathExp(MacroAssembler* masm, | 921 void MathExpGenerator::EmitMathExp(MacroAssembler* masm, |
| 922 XMMRegister input, | 922 XMMRegister input, |
| 923 XMMRegister result, | 923 XMMRegister result, |
| 924 XMMRegister double_scratch, | 924 XMMRegister double_scratch, |
| 925 Register temp1, | 925 Register temp1, |
| 926 Register temp2) { | 926 Register temp2) { |
| 927 ASSERT(!input.is(double_scratch)); | 927 DCHECK(!input.is(double_scratch)); |
| 928 ASSERT(!input.is(result)); | 928 DCHECK(!input.is(result)); |
| 929 ASSERT(!result.is(double_scratch)); | 929 DCHECK(!result.is(double_scratch)); |
| 930 ASSERT(!temp1.is(temp2)); | 930 DCHECK(!temp1.is(temp2)); |
| 931 ASSERT(ExternalReference::math_exp_constants(0).address() != NULL); | 931 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); |
| 932 | 932 |
| 933 Label done; | 933 Label done; |
| 934 | 934 |
| 935 __ movsd(double_scratch, ExpConstant(0)); | 935 __ movsd(double_scratch, ExpConstant(0)); |
| 936 __ xorpd(result, result); | 936 __ xorpd(result, result); |
| 937 __ ucomisd(double_scratch, input); | 937 __ ucomisd(double_scratch, input); |
| 938 __ j(above_equal, &done); | 938 __ j(above_equal, &done); |
| 939 __ ucomisd(input, ExpConstant(1)); | 939 __ ucomisd(input, ExpConstant(1)); |
| 940 __ movsd(result, ExpConstant(2)); | 940 __ movsd(result, ExpConstant(2)); |
| 941 __ j(above_equal, &done); | 941 __ j(above_equal, &done); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 966 temp2, times_8, ExternalReference::math_exp_log_table())); | 966 temp2, times_8, ExternalReference::math_exp_log_table())); |
| 967 __ orps(input, double_scratch); | 967 __ orps(input, double_scratch); |
| 968 __ mulsd(result, input); | 968 __ mulsd(result, input); |
| 969 __ bind(&done); | 969 __ bind(&done); |
| 970 } | 970 } |
| 971 | 971 |
| 972 #undef __ | 972 #undef __ |
| 973 | 973 |
| 974 | 974 |
| 975 CodeAgingHelper::CodeAgingHelper() { | 975 CodeAgingHelper::CodeAgingHelper() { |
| 976 ASSERT(young_sequence_.length() == kNoCodeAgeSequenceLength); | 976 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); |
| 977 CodePatcher patcher(young_sequence_.start(), young_sequence_.length()); | 977 CodePatcher patcher(young_sequence_.start(), young_sequence_.length()); |
| 978 patcher.masm()->push(ebp); | 978 patcher.masm()->push(ebp); |
| 979 patcher.masm()->mov(ebp, esp); | 979 patcher.masm()->mov(ebp, esp); |
| 980 patcher.masm()->push(esi); | 980 patcher.masm()->push(esi); |
| 981 patcher.masm()->push(edi); | 981 patcher.masm()->push(edi); |
| 982 } | 982 } |
| 983 | 983 |
| 984 | 984 |
| 985 #ifdef DEBUG | 985 #ifdef DEBUG |
| 986 bool CodeAgingHelper::IsOld(byte* candidate) const { | 986 bool CodeAgingHelper::IsOld(byte* candidate) const { |
| 987 return *candidate == kCallOpcode; | 987 return *candidate == kCallOpcode; |
| 988 } | 988 } |
| 989 #endif | 989 #endif |
| 990 | 990 |
| 991 | 991 |
| 992 bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) { | 992 bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) { |
| 993 bool result = isolate->code_aging_helper()->IsYoung(sequence); | 993 bool result = isolate->code_aging_helper()->IsYoung(sequence); |
| 994 ASSERT(result || isolate->code_aging_helper()->IsOld(sequence)); | 994 DCHECK(result || isolate->code_aging_helper()->IsOld(sequence)); |
| 995 return result; | 995 return result; |
| 996 } | 996 } |
| 997 | 997 |
| 998 | 998 |
| 999 void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, | 999 void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, |
| 1000 MarkingParity* parity) { | 1000 MarkingParity* parity) { |
| 1001 if (IsYoungSequence(isolate, sequence)) { | 1001 if (IsYoungSequence(isolate, sequence)) { |
| 1002 *age = kNoAgeCodeAge; | 1002 *age = kNoAgeCodeAge; |
| 1003 *parity = NO_MARKING_PARITY; | 1003 *parity = NO_MARKING_PARITY; |
| 1004 } else { | 1004 } else { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1023 Code* stub = GetCodeAgeStub(isolate, age, parity); | 1023 Code* stub = GetCodeAgeStub(isolate, age, parity); |
| 1024 CodePatcher patcher(sequence, young_length); | 1024 CodePatcher patcher(sequence, young_length); |
| 1025 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); | 1025 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); |
| 1026 } | 1026 } |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 | 1029 |
| 1030 } } // namespace v8::internal | 1030 } } // namespace v8::internal |
| 1031 | 1031 |
| 1032 #endif // V8_TARGET_ARCH_IA32 | 1032 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |