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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 masm->set_has_frame(false); | 51 masm->set_has_frame(false); |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 #define __ masm. | 55 #define __ masm. |
56 | 56 |
57 | 57 |
58 UnaryMathFunction CreateTranscendentalFunction(TranscendentalCache::Type type) { | 58 UnaryMathFunction CreateTranscendentalFunction(TranscendentalCache::Type type) { |
59 size_t actual_size; | 59 size_t actual_size; |
60 // Allocate buffer in executable space. | 60 // Allocate buffer in executable space. |
61 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 61 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion( |
62 &actual_size, | 62 1 * KB, &actual_size, VirtualMemory::EXECUTABLE)); |
63 true)); | |
64 if (buffer == NULL) { | 63 if (buffer == NULL) { |
65 // Fallback to library function if function cannot be created. | 64 // Fallback to library function if function cannot be created. |
66 switch (type) { | 65 switch (type) { |
67 case TranscendentalCache::SIN: return &sin; | 66 case TranscendentalCache::SIN: return &sin; |
68 case TranscendentalCache::COS: return &cos; | 67 case TranscendentalCache::COS: return &cos; |
69 case TranscendentalCache::TAN: return &tan; | 68 case TranscendentalCache::TAN: return &tan; |
70 case TranscendentalCache::LOG: return &log; | 69 case TranscendentalCache::LOG: return &log; |
71 default: UNIMPLEMENTED(); | 70 default: UNIMPLEMENTED(); |
72 } | 71 } |
73 } | 72 } |
(...skipping 13 matching lines...) Expand all Loading... |
87 __ movq(xmm0, rbx); | 86 __ movq(xmm0, rbx); |
88 __ pop(rdi); | 87 __ pop(rdi); |
89 __ pop(rbx); | 88 __ pop(rbx); |
90 __ Ret(); | 89 __ Ret(); |
91 | 90 |
92 CodeDesc desc; | 91 CodeDesc desc; |
93 masm.GetCode(&desc); | 92 masm.GetCode(&desc); |
94 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 93 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
95 | 94 |
96 CPU::FlushICache(buffer, actual_size); | 95 CPU::FlushICache(buffer, actual_size); |
97 OS::ProtectCode(buffer, actual_size); | 96 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size); |
| 97 ASSERT(result); |
| 98 USE(result); |
98 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 99 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
99 } | 100 } |
100 | 101 |
101 | 102 |
102 UnaryMathFunction CreateExpFunction() { | 103 UnaryMathFunction CreateExpFunction() { |
103 if (!FLAG_fast_math) return &exp; | 104 if (!FLAG_fast_math) return &exp; |
104 size_t actual_size; | 105 size_t actual_size; |
105 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); | 106 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion( |
| 107 1 * KB, &actual_size, VirtualMemory::EXECUTABLE)); |
106 if (buffer == NULL) return &exp; | 108 if (buffer == NULL) return &exp; |
107 ExternalReference::InitializeMathExpData(); | 109 ExternalReference::InitializeMathExpData(); |
108 | 110 |
109 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 111 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
110 // xmm0: raw double input. | 112 // xmm0: raw double input. |
111 XMMRegister input = xmm0; | 113 XMMRegister input = xmm0; |
112 XMMRegister result = xmm1; | 114 XMMRegister result = xmm1; |
113 __ push(rax); | 115 __ push(rax); |
114 __ push(rbx); | 116 __ push(rbx); |
115 | 117 |
116 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); | 118 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); |
117 | 119 |
118 __ pop(rbx); | 120 __ pop(rbx); |
119 __ pop(rax); | 121 __ pop(rax); |
120 __ movsd(xmm0, result); | 122 __ movsd(xmm0, result); |
121 __ Ret(); | 123 __ Ret(); |
122 | 124 |
123 CodeDesc desc; | 125 CodeDesc desc; |
124 masm.GetCode(&desc); | 126 masm.GetCode(&desc); |
125 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 127 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
126 | 128 |
127 CPU::FlushICache(buffer, actual_size); | 129 CPU::FlushICache(buffer, actual_size); |
128 OS::ProtectCode(buffer, actual_size); | 130 bool ok = VirtualMemory::WriteProtectRegion(buffer, actual_size); |
| 131 ASSERT(ok); |
| 132 USE(ok); |
129 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 133 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
130 } | 134 } |
131 | 135 |
132 | 136 |
133 UnaryMathFunction CreateSqrtFunction() { | 137 UnaryMathFunction CreateSqrtFunction() { |
134 size_t actual_size; | 138 size_t actual_size; |
135 // Allocate buffer in executable space. | 139 // Allocate buffer in executable space. |
136 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 140 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion( |
137 &actual_size, | 141 1 * KB, &actual_size, VirtualMemory::EXECUTABLE)); |
138 true)); | |
139 if (buffer == NULL) return &sqrt; | 142 if (buffer == NULL) return &sqrt; |
140 | 143 |
141 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 144 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
142 // xmm0: raw double input. | 145 // xmm0: raw double input. |
143 // Move double input into registers. | 146 // Move double input into registers. |
144 __ sqrtsd(xmm0, xmm0); | 147 __ sqrtsd(xmm0, xmm0); |
145 __ Ret(); | 148 __ Ret(); |
146 | 149 |
147 CodeDesc desc; | 150 CodeDesc desc; |
148 masm.GetCode(&desc); | 151 masm.GetCode(&desc); |
149 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 152 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
150 | 153 |
151 CPU::FlushICache(buffer, actual_size); | 154 CPU::FlushICache(buffer, actual_size); |
152 OS::ProtectCode(buffer, actual_size); | 155 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size); |
| 156 ASSERT(result); |
| 157 USE(result); |
153 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 158 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
154 } | 159 } |
155 | 160 |
156 | 161 |
157 #ifdef _WIN64 | 162 #ifdef _WIN64 |
158 typedef double (*ModuloFunction)(double, double); | 163 typedef double (*ModuloFunction)(double, double); |
159 // Define custom fmod implementation. | 164 // Define custom fmod implementation. |
160 ModuloFunction CreateModuloFunction() { | 165 ModuloFunction CreateModuloFunction() { |
161 size_t actual_size; | 166 size_t actual_size; |
162 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 167 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Label clear_exceptions; | 235 Label clear_exceptions; |
231 __ testb(rax, Immediate(0x3f /* Any Exception*/)); | 236 __ testb(rax, Immediate(0x3f /* Any Exception*/)); |
232 __ j(not_zero, &clear_exceptions); | 237 __ j(not_zero, &clear_exceptions); |
233 __ ret(0); | 238 __ ret(0); |
234 __ bind(&clear_exceptions); | 239 __ bind(&clear_exceptions); |
235 __ fnclex(); | 240 __ fnclex(); |
236 __ ret(0); | 241 __ ret(0); |
237 | 242 |
238 CodeDesc desc; | 243 CodeDesc desc; |
239 masm.GetCode(&desc); | 244 masm.GetCode(&desc); |
240 OS::ProtectCode(buffer, actual_size); | 245 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size); |
| 246 ASSERT(result); |
| 247 USE(result); |
241 // Call the function from C++ through this pointer. | 248 // Call the function from C++ through this pointer. |
242 return FUNCTION_CAST<ModuloFunction>(buffer); | 249 return FUNCTION_CAST<ModuloFunction>(buffer); |
243 } | 250 } |
244 | 251 |
245 #endif | 252 #endif |
246 | 253 |
247 #undef __ | 254 #undef __ |
248 | 255 |
249 // ------------------------------------------------------------------------- | 256 // ------------------------------------------------------------------------- |
250 // Code generators | 257 // Code generators |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. | 769 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. |
763 return Operand(base_reg_, argument_count_reg_, times_pointer_size, | 770 return Operand(base_reg_, argument_count_reg_, times_pointer_size, |
764 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); | 771 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); |
765 } | 772 } |
766 } | 773 } |
767 | 774 |
768 | 775 |
769 } } // namespace v8::internal | 776 } } // namespace v8::internal |
770 | 777 |
771 #endif // V8_TARGET_ARCH_X64 | 778 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |