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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
|
# Copyright (C) 2011, 2012 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.
# First come the common protocols that both interpreters use. Note that each
# of these must have an ASSERT() in LLIntData.cpp
# Work-around for the fact that the toolchain's awareness of armv7s results in
# a separate slab in the fat binary, yet the offlineasm doesn't know to expect
# it.
if ARMv7s
end
# These declarations must match interpreter/JSStack.h.
const CallFrameHeaderSize = 48
const ArgumentCount = -48
const CallerFrame = -40
const Callee = -32
const ScopeChain = -24
const ReturnPC = -16
const CodeBlock = -8
const ThisArgumentOffset = -CallFrameHeaderSize - 8
# Some register conventions.
if JSVALUE64
# - Use a pair of registers to represent the PC: one register for the
# base of the stack, and one register for the index.
# - The PC base (or PB for short) should be stored in the csr. It will
# get clobbered on calls to other JS code, but will get saved on calls
# to C functions.
# - C calls are still given the Instruction* rather than the PC index.
# This requires an add before the call, and a sub after.
const PC = t4
const PB = t6
const tagTypeNumber = csr1
const tagMask = csr2
macro loadisFromInstruction(offset, dest)
loadis offset * 8[PB, PC, 8], dest
end
macro loadpFromInstruction(offset, dest)
loadp offset * 8[PB, PC, 8], dest
end
macro storepToInstruction(value, offset)
storep value, offset * 8[PB, PC, 8]
end
else
const PC = t4
macro loadisFromInstruction(offset, dest)
loadis offset * 4[PC], dest
end
macro loadpFromInstruction(offset, dest)
loadp offset * 4[PC], dest
end
end
# Constants for reasoning about value representation.
if BIG_ENDIAN
const TagOffset = 0
const PayloadOffset = 4
else
const TagOffset = 4
const PayloadOffset = 0
end
# Constant for reasoning about butterflies.
const IsArray = 1
const IndexingShapeMask = 30
const ContiguousShape = 26
const ArrayStorageShape = 28
const SlowPutArrayStorageShape = 30
# Type constants.
const StringType = 5
const ObjectType = 17
# Type flags constants.
const MasqueradesAsUndefined = 1
const ImplementsHasInstance = 2
const ImplementsDefaultHasInstance = 8
# Bytecode operand constants.
const FirstConstantRegisterIndex = 0x40000000
# Code type constants.
const GlobalCode = 0
const EvalCode = 1
const FunctionCode = 2
# The interpreter steals the tag word of the argument count.
const LLIntReturnPC = ArgumentCount + TagOffset
# String flags.
const HashFlags8BitBuffer = 64
# Copied from PropertyOffset.h
const firstOutOfLineOffset = 100
# From ResolveOperations.h
const ResolveOperationFail = 0
const ResolveOperationSetBaseToUndefined = 1
const ResolveOperationReturnScopeAsBase = 2
const ResolveOperationSetBaseToScope = 3
const ResolveOperationSetBaseToGlobal = 4
const ResolveOperationGetAndReturnScopedVar = 5
const ResolveOperationGetAndReturnGlobalVar = 6
const ResolveOperationGetAndReturnGlobalVarWatchable = 7
const ResolveOperationSkipTopScopeNode = 8
const ResolveOperationSkipScopes = 9
const ResolveOperationReturnGlobalObjectAsBase = 10
const ResolveOperationGetAndReturnGlobalProperty = 11
const ResolveOperationCheckForDynamicEntriesBeforeGlobalScope = 12
const PutToBaseOperationKindUninitialised = 0
const PutToBaseOperationKindGeneric = 1
const PutToBaseOperationKindReadonly = 2
const PutToBaseOperationKindGlobalVariablePut = 3
const PutToBaseOperationKindGlobalVariablePutChecked = 4
const PutToBaseOperationKindGlobalPropertyPut = 5
const PutToBaseOperationKindVariablePut = 6
# Allocation constants
if JSVALUE64
const JSFinalObjectSizeClassIndex = 1
else
const JSFinalObjectSizeClassIndex = 3
end
# This must match wtf/Vector.h
const VectorSizeOffset = 0
if JSVALUE64
const VectorBufferOffset = 8
else
const VectorBufferOffset = 4
end
# Some common utilities.
macro crash()
if C_LOOP
cloopCrash
else
storei t0, 0xbbadbeef[]
move 0, t0
call t0
end
end
macro assert(assertion)
if ASSERT_ENABLED
assertion(.ok)
crash()
.ok:
end
end
macro preserveReturnAddressAfterCall(destinationRegister)
if C_LOOP
# In our case, we're only preserving the bytecode vPC.
move lr, destinationRegister
elsif ARMv7
move lr, destinationRegister
elsif X86 or X86_64
pop destinationRegister
else
error
end
end
macro restoreReturnAddressBeforeReturn(sourceRegister)
if C_LOOP
# In our case, we're only restoring the bytecode vPC.
move sourceRegister, lr
elsif ARMv7
move sourceRegister, lr
elsif X86 or X86_64
push sourceRegister
else
error
end
end
macro traceExecution()
if EXECUTION_TRACING
callSlowPath(_llint_trace)
end
end
macro callTargetFunction(callLinkInfo)
if C_LOOP
cloopCallJSFunction LLIntCallLinkInfo::machineCodeTarget[callLinkInfo]
else
call LLIntCallLinkInfo::machineCodeTarget[callLinkInfo]
dispatchAfterCall()
end
end
macro slowPathForCall(advance, slowPath)
callCallSlowPath(
advance,
slowPath,
macro (callee)
if C_LOOP
cloopCallJSFunction callee
else
call callee
dispatchAfterCall()
end
end)
end
macro arrayProfile(structureAndIndexingType, profile, scratch)
const structure = structureAndIndexingType
const indexingType = structureAndIndexingType
if VALUE_PROFILER
storep structure, ArrayProfile::m_lastSeenStructure[profile]
end
loadb Structure::m_indexingType[structure], indexingType
end
macro checkSwitchToJIT(increment, action)
if JIT_ENABLED
loadp CodeBlock[cfr], t0
baddis increment, CodeBlock::m_llintExecuteCounter + ExecutionCounter::m_counter[t0], .continue
action()
.continue:
end
end
macro checkSwitchToJITForEpilogue()
checkSwitchToJIT(
10,
macro ()
callSlowPath(_llint_replace)
end)
end
macro assertNotConstant(index)
assert(macro (ok) bilt index, FirstConstantRegisterIndex, ok end)
end
macro functionForCallCodeBlockGetter(targetRegister)
loadp Callee[cfr], targetRegister
loadp JSFunction::m_executable[targetRegister], targetRegister
loadp FunctionExecutable::m_codeBlockForCall[targetRegister], targetRegister
end
macro functionForConstructCodeBlockGetter(targetRegister)
loadp Callee[cfr], targetRegister
loadp JSFunction::m_executable[targetRegister], targetRegister
loadp FunctionExecutable::m_codeBlockForConstruct[targetRegister], targetRegister
end
macro notFunctionCodeBlockGetter(targetRegister)
loadp CodeBlock[cfr], targetRegister
end
macro functionCodeBlockSetter(sourceRegister)
storep sourceRegister, CodeBlock[cfr]
end
macro notFunctionCodeBlockSetter(sourceRegister)
# Nothing to do!
end
# Do the bare minimum required to execute code. Sets up the PC, leave the CodeBlock*
# in t1. May also trigger prologue entry OSR.
macro prologue(codeBlockGetter, codeBlockSetter, osrSlowPath, traceSlowPath)
preserveReturnAddressAfterCall(t2)
# Set up the call frame and check if we should OSR.
storep t2, ReturnPC[cfr]
if EXECUTION_TRACING
callSlowPath(traceSlowPath)
end
codeBlockGetter(t1)
if JIT_ENABLED
baddis 5, CodeBlock::m_llintExecuteCounter + ExecutionCounter::m_counter[t1], .continue
cCall2(osrSlowPath, cfr, PC)
move t1, cfr
btpz t0, .recover
loadp ReturnPC[cfr], t2
restoreReturnAddressBeforeReturn(t2)
jmp t0
.recover:
codeBlockGetter(t1)
.continue:
end
codeBlockSetter(t1)
# Set up the PC.
if JSVALUE64
loadp CodeBlock::m_instructions[t1], PB
move 0, PC
else
loadp CodeBlock::m_instructions[t1], PC
end
end
# Expects that CodeBlock is in t1, which is what prologue() leaves behind.
# Must call dispatch(0) after calling this.
macro functionInitialization(profileArgSkip)
if VALUE_PROFILER
# Profile the arguments. Unfortunately, we have no choice but to do this. This
# code is pretty horrendous because of the difference in ordering between
# arguments and value profiles, the desire to have a simple loop-down-to-zero
# loop, and the desire to use only three registers so as to preserve the PC and
# the code block. It is likely that this code should be rewritten in a more
# optimal way for architectures that have more than five registers available
# for arbitrary use in the interpreter.
loadi CodeBlock::m_numParameters[t1], t0
addp -profileArgSkip, t0 # Use addi because that's what has the peephole
assert(macro (ok) bpgteq t0, 0, ok end)
btpz t0, .argumentProfileDone
loadp CodeBlock::m_argumentValueProfiles + VectorBufferOffset[t1], t3
mulp sizeof ValueProfile, t0, t2 # Aaaaahhhh! Need strength reduction!
negp t0
lshiftp 3, t0
addp t2, t3
.argumentProfileLoop:
if JSVALUE64
loadq ThisArgumentOffset + 8 - profileArgSkip * 8[cfr, t0], t2
subp sizeof ValueProfile, t3
storeq t2, profileArgSkip * sizeof ValueProfile + ValueProfile::m_buckets[t3]
else
loadi ThisArgumentOffset + TagOffset + 8 - profileArgSkip * 8[cfr, t0], t2
subp sizeof ValueProfile, t3
storei t2, profileArgSkip * sizeof ValueProfile + ValueProfile::m_buckets + TagOffset[t3]
loadi ThisArgumentOffset + PayloadOffset + 8 - profileArgSkip * 8[cfr, t0], t2
storei t2, profileArgSkip * sizeof ValueProfile + ValueProfile::m_buckets + PayloadOffset[t3]
end
baddpnz 8, t0, .argumentProfileLoop
.argumentProfileDone:
end
# Check stack height.
loadi CodeBlock::m_numCalleeRegisters[t1], t0
loadp CodeBlock::m_globalData[t1], t2
loadp JSGlobalData::interpreter[t2], t2 # FIXME: Can get to the JSStack from the JITStackFrame
lshifti 3, t0
addp t0, cfr, t0
bpaeq Interpreter::m_stack + JSStack::m_end[t2], t0, .stackHeightOK
# Stack height check failed - need to call a slow_path.
callSlowPath(_llint_stack_check)
.stackHeightOK:
end
macro allocateBasicJSObject(sizeClassIndex, structure, result, scratch1, scratch2, slowCase)
if ALWAYS_ALLOCATE_SLOW
jmp slowCase
else
const offsetOfMySizeClass =
JSGlobalData::heap +
Heap::m_objectSpace +
MarkedSpace::m_normalSpace +
MarkedSpace::Subspace::preciseAllocators +
sizeClassIndex * sizeof MarkedAllocator
const offsetOfFirstFreeCell =
MarkedAllocator::m_freeList +
MarkedBlock::FreeList::head
# FIXME: we can get the global data in one load from the stack.
loadp CodeBlock[cfr], scratch1
loadp CodeBlock::m_globalData[scratch1], scratch1
# Get the object from the free list.
loadp offsetOfMySizeClass + offsetOfFirstFreeCell[scratch1], result
btpz result, slowCase
# Remove the object from the free list.
loadp [result], scratch2
storep scratch2, offsetOfMySizeClass + offsetOfFirstFreeCell[scratch1]
# Initialize the object.
storep structure, JSCell::m_structure[result]
storep 0, JSObject::m_butterfly[result]
end
end
macro doReturn()
loadp ReturnPC[cfr], t2
loadp CallerFrame[cfr], cfr
restoreReturnAddressBeforeReturn(t2)
ret
end
# Indicate the beginning of LLInt.
_llint_begin:
crash()
_llint_program_prologue:
prologue(notFunctionCodeBlockGetter, notFunctionCodeBlockSetter, _llint_entry_osr, _llint_trace_prologue)
dispatch(0)
_llint_eval_prologue:
prologue(notFunctionCodeBlockGetter, notFunctionCodeBlockSetter, _llint_entry_osr, _llint_trace_prologue)
dispatch(0)
_llint_function_for_call_prologue:
prologue(functionForCallCodeBlockGetter, functionCodeBlockSetter, _llint_entry_osr_function_for_call, _llint_trace_prologue_function_for_call)
.functionForCallBegin:
functionInitialization(0)
dispatch(0)
_llint_function_for_construct_prologue:
prologue(functionForConstructCodeBlockGetter, functionCodeBlockSetter, _llint_entry_osr_function_for_construct, _llint_trace_prologue_function_for_construct)
.functionForConstructBegin:
functionInitialization(1)
dispatch(0)
_llint_function_for_call_arity_check:
prologue(functionForCallCodeBlockGetter, functionCodeBlockSetter, _llint_entry_osr_function_for_call_arityCheck, _llint_trace_arityCheck_for_call)
functionArityCheck(.functionForCallBegin, _llint_slow_path_call_arityCheck)
_llint_function_for_construct_arity_check:
prologue(functionForConstructCodeBlockGetter, functionCodeBlockSetter, _llint_entry_osr_function_for_construct_arityCheck, _llint_trace_arityCheck_for_construct)
functionArityCheck(.functionForConstructBegin, _llint_slow_path_construct_arityCheck)
# Value-representation-specific code.
if JSVALUE64
include LowLevelInterpreter64
else
include LowLevelInterpreter32_64
end
# Value-representation-agnostic code.
_llint_op_new_array:
traceExecution()
callSlowPath(_llint_slow_path_new_array)
dispatch(4)
_llint_op_new_array_with_size:
traceExecution()
callSlowPath(_llint_slow_path_new_array_with_size)
dispatch(3)
_llint_op_new_array_buffer:
traceExecution()
callSlowPath(_llint_slow_path_new_array_buffer)
dispatch(4)
_llint_op_new_regexp:
traceExecution()
callSlowPath(_llint_slow_path_new_regexp)
dispatch(3)
_llint_op_less:
traceExecution()
callSlowPath(_llint_slow_path_less)
dispatch(4)
_llint_op_lesseq:
traceExecution()
callSlowPath(_llint_slow_path_lesseq)
dispatch(4)
_llint_op_greater:
traceExecution()
callSlowPath(_llint_slow_path_greater)
dispatch(4)
_llint_op_greatereq:
traceExecution()
callSlowPath(_llint_slow_path_greatereq)
dispatch(4)
_llint_op_mod:
traceExecution()
callSlowPath(_llint_slow_path_mod)
dispatch(4)
_llint_op_typeof:
traceExecution()
callSlowPath(_llint_slow_path_typeof)
dispatch(3)
_llint_op_is_object:
traceExecution()
callSlowPath(_llint_slow_path_is_object)
dispatch(3)
_llint_op_is_function:
traceExecution()
callSlowPath(_llint_slow_path_is_function)
dispatch(3)
_llint_op_in:
traceExecution()
callSlowPath(_llint_slow_path_in)
dispatch(4)
macro getPutToBaseOperationField(scratch, scratch1, fieldOffset, fieldGetter)
loadisFromInstruction(4, scratch)
mulp sizeof PutToBaseOperation, scratch, scratch
loadp CodeBlock[cfr], scratch1
loadp VectorBufferOffset + CodeBlock::m_putToBaseOperations[scratch1], scratch1
fieldGetter(fieldOffset[scratch1, scratch, 1])
end
macro moveJSValueFromRegisterWithoutProfiling(value, destBuffer, destOffsetReg)
storeq value, [destBuffer, destOffsetReg, 8]
end
macro moveJSValueFromRegistersWithoutProfiling(tag, payload, destBuffer, destOffsetReg)
storei tag, TagOffset[destBuffer, destOffsetReg, 8]
storei payload, PayloadOffset[destBuffer, destOffsetReg, 8]
end
macro putToBaseVariableBody(variableOffset, scratch1, scratch2, scratch3)
loadisFromInstruction(1, scratch1)
loadp PayloadOffset[cfr, scratch1, 8], scratch1
loadp JSVariableObject::m_registers[scratch1], scratch1
loadisFromInstruction(3, scratch2)
if JSVALUE64
loadConstantOrVariable(scratch2, scratch3)
moveJSValueFromRegisterWithoutProfiling(scratch3, scratch1, variableOffset)
else
loadConstantOrVariable2Reg(scratch2, scratch3, scratch2) # scratch3=tag, scratch2=payload
moveJSValueFromRegistersWithoutProfiling(scratch3, scratch2, scratch1, variableOffset)
end
end
_llint_op_put_to_base_variable:
traceExecution()
getPutToBaseOperationField(t0, t1, PutToBaseOperation::m_offset, macro(addr)
loadis addr, t0
end)
putToBaseVariableBody(t0, t1, t2, t3)
dispatch(5)
_llint_op_put_to_base:
traceExecution()
getPutToBaseOperationField(t0, t1, 0, macro(addr)
leap addr, t0
bbneq PutToBaseOperation::m_kindAsUint8[t0], PutToBaseOperationKindVariablePut, .notPutToBaseVariable
loadis PutToBaseOperation::m_offset[t0], t0
putToBaseVariableBody(t0, t1, t2, t3)
dispatch(5)
.notPutToBaseVariable:
end)
callSlowPath(_llint_slow_path_put_to_base)
dispatch(5)
macro getResolveOperation(resolveOperationIndex, dest, scratch)
loadisFromInstruction(resolveOperationIndex, dest)
mulp sizeof ResolveOperations, dest, dest
loadp CodeBlock[cfr], scratch
loadp VectorBufferOffset + CodeBlock::m_resolveOperations[scratch], scratch
loadp VectorBufferOffset[scratch, dest, 1], dest
end
macro getScope(loadInitialScope, scopeCount, dest, scratch)
loadInitialScope(dest)
loadi scopeCount, scratch
btiz scratch, .done
.loop:
loadp JSScope::m_next[dest], dest
subi 1, scratch
btinz scratch, .loop
.done:
end
macro moveJSValue(sourceBuffer, sourceOffsetReg, destBuffer, destOffsetReg, profileOffset, scratchRegister)
if JSVALUE64
loadq [sourceBuffer, sourceOffsetReg, 8], scratchRegister
storeq scratchRegister, [destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(scratchRegister, destOffsetReg)
else
loadi PayloadOffset[sourceBuffer, sourceOffsetReg, 8], scratchRegister
storei scratchRegister, PayloadOffset[destBuffer, destOffsetReg, 8]
loadi TagOffset[sourceBuffer, sourceOffsetReg, 8], sourceOffsetReg
storei sourceOffsetReg, TagOffset[destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(sourceOffsetReg, scratchRegister, destOffsetReg)
end
end
macro moveJSValueFromSlot(slot, destBuffer, destOffsetReg, profileOffset, scratchRegister)
if JSVALUE64
loadq [slot], scratchRegister
storeq scratchRegister, [destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(scratchRegister, destOffsetReg)
else
loadi PayloadOffset[slot], scratchRegister
storei scratchRegister, PayloadOffset[destBuffer, destOffsetReg, 8]
loadi TagOffset[slot], slot
storei slot, TagOffset[destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(slot, scratchRegister, destOffsetReg)
end
end
macro moveJSValueFromRegister(value, destBuffer, destOffsetReg, profileOffset)
storeq value, [destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(value, destOffsetReg)
end
macro moveJSValueFromRegisters(tag, payload, destBuffer, destOffsetReg, profileOffset)
storei tag, TagOffset[destBuffer, destOffsetReg, 8]
storei payload, PayloadOffset[destBuffer, destOffsetReg, 8]
loadpFromInstruction(profileOffset, destOffsetReg)
valueProfile(tag, payload, destOffsetReg)
end
_llint_op_resolve_global_property:
traceExecution()
getResolveOperation(3, t0, t1)
loadp CodeBlock[cfr], t1
loadp CodeBlock::m_globalObject[t1], t1
loadp ResolveOperation::m_structure[t0], t2
bpneq JSCell::m_structure[t1], t2, .llint_op_resolve_local
loadis ResolveOperation::m_offset[t0], t0
if JSVALUE64
loadPropertyAtVariableOffsetKnownNotInline(t0, t1, t2)
loadisFromInstruction(1, t0)
moveJSValueFromRegister(t2, cfr, t0, 4)
else
loadPropertyAtVariableOffsetKnownNotInline(t0, t1, t2, t3)
loadisFromInstruction(1, t0)
moveJSValueFromRegisters(t2, t3, cfr, t0, 4)
end
dispatch(5)
_llint_op_resolve_global_var:
traceExecution()
getResolveOperation(3, t0, t1)
loadp ResolveOperation::m_registerAddress[t0], t0
loadisFromInstruction(1, t1)
moveJSValueFromSlot(t0, cfr, t1, 4, t3)
dispatch(5)
macro resolveScopedVarBody(resolveOperations)
# First ResolveOperation is to skip scope chain nodes
getScope(macro(dest)
loadp ScopeChain + PayloadOffset[cfr], dest
end,
ResolveOperation::m_scopesToSkip[resolveOperations], t1, t2)
loadp JSVariableObject::m_registers[t1], t1 # t1 now contains the activation registers
# Second ResolveOperation tells us what offset to use
loadis ResolveOperation::m_offset + sizeof ResolveOperation[resolveOperations], t2
loadisFromInstruction(1, t3)
moveJSValue(t1, t2, cfr, t3, 4, t0)
end
_llint_op_resolve_scoped_var:
traceExecution()
getResolveOperation(3, t0, t1)
resolveScopedVarBody(t0)
dispatch(5)
_llint_op_resolve_scoped_var_on_top_scope:
traceExecution()
getResolveOperation(3, t0, t1)
# Load destination index
loadisFromInstruction(1, t3)
# We know we want the top scope chain entry
loadp ScopeChain + PayloadOffset[cfr], t1
loadp JSVariableObject::m_registers[t1], t1 # t1 now contains the activation registers
# Second ResolveOperation tells us what offset to use
loadis ResolveOperation::m_offset + sizeof ResolveOperation[t0], t2
moveJSValue(t1, t2, cfr, t3, 4, t0)
dispatch(5)
_llint_op_resolve_scoped_var_with_top_scope_check:
traceExecution()
getResolveOperation(3, t0, t1)
# First ResolveOperation tells us what register to check
loadis ResolveOperation::m_activationRegister[t0], t1
loadp PayloadOffset[cfr, t1, 8], t1
getScope(macro(dest)
btpz t1, .scopeChainNotCreated
loadp JSScope::m_next[t1], dest
jmp .done
.scopeChainNotCreated:
loadp ScopeChain + PayloadOffset[cfr], dest
.done:
end,
# Second ResolveOperation tells us how many more nodes to skip
ResolveOperation::m_scopesToSkip + sizeof ResolveOperation[t0], t1, t2)
loadp JSVariableObject::m_registers[t1], t1 # t1 now contains the activation registers
# Third operation tells us what offset to use
loadis ResolveOperation::m_offset + 2 * sizeof ResolveOperation[t0], t2
loadisFromInstruction(1, t3)
moveJSValue(t1, t2, cfr, t3, 4, t0)
dispatch(5)
_llint_op_resolve:
.llint_op_resolve_local:
traceExecution()
getResolveOperation(3, t0, t1)
btpz t0, .noInstructions
loadis ResolveOperation::m_operation[t0], t1
bineq t1, ResolveOperationSkipScopes, .notSkipScopes
resolveScopedVarBody(t0)
dispatch(5)
.notSkipScopes:
bineq t1, ResolveOperationGetAndReturnGlobalVar, .notGetAndReturnGlobalVar
loadp ResolveOperation::m_registerAddress[t0], t0
loadisFromInstruction(1, t1)
moveJSValueFromSlot(t0, cfr, t1, 4, t3)
dispatch(5)
.notGetAndReturnGlobalVar:
.noInstructions:
callSlowPath(_llint_slow_path_resolve)
dispatch(5)
_llint_op_resolve_base_to_global:
traceExecution()
loadp CodeBlock[cfr], t1
loadp CodeBlock::m_globalObject[t1], t1
loadisFromInstruction(1, t3)
if JSVALUE64
moveJSValueFromRegister(t1, cfr, t3, 6)
else
move CellTag, t2
moveJSValueFromRegisters(t2, t1, cfr, t3, 6)
end
dispatch(7)
_llint_op_resolve_base_to_global_dynamic:
jmp _llint_op_resolve_base
_llint_op_resolve_base_to_scope:
traceExecution()
getResolveOperation(4, t0, t1)
# First ResolveOperation is to skip scope chain nodes
getScope(macro(dest)
loadp ScopeChain + PayloadOffset[cfr], dest
end,
ResolveOperation::m_scopesToSkip[t0], t1, t2)
loadisFromInstruction(1, t3)
if JSVALUE64
moveJSValueFromRegister(t1, cfr, t3, 6)
else
move CellTag, t2
moveJSValueFromRegisters(t2, t1, cfr, t3, 6)
end
dispatch(7)
_llint_op_resolve_base_to_scope_with_top_scope_check:
traceExecution()
getResolveOperation(4, t0, t1)
# First ResolveOperation tells us what register to check
loadis ResolveOperation::m_activationRegister[t0], t1
loadp PayloadOffset[cfr, t1, 8], t1
getScope(macro(dest)
btpz t1, .scopeChainNotCreated
loadp JSScope::m_next[t1], dest
jmp .done
.scopeChainNotCreated:
loadp ScopeChain + PayloadOffset[cfr], dest
.done:
end,
# Second ResolveOperation tells us how many more nodes to skip
ResolveOperation::m_scopesToSkip + sizeof ResolveOperation[t0], t1, t2)
loadisFromInstruction(1, t3)
if JSVALUE64
moveJSValueFromRegister(t1, cfr, t3, 6)
else
move CellTag, t2
moveJSValueFromRegisters(t2, t1, cfr, t3, 6)
end
dispatch(7)
_llint_op_resolve_base:
traceExecution()
callSlowPath(_llint_slow_path_resolve_base)
dispatch(7)
_llint_op_ensure_property_exists:
traceExecution()
callSlowPath(_llint_slow_path_ensure_property_exists)
dispatch(3)
macro interpretResolveWithBase(opcodeLength, slowPath)
traceExecution()
getResolveOperation(4, t0, t1)
btpz t0, .slowPath
loadp ScopeChain[cfr], t3
# Get the base
loadis ResolveOperation::m_operation[t0], t2
bineq t2, ResolveOperationSkipScopes, .notSkipScopes
getScope(macro(dest) move t3, dest end,
ResolveOperation::m_scopesToSkip[t0], t1, t2)
move t1, t3
addp sizeof ResolveOperation, t0, t0
jmp .haveCorrectScope
.notSkipScopes:
bineq t2, ResolveOperationSkipTopScopeNode, .notSkipTopScopeNode
loadis ResolveOperation::m_activationRegister[t0], t1
loadp PayloadOffset[cfr, t1, 8], t1
getScope(macro(dest)
btpz t1, .scopeChainNotCreated
loadp JSScope::m_next[t1], dest
jmp .done
.scopeChainNotCreated:
loadp ScopeChain + PayloadOffset[cfr], dest
.done:
end,
sizeof ResolveOperation + ResolveOperation::m_scopesToSkip[t0], t1, t2)
move t1, t3
# We've handled two opcodes here
addp 2 * sizeof ResolveOperation, t0, t0
.notSkipTopScopeNode:
.haveCorrectScope:
# t3 now contains the correct Scope
# t0 contains a pointer to the current ResolveOperation
loadis ResolveOperation::m_operation[t0], t2
# t2 contains the next instruction
loadisFromInstruction(1, t1)
# t1 now contains the index for the base register
bineq t2, ResolveOperationSetBaseToScope, .notSetBaseToScope
if JSVALUE64
storeq t3, [cfr, t1, 8]
else
storei t3, PayloadOffset[cfr, t1, 8]
storei CellTag, TagOffset[cfr, t1, 8]
end
jmp .haveSetBase
.notSetBaseToScope:
bineq t2, ResolveOperationSetBaseToUndefined, .notSetBaseToUndefined
if JSVALUE64
storeq ValueUndefined, [cfr, t1, 8]
else
storei 0, PayloadOffset[cfr, t1, 8]
storei UndefinedTag, TagOffset[cfr, t1, 8]
end
jmp .haveSetBase
.notSetBaseToUndefined:
bineq t2, ResolveOperationSetBaseToGlobal, .slowPath
loadp JSCell::m_structure[t3], t2
loadp Structure::m_globalObject[t2], t2
if JSVALUE64
storeq t2, [cfr, t1, 8]
else
storei t2, PayloadOffset[cfr, t1, 8]
storei CellTag, TagOffset[cfr, t1, 8]
end
.haveSetBase:
# Get the value
# Load the operation into t2
loadis ResolveOperation::m_operation + sizeof ResolveOperation[t0], t2
# Load the index for the value register into t1
loadisFromInstruction(2, t1)
bineq t2, ResolveOperationGetAndReturnScopedVar, .notGetAndReturnScopedVar
loadp JSVariableObject::m_registers[t3], t3 # t3 now contains the activation registers
# Second ResolveOperation tells us what offset to use
loadis ResolveOperation::m_offset + sizeof ResolveOperation[t0], t2
moveJSValue(t3, t2, cfr, t1, opcodeLength - 1, t0)
dispatch(opcodeLength)
.notGetAndReturnScopedVar:
bineq t2, ResolveOperationGetAndReturnGlobalProperty, .slowPath
callSlowPath(slowPath)
dispatch(opcodeLength)
.slowPath:
callSlowPath(slowPath)
dispatch(opcodeLength)
end
_llint_op_resolve_with_base:
interpretResolveWithBase(7, _llint_slow_path_resolve_with_base)
_llint_op_resolve_with_this:
interpretResolveWithBase(6, _llint_slow_path_resolve_with_this)
macro withInlineStorage(object, propertyStorage, continuation)
# Indicate that the object is the property storage, and that the
# property storage register is unused.
continuation(object, propertyStorage)
end
macro withOutOfLineStorage(object, propertyStorage, continuation)
loadp JSObject::m_butterfly[object], propertyStorage
# Indicate that the propertyStorage register now points to the
# property storage, and that the object register may be reused
# if the object pointer is not needed anymore.
continuation(propertyStorage, object)
end
_llint_op_del_by_id:
traceExecution()
callSlowPath(_llint_slow_path_del_by_id)
dispatch(4)
_llint_op_del_by_val:
traceExecution()
callSlowPath(_llint_slow_path_del_by_val)
dispatch(4)
_llint_op_put_by_index:
traceExecution()
callSlowPath(_llint_slow_path_put_by_index)
dispatch(4)
_llint_op_put_getter_setter:
traceExecution()
callSlowPath(_llint_slow_path_put_getter_setter)
dispatch(5)
_llint_op_jmp_scopes:
traceExecution()
callSlowPath(_llint_slow_path_jmp_scopes)
dispatch(0)
_llint_op_loop_if_true:
traceExecution()
jumpTrueOrFalse(
macro (value, target) btinz value, target end,
_llint_slow_path_jtrue)
_llint_op_jtrue:
traceExecution()
jumpTrueOrFalse(
macro (value, target) btinz value, target end,
_llint_slow_path_jtrue)
_llint_op_loop_if_false:
traceExecution()
jumpTrueOrFalse(
macro (value, target) btiz value, target end,
_llint_slow_path_jfalse)
_llint_op_jfalse:
traceExecution()
jumpTrueOrFalse(
macro (value, target) btiz value, target end,
_llint_slow_path_jfalse)
_llint_op_loop_if_less:
traceExecution()
compare(
macro (left, right, target) bilt left, right, target end,
macro (left, right, target) bdlt left, right, target end,
_llint_slow_path_jless)
_llint_op_jless:
traceExecution()
compare(
macro (left, right, target) bilt left, right, target end,
macro (left, right, target) bdlt left, right, target end,
_llint_slow_path_jless)
_llint_op_jnless:
traceExecution()
compare(
macro (left, right, target) bigteq left, right, target end,
macro (left, right, target) bdgtequn left, right, target end,
_llint_slow_path_jnless)
_llint_op_loop_if_greater:
traceExecution()
compare(
macro (left, right, target) bigt left, right, target end,
macro (left, right, target) bdgt left, right, target end,
_llint_slow_path_jgreater)
_llint_op_jgreater:
traceExecution()
compare(
macro (left, right, target) bigt left, right, target end,
macro (left, right, target) bdgt left, right, target end,
_llint_slow_path_jgreater)
_llint_op_jngreater:
traceExecution()
compare(
macro (left, right, target) bilteq left, right, target end,
macro (left, right, target) bdltequn left, right, target end,
_llint_slow_path_jngreater)
_llint_op_loop_if_lesseq:
traceExecution()
compare(
macro (left, right, target) bilteq left, right, target end,
macro (left, right, target) bdlteq left, right, target end,
_llint_slow_path_jlesseq)
_llint_op_jlesseq:
traceExecution()
compare(
macro (left, right, target) bilteq left, right, target end,
macro (left, right, target) bdlteq left, right, target end,
_llint_slow_path_jlesseq)
_llint_op_jnlesseq:
traceExecution()
compare(
macro (left, right, target) bigt left, right, target end,
macro (left, right, target) bdgtun left, right, target end,
_llint_slow_path_jnlesseq)
_llint_op_loop_if_greatereq:
traceExecution()
compare(
macro (left, right, target) bigteq left, right, target end,
macro (left, right, target) bdgteq left, right, target end,
_llint_slow_path_jgreatereq)
_llint_op_jgreatereq:
traceExecution()
compare(
macro (left, right, target) bigteq left, right, target end,
macro (left, right, target) bdgteq left, right, target end,
_llint_slow_path_jgreatereq)
_llint_op_jngreatereq:
traceExecution()
compare(
macro (left, right, target) bilt left, right, target end,
macro (left, right, target) bdltun left, right, target end,
_llint_slow_path_jngreatereq)
_llint_op_loop_hint:
traceExecution()
checkSwitchToJITForLoop()
dispatch(1)
_llint_op_switch_string:
traceExecution()
callSlowPath(_llint_slow_path_switch_string)
dispatch(0)
_llint_op_new_func_exp:
traceExecution()
callSlowPath(_llint_slow_path_new_func_exp)
dispatch(3)
_llint_op_call:
traceExecution()
arrayProfileForCall()
doCall(_llint_slow_path_call)
_llint_op_construct:
traceExecution()
doCall(_llint_slow_path_construct)
_llint_op_call_varargs:
traceExecution()
slowPathForCall(6, _llint_slow_path_call_varargs)
_llint_op_call_eval:
traceExecution()
# Eval is executed in one of two modes:
#
# 1) We find that we're really invoking eval() in which case the
# execution is perfomed entirely inside the slow_path, and it
# returns the PC of a function that just returns the return value
# that the eval returned.
#
# 2) We find that we're invoking something called eval() that is not
# the real eval. Then the slow_path returns the PC of the thing to
# call, and we call it.
#
# This allows us to handle two cases, which would require a total of
# up to four pieces of state that cannot be easily packed into two
# registers (C functions can return up to two registers, easily):
#
# - The call frame register. This may or may not have been modified
# by the slow_path, but the convention is that it returns it. It's not
# totally clear if that's necessary, since the cfr is callee save.
# But that's our style in this here interpreter so we stick with it.
#
# - A bit to say if the slow_path successfully executed the eval and has
# the return value, or did not execute the eval but has a PC for us
# to call.
#
# - Either:
# - The JS return value (two registers), or
#
# - The PC to call.
#
# It turns out to be easier to just always have this return the cfr
# and a PC to call, and that PC may be a dummy thunk that just
# returns the JS value that the eval returned.
slowPathForCall(4, _llint_slow_path_call_eval)
_llint_generic_return_point:
dispatchAfterCall()
_llint_op_strcat:
traceExecution()
callSlowPath(_llint_slow_path_strcat)
dispatch(4)
_llint_op_get_pnames:
traceExecution()
callSlowPath(_llint_slow_path_get_pnames)
dispatch(0) # The slow_path either advances the PC or jumps us to somewhere else.
_llint_op_push_with_scope:
traceExecution()
callSlowPath(_llint_slow_path_push_with_scope)
dispatch(2)
_llint_op_pop_scope:
traceExecution()
callSlowPath(_llint_slow_path_pop_scope)
dispatch(1)
_llint_op_push_name_scope:
traceExecution()
callSlowPath(_llint_slow_path_push_name_scope)
dispatch(4)
_llint_op_throw:
traceExecution()
callSlowPath(_llint_slow_path_throw)
dispatch(2)
_llint_op_throw_static_error:
traceExecution()
callSlowPath(_llint_slow_path_throw_static_error)
dispatch(3)
_llint_op_profile_will_call:
traceExecution()
callSlowPath(_llint_slow_path_profile_will_call)
dispatch(2)
_llint_op_profile_did_call:
traceExecution()
callSlowPath(_llint_slow_path_profile_did_call)
dispatch(2)
_llint_op_debug:
traceExecution()
callSlowPath(_llint_slow_path_debug)
dispatch(5)
_llint_native_call_trampoline:
nativeCallTrampoline(NativeExecutable::m_function)
_llint_native_construct_trampoline:
nativeCallTrampoline(NativeExecutable::m_constructor)
# Lastly, make sure that we can link even though we don't support all opcodes.
# These opcodes should never arise when using LLInt or either JIT. We assert
# as much.
macro notSupported()
if ASSERT_ENABLED
crash()
else
# We should use whatever the smallest possible instruction is, just to
# ensure that there is a gap between instruction labels. If multiple
# smallest instructions exist, we should pick the one that is most
# likely result in execution being halted. Currently that is the break
# instruction on all architectures we're interested in. (Break is int3
# on Intel, which is 1 byte, and bkpt on ARMv7, which is 2 bytes.)
break
end
end
_llint_op_get_by_id_chain:
notSupported()
_llint_op_get_by_id_custom_chain:
notSupported()
_llint_op_get_by_id_custom_proto:
notSupported()
_llint_op_get_by_id_custom_self:
notSupported()
_llint_op_get_by_id_generic:
notSupported()
_llint_op_get_by_id_getter_chain:
notSupported()
_llint_op_get_by_id_getter_proto:
notSupported()
_llint_op_get_by_id_getter_self:
notSupported()
_llint_op_get_by_id_proto:
notSupported()
_llint_op_get_by_id_self:
notSupported()
_llint_op_get_string_length:
notSupported()
_llint_op_put_by_id_generic:
notSupported()
_llint_op_put_by_id_replace:
notSupported()
_llint_op_put_by_id_transition:
notSupported()
_llint_op_init_global_const_nop:
dispatch(5)
# Indicate the end of LLInt.
_llint_end:
crash()
|