OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #if defined(V8_TARGET_ARCH_IA32) | 30 #if defined(V8_TARGET_ARCH_IA32) |
31 | 31 |
32 #include "codegen.h" | 32 #include "codegen.h" |
| 33 #include "heap.h" |
33 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 | 39 |
39 // ------------------------------------------------------------------------- | 40 // ------------------------------------------------------------------------- |
40 // Platform-specific RuntimeCallHelper functions. | 41 // Platform-specific RuntimeCallHelper functions. |
41 | 42 |
42 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { | 43 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
43 masm->EnterFrame(StackFrame::INTERNAL); | 44 masm->EnterFrame(StackFrame::INTERNAL); |
44 ASSERT(!masm->has_frame()); | 45 ASSERT(!masm->has_frame()); |
45 masm->set_has_frame(true); | 46 masm->set_has_frame(true); |
46 } | 47 } |
47 | 48 |
48 | 49 |
49 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | 50 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
50 masm->LeaveFrame(StackFrame::INTERNAL); | 51 masm->LeaveFrame(StackFrame::INTERNAL); |
51 ASSERT(masm->has_frame()); | 52 ASSERT(masm->has_frame()); |
52 masm->set_has_frame(false); | 53 masm->set_has_frame(false); |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 #define __ masm. | 57 #define __ masm. |
57 | 58 |
| 59 |
| 60 TranscendentalFunction CreateTranscendentalFunction( |
| 61 TranscendentalCache::Type type) { |
| 62 size_t actual_size; |
| 63 // Allocate buffer in executable space. |
| 64 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, |
| 65 &actual_size, |
| 66 true)); |
| 67 if (buffer == NULL) { |
| 68 // Fallback to library function if function cannot be created. |
| 69 switch (type) { |
| 70 case TranscendentalCache::SIN: return &sin; |
| 71 case TranscendentalCache::COS: return &cos; |
| 72 case TranscendentalCache::TAN: return &tan; |
| 73 case TranscendentalCache::LOG: return &log; |
| 74 default: UNIMPLEMENTED(); |
| 75 } |
| 76 } |
| 77 |
| 78 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 79 // esp[1 * kPointerSize]: raw double input |
| 80 // esp[0 * kPointerSize]: return address |
| 81 // Move double input into registers. |
| 82 __ fld_d(Operand(esp, kPointerSize)); |
| 83 __ push(ebx); |
| 84 __ push(edx); |
| 85 __ push(edi); |
| 86 __ mov(ebx, Operand(esp, kPointerSize)); |
| 87 __ mov(edx, Operand(esp, 2* kPointerSize)); |
| 88 TranscendentalCacheStub::GenerateOperation(&masm, type); |
| 89 // The return value is expected to be on ST(0) of the FPU stack. |
| 90 __ pop(edi); |
| 91 __ pop(edx); |
| 92 __ pop(ebx); |
| 93 __ Ret(); |
| 94 |
| 95 CodeDesc desc; |
| 96 masm.GetCode(&desc); |
| 97 ASSERT(desc.reloc_size == 0); |
| 98 |
| 99 CPU::FlushICache(buffer, actual_size); |
| 100 OS::ProtectCode(buffer, actual_size); |
| 101 return FUNCTION_CAST<TranscendentalFunction>(buffer); |
| 102 } |
| 103 |
| 104 |
58 static void MemCopyWrapper(void* dest, const void* src, size_t size) { | 105 static void MemCopyWrapper(void* dest, const void* src, size_t size) { |
59 memcpy(dest, src, size); | 106 memcpy(dest, src, size); |
60 } | 107 } |
61 | 108 |
62 | 109 |
63 OS::MemCopyFunction CreateMemCopyFunction() { | 110 OS::MemCopyFunction CreateMemCopyFunction() { |
64 size_t actual_size; | 111 size_t actual_size; |
65 // Allocate buffer in executable space. | 112 // Allocate buffer in executable space. |
66 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 113 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, |
67 &actual_size, | 114 &actual_size, |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 times_1, | 704 times_1, |
658 SeqAsciiString::kHeaderSize)); | 705 SeqAsciiString::kHeaderSize)); |
659 __ bind(&done); | 706 __ bind(&done); |
660 } | 707 } |
661 | 708 |
662 #undef __ | 709 #undef __ |
663 | 710 |
664 } } // namespace v8::internal | 711 } } // namespace v8::internal |
665 | 712 |
666 #endif // V8_TARGET_ARCH_IA32 | 713 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |