forked from phoboslab/JavaScriptCore-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLowLevelInterpreter64.asm
More file actions
2158 lines (1828 loc) · 57.2 KB
/
LowLevelInterpreter64.asm
File metadata and controls
2158 lines (1828 loc) · 57.2 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 (C) 2011, 2012, 2013 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 jumpToInstruction()
jmp [PB, PC, 8]
end
macro dispatch(advance)
addp advance, PC
jumpToInstruction()
end
macro dispatchInt(advance)
addi advance, PC
jumpToInstruction()
end
macro dispatchIntIndirect(offset)
dispatchInt(offset * 8[PB, PC, 8])
end
macro dispatchAfterCall()
loadi ArgumentCount + TagOffset[cfr], PC
loadp CodeBlock[cfr], PB
loadp CodeBlock::m_instructions[PB], PB
loadisFromInstruction(1, t1)
storeq t0, [cfr, t1, 8]
valueProfile(t0, 7, t2)
dispatch(8)
end
macro cCall2(function, arg1, arg2)
if X86_64
move arg1, t5
move arg2, t4
call function
elsif ARM64
move arg1, t0
move arg2, t1
call function
elsif C_LOOP
cloopCallSlowPath function, arg1, arg2
else
error
end
end
# This barely works. arg3 and arg4 should probably be immediates.
macro cCall4(function, arg1, arg2, arg3, arg4)
if X86_64
move arg1, t5
move arg2, t4
move arg3, t1
move arg4, t2
call function
elsif ARM64
move arg1, t0
move arg2, t1
move arg3, t2
move arg4, t3
call function
elsif C_LOOP
error
else
error
end
end
macro functionPrologue(extraStackSpace)
if X86_64
push cfr
move sp, cfr
elsif ARM64
pushLRAndFP
end
pushCalleeSaves
if X86_64
subp extraStackSpace, sp
end
end
macro functionEpilogue(extraStackSpace)
if X86_64
addp extraStackSpace, sp
end
popCalleeSaves
if X86_64
pop cfr
elsif ARM64
popLRAndFP
end
end
macro doCallToJavaScript(makeCall, doReturn)
if X86_64
const entry = t5
const vmTopCallFrame = t4
const protoCallFrame = t1
const topOfStack = t2
const extraStackSpace = 8
const previousCFR = t0
const previousPC = t6
const temp1 = t0
const temp2 = t3
const temp3 = t6
elsif ARM64
const entry = a0
const vmTopCallFrame = a1
const protoCallFrame = a2
const topOfStack = a3
const extraStackSpace = 0
const previousCFR = t4
const previousPC = lr
const temp1 = t3
const temp2 = t5
const temp3 = t6
end
if X86_64
loadp [sp], previousPC
end
move cfr, previousCFR
functionPrologue(extraStackSpace)
move topOfStack, cfr
subp (CallFrameHeaderSlots-1)*8, cfr
storep 0, ArgumentCount[cfr]
storep vmTopCallFrame, Callee[cfr]
loadp [vmTopCallFrame], temp1
storep temp1, ScopeChain[cfr]
storep 1, CodeBlock[cfr]
storep previousPC, ReturnPC[cfr]
storep previousCFR, CallerFrame[cfr]
move cfr, temp1
loadi ProtoCallFrame::paddedArgCount[protoCallFrame], temp2
addp CallFrameHeaderSlots, temp2, temp2
lshiftp 3, temp2
subp temp2, cfr
storep temp1, CallerFrame[cfr]
move 5, temp1
.copyHeaderLoop:
subi 1, temp1
loadp [protoCallFrame, temp1, 8], temp3
storep temp3, CodeBlock[cfr, temp1, 8]
btinz temp1, .copyHeaderLoop
loadi ProtoCallFrame::argCountAndCodeOriginValue[protoCallFrame], temp2
subi 1, temp2
loadi ProtoCallFrame::paddedArgCount[protoCallFrame], temp3
subi 1, temp3
bieq temp2, temp3, .copyArgs
move ValueUndefined, temp1
.fillExtraArgsLoop:
subi 1, temp3
storep temp1, ThisArgumentOffset+8[cfr, temp3, 8]
bineq temp2, temp3, .fillExtraArgsLoop
.copyArgs:
loadp ProtoCallFrame::args[protoCallFrame], temp1
.copyArgsLoop:
btiz temp2, .copyArgsDone
subi 1, temp2
loadp [temp1, temp2, 8], temp3
storep temp3, ThisArgumentOffset+8[cfr, temp2, 8]
jmp .copyArgsLoop
.copyArgsDone:
storep cfr, [vmTopCallFrame]
move 0xffff000000000000, csr1
addp 2, csr1, csr2
makeCall(entry, temp1)
bpeq CodeBlock[cfr], 1, .calleeFramePopped
loadp CallerFrame[cfr], cfr
.calleeFramePopped:
loadp Callee[cfr], temp2 # VM.topCallFrame
loadp ScopeChain[cfr], temp3
storep temp3, [temp2]
doReturn(extraStackSpace)
end
macro makeJavaScriptCall(entry, temp)
call entry
end
macro makeHostFunctionCall(entry, temp)
move entry, temp
if X86_64
move cfr, t5
elsif ARM64 or C_LOOP
move cfr, a0
end
call temp
end
macro doReturnFromJavaScript(extraStackSpace)
_returnFromJavaScript:
functionEpilogue(extraStackSpace)
ret
end
macro doReturnFromHostFunction(extraStackSpace)
functionEpilogue(extraStackSpace)
ret
end
macro prepareStateForCCall()
leap [PB, PC, 8], PC
move PB, t3
end
macro restoreStateAfterCCall()
move t0, PC
move t1, cfr
move t3, PB
subp PB, PC
rshiftp 3, PC
end
macro callSlowPath(slowPath)
prepareStateForCCall()
cCall2(slowPath, cfr, PC)
restoreStateAfterCCall()
end
macro traceOperand(fromWhere, operand)
prepareStateForCCall()
cCall4(_llint_trace_operand, cfr, PC, fromWhere, operand)
restoreStateAfterCCall()
end
macro traceValue(fromWhere, operand)
prepareStateForCCall()
cCall4(_llint_trace_value, cfr, PC, fromWhere, operand)
restoreStateAfterCCall()
end
# Call a slow path for call call opcodes.
macro callCallSlowPath(slowPath, action)
storei PC, ArgumentCount + TagOffset[cfr]
prepareStateForCCall()
cCall2(slowPath, cfr, PC)
move t1, cfr
action(t0)
end
macro callWatchdogTimerHandler(throwHandler)
storei PC, ArgumentCount + TagOffset[cfr]
prepareStateForCCall()
cCall2(_llint_slow_path_handle_watchdog_timer, cfr, PC)
move t1, cfr
btpnz t0, throwHandler
move t3, PB
loadi ArgumentCount + TagOffset[cfr], PC
end
macro checkSwitchToJITForLoop()
checkSwitchToJIT(
1,
macro()
storei PC, ArgumentCount + TagOffset[cfr]
prepareStateForCCall()
cCall2(_llint_loop_osr, cfr, PC)
move t1, cfr
btpz t0, .recover
jmp t0
.recover:
move t3, PB
loadi ArgumentCount + TagOffset[cfr], PC
end)
end
macro loadVariable(operand, value)
loadisFromInstruction(operand, value)
loadq [cfr, value, 8], value
end
# Index and value must be different registers. Index may be clobbered.
macro loadConstantOrVariable(index, value)
bpgteq index, FirstConstantRegisterIndex, .constant
loadq [cfr, index, 8], value
jmp .done
.constant:
loadp CodeBlock[cfr], value
loadp CodeBlock::m_constantRegisters + VectorBufferOffset[value], value
subp FirstConstantRegisterIndex, index
loadq [value, index, 8], value
.done:
end
macro loadConstantOrVariableInt32(index, value, slow)
loadConstantOrVariable(index, value)
bqb value, tagTypeNumber, slow
end
macro loadConstantOrVariableCell(index, value, slow)
loadConstantOrVariable(index, value)
btqnz value, tagMask, slow
end
macro writeBarrier(value)
# Nothing to do, since we don't have a generational or incremental collector.
end
macro valueProfile(value, operand, scratch)
if VALUE_PROFILER
loadpFromInstruction(operand, scratch)
storeq value, ValueProfile::m_buckets[scratch]
end
end
# Entrypoints into the interpreter.
# Expects that CodeBlock is in t1, which is what prologue() leaves behind.
macro functionArityCheck(doneLabel, slow_path)
loadi PayloadOffset + ArgumentCount[cfr], t0
biaeq t0, CodeBlock::m_numParameters[t1], doneLabel
prepareStateForCCall()
cCall2(slow_path, cfr, PC) # This slow_path has a simple protocol: t0 = 0 => no error, t0 != 0 => error
btiz t0, .isArityFixupNeeded
move t1, cfr # t1 contains caller frame
jmp _llint_throw_from_slow_path_trampoline
.isArityFixupNeeded:
btiz t1, .continue
// Move frame up "t1" slots
negq t1
move cfr, t3
loadi PayloadOffset + ArgumentCount[cfr], t2
addi CallFrameHeaderSlots, t2
.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
lshiftp 3, t1
addp t1, cfr
.continue:
# Reload CodeBlock and reset PC, since the slow_path clobbered them.
loadp CodeBlock[cfr], t1
loadp CodeBlock::m_instructions[t1], PB
move 0, PC
jmp doneLabel
end
macro branchIfException(label)
loadp ScopeChain[cfr], t3
andp MarkedBlockMask, t3
loadp MarkedBlock::m_weakSet + WeakSet::m_vm[t3], t3
btqz VM::m_exception[t3], .noException
jmp label
.noException:
end
# Instruction implementations
_llint_op_enter:
traceExecution()
loadp CodeBlock[cfr], t2 // t2<CodeBlock> = cfr.CodeBlock
loadi CodeBlock::m_numVars[t2], t2 // t2<size_t> = t2<CodeBlock>.m_numVars
btiz t2, .opEnterDone
move ValueUndefined, t0
negi t2
sxi2q t2, t2
.opEnterLoop:
storeq t0, [cfr, t2, 8]
addq 1, t2
btqnz t2, .opEnterLoop
.opEnterDone:
dispatch(1)
_llint_op_create_activation:
traceExecution()
loadisFromInstruction(1, t0)
bqneq [cfr, t0, 8], ValueEmpty, .opCreateActivationDone
callSlowPath(_llint_slow_path_create_activation)
.opCreateActivationDone:
dispatch(2)
_llint_op_init_lazy_reg:
traceExecution()
loadisFromInstruction(1, t0)
storeq ValueEmpty, [cfr, t0, 8]
dispatch(2)
_llint_op_create_arguments:
traceExecution()
loadisFromInstruction(1, t0)
bqneq [cfr, t0, 8], ValueEmpty, .opCreateArgumentsDone
callSlowPath(_slow_path_create_arguments)
.opCreateArgumentsDone:
dispatch(2)
_llint_op_create_this:
traceExecution()
loadisFromInstruction(2, t0)
loadp [cfr, t0, 8], t0
loadp JSFunction::m_allocationProfile + ObjectAllocationProfile::m_allocator[t0], t1
loadp JSFunction::m_allocationProfile + ObjectAllocationProfile::m_structure[t0], t2
btpz t1, .opCreateThisSlow
allocateJSObject(t1, t2, t0, t3, .opCreateThisSlow)
loadisFromInstruction(1, t1)
storeq t0, [cfr, t1, 8]
dispatch(4)
.opCreateThisSlow:
callSlowPath(_slow_path_create_this)
dispatch(4)
_llint_op_get_callee:
traceExecution()
loadisFromInstruction(1, t0)
loadp Callee[cfr], t1
loadpFromInstruction(2, t2)
bpneq t1, t2, .opGetCalleeSlow
storep t1, [cfr, t0, 8]
dispatch(3)
.opGetCalleeSlow:
callSlowPath(_slow_path_get_callee)
dispatch(3)
_llint_op_to_this:
traceExecution()
loadisFromInstruction(1, t0)
loadq [cfr, t0, 8], t0
btqnz t0, tagMask, .opToThisSlow
loadp JSCell::m_structure[t0], t0
bbneq Structure::m_typeInfo + TypeInfo::m_type[t0], FinalObjectType, .opToThisSlow
loadpFromInstruction(2, t2)
bpneq t0, t2, .opToThisSlow
dispatch(3)
.opToThisSlow:
callSlowPath(_slow_path_to_this)
dispatch(3)
_llint_op_new_object:
traceExecution()
loadpFromInstruction(3, t0)
loadp ObjectAllocationProfile::m_allocator[t0], t1
loadp ObjectAllocationProfile::m_structure[t0], t2
allocateJSObject(t1, t2, t0, t3, .opNewObjectSlow)
loadisFromInstruction(1, t1)
storeq t0, [cfr, t1, 8]
dispatch(4)
.opNewObjectSlow:
callSlowPath(_llint_slow_path_new_object)
dispatch(4)
_llint_op_mov:
traceExecution()
loadisFromInstruction(2, t1)
loadisFromInstruction(1, t0)
loadConstantOrVariable(t1, t2)
storeq t2, [cfr, t0, 8]
dispatch(3)
macro notifyWrite(set, value, scratch, slow)
loadb VariableWatchpointSet::m_state[set], scratch
bieq scratch, IsInvalidated, .done
bineq scratch, ClearWatchpoint, .overwrite
storeq value, VariableWatchpointSet::m_inferredValue[set]
storeb IsWatched, VariableWatchpointSet::m_state[set]
jmp .done
.overwrite:
bqeq value, VariableWatchpointSet::m_inferredValue[set], .done
btbnz VariableWatchpointSet::m_setIsNotEmpty[set], slow
storeq 0, VariableWatchpointSet::m_inferredValue[set]
storeb IsInvalidated, VariableWatchpointSet::m_state[set]
.done:
end
_llint_op_captured_mov:
traceExecution()
loadisFromInstruction(2, t1)
loadConstantOrVariable(t1, t2)
loadpFromInstruction(3, t0)
btpz t0, .opCapturedMovReady
notifyWrite(t0, t2, t1, .opCapturedMovSlow)
.opCapturedMovReady:
loadisFromInstruction(1, t0)
storeq t2, [cfr, t0, 8]
dispatch(4)
.opCapturedMovSlow:
callSlowPath(_slow_path_captured_mov)
dispatch(4)
_llint_op_not:
traceExecution()
loadisFromInstruction(2, t0)
loadisFromInstruction(1, t1)
loadConstantOrVariable(t0, t2)
xorq ValueFalse, t2
btqnz t2, ~1, .opNotSlow
xorq ValueTrue, t2
storeq t2, [cfr, t1, 8]
dispatch(3)
.opNotSlow:
callSlowPath(_slow_path_not)
dispatch(3)
macro equalityComparison(integerComparison, slowPath)
traceExecution()
loadisFromInstruction(3, t0)
loadisFromInstruction(2, t2)
loadisFromInstruction(1, t3)
loadConstantOrVariableInt32(t0, t1, .slow)
loadConstantOrVariableInt32(t2, t0, .slow)
integerComparison(t0, t1, t0)
orq ValueFalse, t0
storeq t0, [cfr, t3, 8]
dispatch(4)
.slow:
callSlowPath(slowPath)
dispatch(4)
end
_llint_op_eq:
equalityComparison(
macro (left, right, result) cieq left, right, result end,
_slow_path_eq)
_llint_op_neq:
equalityComparison(
macro (left, right, result) cineq left, right, result end,
_slow_path_neq)
macro equalNullComparison()
loadisFromInstruction(2, t0)
loadq [cfr, t0, 8], t0
btqnz t0, tagMask, .immediate
loadp JSCell::m_structure[t0], t2
btbnz Structure::m_typeInfo + TypeInfo::m_flags[t2], MasqueradesAsUndefined, .masqueradesAsUndefined
move 0, t0
jmp .done
.masqueradesAsUndefined:
loadp CodeBlock[cfr], t0
loadp CodeBlock::m_globalObject[t0], t0
cpeq Structure::m_globalObject[t2], t0, t0
jmp .done
.immediate:
andq ~TagBitUndefined, t0
cqeq t0, ValueNull, t0
.done:
end
_llint_op_eq_null:
traceExecution()
equalNullComparison()
loadisFromInstruction(1, t1)
orq ValueFalse, t0
storeq t0, [cfr, t1, 8]
dispatch(3)
_llint_op_neq_null:
traceExecution()
equalNullComparison()
loadisFromInstruction(1, t1)
xorq ValueTrue, t0
storeq t0, [cfr, t1, 8]
dispatch(3)
macro strictEq(equalityOperation, slowPath)
traceExecution()
loadisFromInstruction(3, t0)
loadisFromInstruction(2, t2)
loadConstantOrVariable(t0, t1)
loadConstantOrVariable(t2, t0)
move t0, t2
orq t1, t2
btqz t2, tagMask, .slow
bqaeq t0, tagTypeNumber, .leftOK
btqnz t0, tagTypeNumber, .slow
.leftOK:
bqaeq t1, tagTypeNumber, .rightOK
btqnz t1, tagTypeNumber, .slow
.rightOK:
equalityOperation(t0, t1, t0)
loadisFromInstruction(1, t1)
orq ValueFalse, t0
storeq t0, [cfr, t1, 8]
dispatch(4)
.slow:
callSlowPath(slowPath)
dispatch(4)
end
_llint_op_stricteq:
strictEq(
macro (left, right, result) cqeq left, right, result end,
_slow_path_stricteq)
_llint_op_nstricteq:
strictEq(
macro (left, right, result) cqneq left, right, result end,
_slow_path_nstricteq)
macro preOp(arithmeticOperation, slowPath)
traceExecution()
loadisFromInstruction(1, t0)
loadq [cfr, t0, 8], t1
bqb t1, tagTypeNumber, .slow
arithmeticOperation(t1, .slow)
orq tagTypeNumber, t1
storeq t1, [cfr, t0, 8]
dispatch(2)
.slow:
callSlowPath(slowPath)
dispatch(2)
end
_llint_op_inc:
preOp(
macro (value, slow) baddio 1, value, slow end,
_slow_path_inc)
_llint_op_dec:
preOp(
macro (value, slow) bsubio 1, value, slow end,
_slow_path_dec)
_llint_op_to_number:
traceExecution()
loadisFromInstruction(2, t0)
loadisFromInstruction(1, t1)
loadConstantOrVariable(t0, t2)
bqaeq t2, tagTypeNumber, .opToNumberIsImmediate
btqz t2, tagTypeNumber, .opToNumberSlow
.opToNumberIsImmediate:
storeq t2, [cfr, t1, 8]
dispatch(3)
.opToNumberSlow:
callSlowPath(_slow_path_to_number)
dispatch(3)
_llint_op_negate:
traceExecution()
loadisFromInstruction(2, t0)
loadisFromInstruction(1, t1)
loadConstantOrVariable(t0, t2)
bqb t2, tagTypeNumber, .opNegateNotInt
btiz t2, 0x7fffffff, .opNegateSlow
negi t2
orq tagTypeNumber, t2
storeq t2, [cfr, t1, 8]
dispatch(3)
.opNegateNotInt:
btqz t2, tagTypeNumber, .opNegateSlow
xorq 0x8000000000000000, t2
storeq t2, [cfr, t1, 8]
dispatch(3)
.opNegateSlow:
callSlowPath(_slow_path_negate)
dispatch(3)
macro binaryOpCustomStore(integerOperationAndStore, doubleOperation, slowPath)
loadisFromInstruction(3, t0)
loadisFromInstruction(2, t2)
loadConstantOrVariable(t0, t1)
loadConstantOrVariable(t2, t0)
bqb t0, tagTypeNumber, .op1NotInt
bqb t1, tagTypeNumber, .op2NotInt
loadisFromInstruction(1, t2)
integerOperationAndStore(t1, t0, .slow, t2)
dispatch(5)
.op1NotInt:
# First operand is definitely not an int, the second operand could be anything.
btqz t0, tagTypeNumber, .slow
bqaeq t1, tagTypeNumber, .op1NotIntOp2Int
btqz t1, tagTypeNumber, .slow
addq tagTypeNumber, t1
fq2d t1, ft1
jmp .op1NotIntReady
.op1NotIntOp2Int:
ci2d t1, ft1
.op1NotIntReady:
loadisFromInstruction(1, t2)
addq tagTypeNumber, t0
fq2d t0, ft0
doubleOperation(ft1, ft0)
fd2q ft0, t0
subq tagTypeNumber, t0
storeq t0, [cfr, t2, 8]
dispatch(5)
.op2NotInt:
# First operand is definitely an int, the second is definitely not.
loadisFromInstruction(1, t2)
btqz t1, tagTypeNumber, .slow
ci2d t0, ft0
addq tagTypeNumber, t1
fq2d t1, ft1
doubleOperation(ft1, ft0)
fd2q ft0, t0
subq tagTypeNumber, t0
storeq t0, [cfr, t2, 8]
dispatch(5)
.slow:
callSlowPath(slowPath)
dispatch(5)
end
macro binaryOp(integerOperation, doubleOperation, slowPath)
binaryOpCustomStore(
macro (left, right, slow, index)
integerOperation(left, right, slow)
orq tagTypeNumber, right
storeq right, [cfr, index, 8]
end,
doubleOperation, slowPath)
end
_llint_op_add:
traceExecution()
binaryOp(
macro (left, right, slow) baddio left, right, slow end,
macro (left, right) addd left, right end,
_slow_path_add)
_llint_op_mul:
traceExecution()
binaryOpCustomStore(
macro (left, right, slow, index)
# Assume t3 is scratchable.
move right, t3
bmulio left, t3, slow
btinz t3, .done
bilt left, 0, slow
bilt right, 0, slow
.done:
orq tagTypeNumber, t3
storeq t3, [cfr, index, 8]
end,
macro (left, right) muld left, right end,
_slow_path_mul)
_llint_op_sub:
traceExecution()
binaryOp(
macro (left, right, slow) bsubio left, right, slow end,
macro (left, right) subd left, right end,
_slow_path_sub)
_llint_op_div:
traceExecution()
if X86_64
binaryOpCustomStore(
macro (left, right, slow, index)
# Assume t3 is scratchable.
btiz left, slow
bineq left, -1, .notNeg2TwoThe31DivByNeg1
bieq right, -2147483648, .slow
.notNeg2TwoThe31DivByNeg1:
btinz right, .intOK
bilt left, 0, slow
.intOK:
move left, t3
move right, t0
cdqi
idivi t3
btinz t1, slow
orq tagTypeNumber, t0
storeq t0, [cfr, index, 8]
end,
macro (left, right) divd left, right end,
_slow_path_div)
else
callSlowPath(_slow_path_div)
dispatch(5)
end
macro bitOp(operation, slowPath, advance)
loadisFromInstruction(3, t0)
loadisFromInstruction(2, t2)
loadisFromInstruction(1, t3)
loadConstantOrVariable(t0, t1)
loadConstantOrVariable(t2, t0)
bqb t0, tagTypeNumber, .slow
bqb t1, tagTypeNumber, .slow
operation(t1, t0)
orq tagTypeNumber, t0
storeq t0, [cfr, t3, 8]
dispatch(advance)
.slow:
callSlowPath(slowPath)
dispatch(advance)
end
_llint_op_lshift:
traceExecution()
bitOp(
macro (left, right) lshifti left, right end,
_slow_path_lshift,
4)
_llint_op_rshift:
traceExecution()
bitOp(
macro (left, right) rshifti left, right end,
_slow_path_rshift,
4)
_llint_op_urshift:
traceExecution()
bitOp(
macro (left, right) urshifti left, right end,
_slow_path_urshift,
4)
_llint_op_unsigned:
traceExecution()
loadisFromInstruction(1, t0)
loadisFromInstruction(2, t1)
loadConstantOrVariable(t1, t2)
bilt t2, 0, .opUnsignedSlow
storeq t2, [cfr, t0, 8]
dispatch(3)
.opUnsignedSlow:
callSlowPath(_slow_path_unsigned)
dispatch(3)
_llint_op_bitand:
traceExecution()
bitOp(
macro (left, right) andi left, right end,
_slow_path_bitand,
5)
_llint_op_bitxor:
traceExecution()
bitOp(
macro (left, right) xori left, right end,
_slow_path_bitxor,
5)
_llint_op_bitor:
traceExecution()
bitOp(
macro (left, right) ori left, right end,
_slow_path_bitor,
5)
_llint_op_check_has_instance:
traceExecution()
loadisFromInstruction(3, t1)
loadConstantOrVariableCell(t1, t0, .opCheckHasInstanceSlow)
loadp JSCell::m_structure[t0], t0
btbz Structure::m_typeInfo + TypeInfo::m_flags[t0], ImplementsDefaultHasInstance, .opCheckHasInstanceSlow
dispatch(5)
.opCheckHasInstanceSlow:
callSlowPath(_llint_slow_path_check_has_instance)
dispatch(0)
_llint_op_instanceof:
traceExecution()
# Actually do the work.
loadisFromInstruction(3, t0)
loadisFromInstruction(1, t3)
loadConstantOrVariableCell(t0, t1, .opInstanceofSlow)
loadp JSCell::m_structure[t1], t2
bbb Structure::m_typeInfo + TypeInfo::m_type[t2], ObjectType, .opInstanceofSlow
loadisFromInstruction(2, t0)
loadConstantOrVariableCell(t0, t2, .opInstanceofSlow)
# Register state: t1 = prototype, t2 = value
move 1, t0
.opInstanceofLoop:
loadp JSCell::m_structure[t2], t2
loadq Structure::m_prototype[t2], t2
bqeq t2, t1, .opInstanceofDone
btqz t2, tagMask, .opInstanceofLoop
move 0, t0
.opInstanceofDone:
orq ValueFalse, t0
storeq t0, [cfr, t3, 8]
dispatch(4)
.opInstanceofSlow:
callSlowPath(_llint_slow_path_instanceof)
dispatch(4)
_llint_op_is_undefined:
traceExecution()
loadisFromInstruction(2, t1)
loadisFromInstruction(1, t2)
loadConstantOrVariable(t1, t0)
btqz t0, tagMask, .opIsUndefinedCell
cqeq t0, ValueUndefined, t3
orq ValueFalse, t3
storeq t3, [cfr, t2, 8]
dispatch(3)
.opIsUndefinedCell:
loadp JSCell::m_structure[t0], t0
btbnz Structure::m_typeInfo + TypeInfo::m_flags[t0], MasqueradesAsUndefined, .masqueradesAsUndefined
move ValueFalse, t1
storeq t1, [cfr, t2, 8]
dispatch(3)
.masqueradesAsUndefined:
loadp CodeBlock[cfr], t1
loadp CodeBlock::m_globalObject[t1], t1
cpeq Structure::m_globalObject[t0], t1, t3
orq ValueFalse, t3
storeq t3, [cfr, t2, 8]
dispatch(3)