-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
LowLevelInterpreter64.asm
3060 lines (2545 loc) · 94.2 KB
/
LowLevelInterpreter64.asm
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 (C) 2011-2020 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# Utilities.
macro storePC()
storei PC, LLIntReturnPC[cfr]
end
macro loadPC()
loadi LLIntReturnPC[cfr], PC
end
macro getuOperandNarrow(opcodeStruct, fieldName, dst)
loadb constexpr %opcodeStruct%_%fieldName%_index + OpcodeIDNarrowSize[PB, PC, 1], dst
end
macro getOperandNarrow(opcodeStruct, fieldName, dst)
loadbsq constexpr %opcodeStruct%_%fieldName%_index + OpcodeIDNarrowSize[PB, PC, 1], dst
end
macro getuOperandWide16(opcodeStruct, fieldName, dst)
loadh constexpr %opcodeStruct%_%fieldName%_index * 2 + OpcodeIDWide16Size[PB, PC, 1], dst
end
macro getOperandWide16(opcodeStruct, fieldName, dst)
loadhsq constexpr %opcodeStruct%_%fieldName%_index * 2 + OpcodeIDWide16Size[PB, PC, 1], dst
end
macro getuOperandWide32(opcodeStruct, fieldName, dst)
loadi constexpr %opcodeStruct%_%fieldName%_index * 4 + OpcodeIDWide32Size[PB, PC, 1], dst
end
macro getOperandWide32(opcodeStruct, fieldName, dst)
loadis constexpr %opcodeStruct%_%fieldName%_index * 4 + OpcodeIDWide32Size[PB, PC, 1], dst
end
macro makeReturn(get, dispatch, fn)
fn(macro (value)
move value, t2
get(m_dst, t1)
storeq t2, [cfr, t1, 8]
dispatch()
end)
end
macro makeReturnProfiled(opcodeStruct, get, metadata, dispatch, fn)
fn(macro (value)
move value, t3
metadata(t1, t2)
valueProfile(opcodeStruct, m_profile, t1, t3)
get(m_dst, t1)
storeq t3, [cfr, t1, 8]
dispatch()
end)
end
macro valueProfile(opcodeStruct, profileName, metadata, value)
storeq value, %opcodeStruct%::Metadata::%profileName%.m_buckets[metadata]
end
# After calling, calling bytecode is claiming input registers are not used.
macro dispatchAfterCall(size, opcodeStruct, valueProfileName, dstVirtualRegister, dispatch)
loadPC()
loadp CodeBlock[cfr], PB
loadp CodeBlock::m_instructionsRawPointer[PB], PB
get(size, opcodeStruct, dstVirtualRegister, t1)
storeq r0, [cfr, t1, 8]
metadata(size, opcodeStruct, t2, t1)
valueProfile(opcodeStruct, valueProfileName, t2, r0)
dispatch()
end
macro cCall2(function)
checkStackPointerAlignment(t4, 0xbad0c002)
if X86_64 or ARM64 or ARM64E
call function
elsif X86_64_WIN
# Note: this implementation is only correct if the return type size is > 8 bytes.
# See macro cCall2Void for an implementation when the return type <= 8 bytes.
# On Win64, when the return type is larger than 8 bytes, we need to allocate space on the stack for the return value.
# On entry rcx (a0), should contain a pointer to this stack space. The other parameters are shifted to the right,
# rdx (a1) should contain the first argument, and r8 (a2) should contain the second argument.
# On return, rax contains a pointer to this stack value, and we then need to copy the 16 byte return value into rax (r0) and rdx (r1)
# since the return value is expected to be split between the two.
# See http://msdn.microsoft.com/en-us/library/7572ztz4.aspx
move a1, a2
move a0, a1
subp 48, sp
move sp, a0
addp 32, a0
call function
addp 48, sp
move 8[r0], r1
move [r0], r0
elsif C_LOOP or C_LOOP_WIN
cloopCallSlowPath function, a0, a1
else
error
end
end
macro cCall2Void(function)
if C_LOOP or C_LOOP_WIN
cloopCallSlowPathVoid function, a0, a1
elsif X86_64_WIN
# Note: we cannot use the cCall2 macro for Win64 in this case,
# as the Win64 cCall2 implemenation is only correct when the return type size is > 8 bytes.
# On Win64, rcx and rdx are used for passing the first two parameters.
# We also need to make room on the stack for all four parameter registers.
# See http://msdn.microsoft.com/en-us/library/ms235286.aspx
subp 32, sp
call function
addp 32, sp
else
cCall2(function)
end
end
# This barely works. arg3 and arg4 should probably be immediates.
macro cCall4(function)
checkStackPointerAlignment(t4, 0xbad0c004)
if X86_64 or ARM64 or ARM64E
call function
elsif X86_64_WIN
# On Win64, rcx, rdx, r8, and r9 are used for passing the first four parameters.
# We also need to make room on the stack for all four parameter registers.
# See http://msdn.microsoft.com/en-us/library/ms235286.aspx
subp 64, sp
call function
addp 64, sp
else
error
end
end
macro doVMEntry(makeCall)
functionPrologue()
pushCalleeSaves()
const entry = a0
const vm = a1
const protoCallFrame = a2
vmEntryRecord(cfr, sp)
checkStackPointerAlignment(t4, 0xbad0dc01)
loadi VM::disallowVMEntryCount[vm], t4
btinz t4, .checkVMEntryPermission
storep vm, VMEntryRecord::m_vm[sp]
loadp VM::topCallFrame[vm], t4
storep t4, VMEntryRecord::m_prevTopCallFrame[sp]
loadp VM::topEntryFrame[vm], t4
storep t4, VMEntryRecord::m_prevTopEntryFrame[sp]
loadp ProtoCallFrame::calleeValue[protoCallFrame], t4
storep t4, VMEntryRecord::m_callee[sp]
loadi ProtoCallFrame::paddedArgCount[protoCallFrame], t4
addp CallFrameHeaderSlots, t4, t4
lshiftp 3, t4
subp sp, t4, t3
bqbeq sp, t3, .throwStackOverflow
# Ensure that we have enough additional stack capacity for the incoming args,
# and the frame for the JS code we're executing. We need to do this check
# before we start copying the args from the protoCallFrame below.
if C_LOOP or C_LOOP_WIN
bpaeq t3, VM::m_cloopStackLimit[vm], .stackHeightOK
move entry, t4
move vm, t5
cloopCallSlowPath _llint_stack_check_at_vm_entry, vm, t3
bpeq t0, 0, .stackCheckFailed
move t4, entry
move t5, vm
jmp .stackHeightOK
.stackCheckFailed:
move t4, entry
move t5, vm
jmp .throwStackOverflow
else
bpb t3, VM::m_softStackLimit[vm], .throwStackOverflow
end
.stackHeightOK:
move t3, sp
move (constexpr ProtoCallFrame::numberOfRegisters), t3
.copyHeaderLoop:
# Copy the CodeBlock/Callee/ArgumentCountIncludingThis/|this| from protoCallFrame into the callee frame.
subi 1, t3
loadq [protoCallFrame, t3, 8], extraTempReg
storeq extraTempReg, CodeBlock[sp, t3, 8]
btinz t3, .copyHeaderLoop
loadi PayloadOffset + ProtoCallFrame::argCountAndCodeOriginValue[protoCallFrame], t4
subi 1, t4
loadi ProtoCallFrame::paddedArgCount[protoCallFrame], extraTempReg
subi 1, extraTempReg
bieq t4, extraTempReg, .copyArgs
move ValueUndefined, t3
.fillExtraArgsLoop:
subi 1, extraTempReg
storeq t3, ThisArgumentOffset + 8[sp, extraTempReg, 8]
bineq t4, extraTempReg, .fillExtraArgsLoop
.copyArgs:
loadp ProtoCallFrame::args[protoCallFrame], t3
.copyArgsLoop:
btiz t4, .copyArgsDone
subi 1, t4
loadq [t3, t4, 8], extraTempReg
storeq extraTempReg, ThisArgumentOffset + 8[sp, t4, 8]
jmp .copyArgsLoop
.copyArgsDone:
if ARM64 or ARM64E
move sp, t4
storep t4, VM::topCallFrame[vm]
else
storep sp, VM::topCallFrame[vm]
end
storep cfr, VM::topEntryFrame[vm]
checkStackPointerAlignment(extraTempReg, 0xbad0dc02)
makeCall(entry, protoCallFrame, t3, t4)
# We may have just made a call into a JS function, so we can't rely on sp
# for anything but the fact that our own locals (ie the VMEntryRecord) are
# not below it. It also still has to be aligned, though.
checkStackPointerAlignment(t2, 0xbad0dc03)
vmEntryRecord(cfr, t4)
loadp VMEntryRecord::m_vm[t4], vm
loadp VMEntryRecord::m_prevTopCallFrame[t4], t2
storep t2, VM::topCallFrame[vm]
loadp VMEntryRecord::m_prevTopEntryFrame[t4], t2
storep t2, VM::topEntryFrame[vm]
subp cfr, CalleeRegisterSaveSize, sp
popCalleeSaves()
functionEpilogue()
ret
.throwStackOverflow:
move vm, a0
move protoCallFrame, a1
cCall2(_llint_throw_stack_overflow_error)
vmEntryRecord(cfr, t4)
loadp VMEntryRecord::m_vm[t4], vm
loadp VMEntryRecord::m_prevTopCallFrame[t4], extraTempReg
storep extraTempReg, VM::topCallFrame[vm]
loadp VMEntryRecord::m_prevTopEntryFrame[t4], extraTempReg
storep extraTempReg, VM::topEntryFrame[vm]
subp cfr, CalleeRegisterSaveSize, sp
popCalleeSaves()
functionEpilogue()
ret
.checkVMEntryPermission:
move vm, a0
move protoCallFrame, a1
cCall2(_llint_check_vm_entry_permission)
move ValueUndefined, r0
subp cfr, CalleeRegisterSaveSize, sp
popCalleeSaves()
functionEpilogue()
ret
end
# a0, a2, t3, t4
macro makeJavaScriptCall(entry, protoCallFrame, temp1, temp2)
addp 16, sp
if C_LOOP or C_LOOP_WIN
cloopCallJSFunction entry
elsif ARM64E
move entry, t3
leap JSCConfig + constexpr JSC::offsetOfJSCConfigGateMap + (constexpr Gate::vmEntryToJavaScript) * PtrSize, a2
jmp [a2], NativeToJITGatePtrTag # JSEntryPtrTag
global _vmEntryToJavaScriptTrampoline
_vmEntryToJavaScriptTrampoline:
call t3, JSEntryPtrTag
else
call entry, JSEntryPtrTag
end
if ARM64E
global _vmEntryToJavaScriptGateAfter
_vmEntryToJavaScriptGateAfter:
end
subp 16, sp
end
# a0, a2, t3, t4
macro makeHostFunctionCall(entry, protoCallFrame, temp1, temp2)
move entry, temp1
storep cfr, [sp]
loadp ProtoCallFrame::globalObject[protoCallFrame], a0
move sp, a1
if C_LOOP or C_LOOP_WIN
storep lr, 8[sp]
cloopCallNative temp1
elsif X86_64_WIN
# We need to allocate 32 bytes on the stack for the shadow space.
subp 32, sp
call temp1, HostFunctionPtrTag
addp 32, sp
else
call temp1, HostFunctionPtrTag
end
end
op(llint_handle_uncaught_exception, macro ()
loadp Callee[cfr], t3
convertCalleeToVM(t3)
restoreCalleeSavesFromVMEntryFrameCalleeSavesBuffer(t3, t0)
storep 0, VM::callFrameForCatch[t3]
loadp VM::topEntryFrame[t3], cfr
vmEntryRecord(cfr, t2)
loadp VMEntryRecord::m_vm[t2], t3
loadp VMEntryRecord::m_prevTopCallFrame[t2], extraTempReg
storep extraTempReg, VM::topCallFrame[t3]
loadp VMEntryRecord::m_prevTopEntryFrame[t2], extraTempReg
storep extraTempReg, VM::topEntryFrame[t3]
subp cfr, CalleeRegisterSaveSize, sp
popCalleeSaves()
functionEpilogue()
ret
end)
op(llint_get_host_call_return_value, macro ()
functionPrologue()
pushCalleeSaves()
loadp Callee[cfr], t0
convertCalleeToVM(t0)
loadq VM::encodedHostCallReturnValue[t0], t0
popCalleeSaves()
functionEpilogue()
ret
end)
macro prepareStateForCCall()
addp PB, PC
end
macro restoreStateAfterCCall()
move r0, PC
subp PB, PC
end
macro callSlowPath(slowPath)
prepareStateForCCall()
move cfr, a0
move PC, a1
cCall2(slowPath)
restoreStateAfterCCall()
end
macro traceOperand(fromWhere, operand)
prepareStateForCCall()
move fromWhere, a2
move operand, a3
move cfr, a0
move PC, a1
cCall4(_llint_trace_operand)
restoreStateAfterCCall()
end
macro traceValue(fromWhere, operand)
prepareStateForCCall()
move fromWhere, a2
move operand, a3
move cfr, a0
move PC, a1
cCall4(_llint_trace_value)
restoreStateAfterCCall()
end
# Call a slow path for call opcodes.
macro callCallSlowPath(slowPath, action)
storePC()
prepareStateForCCall()
move cfr, a0
move PC, a1
cCall2(slowPath)
action(r0, r1)
end
macro callTrapHandler(throwHandler)
storePC()
prepareStateForCCall()
move cfr, a0
move PC, a1
cCall2(_llint_slow_path_handle_traps)
btpnz r0, throwHandler
loadi LLIntReturnPC[cfr], PC
end
macro checkSwitchToJITForLoop()
checkSwitchToJIT(
1,
macro()
storePC()
prepareStateForCCall()
move cfr, a0
move PC, a1
cCall2(_llint_loop_osr)
btpz r0, .recover
move r1, sp
if ARM64E
leap JSCConfig + constexpr JSC::offsetOfJSCConfigGateMap + (constexpr Gate::loopOSREntry) * PtrSize, a2
jmp [a2], NativeToJITGatePtrTag # JSEntryPtrTag
else
jmp r0, JSEntryPtrTag
end
.recover:
loadPC()
end)
end
macro cage(basePtr, mask, ptr, scratch)
if GIGACAGE_ENABLED and not (C_LOOP or C_LOOP_WIN)
loadp basePtr, scratch
btpz scratch, .done
andp mask, ptr
addp scratch, ptr
.done:
end
end
macro cagePrimitive(basePtr, mask, ptr, scratch)
if GIGACAGE_ENABLED and not (C_LOOP or C_LOOP_WIN)
loadb GigacageConfig + Gigacage::Config::disablingPrimitiveGigacageIsForbidden, scratch
btbnz scratch, .doCaging
loadb _disablePrimitiveGigacageRequested, scratch
btbnz scratch, .done
.doCaging:
cage(basePtr, mask, ptr, scratch)
.done:
end
end
macro cagedPrimitive(ptr, length, scratch, scratch2)
if ARM64E
const source = scratch2
move ptr, scratch2
else
const source = ptr
end
if GIGACAGE_ENABLED
cagePrimitive(GigacageConfig + Gigacage::Config::basePtrs + GigacagePrimitiveBasePtrOffset, constexpr Gigacage::primitiveGigacageMask, source, scratch)
if ARM64E
const numberOfPACBits = constexpr MacroAssembler::numberOfPACBits
bfiq scratch2, 0, 64 - numberOfPACBits, ptr
end
end
if ARM64E
untagArrayPtr length, ptr
end
end
macro loadCagedJSValue(source, dest, scratchOrLength)
loadp source, dest
if GIGACAGE_ENABLED
cage(GigacageConfig + Gigacage::Config::basePtrs + GigacageJSValueBasePtrOffset, constexpr Gigacage::jsValueGigacageMask, dest, scratchOrLength)
end
end
macro loadVariable(get, fieldName, valueReg)
get(fieldName, valueReg)
loadq [cfr, valueReg, 8], valueReg
end
# Index and value must be different registers. Index may be clobbered.
macro loadConstant(size, index, value)
macro loadNarrow()
loadp CodeBlock[cfr], value
loadp CodeBlock::m_constantRegisters + VectorBufferOffset[value], value
loadq -(FirstConstantRegisterIndexNarrow * 8)[value, index, 8], value
end
macro loadWide16()
loadp CodeBlock[cfr], value
loadp CodeBlock::m_constantRegisters + VectorBufferOffset[value], value
loadq -(FirstConstantRegisterIndexWide16 * 8)[value, index, 8], value
end
macro loadWide32()
loadp CodeBlock[cfr], value
loadp CodeBlock::m_constantRegisters + VectorBufferOffset[value], value
subp FirstConstantRegisterIndexWide32, index
loadq [value, index, 8], value
end
size(loadNarrow, loadWide16, loadWide32, macro (load) load() end)
end
# Index and value must be different registers. Index may be clobbered.
macro loadConstantOrVariable(size, index, value)
macro loadNarrow()
bpgteq index, FirstConstantRegisterIndexNarrow, .constant
loadq [cfr, index, 8], value
jmp .done
.constant:
loadConstant(size, index, value)
.done:
end
macro loadWide16()
bpgteq index, FirstConstantRegisterIndexWide16, .constant
loadq [cfr, index, 8], value
jmp .done
.constant:
loadConstant(size, index, value)
.done:
end
macro loadWide32()
bpgteq index, FirstConstantRegisterIndexWide32, .constant
loadq [cfr, index, 8], value
jmp .done
.constant:
loadConstant(size, index, value)
.done:
end
size(loadNarrow, loadWide16, loadWide32, macro (load) load() end)
end
macro loadConstantOrVariableInt32(size, index, value, slow)
loadConstantOrVariable(size, index, value)
bqb value, numberTag, slow
end
macro loadConstantOrVariableCell(size, index, value, slow)
loadConstantOrVariable(size, index, value)
btqnz value, notCellMask, slow
end
macro writeBarrierOnCellWithReload(cell, reloadAfterSlowPath)
skipIfIsRememberedOrInEden(
cell,
macro()
push PB, PC
move cell, a1 # cell can be a0
move cfr, a0
cCall2Void(_llint_write_barrier_slow)
pop PC, PB
reloadAfterSlowPath()
end)
end
macro writeBarrierOnCellAndValueWithReload(cell, value, reloadAfterSlowPath)
btqnz value, notCellMask, .writeBarrierDone
btqz value, .writeBarrierDone
writeBarrierOnCellWithReload(cell, reloadAfterSlowPath)
.writeBarrierDone:
end
macro writeBarrierOnOperandWithReload(size, get, cellFieldName, reloadAfterSlowPath)
get(cellFieldName, t1)
loadConstantOrVariableCell(size, t1, t2, .writeBarrierDone)
writeBarrierOnCellWithReload(t2, reloadAfterSlowPath)
.writeBarrierDone:
end
macro writeBarrierOnOperand(size, get, cellFieldName)
writeBarrierOnOperandWithReload(size, get, cellFieldName, macro () end)
end
macro writeBarrierOnOperands(size, get, cellFieldName, valueFieldName)
get(valueFieldName, t1)
loadConstantOrVariableCell(size, t1, t0, .writeBarrierDone)
btpz t0, .writeBarrierDone
writeBarrierOnOperand(size, get, cellFieldName)
.writeBarrierDone:
end
macro writeBarrierOnGlobal(size, get, valueFieldName, loadMacro)
get(valueFieldName, t1)
loadConstantOrVariableCell(size, t1, t0, .writeBarrierDone)
btpz t0, .writeBarrierDone
loadMacro(t3)
writeBarrierOnCellWithReload(t3, macro() end)
.writeBarrierDone:
end
macro writeBarrierOnGlobalObject(size, get, valueFieldName)
writeBarrierOnGlobal(size, get, valueFieldName,
macro(registerToStoreGlobal)
loadp CodeBlock[cfr], registerToStoreGlobal
loadp CodeBlock::m_globalObject[registerToStoreGlobal], registerToStoreGlobal
end)
end
macro writeBarrierOnGlobalLexicalEnvironment(size, get, valueFieldName)
writeBarrierOnGlobal(size, get, valueFieldName,
macro(registerToStoreGlobal)
loadp CodeBlock[cfr], registerToStoreGlobal
loadp CodeBlock::m_globalObject[registerToStoreGlobal], registerToStoreGlobal
loadp JSGlobalObject::m_globalLexicalEnvironment[registerToStoreGlobal], registerToStoreGlobal
end)
end
macro structureIDToStructureWithScratch(structureIDThenStructure, scratch, scratch2)
loadp CodeBlock[cfr], scratch
move structureIDThenStructure, scratch2
loadp CodeBlock::m_vm[scratch], scratch
rshifti NumberOfStructureIDEntropyBits, scratch2
loadp VM::heap + Heap::m_structureIDTable + StructureIDTable::m_table[scratch], scratch
loadp [scratch, scratch2, PtrSize], scratch2
lshiftp StructureEntropyBitsShift, structureIDThenStructure
xorp scratch2, structureIDThenStructure
end
macro loadStructureWithScratch(cell, structure, scratch, scratch2)
loadi JSCell::m_structureID[cell], structure
structureIDToStructureWithScratch(structure, scratch, scratch2)
end
# Entrypoints into the interpreter.
# Expects that CodeBlock is in t1, which is what prologue() leaves behind.
macro functionArityCheck(opcodeName, doneLabel, slowPath)
loadi PayloadOffset + ArgumentCountIncludingThis[cfr], t0
biaeq t0, CodeBlock::m_numParameters[t1], doneLabel
prepareStateForCCall()
move cfr, a0
move PC, a1
cCall2(slowPath) # This slowPath has the protocol: r0 = 0 => no error, r0 != 0 => error
btiz r0, .noError
# We're throwing before the frame is fully set up. This frame will be
# ignored by the unwinder. So, let's restore the callee saves before we
# start unwinding. We need to do this before we change the cfr.
restoreCalleeSavesUsedByLLInt()
move r1, cfr # r1 contains caller frame
jmp _llint_throw_from_slow_path_trampoline
.noError:
move r1, t1 # r1 contains slotsToAdd.
btiz t1, .continue
loadi PayloadOffset + ArgumentCountIncludingThis[cfr], t2
addi CallFrameHeaderSlots, t2
// Check if there are some unaligned slots we can use
move t1, t3
andi StackAlignmentSlots - 1, t3
btiz t3, .noExtraSlot
move ValueUndefined, t0
.fillExtraSlots:
storeq t0, [cfr, t2, 8]
addi 1, t2
bsubinz 1, t3, .fillExtraSlots
andi ~(StackAlignmentSlots - 1), t1
btiz t1, .continue
.noExtraSlot:
if ARM64E
leap JSCConfig + constexpr JSC::offsetOfJSCConfigGateMap + (constexpr Gate::%opcodeName%Untag) * PtrSize, t3
jmp [t3], NativeToJITGatePtrTag
_js_trampoline_%opcodeName%_untag:
loadp 8[cfr], lr
addp 16, cfr, t3
untagReturnAddress t3
_%opcodeName%UntagGateAfter:
else
_js_trampoline_%opcodeName%_untag:
end
// Move frame up t1 slots
negq t1
move cfr, t3
subp CalleeSaveSpaceAsVirtualRegisters * 8, t3
addi CalleeSaveSpaceAsVirtualRegisters, t2
move t1, t0
# Adds to sp are always 64-bit on arm64 so we need maintain t0's high bits.
lshiftq 3, t0
addp t0, cfr
addp t0, sp
.copyLoop:
loadq [t3], t0
storeq t0, [t3, t1, 8]
addp 8, t3
bsubinz 1, t2, .copyLoop
// Fill new slots with JSUndefined
move t1, t2
move ValueUndefined, t0
.fillLoop:
storeq t0, [t3, t1, 8]
addp 8, t3
baddinz 1, t2, .fillLoop
if ARM64E
leap JSCConfig + constexpr JSC::offsetOfJSCConfigGateMap + (constexpr Gate::%opcodeName%Tag) * PtrSize, t3
jmp [t3], NativeToJITGatePtrTag
_js_trampoline_%opcodeName%_tag:
addp 16, cfr, t1
tagReturnAddress t1
storep lr, 8[cfr]
_%opcodeName%TagGateAfter:
else
_js_trampoline_%opcodeName%_tag:
end
.continue:
# Reload CodeBlock and reset PC, since the slow_path clobbered them.
loadp CodeBlock[cfr], t1
loadp CodeBlock::m_instructionsRawPointer[t1], PB
move 0, PC
jmp doneLabel
end
# Instruction implementations
_llint_op_enter:
traceExecution()
checkStackPointerAlignment(t2, 0xdead00e1)
loadp CodeBlock[cfr], t2 // t2<CodeBlock> = cfr.CodeBlock
loadi CodeBlock::m_numVars[t2], t2 // t2<size_t> = t2<CodeBlock>.m_numVars
subq CalleeSaveSpaceAsVirtualRegisters, t2
move cfr, t1
subq CalleeSaveSpaceAsVirtualRegisters * 8, t1
btiz t2, .opEnterDone
move ValueUndefined, t0
negi t2
sxi2q t2, t2
.opEnterLoop:
storeq t0, [t1, t2, 8]
addq 1, t2
btqnz t2, .opEnterLoop
.opEnterDone:
callSlowPath(_slow_path_enter)
dispatchOp(narrow, op_enter)
llintOpWithProfile(op_get_argument, OpGetArgument, macro (size, get, dispatch, return)
get(m_index, t2)
loadi PayloadOffset + ArgumentCountIncludingThis[cfr], t0
bilteq t0, t2, .opGetArgumentOutOfBounds
loadq ThisArgumentOffset[cfr, t2, 8], t0
return(t0)
.opGetArgumentOutOfBounds:
return(ValueUndefined)
end)
llintOpWithReturn(op_argument_count, OpArgumentCount, macro (size, get, dispatch, return)
loadi PayloadOffset + ArgumentCountIncludingThis[cfr], t0
subi 1, t0
orq TagNumber, t0
return(t0)
end)
llintOpWithReturn(op_get_scope, OpGetScope, macro (size, get, dispatch, return)
loadp Callee[cfr], t0
loadp JSCallee::m_scope[t0], t0
return(t0)
end)
llintOpWithMetadata(op_to_this, OpToThis, macro (size, get, dispatch, metadata, return)
get(m_srcDst, t0)
loadq [cfr, t0, 8], t0
btqnz t0, notCellMask, .opToThisSlow
bbneq JSCell::m_type[t0], FinalObjectType, .opToThisSlow
loadi JSCell::m_structureID[t0], t1
metadata(t2, t3)
loadi OpToThis::Metadata::m_cachedStructureID[t2], t2
bineq t1, t2, .opToThisSlow
dispatch()
.opToThisSlow:
callSlowPath(_slow_path_to_this)
dispatch()
end)
llintOp(op_check_tdz, OpCheckTdz, macro (size, get, dispatch)
get(m_targetVirtualRegister, t0)
loadConstantOrVariable(size, t0, t1)
bqneq t1, ValueEmpty, .opNotTDZ
callSlowPath(_slow_path_throw_tdz_error)
.opNotTDZ:
dispatch()
end)
llintOpWithReturn(op_mov, OpMov, macro (size, get, dispatch, return)
get(m_src, t1)
loadConstantOrVariable(size, t1, t2)
return(t2)
end)
llintOpWithReturn(op_not, OpNot, macro (size, get, dispatch, return)
get(m_operand, t0)
loadConstantOrVariable(size, t0, t2)
xorq ValueFalse, t2
btqnz t2, ~1, .opNotSlow
xorq ValueTrue, t2
return(t2)
.opNotSlow:
callSlowPath(_slow_path_not)
dispatch()
end)
macro equalityComparisonOp(opcodeName, opcodeStruct, integerComparison)
llintOpWithReturn(op_%opcodeName%, opcodeStruct, macro (size, get, dispatch, return)
get(m_rhs, t0)
get(m_lhs, t2)
loadConstantOrVariableInt32(size, t0, t1, .slow)
loadConstantOrVariableInt32(size, t2, t0, .slow)
integerComparison(t0, t1, t0)
orq ValueFalse, t0
return(t0)
.slow:
callSlowPath(_slow_path_%opcodeName%)
dispatch()
end)
end
macro equalNullComparisonOp(opcodeName, opcodeStruct, fn)
llintOpWithReturn(opcodeName, opcodeStruct, macro (size, get, dispatch, return)
get(m_operand, t0)
loadq [cfr, t0, 8], t0
btqnz t0, notCellMask, .immediate
btbnz JSCell::m_flags[t0], MasqueradesAsUndefined, .masqueradesAsUndefined
move 0, t0
jmp .done
.masqueradesAsUndefined:
loadStructureWithScratch(t0, t2, t1, t3)
loadp CodeBlock[cfr], t0
loadp CodeBlock::m_globalObject[t0], t0
cpeq Structure::m_globalObject[t2], t0, t0
jmp .done
.immediate:
andq ~TagUndefined, t0
cqeq t0, ValueNull, t0
.done:
fn(t0)
return(t0)
end)
end
equalNullComparisonOp(op_eq_null, OpEqNull,
macro (value) orq ValueFalse, value end)
equalNullComparisonOp(op_neq_null, OpNeqNull,
macro (value) xorq ValueTrue, value end)
llintOpWithReturn(op_is_undefined_or_null, OpIsUndefinedOrNull, macro (size, get, dispatch, return)
get(m_operand, t1)
loadConstantOrVariable(size, t1, t0)
andq ~TagUndefined, t0
cqeq t0, ValueNull, t0
orq ValueFalse, t0
return(t0)
end)
macro strictEqOp(opcodeName, opcodeStruct, createBoolean)
llintOpWithReturn(op_%opcodeName%, opcodeStruct, macro (size, get, dispatch, return)
get(m_rhs, t0)
get(m_lhs, t2)
loadConstantOrVariable(size, t0, t1)
loadConstantOrVariable(size, t2, t0)
# At a high level we do
# If (left is Double || right is Double)
# goto slowPath;
# result = (left == right);
# if (result)
# goto done;
# if (left is Cell || right is Cell)
# goto slowPath;
# done:
# return result;
# This fragment implements (left is Double || right is Double), with a single branch instead of the 4 that would be naively required if we used branchIfInt32/branchIfNumber
# The trick is that if a JSValue is an Int32, then adding 1<<49 to it will make it overflow, leaving all high bits at 0
# If it is not a number at all, then 1<<49 will be its only high bit set
# Leaving only doubles above or equal 1<<50.
move t0, t2
move t1, t3
move LowestOfHighBits, t5
addq t5, t2
addq t5, t3
orq t2, t3
lshiftq 1, t5
bqaeq t3, t5, .slow
cqeq t0, t1, t5
btqnz t5, t5, .done #is there a better way of checking t5 != 0 ?
move t0, t2
# This andq could be an 'or' if not for BigInt32 (since it makes it possible for a Cell to be strictEqual to a non-Cell)
andq t1, t2
btqz t2, notCellMask, .slow
.done:
createBoolean(t5)
return(t5)
.slow:
callSlowPath(_slow_path_%opcodeName%)
dispatch()
end)
end
strictEqOp(stricteq, OpStricteq,
macro (operand) xorq ValueFalse, operand end)
strictEqOp(nstricteq, OpNstricteq,
macro (operand) xorq ValueTrue, operand end)
macro strictEqualityJumpOp(opcodeName, opcodeStruct, jumpIfEqual, jumpIfNotEqual)
llintOpWithJump(op_%opcodeName%, opcodeStruct, macro (size, get, jump, dispatch)
get(m_lhs, t2)
get(m_rhs, t3)
loadConstantOrVariable(size, t2, t0)
loadConstantOrVariable(size, t3, t1)
# At a high level we do
# If (left is Double || right is Double)
# goto slowPath;
# if (left == right)
# goto jumpTarget;
# if (left is Cell || right is Cell)
# goto slowPath;
# goto otherJumpTarget
# This fragment implements (left is Double || right is Double), with a single branch instead of the 4 that would be naively required if we used branchIfInt32/branchIfNumber
# The trick is that if a JSValue is an Int32, then adding 1<<49 to it will make it overflow, leaving all high bits at 0
# If it is not a number at all, then 1<<49 will be its only high bit set
# Leaving only doubles above or equal 1<<50.
move t0, t2
move t1, t3
move LowestOfHighBits, t5
addq t5, t2
addq t5, t3
orq t2, t3
lshiftq 1, t5
bqaeq t3, t5, .slow
bqeq t0, t1, .equal