-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathops.tab
1664 lines (1236 loc) · 43.2 KB
/
ops.tab
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
#
# %CopyrightBegin%
#
# Copyright Ericsson AB 1997-2016. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# %CopyrightEnd%
#
#
# The instructions that follows are only known by the loader and the emulator.
# They can be changed without recompiling old Beam files.
#
# Instructions starting with a "i_" prefix are instructions produced by
# instruction transformations; thus, they never occur in BEAM files.
#
# The too_old_compiler/0 instruction is specially handled in beam_load.c
# to produce a user-friendly message informing the user that the module
# needs to be re-compiled with a modern compiler.
too_old_compiler/0
too_old_compiler | never() =>
# In R9C and earlier, the loader used to insert special instructions inside
# the module_info/0,1 functions. (In R10B and later, the compiler inserts
# an explicit call to an undocumented BIF, so that no loader trickery is
# necessary.) Since the instructions don't work correctly in R12B, simply
# refuse to load the module.
func_info M=a a==am_module_info A=u==0 | label L | move n x==0 => too_old_compiler
func_info M=a a==am_module_info A=u==1 | label L | move n x==0 => too_old_compiler
# The undocumented and unsupported guard BIF is_constant/1 was removed
# in R13. The is_constant/2 operation is marked as obsolete in genop.tab,
# so the loader will automatically generate a too_old_compiler message
# it is used, but we need to handle the is_constant/1 BIF specially here.
bif1 Fail u$func:erlang:is_constant/1 Src Dst => too_old_compiler
# Since the constant pool was introduced in R12B, empty tuples ({})
# are literals. Therefore we no longer need to allow put_tuple/2
# with a tuple size of zero.
put_tuple u==0 d => too_old_compiler
#
# All the other instructions.
#
label L
i_func_info I a a I
int_code_end
i_generic_breakpoint
i_debug_breakpoint
i_return_time_trace
i_return_to_trace
i_yield
return
#
# To ensure that a "move Src x(0)" instruction can be combined
# with the following call instruction, we need to make sure that
# there is no line/1 instruction between the move and the call.
#
# A tail-recursive call to an external function (non-BIF) will
# never be saved on the stack, so there is no reason to keep
# the line instruction. (The compiler did not remove the line
# instruction because it cannot tell the difference between
# BIFs and ordinary Erlang functions.)
#
move S X0=x==0 | line Loc | call_ext Ar Func => \
line Loc | move S X0 | call_ext Ar Func
move S X0=x==0 | line Loc | call_ext_last Ar Func=u$is_not_bif D => \
move S X0 | call_ext_last Ar Func D
move S X0=x==0 | line Loc | call_ext_only Ar Func=u$is_not_bif => \
move S X0 | call_ext_only Ar Func
move S X0=x==0 | line Loc | call Ar Func => \
line Loc | move S X0 | call Ar Func
line Loc | func_info M F A => func_info M F A | line Loc
line I
%macro: allocate Allocate -pack
%macro: allocate_zero AllocateZero -pack
%macro: allocate_heap AllocateHeap -pack
%macro: allocate_heap_zero AllocateHeapZero -pack
%macro: test_heap TestHeap -pack
allocate t t
allocate_heap t I t
deallocate I
init y
allocate_zero t t
allocate_heap_zero t I t
trim N Remaining => i_trim N
i_trim I
test_heap I t
allocate_heap S u==0 R => allocate S R
allocate_heap_zero S u==0 R => allocate_zero S R
init2 y y
init3 y y y
init Y1 | init Y2 | init Y3 => init3 Y1 Y2 Y3
init Y1 | init Y2 => init2 Y1 Y2
%macro: init2 Init2 -pack
%macro: init3 Init3 -pack
# Selecting values
select_val S=aiq Fail=f Size=u Rest=* => const_select_val(S, Fail, Size, Rest)
select_val S=s Fail=f Size=u Rest=* | use_jump_tab(Size, Rest) => \
gen_jump_tab(S, Fail, Size, Rest)
is_integer Fail=f S | select_val S=s Fail=f Size=u Rest=* | use_jump_tab(Size, Rest) => \
gen_jump_tab(S, Fail, Size, Rest)
is_integer TypeFail=f S | select_val S=s Fail=f Size=u Rest=* | \
mixed_types(Size, Rest) => \
gen_split_values(S, TypeFail, Fail, Size, Rest)
select_val S=s Fail=f Size=u Rest=* | mixed_types(Size, Rest) => \
gen_split_values(S, Fail, Fail, Size, Rest)
is_integer Fail=f S | select_val S=d Fail=f Size=u Rest=* | \
fixed_size_values(Size, Rest) => gen_select_val(S, Fail, Size, Rest)
is_atom Fail=f S | select_val S=d Fail=f Size=u Rest=* | \
fixed_size_values(Size, Rest) => gen_select_val(S, Fail, Size, Rest)
select_val S=s Fail=f Size=u Rest=* | floats_or_bignums(Size, Rest) => \
gen_select_literals(S, Fail, Size, Rest)
select_val S=d Fail=f Size=u Rest=* | fixed_size_values(Size, Rest) => \
gen_select_val(S, Fail, Size, Rest)
is_tuple Fail=f S | select_tuple_arity S=d Fail=f Size=u Rest=* => \
gen_select_tuple_arity(S, Fail, Size, Rest)
select_tuple_arity S=d Fail=f Size=u Rest=* => \
gen_select_tuple_arity(S, Fail, Size, Rest)
i_select_val_bins x f I
i_select_val_bins y f I
i_select_val_lins x f I
i_select_val_lins y f I
i_select_val2 x f c c f f
i_select_val2 y f c c f f
i_select_tuple_arity x f I
i_select_tuple_arity y f I
i_select_tuple_arity2 x f A A f f
i_select_tuple_arity2 y f A A f f
i_jump_on_val_zero x f I
i_jump_on_val_zero y f I
i_jump_on_val x f I I
i_jump_on_val y f I I
%macro: get_list GetList -pack
get_list x x x
get_list x x y
get_list x y x
get_list x y y
get_list y x x
get_list y x y
get_list y y x
get_list y y y
# The following get_list instructions using x(0) are frequently used.
get_list r x x
get_list r r y
get_list x r x
get_list r x y
get_list r y r
get_list r x r
# Old-style catch.
catch y f
catch_end y
# Try/catch.
try Y F => catch Y F
try_case Y => try_end Y
try_end y
try_case_end s
# Destructive set tuple element
set_tuple_element s d P
# Get tuple element
%macro: i_get_tuple_element GetTupleElement -pack
i_get_tuple_element x P x
i_get_tuple_element y P x
%cold
i_get_tuple_element x P y
i_get_tuple_element y P y
%hot
%macro: i_get_tuple_element2 GetTupleElement2 -pack
i_get_tuple_element2 x P x
%macro: i_get_tuple_element2y GetTupleElement2Y -pack
i_get_tuple_element2y x P y y
%macro: i_get_tuple_element3 GetTupleElement3 -pack
i_get_tuple_element3 x P x
%macro: is_number IsNumber -fail_action
%cold
is_number f x
is_number f y
%hot
is_number Fail=f i =>
is_number Fail=f na => jump Fail
is_number Fail Literal=q => move Literal x | is_number Fail x
jump f
case_end NotInX=cy => move NotInX x | case_end x
badmatch NotInX=cy => move NotInX x | badmatch x
case_end x
badmatch x
if_end
# Operands for raise/2 are almost always in x(2) and x(1).
# Optimize for that case.
raise x==2 x==1 => i_raise
raise Trace=y Value=y => move Trace x=2 | move Value x=1 | i_raise
raise Trace Value => move Trace x=3 | move Value x=1 | move x=3 x=2 | i_raise
i_raise
# Internal now, but could be useful to make known to the compiler.
badarg j
system_limit j
move C=cxy x==0 | jump Lbl => move_jump Lbl C
%macro: move_jump MoveJump -nonext
move_jump f n
move_jump f c
move_jump f x
move_jump f y
# Movement to and from the stack is common
# Try to pack as much as we can into one instruction
# Window move
move_window/5
move_window/6
# x -> y
move X1=x Y1=y | move X2=x Y2=y | move X3=x Y3=y | succ(Y1,Y2) | succ(Y2,Y3) => \
move_window X1 X2 X3 Y1 Y3
move_window X1=x X2=x X3=x Y1=y Y3=y | move X4=x Y4=y | succ(Y3,Y4) => \
move_window X1 X2 X3 X4 Y1 Y4
move_window X1=x X2=x X3=x X4=x Y1=y Y4=y | move X5=x Y5=y | succ(Y4,Y5) => \
move_window5 X1 X2 X3 X4 X5 Y1
move_window X1=x X2=x X3=x Y1=y Y3=y => move_window3 X1 X2 X3 Y1
move_window X1=x X2=x X3=x X4=x Y1=y Y4=y => move_window4 X1 X2 X3 X4 Y1
%macro: move_window3 MoveWindow3 -pack
%macro: move_window4 MoveWindow4 -pack
%macro: move_window5 MoveWindow5 -pack
move_window3 x x x y
move_window4 x x x x y
move_window5 x x x x x y
# Swap registers.
move R1=x Tmp=x | move R2=xy R1 | move Tmp R2 => swap_temp R1 R2 Tmp
swap_temp R1 R2 Tmp | line Loc | apply Live | is_killed_apply(Tmp, Live) => \
swap R1 R2 | line Loc | apply Live
swap_temp R1 R2 Tmp | line Loc | call Live Addr | is_killed(Tmp, Live) => \
swap R1 R2 | line Loc | call Live Addr
swap_temp R1 R2 Tmp | call_only Live Addr | \
is_killed(Tmp, Live) => swap R1 R2 | call_only Live Addr
swap_temp R1 R2 Tmp | call_last Live Addr D | \
is_killed(Tmp, Live) => swap R1 R2 | call_last Live Addr D
swap_temp R1 R2 Tmp | line Loc | call_ext Live Addr | is_killed(Tmp, Live) => \
swap R1 R2 | line Loc | call_ext Live Addr
swap_temp R1 R2 Tmp | line Loc | call_ext_only Live Addr | \
is_killed(Tmp, Live) => swap R1 R2 | line Loc | call_ext_only Live Addr
swap_temp R1 R2 Tmp | line Loc | call_ext_last Live Addr D | \
is_killed(Tmp, Live) => swap R1 R2 | line Loc | call_ext_last Live Addr D
%macro: swap_temp SwapTemp -pack
swap_temp x x x
swap_temp x y x
%macro: swap Swap -pack
swap x x
swap x y
move Src=x D1=x | move Src=x D2=x => move_dup Src D1 D2
move Src=x SD=x | move SD=x D=x => move_dup Src SD D
move Src=x D1=x | move Src=x D2=y => move_dup Src D1 D2
move Src=y SD=x | move SD=x D=y => move_dup Src SD D
move Src=x SD=x | move SD=x D=y => move_dup Src SD D
move Src=y SD=x | move SD=x D=x => move_dup Src SD D
move SD=x D=x | move Src=xy SD=x => move_shift Src SD D
move SD=y D=x | move Src=x SD=y => move_shift Src SD D
move SD=x D=y | move Src=x SD=x => move_shift Src SD D
# The transformations above guarantee that the source for
# the second move is not the same as the destination for
# the first move. That means that we can do the moves in
# parallel (fetch both values, then store them) which could
# be faster.
move X1=x Y1=y | move X2=x Y2=y => move2_par X1 Y1 X2 Y2
move Y1=y X1=x | move Y2=y X2=x => move2_par Y1 X1 Y2 X2
move X1=x X2=x | move X3=x X4=x => move2_par X1 X2 X3 X4
move X1=x X2=x | move X3=x Y1=y => move2_par X1 X2 X3 Y1
move S1=x S2=x | move X1=x Y1=y => move2_par S1 S2 X1 Y1
move S1=y S2=x | move X1=x Y1=y => move2_par S1 S2 X1 Y1
move Y1=y X1=x | move S1=x D1=x => move2_par Y1 X1 S1 D1
move S1=x D1=x | move Y1=y X1=x => move2_par S1 D1 Y1 X1
move2_par X1=x Y1=y X2=x Y2=y | move X3=x Y3=y => move3 X1 Y1 X2 Y2 X3 Y3
move2_par Y1=y X1=x Y2=y X2=x | move Y3=y X3=x => move3 Y1 X1 Y2 X2 Y3 X3
move2_par X1=x X2=x X3=x X4=x | move X5=x X6=x => move3 X1 X2 X3 X4 X5 X6
move C=aiq X=x==1 => move_x1 C
move C=aiq X=x==2 => move_x2 C
move_x1 c
move_x2 c
%macro: move_shift MoveShift -pack
move_shift x x x
move_shift y x x
move_shift x y x
move_shift x x y
%macro: move_dup MoveDup -pack
move_dup x x x
move_dup x x y
move_dup y x x
move_dup y x y
%macro: move2_par Move2Par -pack
move2_par x y x y
move2_par y x y x
move2_par x x x x
move2_par x x x y
move2_par y x x y
move2_par x x y x
move2_par y x x x
%macro: move3 Move3 -pack
move3 x y x y x y
move3 y x y x y x
move3 x x x x x x
# The compiler almost never generates a "move Literal y(Y)" instruction,
# so let's cheat if we encounter one.
move S=n D=y => init D
move S=c D=y => move S x | move x D
%macro:move Move -pack -gen_dest
move x x
move x y
move y x
move c x
move n x
move y y
# The following move instructions using x(0) are frequently used.
move x r
move r x
move y r
move c r
move r y
# Receive operations.
loop_rec Fail x==0 | smp_mark_target_label(Fail) => i_loop_rec Fail
label L | wait_timeout Fail Src | smp_already_locked(L) => label L | i_wait_timeout_locked Fail Src
wait_timeout Fail Src => i_wait_timeout Fail Src
i_wait_timeout Fail Src=aiq => gen_literal_timeout(Fail, Src)
i_wait_timeout_locked Fail Src=aiq => gen_literal_timeout_locked(Fail, Src)
label L | wait Fail | smp_already_locked(L) => label L | wait_locked Fail
wait Fail | smp() => wait_unlocked Fail
label L | timeout | smp_already_locked(L) => label L | timeout_locked
remove_message
timeout
timeout_locked
i_loop_rec f
loop_rec_end f
wait f
wait_locked f
wait_unlocked f
i_wait_timeout f I
i_wait_timeout f s
i_wait_timeout_locked f I
i_wait_timeout_locked f s
i_wait_error
i_wait_error_locked
send
#
# Optimized comparisons with one immediate/literal operand.
#
is_eq_exact Lbl R=xy C=ian => i_is_eq_exact_immed Lbl R C
is_eq_exact Lbl R=xy C=q => i_is_eq_exact_literal Lbl R C
is_ne_exact Lbl R=xy C=ian => i_is_ne_exact_immed Lbl R C
is_ne_exact Lbl R=xy C=q => i_is_ne_exact_literal Lbl R C
%macro: i_is_eq_exact_immed EqualImmed -fail_action
i_is_eq_exact_immed f r c
i_is_eq_exact_immed f x c
i_is_eq_exact_immed f y c
i_is_eq_exact_literal f x c
i_is_eq_exact_literal f y c
%macro: i_is_ne_exact_immed NotEqualImmed -fail_action
i_is_ne_exact_immed f x c
i_is_ne_exact_immed f y c
i_is_ne_exact_literal f x c
i_is_ne_exact_literal f y c
is_eq_exact Lbl Y=y X=x => is_eq_exact Lbl X Y
%macro: is_eq_exact EqualExact -fail_action -pack
is_eq_exact f x x
is_eq_exact f x y
is_eq_exact f s s
%macro: is_lt IsLessThan -fail_action
is_lt f x x
is_lt f x c
is_lt f c x
%cold
is_lt f s s
%hot
%macro: is_ge IsGreaterEqual -fail_action
is_ge f x x
is_ge f x c
is_ge f c x
%cold
is_ge f s s
%hot
%macro: is_ne_exact NotEqualExact -fail_action
is_ne_exact f s s
%macro: is_eq Equal -fail_action
is_eq f s s
%macro: is_ne NotEqual -fail_action
is_ne f s s
#
# Putting things.
#
put_tuple Arity Dst => i_put_tuple Dst u
i_put_tuple Dst Arity Puts=* | put S1 | put S2 | \
put S3 | put S4 | put S5 => \
tuple_append_put5(Arity, Dst, Puts, S1, S2, S3, S4, S5)
i_put_tuple Dst Arity Puts=* | put S => \
tuple_append_put(Arity, Dst, Puts, S)
i_put_tuple/2
%macro:i_put_tuple PutTuple -pack -goto:do_put_tuple
i_put_tuple x I
i_put_tuple y I
#
# The instruction "put_list Const [] Dst" were generated in rare
# circumstances up to and including OTP 18. Starting with OTP 19,
# AFAIK, it should never be generated.
#
put_list Const=c n Dst => move Const x | put_list x n Dst
%macro:put_list PutList -pack -gen_dest
put_list x n x
put_list y n x
put_list x x x
put_list y x x
put_list y y x
put_list x y x
put_list y x x
# put_list SrcReg Constant Dst
put_list x c x
put_list x c y
put_list y c x
# put_list Constant SrcReg Dst
put_list c x x
put_list c y x
# The following put_list instructions using x(0) are frequently used.
put_list y r r
put_list x r r
put_list r n r
put_list r n x
put_list r x x
put_list r x r
put_list x x r
%cold
put_list s s d
%hot
#
# Some more only used by the emulator
#
normal_exit
continue_exit
apply_bif
call_nif
call_error_handler
error_action_code
return_trace
#
# Instruction transformations & folded instructions.
#
# Note: There is no 'move_return y r', since there never are any y registers
# when we do move_return (if we have y registers, we must do move_deallocate_return).
move S x==0 | return => move_return S
%macro: move_return MoveReturn -nonext
move_return x
move_return c
move_return n
move S x==0 | deallocate D | return => move_deallocate_return S D
%macro: move_deallocate_return MoveDeallocateReturn -pack -nonext
move_deallocate_return x Q
move_deallocate_return y Q
move_deallocate_return c Q
move_deallocate_return n Q
deallocate D | return => deallocate_return D
%macro: deallocate_return DeallocateReturn -nonext
deallocate_return Q
test_heap Need u==1 | put_list Y=y x==0 x==0 => test_heap_1_put_list Need Y
%macro: test_heap_1_put_list TestHeapPutList -pack
test_heap_1_put_list I y
# Test tuple & arity (head)
is_tuple Fail Literal=q => move Literal x | is_tuple Fail x
is_tuple Fail=f c => jump Fail
is_tuple Fail=f S=xy | test_arity Fail=f S=xy Arity => is_tuple_of_arity Fail S Arity
%macro:is_tuple_of_arity IsTupleOfArity -fail_action
is_tuple_of_arity f r A
is_tuple_of_arity f x A
is_tuple_of_arity f y A
%macro: is_tuple IsTuple -fail_action
is_tuple f r
is_tuple f x
is_tuple f y
test_arity Fail Literal=q Arity => move Literal x | test_arity Fail x Arity
test_arity Fail=f c Arity => jump Fail
%macro: test_arity IsArity -fail_action
test_arity f x A
test_arity f y A
get_tuple_element Reg=x P1 D1=x | get_tuple_element Reg=x P2 D2=x | \
get_tuple_element Reg=x P3 D3=x | \
succ(P1, P2) | succ(P2, P3) | \
succ(D1, D2) | succ(D2, D3) => i_get_tuple_element3 Reg P1 D1
get_tuple_element Reg=x P1 D1=x | get_tuple_element Reg=x P2 D2=x | \
succ(P1, P2) | succ(D1, D2) => i_get_tuple_element2 Reg P1 D1
get_tuple_element Reg=x P1 D1=y | get_tuple_element Reg=x P2 D2=y | \
succ(P1, P2) => i_get_tuple_element2y Reg P1 D1 D2
get_tuple_element Reg P Dst => i_get_tuple_element Reg P Dst
is_integer Fail=f i =>
is_integer Fail=f an => jump Fail
is_integer Fail Literal=q => move Literal x | is_integer Fail x
is_integer Fail=f S=x | allocate Need Regs => is_integer_allocate Fail S Need Regs
%macro: is_integer_allocate IsIntegerAllocate -fail_action
is_integer_allocate f x I I
%macro: is_integer IsInteger -fail_action
is_integer f x
is_integer f y
is_list Fail=f n =>
is_list Fail Literal=q => move Literal x | is_list Fail x
is_list Fail=f c => jump Fail
%macro: is_list IsList -fail_action
is_list f x
%cold
is_list f y
%hot
is_nonempty_list Fail=f S=x | allocate Need Rs => is_nonempty_list_allocate Fail S Need Rs
%macro:is_nonempty_list_allocate IsNonemptyListAllocate -fail_action -pack
is_nonempty_list_allocate f r I t
is_nonempty_list_allocate f x I t
is_nonempty_list F=f x==0 | test_heap I1 I2 => is_non_empty_list_test_heap F I1 I2
%macro: is_non_empty_list_test_heap IsNonemptyListTestHeap -fail_action -pack
is_non_empty_list_test_heap f I t
is_nonempty_list Fail=f S=x | get_list S D1=x D2=x => \
is_nonempty_list_get_list Fail S D1 D2
%macro: is_nonempty_list_get_list IsNonemptyListGetList -fail_action -pack
is_nonempty_list_get_list f r x x
is_nonempty_list_get_list f x x x
%macro: is_nonempty_list IsNonemptyList -fail_action
is_nonempty_list f x
is_nonempty_list f y
%macro: is_atom IsAtom -fail_action
is_atom f x
%cold
is_atom f y
%hot
is_atom Fail=f a =>
is_atom Fail=f niq => jump Fail
%macro: is_float IsFloat -fail_action
is_float f x
%cold
is_float f y
%hot
is_float Fail=f nai => jump Fail
is_float Fail Literal=q => move Literal x | is_float Fail x
is_nil Fail=f n =>
is_nil Fail=f qia => jump Fail
%macro: is_nil IsNil -fail_action
is_nil f x
is_nil f y
is_binary Fail Literal=q => move Literal x | is_binary Fail x
is_binary Fail=f c => jump Fail
%macro: is_binary IsBinary -fail_action
is_binary f x
%cold
is_binary f y
%hot
# XXX Deprecated.
is_bitstr Fail Term => is_bitstring Fail Term
is_bitstring Fail Literal=q => move Literal x | is_bitstring Fail x
is_bitstring Fail=f c => jump Fail
%macro: is_bitstring IsBitstring -fail_action
is_bitstring f x
%cold
is_bitstring f y
%hot
is_reference Fail=f cq => jump Fail
%macro: is_reference IsRef -fail_action
is_reference f x
%cold
is_reference f y
%hot
is_pid Fail=f cq => jump Fail
%macro: is_pid IsPid -fail_action
is_pid f x
%cold
is_pid f y
%hot
is_port Fail=f cq => jump Fail
%macro: is_port IsPort -fail_action
is_port f x
%cold
is_port f y
%hot
is_boolean Fail=f a==am_true =>
is_boolean Fail=f a==am_false =>
is_boolean Fail=f ac => jump Fail
%cold
%macro: is_boolean IsBoolean -fail_action
is_boolean f x
is_boolean f y
%hot
is_function2 Fail=f acq Arity => jump Fail
is_function2 Fail=f Fun a => jump Fail
is_function2 f s s
%macro: is_function2 IsFunction2 -fail_action
# Allocating & initializing.
allocate Need Regs | init Y => allocate_init Need Regs Y
init Y1 | init Y2 => init2 Y1 Y2
%macro: allocate_init AllocateInit -pack
allocate_init t I y
#################################################################
# External function and bif calls.
#################################################################
#
# The BIFs erts_internal:check_process_code/2 must be called like a function,
# to ensure that c_p->i (program counter) is set correctly (an ordinary
# BIF call doesn't set it).
#
call_ext u==2 Bif=u$bif:erts_internal:check_process_code/2 => i_call_ext Bif
call_ext_last u==2 Bif=u$bif:erts_internal:check_process_code/2 D => i_call_ext_last Bif D
call_ext_only u==2 Bif=u$bif:erts_internal:check_process_code/2 => i_call_ext_only Bif
#
# The BIFs erlang:garbage_collect/0 must be called like a function,
# to allow them to invoke the garbage collector. (The stack pointer must
# be saved and p->arity must be zeroed, which is not done on ordinary BIF calls.)
#
call_ext u==0 Bif=u$bif:erlang:garbage_collect/0 => i_call_ext Bif
call_ext_last u==0 Bif=u$bif:erlang:garbage_collect/0 D => i_call_ext_last Bif D
call_ext_only u==0 Bif=u$bif:erlang:garbage_collect/0 => i_call_ext_only Bif
#
# put/2 and erase/1 must be able to do garbage collection, so we must call
# them like functions.
#
call_ext u==2 Bif=u$bif:erlang:put/2 => i_call_ext Bif
call_ext_last u==2 Bif=u$bif:erlang:put/2 D => i_call_ext_last Bif D
call_ext_only u==2 Bif=u$bif:erlang:put/2 => i_call_ext_only Bif
call_ext u==1 Bif=u$bif:erlang:erase/1 => i_call_ext Bif
call_ext_last u==1 Bif=u$bif:erlang:erase/1 D => i_call_ext_last Bif D
call_ext_only u==1 Bif=u$bif:erlang:erase/1 => i_call_ext_only Bif
#
# The process_info/1,2 BIF should be called like a function, to force
# the emulator to set c_p->current before calling it (a BIF call doesn't
# set it).
#
# In addition, we force the use of a non-tail-recursive call. This will ensure
# that c_p->cp points into the function making the call.
#
call_ext u==1 Bif=u$bif:erlang:process_info/1 => i_call_ext Bif
call_ext_last u==1 Bif=u$bif:erlang:process_info/1 D => i_call_ext Bif | deallocate_return D
call_ext_only Ar=u==1 Bif=u$bif:erlang:process_info/1 => allocate u Ar | i_call_ext Bif | deallocate_return u
call_ext u==2 Bif=u$bif:erlang:process_info/2 => i_call_ext Bif
call_ext_last u==2 Bif=u$bif:erlang:process_info/2 D => i_call_ext Bif | deallocate_return D
call_ext_only Ar=u==2 Bif=u$bif:erlang:process_info/2 => allocate u Ar | i_call_ext Bif | deallocate_return u
#
# load_nif/2 also needs to know calling function like process_info
#
call_ext u==2 Bif=u$bif:erlang:load_nif/2 => i_call_ext Bif
call_ext_last u==2 Bif=u$bif:erlang:load_nif/2 D => i_call_ext Bif | deallocate_return D
call_ext_only Ar=u==2 Bif=u$bif:erlang:load_nif/2 => allocate u Ar | i_call_ext Bif | deallocate_return u
#
# apply/2 is an instruction, not a BIF.
#
call_ext u==2 u$func:erlang:apply/2 => i_apply_fun
call_ext_last u==2 u$func:erlang:apply/2 D => i_apply_fun_last D
call_ext_only u==2 u$func:erlang:apply/2 => i_apply_fun_only
#
# The apply/3 BIF is an instruction.
#
call_ext u==3 u$bif:erlang:apply/3 => i_apply
call_ext_last u==3 u$bif:erlang:apply/3 D => i_apply_last D
call_ext_only u==3 u$bif:erlang:apply/3 => i_apply_only
#
# The exit/1 and throw/1 BIFs never execute the instruction following them;
# thus there is no need to generate any return instruction.
#
call_ext_last u==1 Bif=u$bif:erlang:exit/1 D => call_bif Bif
call_ext_last u==1 Bif=u$bif:erlang:throw/1 D => call_bif Bif
call_ext_only u==1 Bif=u$bif:erlang:exit/1 => call_bif Bif
call_ext_only u==1 Bif=u$bif:erlang:throw/1 => call_bif Bif
#
# The error/1 and error/2 BIFs never execute the instruction following them;
# thus there is no need to generate any return instruction.
# However, they generate stack backtraces, so if the call instruction
# is call_ext_only/2 instruction, we explicitly do an allocate/2 to store
# the continuation pointer on the stack.
#
call_ext_last u==1 Bif=u$bif:erlang:error/1 D => call_bif Bif
call_ext_last u==2 Bif=u$bif:erlang:error/2 D => call_bif Bif
call_ext_only Ar=u==1 Bif=u$bif:erlang:error/1 => \
allocate u Ar | call_bif Bif
call_ext_only Ar=u==2 Bif=u$bif:erlang:error/2 => \
allocate u Ar | call_bif Bif
#
# The yield/0 BIF is an instruction
#
call_ext u==0 u$func:erlang:yield/0 => i_yield
call_ext_last u==0 u$func:erlang:yield/0 D => i_yield | deallocate_return D
call_ext_only u==0 u$func:erlang:yield/0 => i_yield | return
#
# The hibernate/3 BIF is an instruction.
#
call_ext u==3 u$func:erlang:hibernate/3 => i_hibernate
call_ext_last u==3 u$func:erlang:hibernate/3 D => i_hibernate
call_ext_only u==3 u$func:erlang:hibernate/3 => i_hibernate
#
# If VM probes are not enabled, we want to short-circult calls to
# the dt tag BIFs to make them as cheap as possible.
#
%unless USE_VM_PROBES
call_ext Arity u$func:erlang:dt_get_tag/0 => \
move a=am_undefined x=0
call_ext_last Arity u$func:erlang:dt_get_tag/0 D => \
move a=am_undefined x=0 | deallocate D | return
call_ext_only Arity u$func:erlang:dt_get_tag/0 => \
move a=am_undefined x=0 | return
move Any x==0 | call_ext Arity u$func:erlang:dt_put_tag/1 => \
move a=am_undefined x=0
move Any x==0 | call_ext_last Arity u$func:erlang:dt_put_tag/1 D => \
move a=am_undefined x=0 | deallocate D | return
move Any x==0 | call_ext_only Arity u$func:erlang:dt_put_tag/1 => \
move a=am_undefined x=0 | return
call_ext Arity u$func:erlang:dt_put_tag/1 => \
move a=am_undefined x=0
call_ext_last Arity u$func:erlang:dt_put_tag/1 D => \
move a=am_undefined x=0 | deallocate D | return
call_ext_only Arity u$func:erlang:dt_put_tag/1 => \
move a=am_undefined x=0 | return
call_ext Arity u$func:erlang:dt_get_tag_data/0 => \
move a=am_undefined x=0
call_ext_last Arity u$func:erlang:dt_get_tag_data/0 D => \
move a=am_undefined x=0 | deallocate D | return
call_ext_only Arity u$func:erlang:dt_get_tag_data/0 => \
move a=am_undefined x=0 | return
move Any x==0 | call_ext Arity u$func:erlang:dt_spread_tag/1 => \
move a=am_true x=0
move Any x==0 | call_ext_last Arity u$func:erlang:dt_spread_tag/1 D => \
move a=am_true x=0 | deallocate D | return
move Any x==0 | call_ext_only Arity u$func:erlang:dt_spread_tag/1 => \
move a=am_true x=0 | return
call_ext Arity u$func:erlang:dt_spread_tag/1 => \
move a=am_true x=0
call_ext_last Arity u$func:erlang:dt_spread_tag/1 D => \
move a=am_true x=0 | deallocate D | return
call_ext_only Arity u$func:erlang:dt_spread_tag/1 => \
move a=am_true x=0 | return
move Any x==0 | call_ext Arity u$func:erlang:dt_restore_tag/1 => \
move a=am_true x=0
move Any x==0 | call_ext_last Arity u$func:erlang:dt_restore_tag/1 D => \
move a=am_true x=0 | deallocate D | return
move Any x==0 | call_ext_only Arity u$func:erlang:dt_restore_tag/1 => \
move a=am_true x=0 | return
call_ext Arity u$func:erlang:dt_restore_tag/1 => \
move a=am_true x=0
call_ext_last Arity u$func:erlang:dt_restore_tag/1 D => \
move a=am_true x=0 | deallocate D | return
call_ext_only Arity u$func:erlang:dt_restore_tag/1 => \
move a=am_true x=0 | return
move Any x==0 | call_ext Arity u$func:erlang:dt_prepend_vm_tag_data/1 => \
move Any x=0
move Any x==0 | call_ext_last Arity u$func:erlang:dt_prepend_vm_tag_data/1 D => \
move Any x=0 | deallocate D | return
move Any x==0 | call_ext_only Arity u$func:erlang:dt_prepend_vm_tag_data/1 => \
move Any x=0 | return
call_ext Arity u$func:erlang:dt_prepend_vm_tag_data/1 =>
call_ext_last Arity u$func:erlang:dt_prepend_vm_tag_data/1 D => \
deallocate D | return
call_ext_only Arity u$func:erlang:dt_prepend_vm_tag_data/1 => \
return
move Any x==0 | call_ext Arity u$func:erlang:dt_append_vm_tag_data/1 => \
move Any x=0
move Any x==0 | call_ext_last Arity u$func:erlang:dt_append_vm_tag_data/1 D => \
move Any x=0 | deallocate D | return
move Any x==0 | call_ext_only Arity u$func:erlang:dt_append_vm_tag_data/1 => \
move Any x=0 | return
call_ext Arity u$func:erlang:dt_append_vm_tag_data/1 =>
call_ext_last Arity u$func:erlang:dt_append_vm_tag_data/1 D => \
deallocate D | return
call_ext_only Arity u$func:erlang:dt_append_vm_tag_data/1 => \
return
# Can happen after one of the transformations above.
move Discarded x==0 | move Something x==0 => move Something x=0
%endif
call_ext u==0 u$func:os:perf_counter/0 => \
i_perf_counter