blob: cda6e5b6c0c8e5ec5ad8b8aa707aa7ebfcbfa635 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/v8.h"
6
7#if V8_TARGET_ARCH_ARM64
8
9#include "src/arm64/simulator-arm64.h"
10#include "src/codegen.h"
11#include "src/macro-assembler.h"
12
13namespace v8 {
14namespace internal {
15
16#define __ ACCESS_MASM(masm)
17
18#if defined(USE_SIMULATOR)
19byte* fast_exp_arm64_machine_code = NULL;
20double fast_exp_simulator(double x) {
21 Simulator * simulator = Simulator::current(Isolate::Current());
22 Simulator::CallArgument args[] = {
23 Simulator::CallArgument(x),
24 Simulator::CallArgument::End()
25 };
26 return simulator->CallDouble(fast_exp_arm64_machine_code, args);
27}
28#endif
29
30
31UnaryMathFunction CreateExpFunction() {
32 if (!FLAG_fast_math) return &std::exp;
33
34 // Use the Math.exp implemetation in MathExpGenerator::EmitMathExp() to create
35 // an AAPCS64-compliant exp() function. This will be faster than the C
36 // library's exp() function, but probably less accurate.
37 size_t actual_size;
38 byte* buffer =
39 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
40 if (buffer == NULL) return &std::exp;
41
42 ExternalReference::InitializeMathExpData();
43 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
44 masm.SetStackPointer(csp);
45
46 // The argument will be in d0 on entry.
47 DoubleRegister input = d0;
48 // Use other caller-saved registers for all other values.
49 DoubleRegister result = d1;
50 DoubleRegister double_temp1 = d2;
51 DoubleRegister double_temp2 = d3;
52 Register temp1 = x10;
53 Register temp2 = x11;
54 Register temp3 = x12;
55
56 MathExpGenerator::EmitMathExp(&masm, input, result,
57 double_temp1, double_temp2,
58 temp1, temp2, temp3);
59 // Move the result to the return register.
60 masm.Fmov(d0, result);
61 masm.Ret();
62
63 CodeDesc desc;
64 masm.GetCode(&desc);
65 DCHECK(!RelocInfo::RequiresRelocation(desc));
66
67 CpuFeatures::FlushICache(buffer, actual_size);
68 base::OS::ProtectCode(buffer, actual_size);
69
70#if !defined(USE_SIMULATOR)
71 return FUNCTION_CAST<UnaryMathFunction>(buffer);
72#else
73 fast_exp_arm64_machine_code = buffer;
74 return &fast_exp_simulator;
75#endif
76}
77
78
79UnaryMathFunction CreateSqrtFunction() {
80 return &std::sqrt;
81}
82
83
84// -------------------------------------------------------------------------
85// Platform-specific RuntimeCallHelper functions.
86
87void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const {
88 masm->EnterFrame(StackFrame::INTERNAL);
89 DCHECK(!masm->has_frame());
90 masm->set_has_frame(true);
91}
92
93
94void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
95 masm->LeaveFrame(StackFrame::INTERNAL);
96 DCHECK(masm->has_frame());
97 masm->set_has_frame(false);
98}
99
100
101// -------------------------------------------------------------------------
102// Code generators
103
104void ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
105 MacroAssembler* masm,
106 Register receiver,
107 Register key,
108 Register value,
109 Register target_map,
110 AllocationSiteMode mode,
111 Label* allocation_memento_found) {
112 ASM_LOCATION(
113 "ElementsTransitionGenerator::GenerateMapChangeElementsTransition");
114 DCHECK(!AreAliased(receiver, key, value, target_map));
115
116 if (mode == TRACK_ALLOCATION_SITE) {
117 DCHECK(allocation_memento_found != NULL);
118 __ JumpIfJSArrayHasAllocationMemento(receiver, x10, x11,
119 allocation_memento_found);
120 }
121
122 // Set transitioned map.
123 __ Str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
124 __ RecordWriteField(receiver,
125 HeapObject::kMapOffset,
126 target_map,
127 x10,
128 kLRHasNotBeenSaved,
129 kDontSaveFPRegs,
130 EMIT_REMEMBERED_SET,
131 OMIT_SMI_CHECK);
132}
133
134
135void ElementsTransitionGenerator::GenerateSmiToDouble(
136 MacroAssembler* masm,
137 Register receiver,
138 Register key,
139 Register value,
140 Register target_map,
141 AllocationSiteMode mode,
142 Label* fail) {
143 ASM_LOCATION("ElementsTransitionGenerator::GenerateSmiToDouble");
144 Label gc_required, only_change_map;
145 Register elements = x4;
146 Register length = x5;
147 Register array_size = x6;
148 Register array = x7;
149
150 Register scratch = x6;
151
152 // Verify input registers don't conflict with locals.
153 DCHECK(!AreAliased(receiver, key, value, target_map,
154 elements, length, array_size, array));
155
156 if (mode == TRACK_ALLOCATION_SITE) {
157 __ JumpIfJSArrayHasAllocationMemento(receiver, x10, x11, fail);
158 }
159
160 // Check for empty arrays, which only require a map transition and no changes
161 // to the backing store.
162 __ Ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
163 __ JumpIfRoot(elements, Heap::kEmptyFixedArrayRootIndex, &only_change_map);
164
165 __ Push(lr);
166 __ Ldrsw(length, UntagSmiFieldMemOperand(elements,
167 FixedArray::kLengthOffset));
168
169 // Allocate new FixedDoubleArray.
170 __ Lsl(array_size, length, kDoubleSizeLog2);
171 __ Add(array_size, array_size, FixedDoubleArray::kHeaderSize);
172 __ Allocate(array_size, array, x10, x11, &gc_required, DOUBLE_ALIGNMENT);
173 // Register array is non-tagged heap object.
174
175 // Set the destination FixedDoubleArray's length and map.
176 Register map_root = array_size;
177 __ LoadRoot(map_root, Heap::kFixedDoubleArrayMapRootIndex);
178 __ SmiTag(x11, length);
179 __ Str(x11, MemOperand(array, FixedDoubleArray::kLengthOffset));
180 __ Str(map_root, MemOperand(array, HeapObject::kMapOffset));
181
182 __ Str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
183 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, scratch,
184 kLRHasBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
185 OMIT_SMI_CHECK);
186
187 // Replace receiver's backing store with newly created FixedDoubleArray.
188 __ Add(x10, array, kHeapObjectTag);
189 __ Str(x10, FieldMemOperand(receiver, JSObject::kElementsOffset));
190 __ RecordWriteField(receiver, JSObject::kElementsOffset, x10,
191 scratch, kLRHasBeenSaved, kDontSaveFPRegs,
192 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
193
194 // Prepare for conversion loop.
195 Register src_elements = x10;
196 Register dst_elements = x11;
197 Register dst_end = x12;
198 __ Add(src_elements, elements, FixedArray::kHeaderSize - kHeapObjectTag);
199 __ Add(dst_elements, array, FixedDoubleArray::kHeaderSize);
200 __ Add(dst_end, dst_elements, Operand(length, LSL, kDoubleSizeLog2));
201
202 FPRegister nan_d = d1;
203 __ Fmov(nan_d, rawbits_to_double(kHoleNanInt64));
204
205 Label entry, done;
206 __ B(&entry);
207
208 __ Bind(&only_change_map);
209 __ Str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
210 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, scratch,
211 kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
212 OMIT_SMI_CHECK);
213 __ B(&done);
214
215 // Call into runtime if GC is required.
216 __ Bind(&gc_required);
217 __ Pop(lr);
218 __ B(fail);
219
220 // Iterate over the array, copying and coverting smis to doubles. If an
221 // element is non-smi, write a hole to the destination.
222 {
223 Label loop;
224 __ Bind(&loop);
225 __ Ldr(x13, MemOperand(src_elements, kPointerSize, PostIndex));
226 __ SmiUntagToDouble(d0, x13, kSpeculativeUntag);
227 __ Tst(x13, kSmiTagMask);
228 __ Fcsel(d0, d0, nan_d, eq);
229 __ Str(d0, MemOperand(dst_elements, kDoubleSize, PostIndex));
230
231 __ Bind(&entry);
232 __ Cmp(dst_elements, dst_end);
233 __ B(lt, &loop);
234 }
235
236 __ Pop(lr);
237 __ Bind(&done);
238}
239
240
241void ElementsTransitionGenerator::GenerateDoubleToObject(
242 MacroAssembler* masm,
243 Register receiver,
244 Register key,
245 Register value,
246 Register target_map,
247 AllocationSiteMode mode,
248 Label* fail) {
249 ASM_LOCATION("ElementsTransitionGenerator::GenerateDoubleToObject");
250 Register elements = x4;
251 Register array_size = x6;
252 Register array = x7;
253 Register length = x5;
254
255 // Verify input registers don't conflict with locals.
256 DCHECK(!AreAliased(receiver, key, value, target_map,
257 elements, array_size, array, length));
258
259 if (mode == TRACK_ALLOCATION_SITE) {
260 __ JumpIfJSArrayHasAllocationMemento(receiver, x10, x11, fail);
261 }
262
263 // Check for empty arrays, which only require a map transition and no changes
264 // to the backing store.
265 Label only_change_map;
266
267 __ Ldr(elements, FieldMemOperand(receiver, JSObject::kElementsOffset));
268 __ JumpIfRoot(elements, Heap::kEmptyFixedArrayRootIndex, &only_change_map);
269
270 __ Push(lr);
271 // TODO(all): These registers may not need to be pushed. Examine
272 // RecordWriteStub and check whether it's needed.
273 __ Push(target_map, receiver, key, value);
274 __ Ldrsw(length, UntagSmiFieldMemOperand(elements,
275 FixedArray::kLengthOffset));
276 // Allocate new FixedArray.
277 Label gc_required;
278 __ Mov(array_size, FixedDoubleArray::kHeaderSize);
279 __ Add(array_size, array_size, Operand(length, LSL, kPointerSizeLog2));
280 __ Allocate(array_size, array, x10, x11, &gc_required, NO_ALLOCATION_FLAGS);
281
282 // Set destination FixedDoubleArray's length and map.
283 Register map_root = array_size;
284 __ LoadRoot(map_root, Heap::kFixedArrayMapRootIndex);
285 __ SmiTag(x11, length);
286 __ Str(x11, MemOperand(array, FixedDoubleArray::kLengthOffset));
287 __ Str(map_root, MemOperand(array, HeapObject::kMapOffset));
288
289 // Prepare for conversion loop.
290 Register src_elements = x10;
291 Register dst_elements = x11;
292 Register dst_end = x12;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400293 Register the_hole = x14;
294 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000295 __ Add(src_elements, elements,
296 FixedDoubleArray::kHeaderSize - kHeapObjectTag);
297 __ Add(dst_elements, array, FixedArray::kHeaderSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298 __ Add(dst_end, dst_elements, Operand(length, LSL, kPointerSizeLog2));
299
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400300 // Allocating heap numbers in the loop below can fail and cause a jump to
301 // gc_required. We can't leave a partly initialized FixedArray behind,
302 // so pessimistically fill it with holes now.
303 Label initialization_loop, initialization_loop_entry;
304 __ B(&initialization_loop_entry);
305 __ bind(&initialization_loop);
306 __ Str(the_hole, MemOperand(dst_elements, kPointerSize, PostIndex));
307 __ bind(&initialization_loop_entry);
308 __ Cmp(dst_elements, dst_end);
309 __ B(lt, &initialization_loop);
310
311 __ Add(dst_elements, array, FixedArray::kHeaderSize);
312 __ Add(array, array, kHeapObjectTag);
313
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000314 Register heap_num_map = x15;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315 __ LoadRoot(heap_num_map, Heap::kHeapNumberMapRootIndex);
316
317 Label entry;
318 __ B(&entry);
319
320 // Call into runtime if GC is required.
321 __ Bind(&gc_required);
322 __ Pop(value, key, receiver, target_map);
323 __ Pop(lr);
324 __ B(fail);
325
326 {
327 Label loop, convert_hole;
328 __ Bind(&loop);
329 __ Ldr(x13, MemOperand(src_elements, kPointerSize, PostIndex));
330 __ Cmp(x13, kHoleNanInt64);
331 __ B(eq, &convert_hole);
332
333 // Non-hole double, copy value into a heap number.
334 Register heap_num = length;
335 Register scratch = array_size;
336 Register scratch2 = elements;
337 __ AllocateHeapNumber(heap_num, &gc_required, scratch, scratch2,
338 x13, heap_num_map);
339 __ Mov(x13, dst_elements);
340 __ Str(heap_num, MemOperand(dst_elements, kPointerSize, PostIndex));
341 __ RecordWrite(array, x13, heap_num, kLRHasBeenSaved, kDontSaveFPRegs,
342 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
343
344 __ B(&entry);
345
346 // Replace the-hole NaN with the-hole pointer.
347 __ Bind(&convert_hole);
348 __ Str(the_hole, MemOperand(dst_elements, kPointerSize, PostIndex));
349
350 __ Bind(&entry);
351 __ Cmp(dst_elements, dst_end);
352 __ B(lt, &loop);
353 }
354
355 __ Pop(value, key, receiver, target_map);
356 // Replace receiver's backing store with newly created and filled FixedArray.
357 __ Str(array, FieldMemOperand(receiver, JSObject::kElementsOffset));
358 __ RecordWriteField(receiver, JSObject::kElementsOffset, array, x13,
359 kLRHasBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
360 OMIT_SMI_CHECK);
361 __ Pop(lr);
362
363 __ Bind(&only_change_map);
364 __ Str(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
365 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, x13,
366 kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
367 OMIT_SMI_CHECK);
368}
369
370
371CodeAgingHelper::CodeAgingHelper() {
372 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength);
373 // The sequence of instructions that is patched out for aging code is the
374 // following boilerplate stack-building prologue that is found both in
375 // FUNCTION and OPTIMIZED_FUNCTION code:
376 PatchingAssembler patcher(young_sequence_.start(),
377 young_sequence_.length() / kInstructionSize);
378 // The young sequence is the frame setup code for FUNCTION code types. It is
379 // generated by FullCodeGenerator::Generate.
380 MacroAssembler::EmitFrameSetupForCodeAgePatching(&patcher);
381
382#ifdef DEBUG
383 const int length = kCodeAgeStubEntryOffset / kInstructionSize;
384 DCHECK(old_sequence_.length() >= kCodeAgeStubEntryOffset);
385 PatchingAssembler patcher_old(old_sequence_.start(), length);
386 MacroAssembler::EmitCodeAgeSequence(&patcher_old, NULL);
387#endif
388}
389
390
391#ifdef DEBUG
392bool CodeAgingHelper::IsOld(byte* candidate) const {
393 return memcmp(candidate, old_sequence_.start(), kCodeAgeStubEntryOffset) == 0;
394}
395#endif
396
397
398bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) {
399 return MacroAssembler::IsYoungSequence(isolate, sequence);
400}
401
402
403void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age,
404 MarkingParity* parity) {
405 if (IsYoungSequence(isolate, sequence)) {
406 *age = kNoAgeCodeAge;
407 *parity = NO_MARKING_PARITY;
408 } else {
409 byte* target = sequence + kCodeAgeStubEntryOffset;
410 Code* stub = GetCodeFromTargetAddress(Memory::Address_at(target));
411 GetCodeAgeAndParity(stub, age, parity);
412 }
413}
414
415
416void Code::PatchPlatformCodeAge(Isolate* isolate,
417 byte* sequence,
418 Code::Age age,
419 MarkingParity parity) {
420 PatchingAssembler patcher(sequence,
421 kNoCodeAgeSequenceLength / kInstructionSize);
422 if (age == kNoAgeCodeAge) {
423 MacroAssembler::EmitFrameSetupForCodeAgePatching(&patcher);
424 } else {
425 Code * stub = GetCodeAgeStub(isolate, age, parity);
426 MacroAssembler::EmitCodeAgeSequence(&patcher, stub);
427 }
428}
429
430
431void StringCharLoadGenerator::Generate(MacroAssembler* masm,
432 Register string,
433 Register index,
434 Register result,
435 Label* call_runtime) {
436 DCHECK(string.Is64Bits() && index.Is32Bits() && result.Is64Bits());
437 // Fetch the instance type of the receiver into result register.
438 __ Ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
439 __ Ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
440
441 // We need special handling for indirect strings.
442 Label check_sequential;
443 __ TestAndBranchIfAllClear(result, kIsIndirectStringMask, &check_sequential);
444
445 // Dispatch on the indirect string shape: slice or cons.
446 Label cons_string;
447 __ TestAndBranchIfAllClear(result, kSlicedNotConsMask, &cons_string);
448
449 // Handle slices.
450 Label indirect_string_loaded;
451 __ Ldr(result.W(),
452 UntagSmiFieldMemOperand(string, SlicedString::kOffsetOffset));
453 __ Ldr(string, FieldMemOperand(string, SlicedString::kParentOffset));
454 __ Add(index, index, result.W());
455 __ B(&indirect_string_loaded);
456
457 // Handle cons strings.
458 // Check whether the right hand side is the empty string (i.e. if
459 // this is really a flat string in a cons string). If that is not
460 // the case we would rather go to the runtime system now to flatten
461 // the string.
462 __ Bind(&cons_string);
463 __ Ldr(result, FieldMemOperand(string, ConsString::kSecondOffset));
464 __ JumpIfNotRoot(result, Heap::kempty_stringRootIndex, call_runtime);
465 // Get the first of the two strings and load its instance type.
466 __ Ldr(string, FieldMemOperand(string, ConsString::kFirstOffset));
467
468 __ Bind(&indirect_string_loaded);
469 __ Ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
470 __ Ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
471
472 // Distinguish sequential and external strings. Only these two string
473 // representations can reach here (slices and flat cons strings have been
474 // reduced to the underlying sequential or external string).
475 Label external_string, check_encoding;
476 __ Bind(&check_sequential);
477 STATIC_ASSERT(kSeqStringTag == 0);
478 __ TestAndBranchIfAnySet(result, kStringRepresentationMask, &external_string);
479
480 // Prepare sequential strings
481 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
482 __ Add(string, string, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
483 __ B(&check_encoding);
484
485 // Handle external strings.
486 __ Bind(&external_string);
487 if (FLAG_debug_code) {
488 // Assert that we do not have a cons or slice (indirect strings) here.
489 // Sequential strings have already been ruled out.
490 __ Tst(result, kIsIndirectStringMask);
491 __ Assert(eq, kExternalStringExpectedButNotFound);
492 }
493 // Rule out short external strings.
494 STATIC_ASSERT(kShortExternalStringTag != 0);
495 // TestAndBranchIfAnySet can emit Tbnz. Do not use it because call_runtime
496 // can be bound far away in deferred code.
497 __ Tst(result, kShortExternalStringMask);
498 __ B(ne, call_runtime);
499 __ Ldr(string, FieldMemOperand(string, ExternalString::kResourceDataOffset));
500
501 Label one_byte, done;
502 __ Bind(&check_encoding);
503 STATIC_ASSERT(kTwoByteStringTag == 0);
504 __ TestAndBranchIfAnySet(result, kStringEncodingMask, &one_byte);
505 // Two-byte string.
506 __ Ldrh(result, MemOperand(string, index, SXTW, 1));
507 __ B(&done);
508 __ Bind(&one_byte);
509 // One-byte string.
510 __ Ldrb(result, MemOperand(string, index, SXTW));
511 __ Bind(&done);
512}
513
514
515static MemOperand ExpConstant(Register base, int index) {
516 return MemOperand(base, index * kDoubleSize);
517}
518
519
520void MathExpGenerator::EmitMathExp(MacroAssembler* masm,
521 DoubleRegister input,
522 DoubleRegister result,
523 DoubleRegister double_temp1,
524 DoubleRegister double_temp2,
525 Register temp1,
526 Register temp2,
527 Register temp3) {
528 // TODO(jbramley): There are several instances where fnmsub could be used
529 // instead of fmul and fsub. Doing this changes the result, but since this is
530 // an estimation anyway, does it matter?
531
532 DCHECK(!AreAliased(input, result,
533 double_temp1, double_temp2,
534 temp1, temp2, temp3));
535 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL);
536 DCHECK(!masm->serializer_enabled()); // External references not serializable.
537
538 Label done;
539 DoubleRegister double_temp3 = result;
540 Register constants = temp3;
541
542 // The algorithm used relies on some magic constants which are initialized in
543 // ExternalReference::InitializeMathExpData().
544
545 // Load the address of the start of the array.
546 __ Mov(constants, ExternalReference::math_exp_constants(0));
547
548 // We have to do a four-way split here:
549 // - If input <= about -708.4, the output always rounds to zero.
550 // - If input >= about 709.8, the output always rounds to +infinity.
551 // - If the input is NaN, the output is NaN.
552 // - Otherwise, the result needs to be calculated.
553 Label result_is_finite_non_zero;
554 // Assert that we can load offset 0 (the small input threshold) and offset 1
555 // (the large input threshold) with a single ldp.
556 DCHECK(kDRegSize == (ExpConstant(constants, 1).offset() -
557 ExpConstant(constants, 0).offset()));
558 __ Ldp(double_temp1, double_temp2, ExpConstant(constants, 0));
559
560 __ Fcmp(input, double_temp1);
561 __ Fccmp(input, double_temp2, NoFlag, hi);
562 // At this point, the condition flags can be in one of five states:
563 // NZCV
564 // 1000 -708.4 < input < 709.8 result = exp(input)
565 // 0110 input == 709.8 result = +infinity
566 // 0010 input > 709.8 result = +infinity
567 // 0011 input is NaN result = input
568 // 0000 input <= -708.4 result = +0.0
569
570 // Continue the common case first. 'mi' tests N == 1.
571 __ B(&result_is_finite_non_zero, mi);
572
573 // TODO(jbramley): Consider adding a +infinity register for ARM64.
574 __ Ldr(double_temp2, ExpConstant(constants, 2)); // Synthesize +infinity.
575
576 // Select between +0.0 and +infinity. 'lo' tests C == 0.
577 __ Fcsel(result, fp_zero, double_temp2, lo);
578 // Select between {+0.0 or +infinity} and input. 'vc' tests V == 0.
579 __ Fcsel(result, result, input, vc);
580 __ B(&done);
581
582 // The rest is magic, as described in InitializeMathExpData().
583 __ Bind(&result_is_finite_non_zero);
584
585 // Assert that we can load offset 3 and offset 4 with a single ldp.
586 DCHECK(kDRegSize == (ExpConstant(constants, 4).offset() -
587 ExpConstant(constants, 3).offset()));
588 __ Ldp(double_temp1, double_temp3, ExpConstant(constants, 3));
589 __ Fmadd(double_temp1, double_temp1, input, double_temp3);
590 __ Fmov(temp2.W(), double_temp1.S());
591 __ Fsub(double_temp1, double_temp1, double_temp3);
592
593 // Assert that we can load offset 5 and offset 6 with a single ldp.
594 DCHECK(kDRegSize == (ExpConstant(constants, 6).offset() -
595 ExpConstant(constants, 5).offset()));
596 __ Ldp(double_temp2, double_temp3, ExpConstant(constants, 5));
597 // TODO(jbramley): Consider using Fnmsub here.
598 __ Fmul(double_temp1, double_temp1, double_temp2);
599 __ Fsub(double_temp1, double_temp1, input);
600
601 __ Fmul(double_temp2, double_temp1, double_temp1);
602 __ Fsub(double_temp3, double_temp3, double_temp1);
603 __ Fmul(double_temp3, double_temp3, double_temp2);
604
605 __ Mov(temp1.W(), Operand(temp2.W(), LSR, 11));
606
607 __ Ldr(double_temp2, ExpConstant(constants, 7));
608 // TODO(jbramley): Consider using Fnmsub here.
609 __ Fmul(double_temp3, double_temp3, double_temp2);
610 __ Fsub(double_temp3, double_temp3, double_temp1);
611
612 // The 8th constant is 1.0, so use an immediate move rather than a load.
613 // We can't generate a runtime assertion here as we would need to call Abort
614 // in the runtime and we don't have an Isolate when we generate this code.
615 __ Fmov(double_temp2, 1.0);
616 __ Fadd(double_temp3, double_temp3, double_temp2);
617
618 __ And(temp2, temp2, 0x7ff);
619 __ Add(temp1, temp1, 0x3ff);
620
621 // Do the final table lookup.
622 __ Mov(temp3, ExternalReference::math_exp_log_table());
623
624 __ Add(temp3, temp3, Operand(temp2, LSL, kDRegSizeLog2));
625 __ Ldp(temp2.W(), temp3.W(), MemOperand(temp3));
626 __ Orr(temp1.W(), temp3.W(), Operand(temp1.W(), LSL, 20));
627 __ Bfi(temp2, temp1, 32, 32);
628 __ Fmov(double_temp1, temp2);
629
630 __ Fmul(result, double_temp3, double_temp1);
631
632 __ Bind(&done);
633}
634
635#undef __
636
637} } // namespace v8::internal
638
639#endif // V8_TARGET_ARCH_ARM64