forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode-stubs-arm64.cc
More file actions
6000 lines (5007 loc) · 214 KB
/
code-stubs-arm64.cc
File metadata and controls
6000 lines (5007 loc) · 214 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if V8_TARGET_ARCH_ARM64
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
#include "src/ic/handler-compiler.h"
#include "src/ic/ic.h"
#include "src/ic/stub-cache.h"
#include "src/isolate.h"
#include "src/regexp/jsregexp.h"
#include "src/regexp/regexp-macro-assembler.h"
#include "src/runtime/runtime.h"
#include "src/arm64/code-stubs-arm64.h"
#include "src/arm64/frames-arm64.h"
namespace v8 {
namespace internal {
static void InitializeArrayConstructorDescriptor(
Isolate* isolate, CodeStubDescriptor* descriptor,
int constant_stack_parameter_count) {
// cp: context
// x1: function
// x2: allocation site with elements kind
// x0: number of arguments to the constructor function
Address deopt_handler = Runtime::FunctionForId(
Runtime::kArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) {
descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else {
descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
}
}
void ArrayNoArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
}
void ArraySingleArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
}
void ArrayNArgumentsConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
}
static void InitializeInternalArrayConstructorDescriptor(
Isolate* isolate, CodeStubDescriptor* descriptor,
int constant_stack_parameter_count) {
Address deopt_handler = Runtime::FunctionForId(
Runtime::kInternalArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) {
descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else {
descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
}
}
void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
}
void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
}
void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
}
#define __ ACCESS_MASM(masm)
void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
ExternalReference miss) {
// Update the static counter each time a new code stub is generated.
isolate()->counters()->code_stubs()->Increment();
CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
int param_count = descriptor.GetRegisterParameterCount();
{
// Call the runtime system in a fresh internal frame.
FrameScope scope(masm, StackFrame::INTERNAL);
DCHECK((param_count == 0) ||
x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
// Push arguments
MacroAssembler::PushPopQueue queue(masm);
for (int i = 0; i < param_count; ++i) {
queue.Queue(descriptor.GetRegisterParameter(i));
}
queue.PushQueued();
__ CallExternalReference(miss, param_count);
}
__ Ret();
}
void DoubleToIStub::Generate(MacroAssembler* masm) {
Label done;
Register input = source();
Register result = destination();
DCHECK(is_truncating());
DCHECK(result.Is64Bits());
DCHECK(jssp.Is(masm->StackPointer()));
int double_offset = offset();
DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
Register scratch2 =
GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
__ Push(scratch1, scratch2);
// Account for saved regs if input is jssp.
if (input.is(jssp)) double_offset += 2 * kPointerSize;
if (!skip_fastpath()) {
__ Push(double_scratch);
if (input.is(jssp)) double_offset += 1 * kDoubleSize;
__ Ldr(double_scratch, MemOperand(input, double_offset));
// Try to convert with a FPU convert instruction. This handles all
// non-saturating cases.
__ TryConvertDoubleToInt64(result, double_scratch, &done);
__ Fmov(result, double_scratch);
} else {
__ Ldr(result, MemOperand(input, double_offset));
}
// If we reach here we need to manually convert the input to an int32.
// Extract the exponent.
Register exponent = scratch1;
__ Ubfx(exponent, result, HeapNumber::kMantissaBits,
HeapNumber::kExponentBits);
// It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
// the mantissa gets shifted completely out of the int32_t result.
__ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
__ CzeroX(result, ge);
__ B(ge, &done);
// The Fcvtzs sequence handles all cases except where the conversion causes
// signed overflow in the int64_t target. Since we've already handled
// exponents >= 84, we can guarantee that 63 <= exponent < 84.
if (masm->emit_debug_code()) {
__ Cmp(exponent, HeapNumber::kExponentBias + 63);
// Exponents less than this should have been handled by the Fcvt case.
__ Check(ge, kUnexpectedValue);
}
// Isolate the mantissa bits, and set the implicit '1'.
Register mantissa = scratch2;
__ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
__ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
// Negate the mantissa if necessary.
__ Tst(result, kXSignMask);
__ Cneg(mantissa, mantissa, ne);
// Shift the mantissa bits in the correct place. We know that we have to shift
// it left here, because exponent >= 63 >= kMantissaBits.
__ Sub(exponent, exponent,
HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
__ Lsl(result, mantissa, exponent);
__ Bind(&done);
if (!skip_fastpath()) {
__ Pop(double_scratch);
}
__ Pop(scratch2, scratch1);
__ Ret();
}
// See call site for description.
static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
Register right, Register scratch,
FPRegister double_scratch,
Label* slow, Condition cond) {
DCHECK(!AreAliased(left, right, scratch));
Label not_identical, return_equal, heap_number;
Register result = x0;
__ Cmp(right, left);
__ B(ne, ¬_identical);
// Test for NaN. Sadly, we can't just compare to factory::nan_value(),
// so we do the second best thing - test it ourselves.
// They are both equal and they are not both Smis so both of them are not
// Smis. If it's not a heap number, then return equal.
Register right_type = scratch;
if ((cond == lt) || (cond == gt)) {
// Call runtime on identical JSObjects. Otherwise return equal.
__ JumpIfObjectType(right, right_type, right_type, FIRST_JS_RECEIVER_TYPE,
slow, ge);
// Call runtime on identical symbols since we need to throw a TypeError.
__ Cmp(right_type, SYMBOL_TYPE);
__ B(eq, slow);
// Call runtime on identical SIMD values since we must throw a TypeError.
__ Cmp(right_type, SIMD128_VALUE_TYPE);
__ B(eq, slow);
} else if (cond == eq) {
__ JumpIfHeapNumber(right, &heap_number);
} else {
__ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
&heap_number);
// Comparing JS objects with <=, >= is complicated.
__ Cmp(right_type, FIRST_JS_RECEIVER_TYPE);
__ B(ge, slow);
// Call runtime on identical symbols since we need to throw a TypeError.
__ Cmp(right_type, SYMBOL_TYPE);
__ B(eq, slow);
// Call runtime on identical SIMD values since we must throw a TypeError.
__ Cmp(right_type, SIMD128_VALUE_TYPE);
__ B(eq, slow);
// Normally here we fall through to return_equal, but undefined is
// special: (undefined == undefined) == true, but
// (undefined <= undefined) == false! See ECMAScript 11.8.5.
if ((cond == le) || (cond == ge)) {
__ Cmp(right_type, ODDBALL_TYPE);
__ B(ne, &return_equal);
__ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
if (cond == le) {
// undefined <= undefined should fail.
__ Mov(result, GREATER);
} else {
// undefined >= undefined should fail.
__ Mov(result, LESS);
}
__ Ret();
}
}
__ Bind(&return_equal);
if (cond == lt) {
__ Mov(result, GREATER); // Things aren't less than themselves.
} else if (cond == gt) {
__ Mov(result, LESS); // Things aren't greater than themselves.
} else {
__ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
}
__ Ret();
// Cases lt and gt have been handled earlier, and case ne is never seen, as
// it is handled in the parser (see Parser::ParseBinaryExpression). We are
// only concerned with cases ge, le and eq here.
if ((cond != lt) && (cond != gt)) {
DCHECK((cond == ge) || (cond == le) || (cond == eq));
__ Bind(&heap_number);
// Left and right are identical pointers to a heap number object. Return
// non-equal if the heap number is a NaN, and equal otherwise. Comparing
// the number to itself will set the overflow flag iff the number is NaN.
__ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
__ Fcmp(double_scratch, double_scratch);
__ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
if (cond == le) {
__ Mov(result, GREATER);
} else {
__ Mov(result, LESS);
}
__ Ret();
}
// No fall through here.
if (FLAG_debug_code) {
__ Unreachable();
}
__ Bind(¬_identical);
}
// See call site for description.
static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
Register left,
Register right,
Register left_type,
Register right_type,
Register scratch) {
DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
if (masm->emit_debug_code()) {
// We assume that the arguments are not identical.
__ Cmp(left, right);
__ Assert(ne, kExpectedNonIdenticalObjects);
}
// If either operand is a JS object or an oddball value, then they are not
// equal since their pointers are different.
// There is no test for undetectability in strict equality.
STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Label right_non_object;
__ Cmp(right_type, FIRST_JS_RECEIVER_TYPE);
__ B(lt, &right_non_object);
// Return non-zero - x0 already contains a non-zero pointer.
DCHECK(left.is(x0) || right.is(x0));
Label return_not_equal;
__ Bind(&return_not_equal);
__ Ret();
__ Bind(&right_non_object);
// Check for oddballs: true, false, null, undefined.
__ Cmp(right_type, ODDBALL_TYPE);
// If right is not ODDBALL, test left. Otherwise, set eq condition.
__ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
// If right or left is not ODDBALL, test left >= FIRST_JS_RECEIVER_TYPE.
// Otherwise, right or left is ODDBALL, so set a ge condition.
__ Ccmp(left_type, FIRST_JS_RECEIVER_TYPE, NVFlag, ne);
__ B(ge, &return_not_equal);
// Internalized strings are unique, so they can only be equal if they are the
// same object. We have already tested that case, so if left and right are
// both internalized strings, they cannot be equal.
STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
__ Orr(scratch, left_type, right_type);
__ TestAndBranchIfAllClear(
scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
}
// See call site for description.
static void EmitSmiNonsmiComparison(MacroAssembler* masm,
Register left,
Register right,
FPRegister left_d,
FPRegister right_d,
Label* slow,
bool strict) {
DCHECK(!AreAliased(left_d, right_d));
DCHECK((left.is(x0) && right.is(x1)) ||
(right.is(x0) && left.is(x1)));
Register result = x0;
Label right_is_smi, done;
__ JumpIfSmi(right, &right_is_smi);
// Left is the smi. Check whether right is a heap number.
if (strict) {
// If right is not a number and left is a smi, then strict equality cannot
// succeed. Return non-equal.
Label is_heap_number;
__ JumpIfHeapNumber(right, &is_heap_number);
// Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
if (!right.is(result)) {
__ Mov(result, NOT_EQUAL);
}
__ Ret();
__ Bind(&is_heap_number);
} else {
// Smi compared non-strictly with a non-smi, non-heap-number. Call the
// runtime.
__ JumpIfNotHeapNumber(right, slow);
}
// Left is the smi. Right is a heap number. Load right value into right_d, and
// convert left smi into double in left_d.
__ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
__ SmiUntagToDouble(left_d, left);
__ B(&done);
__ Bind(&right_is_smi);
// Right is a smi. Check whether the non-smi left is a heap number.
if (strict) {
// If left is not a number and right is a smi then strict equality cannot
// succeed. Return non-equal.
Label is_heap_number;
__ JumpIfHeapNumber(left, &is_heap_number);
// Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
if (!left.is(result)) {
__ Mov(result, NOT_EQUAL);
}
__ Ret();
__ Bind(&is_heap_number);
} else {
// Smi compared non-strictly with a non-smi, non-heap-number. Call the
// runtime.
__ JumpIfNotHeapNumber(left, slow);
}
// Right is the smi. Left is a heap number. Load left value into left_d, and
// convert right smi into double in right_d.
__ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
__ SmiUntagToDouble(right_d, right);
// Fall through to both_loaded_as_doubles.
__ Bind(&done);
}
// Fast negative check for internalized-to-internalized equality.
// See call site for description.
static void EmitCheckForInternalizedStringsOrObjects(
MacroAssembler* masm, Register left, Register right, Register left_map,
Register right_map, Register left_type, Register right_type,
Label* possible_strings, Label* runtime_call) {
DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
Register result = x0;
DCHECK(left.is(x0) || right.is(x0));
Label object_test, return_unequal, undetectable;
STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
// TODO(all): reexamine this branch sequence for optimisation wrt branch
// prediction.
__ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
__ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
__ Tbnz(left_type, MaskToBit(kIsNotStringMask), runtime_call);
__ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
// Both are internalized. We already checked they weren't the same pointer so
// they are not equal. Return non-equal by returning the non-zero object
// pointer in x0.
__ Ret();
__ Bind(&object_test);
Register left_bitfield = left_type;
Register right_bitfield = right_type;
__ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
__ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
__ Tbnz(right_bitfield, MaskToBit(1 << Map::kIsUndetectable), &undetectable);
__ Tbnz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal);
__ CompareInstanceType(right_map, right_type, FIRST_JS_RECEIVER_TYPE);
__ B(lt, runtime_call);
__ CompareInstanceType(left_map, left_type, FIRST_JS_RECEIVER_TYPE);
__ B(lt, runtime_call);
__ bind(&return_unequal);
// Return non-equal by returning the non-zero object pointer in x0.
__ Ret();
__ bind(&undetectable);
__ Tbz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal);
__ Mov(result, EQUAL);
__ Ret();
}
static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
CompareICState::State expected,
Label* fail) {
Label ok;
if (expected == CompareICState::SMI) {
__ JumpIfNotSmi(input, fail);
} else if (expected == CompareICState::NUMBER) {
__ JumpIfSmi(input, &ok);
__ JumpIfNotHeapNumber(input, fail);
}
// We could be strict about internalized/non-internalized here, but as long as
// hydrogen doesn't care, the stub doesn't have to care either.
__ Bind(&ok);
}
void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
Register lhs = x1;
Register rhs = x0;
Register result = x0;
Condition cond = GetCondition();
Label miss;
CompareICStub_CheckInputType(masm, lhs, left(), &miss);
CompareICStub_CheckInputType(masm, rhs, right(), &miss);
Label slow; // Call builtin.
Label not_smis, both_loaded_as_doubles;
Label not_two_smis, smi_done;
__ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis);
__ SmiUntag(lhs);
__ Sub(result, lhs, Operand::UntagSmi(rhs));
__ Ret();
__ Bind(¬_two_smis);
// NOTICE! This code is only reached after a smi-fast-case check, so it is
// certain that at least one operand isn't a smi.
// Handle the case where the objects are identical. Either returns the answer
// or goes to slow. Only falls through if the objects were not identical.
EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond);
// If either is a smi (we know that at least one is not a smi), then they can
// only be strictly equal if the other is a HeapNumber.
__ JumpIfBothNotSmi(lhs, rhs, ¬_smis);
// Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
// can:
// 1) Return the answer.
// 2) Branch to the slow case.
// 3) Fall through to both_loaded_as_doubles.
// In case 3, we have found out that we were dealing with a number-number
// comparison. The double values of the numbers have been loaded, right into
// rhs_d, left into lhs_d.
FPRegister rhs_d = d0;
FPRegister lhs_d = d1;
EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
__ Bind(&both_loaded_as_doubles);
// The arguments have been converted to doubles and stored in rhs_d and
// lhs_d.
Label nan;
__ Fcmp(lhs_d, rhs_d);
__ B(vs, &nan); // Overflow flag set if either is NaN.
STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
__ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
__ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
__ Ret();
__ Bind(&nan);
// Left and/or right is a NaN. Load the result register with whatever makes
// the comparison fail, since comparisons with NaN always fail (except ne,
// which is filtered out at a higher level.)
DCHECK(cond != ne);
if ((cond == lt) || (cond == le)) {
__ Mov(result, GREATER);
} else {
__ Mov(result, LESS);
}
__ Ret();
__ Bind(¬_smis);
// At this point we know we are dealing with two different objects, and
// neither of them is a smi. The objects are in rhs_ and lhs_.
// Load the maps and types of the objects.
Register rhs_map = x10;
Register rhs_type = x11;
Register lhs_map = x12;
Register lhs_type = x13;
__ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
__ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
__ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
__ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
if (strict()) {
// This emits a non-equal return sequence for some object types, or falls
// through if it was not lucky.
EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
}
Label check_for_internalized_strings;
Label flat_string_check;
// Check for heap number comparison. Branch to earlier double comparison code
// if they are heap numbers, otherwise, branch to internalized string check.
__ Cmp(rhs_type, HEAP_NUMBER_TYPE);
__ B(ne, &check_for_internalized_strings);
__ Cmp(lhs_map, rhs_map);
// If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
// string check.
__ B(ne, &flat_string_check);
// Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
// comparison code.
__ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
__ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
__ B(&both_loaded_as_doubles);
__ Bind(&check_for_internalized_strings);
// In the strict case, the EmitStrictTwoHeapObjectCompare already took care
// of internalized strings.
if ((cond == eq) && !strict()) {
// Returns an answer for two internalized strings or two detectable objects.
// Otherwise branches to the string case or not both strings case.
EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
lhs_type, rhs_type,
&flat_string_check, &slow);
}
// Check for both being sequential one-byte strings,
// and inline if that is the case.
__ Bind(&flat_string_check);
__ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
x15, &slow);
__ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
x11);
if (cond == eq) {
StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
x12);
} else {
StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
x12, x13);
}
// Never fall through to here.
if (FLAG_debug_code) {
__ Unreachable();
}
__ Bind(&slow);
if (cond == eq) {
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ Push(lhs, rhs);
__ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
}
// Turn true into 0 and false into some non-zero value.
STATIC_ASSERT(EQUAL == 0);
__ LoadRoot(x1, Heap::kTrueValueRootIndex);
__ Sub(x0, x0, x1);
__ Ret();
} else {
__ Push(lhs, rhs);
int ncr; // NaN compare result
if ((cond == lt) || (cond == le)) {
ncr = GREATER;
} else {
DCHECK((cond == gt) || (cond == ge)); // remaining cases
ncr = LESS;
}
__ Mov(x10, Smi::FromInt(ncr));
__ Push(x10);
// Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
// tagged as a small integer.
__ TailCallRuntime(Runtime::kCompare);
}
__ Bind(&miss);
GenerateMiss(masm);
}
void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
CPURegList saved_regs = kCallerSaved;
CPURegList saved_fp_regs = kCallerSavedFP;
// We don't allow a GC during a store buffer overflow so there is no need to
// store the registers in any particular way, but we do have to store and
// restore them.
// We don't care if MacroAssembler scratch registers are corrupted.
saved_regs.Remove(*(masm->TmpList()));
saved_fp_regs.Remove(*(masm->FPTmpList()));
__ PushCPURegList(saved_regs);
if (save_doubles()) {
__ PushCPURegList(saved_fp_regs);
}
AllowExternalCallThatCantCauseGC scope(masm);
__ Mov(x0, ExternalReference::isolate_address(isolate()));
__ CallCFunction(
ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
if (save_doubles()) {
__ PopCPURegList(saved_fp_regs);
}
__ PopCPURegList(saved_regs);
__ Ret();
}
void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
Isolate* isolate) {
StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
stub1.GetCode();
StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
stub2.GetCode();
}
void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
UseScratchRegisterScope temps(masm);
Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
Register return_address = temps.AcquireX();
__ Mov(return_address, lr);
// Restore lr with the value it had before the call to this stub (the value
// which must be pushed).
__ Mov(lr, saved_lr);
__ PushSafepointRegisters();
__ Ret(return_address);
}
void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
UseScratchRegisterScope temps(masm);
Register return_address = temps.AcquireX();
// Preserve the return address (lr will be clobbered by the pop).
__ Mov(return_address, lr);
__ PopSafepointRegisters();
__ Ret(return_address);
}
void MathPowStub::Generate(MacroAssembler* masm) {
// Stack on entry:
// jssp[0]: Exponent (as a tagged value).
// jssp[1]: Base (as a tagged value).
//
// The (tagged) result will be returned in x0, as a heap number.
Register result_tagged = x0;
Register base_tagged = x10;
Register exponent_tagged = MathPowTaggedDescriptor::exponent();
DCHECK(exponent_tagged.is(x11));
Register exponent_integer = MathPowIntegerDescriptor::exponent();
DCHECK(exponent_integer.is(x12));
Register scratch1 = x14;
Register scratch0 = x15;
Register saved_lr = x19;
FPRegister result_double = d0;
FPRegister base_double = d0;
FPRegister exponent_double = d1;
FPRegister base_double_copy = d2;
FPRegister scratch1_double = d6;
FPRegister scratch0_double = d7;
// A fast-path for integer exponents.
Label exponent_is_smi, exponent_is_integer;
// Bail out to runtime.
Label call_runtime;
// Allocate a heap number for the result, and return it.
Label done;
// Unpack the inputs.
if (exponent_type() == ON_STACK) {
Label base_is_smi;
Label unpack_exponent;
__ Pop(exponent_tagged, base_tagged);
__ JumpIfSmi(base_tagged, &base_is_smi);
__ JumpIfNotHeapNumber(base_tagged, &call_runtime);
// base_tagged is a heap number, so load its double value.
__ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
__ B(&unpack_exponent);
__ Bind(&base_is_smi);
// base_tagged is a SMI, so untag it and convert it to a double.
__ SmiUntagToDouble(base_double, base_tagged);
__ Bind(&unpack_exponent);
// x10 base_tagged The tagged base (input).
// x11 exponent_tagged The tagged exponent (input).
// d1 base_double The base as a double.
__ JumpIfSmi(exponent_tagged, &exponent_is_smi);
__ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
// exponent_tagged is a heap number, so load its double value.
__ Ldr(exponent_double,
FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
} else if (exponent_type() == TAGGED) {
__ JumpIfSmi(exponent_tagged, &exponent_is_smi);
__ Ldr(exponent_double,
FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
}
// Handle double (heap number) exponents.
if (exponent_type() != INTEGER) {
// Detect integer exponents stored as doubles and handle those in the
// integer fast-path.
__ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
scratch0_double, &exponent_is_integer);
if (exponent_type() == ON_STACK) {
FPRegister half_double = d3;
FPRegister minus_half_double = d4;
// Detect square root case. Crankshaft detects constant +/-0.5 at compile
// time and uses DoMathPowHalf instead. We then skip this check for
// non-constant cases of +/-0.5 as these hardly occur.
__ Fmov(minus_half_double, -0.5);
__ Fmov(half_double, 0.5);
__ Fcmp(minus_half_double, exponent_double);
__ Fccmp(half_double, exponent_double, NZFlag, ne);
// Condition flags at this point:
// 0.5; nZCv // Identified by eq && pl
// -0.5: NZcv // Identified by eq && mi
// other: ?z?? // Identified by ne
__ B(ne, &call_runtime);
// The exponent is 0.5 or -0.5.
// Given that exponent is known to be either 0.5 or -0.5, the following
// special cases could apply (according to ECMA-262 15.8.2.13):
//
// base.isNaN(): The result is NaN.
// (base == +INFINITY) || (base == -INFINITY)
// exponent == 0.5: The result is +INFINITY.
// exponent == -0.5: The result is +0.
// (base == +0) || (base == -0)
// exponent == 0.5: The result is +0.
// exponent == -0.5: The result is +INFINITY.
// (base < 0) && base.isFinite(): The result is NaN.
//
// Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
// where base is -INFINITY or -0.
// Add +0 to base. This has no effect other than turning -0 into +0.
__ Fadd(base_double, base_double, fp_zero);
// The operation -0+0 results in +0 in all cases except where the
// FPCR rounding mode is 'round towards minus infinity' (RM). The
// ARM64 simulator does not currently simulate FPCR (where the rounding
// mode is set), so test the operation with some debug code.
if (masm->emit_debug_code()) {
UseScratchRegisterScope temps(masm);
Register temp = temps.AcquireX();
__ Fneg(scratch0_double, fp_zero);
// Verify that we correctly generated +0.0 and -0.0.
// bits(+0.0) = 0x0000000000000000
// bits(-0.0) = 0x8000000000000000
__ Fmov(temp, fp_zero);
__ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
__ Fmov(temp, scratch0_double);
__ Eor(temp, temp, kDSignMask);
__ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
// Check that -0.0 + 0.0 == +0.0.
__ Fadd(scratch0_double, scratch0_double, fp_zero);
__ Fmov(temp, scratch0_double);
__ CheckRegisterIsClear(temp, kExpectedPositiveZero);
}
// If base is -INFINITY, make it +INFINITY.
// * Calculate base - base: All infinities will become NaNs since both
// -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
// * If the result is NaN, calculate abs(base).
__ Fsub(scratch0_double, base_double, base_double);
__ Fcmp(scratch0_double, 0.0);
__ Fabs(scratch1_double, base_double);
__ Fcsel(base_double, scratch1_double, base_double, vs);
// Calculate the square root of base.
__ Fsqrt(result_double, base_double);
__ Fcmp(exponent_double, 0.0);
__ B(ge, &done); // Finish now for exponents of 0.5.
// Find the inverse for exponents of -0.5.
__ Fmov(scratch0_double, 1.0);
__ Fdiv(result_double, scratch0_double, result_double);
__ B(&done);
}
{
AllowExternalCallThatCantCauseGC scope(masm);
__ Mov(saved_lr, lr);
__ CallCFunction(
ExternalReference::power_double_double_function(isolate()),
0, 2);
__ Mov(lr, saved_lr);
__ B(&done);
}
// Handle SMI exponents.
__ Bind(&exponent_is_smi);
// x10 base_tagged The tagged base (input).
// x11 exponent_tagged The tagged exponent (input).
// d1 base_double The base as a double.
__ SmiUntag(exponent_integer, exponent_tagged);
}
__ Bind(&exponent_is_integer);
// x10 base_tagged The tagged base (input).
// x11 exponent_tagged The tagged exponent (input).
// x12 exponent_integer The exponent as an integer.
// d1 base_double The base as a double.
// Find abs(exponent). For negative exponents, we can find the inverse later.
Register exponent_abs = x13;
__ Cmp(exponent_integer, 0);
__ Cneg(exponent_abs, exponent_integer, mi);
// x13 exponent_abs The value of abs(exponent_integer).
// Repeatedly multiply to calculate the power.
// result = 1.0;
// For each bit n (exponent_integer{n}) {
// if (exponent_integer{n}) {
// result *= base;
// }
// base *= base;
// if (remaining bits in exponent_integer are all zero) {
// break;
// }
// }
Label power_loop, power_loop_entry, power_loop_exit;
__ Fmov(scratch1_double, base_double);
__ Fmov(base_double_copy, base_double);
__ Fmov(result_double, 1.0);
__ B(&power_loop_entry);
__ Bind(&power_loop);
__ Fmul(scratch1_double, scratch1_double, scratch1_double);
__ Lsr(exponent_abs, exponent_abs, 1);
__ Cbz(exponent_abs, &power_loop_exit);
__ Bind(&power_loop_entry);
__ Tbz(exponent_abs, 0, &power_loop);
__ Fmul(result_double, result_double, scratch1_double);
__ B(&power_loop);
__ Bind(&power_loop_exit);
// If the exponent was positive, result_double holds the result.
__ Tbz(exponent_integer, kXSignBit, &done);
// The exponent was negative, so find the inverse.
__ Fmov(scratch0_double, 1.0);
__ Fdiv(result_double, scratch0_double, result_double);
// ECMA-262 only requires Math.pow to return an 'implementation-dependent
// approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
// to calculate the subnormal value 2^-1074. This method of calculating
// negative powers doesn't work because 2^1074 overflows to infinity. To
// catch this corner-case, we bail out if the result was 0. (This can only
// occur if the divisor is infinity or the base is zero.)
__ Fcmp(result_double, 0.0);
__ B(&done, ne);
if (exponent_type() == ON_STACK) {
// Bail out to runtime code.
__ Bind(&call_runtime);
// Put the arguments back on the stack.
__ Push(base_tagged, exponent_tagged);
__ TailCallRuntime(Runtime::kMathPowRT);
// Return.
__ Bind(&done);
__ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
result_double);
DCHECK(result_tagged.is(x0));
__ Ret();
} else {
AllowExternalCallThatCantCauseGC scope(masm);
__ Mov(saved_lr, lr);
__ Fmov(base_double, base_double_copy);
__ Scvtf(exponent_double, exponent_integer);
__ CallCFunction(
ExternalReference::power_double_double_function(isolate()),
0, 2);
__ Mov(lr, saved_lr);
__ Bind(&done);
__ Ret();
}
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
// It is important that the following stubs are generated in this order
// because pregenerated stubs can only call other pregenerated stubs.
// RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
// CEntryStub.
CEntryStub::GenerateAheadOfTime(isolate);
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
CreateWeakCellStub::GenerateAheadOfTime(isolate);
BinaryOpICStub::GenerateAheadOfTime(isolate);
StoreRegistersStateStub::GenerateAheadOfTime(isolate);
RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
StoreFastElementStub::GenerateAheadOfTime(isolate);
TypeofStub::GenerateAheadOfTime(isolate);
}
void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
StoreRegistersStateStub stub(isolate);
stub.GetCode();
}