| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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; |
| 40 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); | 40 byte* buffer = |
| 41 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 41 if (buffer == NULL) return &std::exp; | 42 if (buffer == NULL) return &std::exp; |
| 42 ExternalReference::InitializeMathExpData(); | 43 ExternalReference::InitializeMathExpData(); |
| 43 | 44 |
| 44 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 45 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 45 // esp[1 * kPointerSize]: raw double input | 46 // esp[1 * kPointerSize]: raw double input |
| 46 // esp[0 * kPointerSize]: return address | 47 // esp[0 * kPointerSize]: return address |
| 47 { | 48 { |
| 48 XMMRegister input = xmm1; | 49 XMMRegister input = xmm1; |
| 49 XMMRegister result = xmm2; | 50 XMMRegister result = xmm2; |
| 50 __ movsd(input, Operand(esp, 1 * kPointerSize)); | 51 __ movsd(input, Operand(esp, 1 * kPointerSize)); |
| 51 __ push(eax); | 52 __ push(eax); |
| 52 __ push(ebx); | 53 __ push(ebx); |
| 53 | 54 |
| 54 MathExpGenerator::EmitMathExp(&masm, input, result, xmm0, eax, ebx); | 55 MathExpGenerator::EmitMathExp(&masm, input, result, xmm0, eax, ebx); |
| 55 | 56 |
| 56 __ pop(ebx); | 57 __ pop(ebx); |
| 57 __ pop(eax); | 58 __ pop(eax); |
| 58 __ movsd(Operand(esp, 1 * kPointerSize), result); | 59 __ movsd(Operand(esp, 1 * kPointerSize), result); |
| 59 __ fld_d(Operand(esp, 1 * kPointerSize)); | 60 __ fld_d(Operand(esp, 1 * kPointerSize)); |
| 60 __ Ret(); | 61 __ Ret(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 CodeDesc desc; | 64 CodeDesc desc; |
| 64 masm.GetCode(&desc); | 65 masm.GetCode(&desc); |
| 65 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 66 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
| 66 | 67 |
| 67 CPU::FlushICache(buffer, actual_size); | 68 CpuFeatures::FlushICache(buffer, actual_size); |
| 68 OS::ProtectCode(buffer, actual_size); | 69 base::OS::ProtectCode(buffer, actual_size); |
| 69 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 70 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
| 70 } | 71 } |
| 71 | 72 |
| 72 | 73 |
| 73 UnaryMathFunction CreateSqrtFunction() { | 74 UnaryMathFunction CreateSqrtFunction() { |
| 74 size_t actual_size; | 75 size_t actual_size; |
| 75 // Allocate buffer in executable space. | 76 // Allocate buffer in executable space. |
| 76 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 77 byte* buffer = |
| 77 &actual_size, | 78 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 78 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 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
| 96 | 96 |
| 97 CPU::FlushICache(buffer, actual_size); | 97 CpuFeatures::FlushICache(buffer, actual_size); |
| 98 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) |
| 106 | 106 |
| 107 enum Direction { FORWARD, BACKWARD }; | 107 enum Direction { FORWARD, BACKWARD }; |
| 108 enum Alignment { MOVE_ALIGNED, MOVE_UNALIGNED }; | 108 enum Alignment { MOVE_ALIGNED, MOVE_UNALIGNED }; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return reinterpret_cast<int32_t>(buffer_) + l->pos(); | 182 return reinterpret_cast<int32_t>(buffer_) + l->pos(); |
| 183 } | 183 } |
| 184 private: | 184 private: |
| 185 byte* buffer_; | 185 byte* buffer_; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 | 188 |
| 189 MemMoveFunction CreateMemMoveFunction() { | 189 MemMoveFunction CreateMemMoveFunction() { |
| 190 size_t actual_size; | 190 size_t actual_size; |
| 191 // Allocate buffer in executable space. | 191 // Allocate buffer in executable space. |
| 192 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); | 192 byte* buffer = |
| 193 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 193 if (buffer == NULL) return NULL; | 194 if (buffer == NULL) return NULL; |
| 194 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 195 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 195 LabelConverter conv(buffer); | 196 LabelConverter conv(buffer); |
| 196 | 197 |
| 197 // Generated code is put into a fixed, unmovable buffer, and not into | 198 // Generated code is put into a fixed, unmovable buffer, and not into |
| 198 // the V8 heap. We can't, and don't, refer to any relocatable addresses | 199 // the V8 heap. We can't, and don't, refer to any relocatable addresses |
| 199 // (e.g. the JavaScript nan-object). | 200 // (e.g. the JavaScript nan-object). |
| 200 | 201 |
| 201 // 32-bit C declaration function calls pass arguments on stack. | 202 // 32-bit C declaration function calls pass arguments on stack. |
| 202 | 203 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 __ mov(eax, Operand(count, times_4, conv.address(&small_handlers))); | 498 __ mov(eax, Operand(count, times_4, conv.address(&small_handlers))); |
| 498 __ jmp(eax); | 499 __ jmp(eax); |
| 499 } | 500 } |
| 500 | 501 |
| 501 __ bind(&pop_and_return); | 502 __ bind(&pop_and_return); |
| 502 MemMoveEmitPopAndReturn(&masm); | 503 MemMoveEmitPopAndReturn(&masm); |
| 503 | 504 |
| 504 CodeDesc desc; | 505 CodeDesc desc; |
| 505 masm.GetCode(&desc); | 506 masm.GetCode(&desc); |
| 506 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 507 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
| 507 CPU::FlushICache(buffer, actual_size); | 508 CpuFeatures::FlushICache(buffer, actual_size); |
| 508 OS::ProtectCode(buffer, actual_size); | 509 base::OS::ProtectCode(buffer, actual_size); |
| 509 // 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 |
| 510 // with the PROFILE / GDBJIT system. | 511 // with the PROFILE / GDBJIT system. |
| 511 return FUNCTION_CAST<MemMoveFunction>(buffer); | 512 return FUNCTION_CAST<MemMoveFunction>(buffer); |
| 512 } | 513 } |
| 513 | 514 |
| 514 | 515 |
| 515 #undef __ | 516 #undef __ |
| 516 | 517 |
| 517 // ------------------------------------------------------------------------- | 518 // ------------------------------------------------------------------------- |
| 518 // Code generators | 519 // Code generators |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 | 1001 |
| 1001 void Code::PatchPlatformCodeAge(Isolate* isolate, | 1002 void Code::PatchPlatformCodeAge(Isolate* isolate, |
| 1002 byte* sequence, | 1003 byte* sequence, |
| 1003 Code::Age age, | 1004 Code::Age age, |
| 1004 MarkingParity parity) { | 1005 MarkingParity parity) { |
| 1005 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); | 1006 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); |
| 1006 if (age == kNoAgeCodeAge) { | 1007 if (age == kNoAgeCodeAge) { |
| 1007 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); | 1008 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); |
| 1008 CPU::FlushICache(sequence, young_length); | 1009 CpuFeatures::FlushICache(sequence, young_length); |
| 1009 } else { | 1010 } else { |
| 1010 Code* stub = GetCodeAgeStub(isolate, age, parity); | 1011 Code* stub = GetCodeAgeStub(isolate, age, parity); |
| 1011 CodePatcher patcher(sequence, young_length); | 1012 CodePatcher patcher(sequence, young_length); |
| 1012 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); | 1013 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); |
| 1013 } | 1014 } |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 | 1017 |
| 1017 } } // namespace v8::internal | 1018 } } // namespace v8::internal |
| 1018 | 1019 |
| 1019 #endif // V8_TARGET_ARCH_IA32 | 1020 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |