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" | |
34 #include "macro-assembler.h" | 33 #include "macro-assembler.h" |
35 | 34 |
36 namespace v8 { | 35 namespace v8 { |
37 namespace internal { | 36 namespace internal { |
38 | 37 |
39 | 38 |
40 // ------------------------------------------------------------------------- | 39 // ------------------------------------------------------------------------- |
41 // Platform-specific RuntimeCallHelper functions. | 40 // Platform-specific RuntimeCallHelper functions. |
42 | 41 |
43 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { | 42 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
44 masm->EnterFrame(StackFrame::INTERNAL); | 43 masm->EnterFrame(StackFrame::INTERNAL); |
45 ASSERT(!masm->has_frame()); | 44 ASSERT(!masm->has_frame()); |
46 masm->set_has_frame(true); | 45 masm->set_has_frame(true); |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | 49 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
51 masm->LeaveFrame(StackFrame::INTERNAL); | 50 masm->LeaveFrame(StackFrame::INTERNAL); |
52 ASSERT(masm->has_frame()); | 51 ASSERT(masm->has_frame()); |
53 masm->set_has_frame(false); | 52 masm->set_has_frame(false); |
54 } | 53 } |
55 | 54 |
56 | 55 |
57 #define __ masm. | 56 #define __ masm. |
58 | 57 |
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 | |
105 static void MemCopyWrapper(void* dest, const void* src, size_t size) { | 58 static void MemCopyWrapper(void* dest, const void* src, size_t size) { |
106 memcpy(dest, src, size); | 59 memcpy(dest, src, size); |
107 } | 60 } |
108 | 61 |
109 | 62 |
110 OS::MemCopyFunction CreateMemCopyFunction() { | 63 OS::MemCopyFunction CreateMemCopyFunction() { |
111 size_t actual_size; | 64 size_t actual_size; |
112 // Allocate buffer in executable space. | 65 // Allocate buffer in executable space. |
113 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 66 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, |
114 &actual_size, | 67 &actual_size, |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 times_1, | 657 times_1, |
705 SeqAsciiString::kHeaderSize)); | 658 SeqAsciiString::kHeaderSize)); |
706 __ bind(&done); | 659 __ bind(&done); |
707 } | 660 } |
708 | 661 |
709 #undef __ | 662 #undef __ |
710 | 663 |
711 } } // namespace v8::internal | 664 } } // namespace v8::internal |
712 | 665 |
713 #endif // V8_TARGET_ARCH_IA32 | 666 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |