blob: 4014aba10ebc902bb6855635453f38d3300c6f00 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/arm/codegen-arm.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#if V8_TARGET_ARCH_ARM
Leon Clarkef7060e22010-06-03 12:02:55 +01008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/arm/simulator-arm.h"
10#include "src/codegen.h"
11#include "src/macro-assembler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000012
13namespace v8 {
14namespace internal {
15
Ben Murdoch3ef787d2012-04-12 10:51:47 +010016
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017#define __ masm.
18
19
20#if defined(USE_SIMULATOR)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000021byte* fast_exp_arm_machine_code = nullptr;
22double fast_exp_simulator(double x, Isolate* isolate) {
23 return Simulator::current(isolate)
24 ->CallFPReturnsDouble(fast_exp_arm_machine_code, x, 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025}
26#endif
27
28
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 size_t actual_size;
31 byte* buffer =
32 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 if (buffer == nullptr) return nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 ExternalReference::InitializeMathExpData();
35
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size),
37 CodeObjectRequired::kNo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038
39 {
40 DwVfpRegister input = d0;
41 DwVfpRegister result = d1;
42 DwVfpRegister double_scratch1 = d2;
43 DwVfpRegister double_scratch2 = d3;
44 Register temp1 = r4;
45 Register temp2 = r5;
46 Register temp3 = r6;
47
48 if (masm.use_eabi_hardfloat()) {
49 // Input value is in d0 anyway, nothing to do.
50 } else {
51 __ vmov(input, r0, r1);
52 }
53 __ Push(temp3, temp2, temp1);
54 MathExpGenerator::EmitMathExp(
55 &masm, input, result, double_scratch1, double_scratch2,
56 temp1, temp2, temp3);
57 __ Pop(temp3, temp2, temp1);
58 if (masm.use_eabi_hardfloat()) {
59 __ vmov(d0, result);
60 } else {
61 __ vmov(r0, r1, result);
62 }
63 __ Ret();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010064 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065
66 CodeDesc desc;
67 masm.GetCode(&desc);
68 DCHECK(!RelocInfo::RequiresRelocation(desc));
69
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 Assembler::FlushICache(isolate, buffer, actual_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 base::OS::ProtectCode(buffer, actual_size);
72
73#if !defined(USE_SIMULATOR)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074 return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075#else
76 fast_exp_arm_machine_code = buffer;
77 return &fast_exp_simulator;
78#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010079}
80
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081#if defined(V8_HOST_ARCH_ARM)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000082MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
83 MemCopyUint8Function stub) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000084#if defined(USE_SIMULATOR)
85 return stub;
86#else
87 if (!CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) return stub;
88 size_t actual_size;
89 byte* buffer =
90 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000091 if (buffer == nullptr) return stub;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000092
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size),
94 CodeObjectRequired::kNo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095
96 Register dest = r0;
97 Register src = r1;
98 Register chars = r2;
99 Register temp1 = r3;
100 Label less_4;
101
102 if (CpuFeatures::IsSupported(NEON)) {
103 Label loop, less_256, less_128, less_64, less_32, _16_or_less, _8_or_less;
104 Label size_less_than_8;
105 __ pld(MemOperand(src, 0));
106
107 __ cmp(chars, Operand(8));
108 __ b(lt, &size_less_than_8);
109 __ cmp(chars, Operand(32));
110 __ b(lt, &less_32);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100111 if (CpuFeatures::dcache_line_size() == 32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112 __ pld(MemOperand(src, 32));
113 }
114 __ cmp(chars, Operand(64));
115 __ b(lt, &less_64);
116 __ pld(MemOperand(src, 64));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100117 if (CpuFeatures::dcache_line_size() == 32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118 __ pld(MemOperand(src, 96));
119 }
120 __ cmp(chars, Operand(128));
121 __ b(lt, &less_128);
122 __ pld(MemOperand(src, 128));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100123 if (CpuFeatures::dcache_line_size() == 32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 __ pld(MemOperand(src, 160));
125 }
126 __ pld(MemOperand(src, 192));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100127 if (CpuFeatures::dcache_line_size() == 32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 __ pld(MemOperand(src, 224));
129 }
130 __ cmp(chars, Operand(256));
131 __ b(lt, &less_256);
132 __ sub(chars, chars, Operand(256));
133
134 __ bind(&loop);
135 __ pld(MemOperand(src, 256));
136 __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100137 if (CpuFeatures::dcache_line_size() == 32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 __ pld(MemOperand(src, 256));
139 }
140 __ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex));
141 __ sub(chars, chars, Operand(64), SetCC);
142 __ vst1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(dest, PostIndex));
143 __ vst1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(dest, PostIndex));
144 __ b(ge, &loop);
145 __ add(chars, chars, Operand(256));
146
147 __ bind(&less_256);
148 __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
149 __ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex));
150 __ sub(chars, chars, Operand(128));
151 __ vst1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(dest, PostIndex));
152 __ vst1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(dest, PostIndex));
153 __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
154 __ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex));
155 __ vst1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(dest, PostIndex));
156 __ vst1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(dest, PostIndex));
157 __ cmp(chars, Operand(64));
158 __ b(lt, &less_64);
159
160 __ bind(&less_128);
161 __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
162 __ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex));
163 __ sub(chars, chars, Operand(64));
164 __ vst1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(dest, PostIndex));
165 __ vst1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(dest, PostIndex));
166
167 __ bind(&less_64);
168 __ cmp(chars, Operand(32));
169 __ b(lt, &less_32);
170 __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
171 __ vst1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(dest, PostIndex));
172 __ sub(chars, chars, Operand(32));
173
174 __ bind(&less_32);
175 __ cmp(chars, Operand(16));
176 __ b(le, &_16_or_less);
177 __ vld1(Neon8, NeonListOperand(d0, 2), NeonMemOperand(src, PostIndex));
178 __ vst1(Neon8, NeonListOperand(d0, 2), NeonMemOperand(dest, PostIndex));
179 __ sub(chars, chars, Operand(16));
180
181 __ bind(&_16_or_less);
182 __ cmp(chars, Operand(8));
183 __ b(le, &_8_or_less);
184 __ vld1(Neon8, NeonListOperand(d0), NeonMemOperand(src, PostIndex));
185 __ vst1(Neon8, NeonListOperand(d0), NeonMemOperand(dest, PostIndex));
186 __ sub(chars, chars, Operand(8));
187
188 // Do a last copy which may overlap with the previous copy (up to 8 bytes).
189 __ bind(&_8_or_less);
190 __ rsb(chars, chars, Operand(8));
191 __ sub(src, src, Operand(chars));
192 __ sub(dest, dest, Operand(chars));
193 __ vld1(Neon8, NeonListOperand(d0), NeonMemOperand(src));
194 __ vst1(Neon8, NeonListOperand(d0), NeonMemOperand(dest));
195
196 __ Ret();
197
198 __ bind(&size_less_than_8);
199
200 __ bic(temp1, chars, Operand(0x3), SetCC);
201 __ b(&less_4, eq);
202 __ ldr(temp1, MemOperand(src, 4, PostIndex));
203 __ str(temp1, MemOperand(dest, 4, PostIndex));
204 } else {
205 Register temp2 = ip;
206 Label loop;
207
208 __ bic(temp2, chars, Operand(0x3), SetCC);
209 __ b(&less_4, eq);
210 __ add(temp2, dest, temp2);
211
212 __ bind(&loop);
213 __ ldr(temp1, MemOperand(src, 4, PostIndex));
214 __ str(temp1, MemOperand(dest, 4, PostIndex));
215 __ cmp(dest, temp2);
216 __ b(&loop, ne);
217 }
218
219 __ bind(&less_4);
220 __ mov(chars, Operand(chars, LSL, 31), SetCC);
221 // bit0 => Z (ne), bit1 => C (cs)
222 __ ldrh(temp1, MemOperand(src, 2, PostIndex), cs);
223 __ strh(temp1, MemOperand(dest, 2, PostIndex), cs);
224 __ ldrb(temp1, MemOperand(src), ne);
225 __ strb(temp1, MemOperand(dest), ne);
226 __ Ret();
227
228 CodeDesc desc;
229 masm.GetCode(&desc);
230 DCHECK(!RelocInfo::RequiresRelocation(desc));
231
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000232 Assembler::FlushICache(isolate, buffer, actual_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 base::OS::ProtectCode(buffer, actual_size);
234 return FUNCTION_CAST<MemCopyUint8Function>(buffer);
235#endif
236}
237
238
239// Convert 8 to 16. The number of character to copy must be at least 8.
240MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000241 Isolate* isolate, MemCopyUint16Uint8Function stub) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242#if defined(USE_SIMULATOR)
243 return stub;
244#else
245 if (!CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) return stub;
246 size_t actual_size;
247 byte* buffer =
248 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000249 if (buffer == nullptr) return stub;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000251 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size),
252 CodeObjectRequired::kNo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253
254 Register dest = r0;
255 Register src = r1;
256 Register chars = r2;
257 if (CpuFeatures::IsSupported(NEON)) {
258 Register temp = r3;
259 Label loop;
260
261 __ bic(temp, chars, Operand(0x7));
262 __ sub(chars, chars, Operand(temp));
263 __ add(temp, dest, Operand(temp, LSL, 1));
264
265 __ bind(&loop);
266 __ vld1(Neon8, NeonListOperand(d0), NeonMemOperand(src, PostIndex));
267 __ vmovl(NeonU8, q0, d0);
268 __ vst1(Neon16, NeonListOperand(d0, 2), NeonMemOperand(dest, PostIndex));
269 __ cmp(dest, temp);
270 __ b(&loop, ne);
271
272 // Do a last copy which will overlap with the previous copy (1 to 8 bytes).
273 __ rsb(chars, chars, Operand(8));
274 __ sub(src, src, Operand(chars));
275 __ sub(dest, dest, Operand(chars, LSL, 1));
276 __ vld1(Neon8, NeonListOperand(d0), NeonMemOperand(src));
277 __ vmovl(NeonU8, q0, d0);
278 __ vst1(Neon16, NeonListOperand(d0, 2), NeonMemOperand(dest));
279 __ Ret();
280 } else {
281 Register temp1 = r3;
282 Register temp2 = ip;
283 Register temp3 = lr;
284 Register temp4 = r4;
285 Label loop;
286 Label not_two;
287
288 __ Push(lr, r4);
289 __ bic(temp2, chars, Operand(0x3));
290 __ add(temp2, dest, Operand(temp2, LSL, 1));
291
292 __ bind(&loop);
293 __ ldr(temp1, MemOperand(src, 4, PostIndex));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400294 __ uxtb16(temp3, temp1);
295 __ uxtb16(temp4, temp1, 8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296 __ pkhbt(temp1, temp3, Operand(temp4, LSL, 16));
297 __ str(temp1, MemOperand(dest));
298 __ pkhtb(temp1, temp4, Operand(temp3, ASR, 16));
299 __ str(temp1, MemOperand(dest, 4));
300 __ add(dest, dest, Operand(8));
301 __ cmp(dest, temp2);
302 __ b(&loop, ne);
303
304 __ mov(chars, Operand(chars, LSL, 31), SetCC); // bit0 => ne, bit1 => cs
305 __ b(&not_two, cc);
306 __ ldrh(temp1, MemOperand(src, 2, PostIndex));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400307 __ uxtb(temp3, temp1, 8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000308 __ mov(temp3, Operand(temp3, LSL, 16));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400309 __ uxtab(temp3, temp3, temp1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 __ str(temp3, MemOperand(dest, 4, PostIndex));
311 __ bind(&not_two);
312 __ ldrb(temp1, MemOperand(src), ne);
313 __ strh(temp1, MemOperand(dest), ne);
314 __ Pop(pc, r4);
315 }
316
317 CodeDesc desc;
318 masm.GetCode(&desc);
319
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000320 Assembler::FlushICache(isolate, buffer, actual_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321 base::OS::ProtectCode(buffer, actual_size);
322
323 return FUNCTION_CAST<MemCopyUint16Uint8Function>(buffer);
324#endif
325}
326#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100327
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000328UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329#if defined(USE_SIMULATOR)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000330 return nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331#else
332 size_t actual_size;
333 byte* buffer =
334 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000335 if (buffer == nullptr) return nullptr;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000336
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000337 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size),
338 CodeObjectRequired::kNo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000339
340 __ MovFromFloatParameter(d0);
341 __ vsqrt(d0, d0);
342 __ MovToFloatResult(d0);
343 __ Ret();
344
345 CodeDesc desc;
346 masm.GetCode(&desc);
347 DCHECK(!RelocInfo::RequiresRelocation(desc));
348
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000349 Assembler::FlushICache(isolate, buffer, actual_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 base::OS::ProtectCode(buffer, actual_size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000351 return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000352#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100353}
354
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000355#undef __
356
357
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100358// -------------------------------------------------------------------------
359// Platform-specific RuntimeCallHelper functions.
360
Ben Murdochb0fe1622011-05-05 13:52:32 +0100361void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100362 masm->EnterFrame(StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363 DCHECK(!masm->has_frame());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100364 masm->set_has_frame(true);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100365}
366
367
Ben Murdochb0fe1622011-05-05 13:52:32 +0100368void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100369 masm->LeaveFrame(StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 DCHECK(masm->has_frame());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100371 masm->set_has_frame(false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000372}
373
374
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100375// -------------------------------------------------------------------------
376// Code generators
377
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378#define __ ACCESS_MASM(masm)
379
380void ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
381 MacroAssembler* masm,
382 Register receiver,
383 Register key,
384 Register value,
385 Register target_map,
386 AllocationSiteMode mode,
387 Label* allocation_memento_found) {
388 Register scratch_elements = r4;
389 DCHECK(!AreAliased(receiver, key, value, target_map,
390 scratch_elements));
391
392 if (mode == TRACK_ALLOCATION_SITE) {
393 DCHECK(allocation_memento_found != NULL);
394 __ JumpIfJSArrayHasAllocationMemento(
395 receiver, scratch_elements, allocation_memento_found);
396 }
397
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100398 // Set transitioned map.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000399 __ str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
400 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100401 HeapObject::kMapOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000402 target_map,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100403 r9,
404 kLRHasNotBeenSaved,
405 kDontSaveFPRegs,
406 EMIT_REMEMBERED_SET,
407 OMIT_SMI_CHECK);
408}
409
410
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411void ElementsTransitionGenerator::GenerateSmiToDouble(
412 MacroAssembler* masm,
413 Register receiver,
414 Register key,
415 Register value,
416 Register target_map,
417 AllocationSiteMode mode,
418 Label* fail) {
419 // Register lr contains the return address.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100420 Label loop, entry, convert_hole, gc_required, only_change_map, done;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000421 Register elements = r4;
422 Register length = r5;
423 Register array = r6;
424 Register array_end = array;
425
426 // target_map parameter can be clobbered.
427 Register scratch1 = target_map;
428 Register scratch2 = r9;
429
430 // Verify input registers don't conflict with locals.
431 DCHECK(!AreAliased(receiver, key, value, target_map,
432 elements, length, array, scratch2));
433
434 if (mode == TRACK_ALLOCATION_SITE) {
435 __ JumpIfJSArrayHasAllocationMemento(receiver, elements, fail);
436 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100437
438 // Check for empty arrays, which only require a map transition and no changes
439 // to the backing store.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000440 __ ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
441 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100442 __ b(eq, &only_change_map);
443
444 __ push(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000445 __ ldr(length, FieldMemOperand(elements, FixedArray::kLengthOffset));
446 // length: number of elements (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100447
448 // Allocate new FixedDoubleArray.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000449 // Use lr as a temporary register.
450 __ mov(lr, Operand(length, LSL, 2));
451 __ add(lr, lr, Operand(FixedDoubleArray::kHeaderSize));
452 __ Allocate(lr, array, elements, scratch2, &gc_required, DOUBLE_ALIGNMENT);
Ben Murdochc5610432016-08-08 18:44:38 +0100453 __ sub(array, array, Operand(kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454 // array: destination FixedDoubleArray, not tagged as heap object.
455 __ ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
456 // r4: source FixedArray.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100457
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000458 // Set destination FixedDoubleArray's length and map.
459 __ LoadRoot(scratch2, Heap::kFixedDoubleArrayMapRootIndex);
460 __ str(length, MemOperand(array, FixedDoubleArray::kLengthOffset));
461 // Update receiver's map.
462 __ str(scratch2, MemOperand(array, HeapObject::kMapOffset));
463
464 __ str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
465 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100466 HeapObject::kMapOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000467 target_map,
468 scratch2,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100469 kLRHasBeenSaved,
470 kDontSaveFPRegs,
471 OMIT_REMEMBERED_SET,
472 OMIT_SMI_CHECK);
473 // Replace receiver's backing store with newly created FixedDoubleArray.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000474 __ add(scratch1, array, Operand(kHeapObjectTag));
475 __ str(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset));
476 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100477 JSObject::kElementsOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000478 scratch1,
479 scratch2,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100480 kLRHasBeenSaved,
481 kDontSaveFPRegs,
482 EMIT_REMEMBERED_SET,
483 OMIT_SMI_CHECK);
484
485 // Prepare for conversion loop.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000486 __ add(scratch1, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
487 __ add(scratch2, array, Operand(FixedDoubleArray::kHeaderSize));
488 __ add(array_end, scratch2, Operand(length, LSL, 2));
489
490 // Repurpose registers no longer in use.
491 Register hole_lower = elements;
492 Register hole_upper = length;
493
494 __ mov(hole_lower, Operand(kHoleNanLower32));
495 __ mov(hole_upper, Operand(kHoleNanUpper32));
496 // scratch1: begin of source FixedArray element fields, not tagged
497 // hole_lower: kHoleNanLower32
498 // hole_upper: kHoleNanUpper32
499 // array_end: end of destination FixedDoubleArray, not tagged
500 // scratch2: begin of FixedDoubleArray element fields, not tagged
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100501
502 __ b(&entry);
503
504 __ bind(&only_change_map);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000505 __ str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
506 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100507 HeapObject::kMapOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000508 target_map,
509 scratch2,
510 kLRHasNotBeenSaved,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100511 kDontSaveFPRegs,
512 OMIT_REMEMBERED_SET,
513 OMIT_SMI_CHECK);
514 __ b(&done);
515
516 // Call into runtime if GC is required.
517 __ bind(&gc_required);
518 __ pop(lr);
519 __ b(fail);
520
521 // Convert and copy elements.
522 __ bind(&loop);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000523 __ ldr(lr, MemOperand(scratch1, 4, PostIndex));
524 // lr: current element
525 __ UntagAndJumpIfNotSmi(lr, lr, &convert_hole);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100526
527 // Normal smi, convert to double and store.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000528 __ vmov(s0, lr);
529 __ vcvt_f64_s32(d0, s0);
530 __ vstr(d0, scratch2, 0);
531 __ add(scratch2, scratch2, Operand(8));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100532 __ b(&entry);
533
534 // Hole found, store the-hole NaN.
535 __ bind(&convert_hole);
536 if (FLAG_debug_code) {
537 // Restore a "smi-untagged" heap object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000538 __ SmiTag(lr);
539 __ orr(lr, lr, Operand(1));
540 __ CompareRoot(lr, Heap::kTheHoleValueRootIndex);
541 __ Assert(eq, kObjectFoundInSmiOnlyArray);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100542 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000543 __ Strd(hole_lower, hole_upper, MemOperand(scratch2, 8, PostIndex));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100544
545 __ bind(&entry);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 __ cmp(scratch2, array_end);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100547 __ b(lt, &loop);
548
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100549 __ pop(lr);
550 __ bind(&done);
551}
552
553
554void ElementsTransitionGenerator::GenerateDoubleToObject(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000555 MacroAssembler* masm,
556 Register receiver,
557 Register key,
558 Register value,
559 Register target_map,
560 AllocationSiteMode mode,
561 Label* fail) {
562 // Register lr contains the return address.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100563 Label entry, loop, convert_hole, gc_required, only_change_map;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000564 Register elements = r4;
565 Register array = r6;
566 Register length = r5;
567 Register scratch = r9;
568
569 // Verify input registers don't conflict with locals.
570 DCHECK(!AreAliased(receiver, key, value, target_map,
571 elements, array, length, scratch));
572
573 if (mode == TRACK_ALLOCATION_SITE) {
574 __ JumpIfJSArrayHasAllocationMemento(receiver, elements, fail);
575 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100576
577 // Check for empty arrays, which only require a map transition and no changes
578 // to the backing store.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000579 __ ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
580 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100581 __ b(eq, &only_change_map);
582
583 __ push(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000584 __ Push(target_map, receiver, key, value);
585 __ ldr(length, FieldMemOperand(elements, FixedArray::kLengthOffset));
586 // elements: source FixedDoubleArray
587 // length: number of elements (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100588
589 // Allocate new FixedArray.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000590 // Re-use value and target_map registers, as they have been saved on the
591 // stack.
592 Register array_size = value;
593 Register allocate_scratch = target_map;
594 __ mov(array_size, Operand(FixedDoubleArray::kHeaderSize));
595 __ add(array_size, array_size, Operand(length, LSL, 1));
596 __ Allocate(array_size, array, allocate_scratch, scratch, &gc_required,
597 NO_ALLOCATION_FLAGS);
Ben Murdochc5610432016-08-08 18:44:38 +0100598 // array: destination FixedArray, tagged as heap object
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100599 // Set destination FixedDoubleArray's length and map.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000600 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
Ben Murdochc5610432016-08-08 18:44:38 +0100601 __ str(length, FieldMemOperand(array, FixedDoubleArray::kLengthOffset));
602 __ str(scratch, FieldMemOperand(array, HeapObject::kMapOffset));
603
604 __ sub(array, array, Operand(kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100605
606 // Prepare for conversion loop.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000607 Register src_elements = elements;
608 Register dst_elements = target_map;
609 Register dst_end = length;
610 Register heap_number_map = scratch;
611 __ add(src_elements, elements,
612 Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag + 4));
613 __ add(dst_elements, array, Operand(FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000614 __ add(dst_end, dst_elements, Operand(length, LSL, 1));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400615
616 // Allocating heap numbers in the loop below can fail and cause a jump to
617 // gc_required. We can't leave a partly initialized FixedArray behind,
618 // so pessimistically fill it with holes now.
619 Label initialization_loop, initialization_loop_entry;
620 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
621 __ b(&initialization_loop_entry);
622 __ bind(&initialization_loop);
623 __ str(scratch, MemOperand(dst_elements, kPointerSize, PostIndex));
624 __ bind(&initialization_loop_entry);
625 __ cmp(dst_elements, dst_end);
626 __ b(lt, &initialization_loop);
627
628 __ add(dst_elements, array, Operand(FixedArray::kHeaderSize));
629 __ add(array, array, Operand(kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000630 __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
631 // Using offsetted addresses in src_elements to fully take advantage of
632 // post-indexing.
633 // dst_elements: begin of destination FixedArray element fields, not tagged
634 // src_elements: begin of source FixedDoubleArray element fields,
635 // not tagged, +4
636 // dst_end: end of destination FixedArray, not tagged
637 // array: destination FixedArray
638 // heap_number_map: heap number map
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639 __ b(&entry);
640
641 // Call into runtime if GC is required.
642 __ bind(&gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000643 __ Pop(target_map, receiver, key, value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100644 __ pop(lr);
645 __ b(fail);
646
647 __ bind(&loop);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648 Register upper_bits = key;
649 __ ldr(upper_bits, MemOperand(src_elements, 8, PostIndex));
650 // upper_bits: current element's upper 32 bit
651 // src_elements: address of next element's upper 32 bit
652 __ cmp(upper_bits, Operand(kHoleNanUpper32));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100653 __ b(eq, &convert_hole);
654
655 // Non-hole double, copy value into a heap number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 Register heap_number = receiver;
657 Register scratch2 = value;
658 __ AllocateHeapNumber(heap_number, scratch2, lr, heap_number_map,
659 &gc_required);
660 // heap_number: new heap number
661 __ ldr(scratch2, MemOperand(src_elements, 12, NegOffset));
662 __ Strd(scratch2, upper_bits,
663 FieldMemOperand(heap_number, HeapNumber::kValueOffset));
664 __ mov(scratch2, dst_elements);
665 __ str(heap_number, MemOperand(dst_elements, 4, PostIndex));
666 __ RecordWrite(array,
667 scratch2,
668 heap_number,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100669 kLRHasBeenSaved,
670 kDontSaveFPRegs,
671 EMIT_REMEMBERED_SET,
672 OMIT_SMI_CHECK);
673 __ b(&entry);
674
675 // Replace the-hole NaN with the-hole pointer.
676 __ bind(&convert_hole);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000677 __ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex);
678 __ str(scratch2, MemOperand(dst_elements, 4, PostIndex));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100679
680 __ bind(&entry);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000681 __ cmp(dst_elements, dst_end);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100682 __ b(lt, &loop);
683
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 __ Pop(target_map, receiver, key, value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100685 // Replace receiver's backing store with newly created and filled FixedArray.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000686 __ str(array, FieldMemOperand(receiver, JSObject::kElementsOffset));
687 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100688 JSObject::kElementsOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000689 array,
690 scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100691 kLRHasBeenSaved,
692 kDontSaveFPRegs,
693 EMIT_REMEMBERED_SET,
694 OMIT_SMI_CHECK);
695 __ pop(lr);
696
697 __ bind(&only_change_map);
698 // Update receiver's map.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000699 __ str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
700 __ RecordWriteField(receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100701 HeapObject::kMapOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000702 target_map,
703 scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100704 kLRHasNotBeenSaved,
705 kDontSaveFPRegs,
706 OMIT_REMEMBERED_SET,
707 OMIT_SMI_CHECK);
708}
709
710
711void StringCharLoadGenerator::Generate(MacroAssembler* masm,
712 Register string,
713 Register index,
714 Register result,
715 Label* call_runtime) {
716 // Fetch the instance type of the receiver into result register.
717 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
718 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
719
720 // We need special handling for indirect strings.
721 Label check_sequential;
722 __ tst(result, Operand(kIsIndirectStringMask));
723 __ b(eq, &check_sequential);
724
725 // Dispatch on the indirect string shape: slice or cons.
726 Label cons_string;
727 __ tst(result, Operand(kSlicedNotConsMask));
728 __ b(eq, &cons_string);
729
730 // Handle slices.
731 Label indirect_string_loaded;
732 __ ldr(result, FieldMemOperand(string, SlicedString::kOffsetOffset));
733 __ ldr(string, FieldMemOperand(string, SlicedString::kParentOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000734 __ add(index, index, Operand::SmiUntag(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100735 __ jmp(&indirect_string_loaded);
736
737 // Handle cons strings.
738 // Check whether the right hand side is the empty string (i.e. if
739 // this is really a flat string in a cons string). If that is not
740 // the case we would rather go to the runtime system now to flatten
741 // the string.
742 __ bind(&cons_string);
743 __ ldr(result, FieldMemOperand(string, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000744 __ CompareRoot(result, Heap::kempty_stringRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100745 __ b(ne, call_runtime);
746 // Get the first of the two strings and load its instance type.
747 __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset));
748
749 __ bind(&indirect_string_loaded);
750 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
751 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
752
753 // Distinguish sequential and external strings. Only these two string
754 // representations can reach here (slices and flat cons strings have been
755 // reduced to the underlying sequential or external string).
756 Label external_string, check_encoding;
757 __ bind(&check_sequential);
758 STATIC_ASSERT(kSeqStringTag == 0);
759 __ tst(result, Operand(kStringRepresentationMask));
760 __ b(ne, &external_string);
761
762 // Prepare sequential strings
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000763 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100764 __ add(string,
765 string,
766 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
767 __ jmp(&check_encoding);
768
769 // Handle external strings.
770 __ bind(&external_string);
771 if (FLAG_debug_code) {
772 // Assert that we do not have a cons or slice (indirect strings) here.
773 // Sequential strings have already been ruled out.
774 __ tst(result, Operand(kIsIndirectStringMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000775 __ Assert(eq, kExternalStringExpectedButNotFound);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100776 }
777 // Rule out short external strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000778 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100779 __ tst(result, Operand(kShortExternalStringMask));
780 __ b(ne, call_runtime);
781 __ ldr(string, FieldMemOperand(string, ExternalString::kResourceDataOffset));
782
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000783 Label one_byte, done;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100784 __ bind(&check_encoding);
785 STATIC_ASSERT(kTwoByteStringTag == 0);
786 __ tst(result, Operand(kStringEncodingMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000787 __ b(ne, &one_byte);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100788 // Two-byte string.
789 __ ldrh(result, MemOperand(string, index, LSL, 1));
790 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791 __ bind(&one_byte);
792 // One-byte string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100793 __ ldrb(result, MemOperand(string, index));
794 __ bind(&done);
795}
796
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797
798static MemOperand ExpConstant(int index, Register base) {
799 return MemOperand(base, index * kDoubleSize);
800}
801
802
803void MathExpGenerator::EmitMathExp(MacroAssembler* masm,
804 DwVfpRegister input,
805 DwVfpRegister result,
806 DwVfpRegister double_scratch1,
807 DwVfpRegister double_scratch2,
808 Register temp1,
809 Register temp2,
810 Register temp3) {
811 DCHECK(!input.is(result));
812 DCHECK(!input.is(double_scratch1));
813 DCHECK(!input.is(double_scratch2));
814 DCHECK(!result.is(double_scratch1));
815 DCHECK(!result.is(double_scratch2));
816 DCHECK(!double_scratch1.is(double_scratch2));
817 DCHECK(!temp1.is(temp2));
818 DCHECK(!temp1.is(temp3));
819 DCHECK(!temp2.is(temp3));
820 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL);
821 DCHECK(!masm->serializer_enabled()); // External references not serializable.
822
823 Label zero, infinity, done;
824
825 __ mov(temp3, Operand(ExternalReference::math_exp_constants(0)));
826
827 __ vldr(double_scratch1, ExpConstant(0, temp3));
828 __ VFPCompareAndSetFlags(double_scratch1, input);
829 __ b(ge, &zero);
830
831 __ vldr(double_scratch2, ExpConstant(1, temp3));
832 __ VFPCompareAndSetFlags(input, double_scratch2);
833 __ b(ge, &infinity);
834
835 __ vldr(double_scratch1, ExpConstant(3, temp3));
836 __ vldr(result, ExpConstant(4, temp3));
837 __ vmul(double_scratch1, double_scratch1, input);
838 __ vadd(double_scratch1, double_scratch1, result);
839 __ VmovLow(temp2, double_scratch1);
840 __ vsub(double_scratch1, double_scratch1, result);
841 __ vldr(result, ExpConstant(6, temp3));
842 __ vldr(double_scratch2, ExpConstant(5, temp3));
843 __ vmul(double_scratch1, double_scratch1, double_scratch2);
844 __ vsub(double_scratch1, double_scratch1, input);
845 __ vsub(result, result, double_scratch1);
846 __ vmul(double_scratch2, double_scratch1, double_scratch1);
847 __ vmul(result, result, double_scratch2);
848 __ vldr(double_scratch2, ExpConstant(7, temp3));
849 __ vmul(result, result, double_scratch2);
850 __ vsub(result, result, double_scratch1);
851 // Mov 1 in double_scratch2 as math_exp_constants_array[8] == 1.
852 DCHECK(*reinterpret_cast<double*>
853 (ExternalReference::math_exp_constants(8).address()) == 1);
854 __ vmov(double_scratch2, 1);
855 __ vadd(result, result, double_scratch2);
856 __ mov(temp1, Operand(temp2, LSR, 11));
857 __ Ubfx(temp2, temp2, 0, 11);
858 __ add(temp1, temp1, Operand(0x3ff));
859
860 // Must not call ExpConstant() after overwriting temp3!
861 __ mov(temp3, Operand(ExternalReference::math_exp_log_table()));
862 __ add(temp3, temp3, Operand(temp2, LSL, 3));
863 __ ldm(ia, temp3, temp2.bit() | temp3.bit());
864 // The first word is loaded is the lower number register.
865 if (temp2.code() < temp3.code()) {
866 __ orr(temp1, temp3, Operand(temp1, LSL, 20));
867 __ vmov(double_scratch1, temp2, temp1);
868 } else {
869 __ orr(temp1, temp2, Operand(temp1, LSL, 20));
870 __ vmov(double_scratch1, temp3, temp1);
871 }
872 __ vmul(result, result, double_scratch1);
873 __ b(&done);
874
875 __ bind(&zero);
876 __ vmov(result, kDoubleRegZero);
877 __ b(&done);
878
879 __ bind(&infinity);
880 __ vldr(result, ExpConstant(2, temp3));
881
882 __ bind(&done);
883}
884
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100885#undef __
886
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000887#ifdef DEBUG
888// add(r0, pc, Operand(-8))
889static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008;
890#endif
891
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000892CodeAgingHelper::CodeAgingHelper(Isolate* isolate) {
893 USE(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000894 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength);
895 // Since patcher is a large object, allocate it dynamically when needed,
896 // to avoid overloading the stack in stress conditions.
897 // DONT_FLUSH is used because the CodeAgingHelper is initialized early in
898 // the process, before ARM simulator ICache is setup.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000899 base::SmartPointer<CodePatcher> patcher(
900 new CodePatcher(isolate, young_sequence_.start(),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901 young_sequence_.length() / Assembler::kInstrSize,
902 CodePatcher::DONT_FLUSH));
903 PredictableCodeSizeScope scope(patcher->masm(), young_sequence_.length());
Ben Murdochda12d292016-06-02 14:46:10 +0100904 patcher->masm()->PushStandardFrame(r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 patcher->masm()->nop(ip.code());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000906}
907
908
909#ifdef DEBUG
910bool CodeAgingHelper::IsOld(byte* candidate) const {
911 return Memory::uint32_at(candidate) == kCodeAgePatchFirstInstruction;
912}
913#endif
914
915
916bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) {
917 bool result = isolate->code_aging_helper()->IsYoung(sequence);
918 DCHECK(result || isolate->code_aging_helper()->IsOld(sequence));
919 return result;
920}
921
922
923void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age,
924 MarkingParity* parity) {
925 if (IsYoungSequence(isolate, sequence)) {
926 *age = kNoAgeCodeAge;
927 *parity = NO_MARKING_PARITY;
928 } else {
929 Address target_address = Memory::Address_at(
930 sequence + (kNoCodeAgeSequenceLength - Assembler::kInstrSize));
931 Code* stub = GetCodeFromTargetAddress(target_address);
932 GetCodeAgeAndParity(stub, age, parity);
933 }
934}
935
936
937void Code::PatchPlatformCodeAge(Isolate* isolate,
938 byte* sequence,
939 Code::Age age,
940 MarkingParity parity) {
941 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length();
942 if (age == kNoAgeCodeAge) {
943 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 Assembler::FlushICache(isolate, sequence, young_length);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000945 } else {
946 Code* stub = GetCodeAgeStub(isolate, age, parity);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000947 CodePatcher patcher(isolate, sequence,
948 young_length / Assembler::kInstrSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000949 patcher.masm()->add(r0, pc, Operand(-8));
950 patcher.masm()->ldr(pc, MemOperand(pc, -4));
951 patcher.masm()->emit_code_stub_address(stub);
952 }
953}
954
955
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000956} // namespace internal
957} // namespace v8
Leon Clarkef7060e22010-06-03 12:02:55 +0100958
959#endif // V8_TARGET_ARCH_ARM