This repository was archived by the owner on Nov 17, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathaot_ceval_jit.c
More file actions
5897 lines (5239 loc) · 228 KB
/
Copy pathaot_ceval_jit.c
File metadata and controls
5897 lines (5239 loc) · 228 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
// This file contains the JIT compiler
// The main design choices/goals are:
// - removing the dispatching overhead of the interpreter
// - reducing reference counting overhead
// - reducing overhead related to Python value stack push/pops
// - inlined caches
// - generates calls to ahead of time generated type specific traces of bytescodes
// - e.g. 'float * float' -> PyNumber_MultiplyFloatFloat2
// - very fast compilation speed
// - uses DynAsm - good documentation at: https://corsix.github.io/dynasm-doc/index.html
// - jit thresholds are very low
// - most bytecode instructions are complex and are handled by calls to functions
// which means even a more clever compiler can't do much better (when not inlining)
// - mostly using static register allocation is fine
// because of all the external calls which restrict register assignment
// - machine code gets emitted immediately, no IR, passes etc..
// - can switch from interpreter to compiled function at
// - function entry
// - any bytecode which is the target of jump from another bytecode
// - deoptimization is possible at the start of every bytecode
// - currently used to implement cpythons 'tracing' support
// - main task is creating the python value stack for the interpreter to continue
//
// Some assumptions:
// - we currently only support amd64 systems with SystemV calling convention and AArch64
// - code gets emitted into memory area which fits into 32bit address
// - makes sure we can use relative addressing most of the time
// - saves some space
// - we use a custom calling convention to make external calls fast:
// - args get past/returned following the SystemV calling convention
// - in addition we have the following often used values in fixed callee saved registers
// (which means we can call normal C function without changes because have to save them):
// - r12/x23 - PyObject** python value stack pointer
// - r13/x19 - PyFrameObject* frame object of currently executing function
// - r15/x22 - PyThreadState* tstate of currently executing thread
// - code inside aot_ceval_jit_helper.c is using this special convention
// via gcc global register variable extension
// (which prevents us from using LTO on that translation unit)
//
// 'Deferred value stack':
// - we don't emit python value stack operations (PUSH(), POP(),...) immediately
// like the interpreter does instead we defer them until the use
// - this removes many memory operations
// - we can directly use the correct register when doing a external call
// - we can avoid some reference counting updates
// - code which needs the interpreters value stack needs to call:
// - deferred_vs_apply()
// - if a instruction modifies register 'res' (=rax) it needs to first call:
// - deferred_vs_convert_reg_to_stack()
//
// Future bigger ideas:
// - we support deoptimizations at the start of every bytecode which we could use
// to generate faster more specialiced code which makes some assumptions
// - get ride of frame->f_lasti updates
// - update/overwrite inline cache entries when they start to fail
//
#define PY_LOCAL_AGGRESSIVE
#include "../../Python/aot_ceval_includes.h"
#ifdef PYSTON_LITE
// Use the cpython version of this file:
#include "dict-common.h"
#else
#include "../Objects/dict-common.h"
#endif
#ifdef PYSTON_LITE
#define IS_IMMORTAL(x) (0)
#endif
// enable runtime checks to catch jit compiler bugs
//#define JIT_DEBUG 1
#if JIT_DEBUG
#define DASM_CHECKS 1
#define _STRINGIFY(N) #N
#define STRINGIFY(N) _STRINGIFY(N)
#define JIT_ASSERT(condition, fmt, ...) \
do { \
if (!(condition)) { \
fprintf(stderr, __FILE__ ":" STRINGIFY(__LINE__) ": %s: Assertion `" #condition "' failed: " fmt "\n", \
__PRETTY_FUNCTION__, ##__VA_ARGS__); \
abort(); \
} \
} while (0)
#else
#define JIT_ASSERT(x, m, ...) assert(x)
#endif
#ifdef PYSTON_LITE
#define ENABLE_DEFINED_TRACKING 0
#else
#define ENABLE_DEFINED_TRACKING 1
#endif
#define DEFERRED_VS_MAX 16 /* used by STORE_SUBSCR */
// stack layout looks like this:
// on 3.7:
// manual_stack_slots | pointer_to_why | deferred_stack
// on 3.8:
// manual_stack_slots | deferred_stack
#define NUM_MANUAL_STACK_SLOTS 2 /* used by STORE_SUBSCR */
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 7
#define DEFERRED_STACK_SLOT_START (NUM_MANUAL_STACK_SLOTS + 1)
#define WHY_SLOT NUM_MANUAL_STACK_SLOTS
#else
#define DEFERRED_STACK_SLOT_START NUM_MANUAL_STACK_SLOTS
#endif
typedef enum ValueStackLoc {
CONST,
FAST,
REGISTER,
STACK,
} ValueStackLoc;
// Enum values for ref_status:
typedef enum RefStatus {
BORROWED,
OWNED,
IMMORTAL,
} RefStatus;
typedef enum Section {
SECTION_CODE,
SECTION_COLD,
SECTION_DEOPT,
SECTION_ENTRY,
SECTION_OPCODE_ADDR,
} Section;
typedef struct DeferredValueStackEntry {
ValueStackLoc loc;
unsigned long val;
} DeferredValueStackEntry;
// We have a very simple analysis method:
// When we see a LOAD_METHOD bytecode, we try to gather some hints that
// can help the corresponding CALL_METHOD.
//
// The corresponding LOAD_METHOD and CALL_METHOD can be a bit hard to determine,
// so the strategy used here is to just put the hints in a stack for LOAD_METHOD,
// and pop them off for CALL_METHOD.
//
// The reason this optimization is valuable is because the LOAD_METHOD bytecode
// might have a decent amount of information available: typically the value of
// the callable on the fast path.
//
// Some of this is gained from using AOT speculation, but there are more fields
// that can be specialized on than we have in our traces. Plus we can skip extra
// guards by doing a single type check at the beginning.
//
// There is always a hint object defined for each LOAD_METHOD bytecode, and one
// consumed by each CALL_METHOD bytecode. If no hinting information was found
// then the hint object will contain NULL entries.
typedef struct CallMethodHint {
struct CallMethodHint* next; // next item in this linked list
PyTypeObject* type; // type of the object we got the attribute from
PyObject* attr; // the attribute that we fetched
char meth_found;
char is_self_const; // self set via LOAD_CONST
} CallMethodHint;
typedef struct Jit {
struct dasm_State* d;
char failed;
PyCodeObject* co;
OpCache* opcache;
PyObject* co_consts;
PyObject* co_names;
int deferred_vs_next;
DeferredValueStackEntry deferred_vs[DEFERRED_VS_MAX];
int num_deferred_stack_slots;
int deferred_stack_slot_next;
Section current_section;
// =1 if an entry in deferred_vs is using the vs_preserved_reg
int deferred_vs_preserved_reg_used;
// =1 if an entry in deferred_vs is using the 'res' register
int deferred_vs_res_used;
int num_opcodes;
const _Py_CODEUNIT *first_instr;
char* is_jmp_target; // need to be free()d
#if ENABLE_DEFINED_TRACKING
// this keeps track of which fast local variable we know are set (!= 0)
// if we don't know if they are set or if they are 0 is defined will be 0
// currently we only track definedness inside a basic block and in addition the function args
// TODO: could use a bitvector instead of a byte per local variable
char* known_defined; // need to be free()d
#endif
// used by emit_instr_start to keep state across calls
int old_line_number;
int emitted_trace_check_for_line;
CallMethodHint* call_method_hints; // linked list, each item needs to be freed
} Jit;
#define Dst_DECL Jit* Dst
#define Dst_REF Dst->d
// ignore this false warning
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#include <dynasm/dasm_proto.h>
#ifdef __aarch64__
#include <dynasm/dasm_arm64.h>
#else
#include <dynasm/dasm_x86.h>
#endif
#pragma GCC diagnostic pop
#if JIT_DEBUG
// checks after every instruction sequence emitted if a DynASM error got generated
// helps with catching operands which are out of range for the specified instruction.
#define dasm_put(...) do { dasm_put(__VA_ARGS__); JIT_ASSERT(Dst_REF->status == DASM_S_OK, "dasm check failed %x", Dst_REF->status); } while (0)
#endif
#include <sys/mman.h>
#include <ctype.h>
#ifdef PYSTON_LITE
PyObject* cmp_outcome(PyThreadState *tstate, int, PyObject *v, PyObject *w);
PyObject* PyNumber_PowerNone(PyObject *v, PyObject *w);
PyObject* PyNumber_InPlacePowerNone(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_LT(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_LE(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_EQ(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_NE(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_GT(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_GE(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_IN(PyObject *v, PyObject *w);
PyObject* cmp_outcomePyCmp_NOT_IN(PyObject *v, PyObject *w);
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9
PyObject* call_function_ceval_no_kw(PyThreadState *tstate, PyObject **stack, Py_ssize_t oparg);
PyObject* call_function_ceval_kw(PyThreadState *tstate, PyObject **stack, Py_ssize_t oparg, PyObject* kwnames);
PyObject* call_function_ceval_no_kwProfile(PyThreadState * tstate, PyObject ** restrict stack, Py_ssize_t oparg);
#else
PyObject* call_function_ceval_no_kw(PyThreadState *tstate, PyTraceInfo* trace_info, PyObject **stack, Py_ssize_t oparg);
PyObject* call_function_ceval_kw(PyThreadState *tstate, PyTraceInfo* trace_info, PyObject **stack, Py_ssize_t oparg, PyObject* kwnames);
PyObject* call_function_ceval_no_kwProfile(PyThreadState * tstate, PyTraceInfo* trace_info, PyObject ** restrict stack, Py_ssize_t oparg);
#endif
#else
#include "aot.h"
#endif
#include "aot_ceval_jit_helper.h"
// used if JIT_PERF_MAP is enabled
static FILE *perf_map_file = NULL, *perf_map_opcode_map = NULL;
static long perf_map_num_funcs = 0;
struct PerfMapEntry {
char* func_name; // must call free() on it
void* func_addr;
long func_size;
} *perf_map_funcs;
static int jit_use_aot = 1, jit_use_ics = 1;
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 8
static PyObject* cmp_outcomePyCmp_BAD(PyObject *v, PyObject *w) {
return cmp_outcome(NULL, PyCmp_BAD, v, w);
}
#endif
PyObject* cmp_outcomePyCmp_EXC_MATCH(PyObject *v, PyObject *w);
int eval_breaker_jit_helper();
PyObject* loadAttrCacheAttrNotFound(PyObject *owner, PyObject *name);
int setItemSplitDictCache(PyObject* dict, Py_ssize_t splitdict_index, PyObject* v, PyObject* name);
int setItemInitSplitDictCache(PyObject** dictptr, PyObject* obj, PyObject* v, Py_ssize_t splitdict_index,PyObject* name);
PyObject * import_name(PyThreadState *, PyFrameObject *,
PyObject *, PyObject *, PyObject *);
PyObject * import_from(PyThreadState *, PyObject *, PyObject *);
void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
#ifdef PYSTON_LITE
void* lookdict_split_value;
#define lookdict_split lookdict_split_value
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8
static void* method_vectorcall_NOARGS_value;
static void* method_vectorcall_O_value;
static void* method_vectorcall_FASTCALL_value;
static void* method_vectorcall_FASTCALL_KEYWORDS_value;
static void* method_vectorcall_VARARGS_value;
static void* method_vectorcall_VARARGS_KEYWORDS_value;
#define method_vectorcall_NOARGS method_vectorcall_NOARGS_value
#define method_vectorcall_O method_vectorcall_O_value
#define method_vectorcall_FASTCALL method_vectorcall_FASTCALL_value
#define method_vectorcall_FASTCALL_KEYWORDS method_vectorcall_FASTCALL_KEYWORDS_value
#define method_vectorcall_VARARGS method_vectorcall_VARARGS_value
#define method_vectorcall_VARARGS_KEYWORDS method_vectorcall_VARARGS_KEYWORDS_value
#endif
#else
Py_ssize_t lookdict_split(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
PyObject * method_vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
PyObject * method_vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
PyObject * method_vectorcall_FASTCALL(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
PyObject * method_vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
PyObject * method_vectorcall_VARARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
PyObject * method_vectorcall_VARARGS_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
#endif
PyObject* PySlice_NewSteal(PyObject *start, PyObject *stop, PyObject *step);
static void decref_array(PyObject** vec, int n) {
for (int i = -1; i >= -n; i--) {
Py_DECREF(vec[i]);
}
}
__attribute__((flatten))
static void decref_array3(PyObject** vec) {
decref_array(vec, 3);
}
__attribute__((flatten))
static void decref_array4(PyObject** vec) {
decref_array(vec, 4);
}
static void* __attribute__ ((const)) get_addr_of_helper_func(int opcode, int oparg) {
switch (opcode) {
#define JIT_HELPER_ADDR(name) case name: return JIT_HELPER_##name
JIT_HELPER_ADDR(PRINT_EXPR);
JIT_HELPER_ADDR(RAISE_VARARGS);
JIT_HELPER_ADDR(GET_AITER);
JIT_HELPER_ADDR(GET_ANEXT);
JIT_HELPER_ADDR(GET_AWAITABLE);
JIT_HELPER_ADDR(YIELD_FROM);
JIT_HELPER_ADDR(POP_EXCEPT);
JIT_HELPER_ADDR(LOAD_BUILD_CLASS);
JIT_HELPER_ADDR(STORE_NAME);
JIT_HELPER_ADDR(DELETE_NAME);
JIT_HELPER_ADDR(UNPACK_EX);
JIT_HELPER_ADDR(DELETE_GLOBAL);
JIT_HELPER_ADDR(LOAD_NAME);
JIT_HELPER_ADDR(LOAD_CLASSDEREF);
JIT_HELPER_ADDR(BUILD_STRING);
JIT_HELPER_ADDR(BUILD_SET);
JIT_HELPER_ADDR(BUILD_MAP);
JIT_HELPER_ADDR(SETUP_ANNOTATIONS);
JIT_HELPER_ADDR(BUILD_CONST_KEY_MAP);
JIT_HELPER_ADDR(IMPORT_STAR);
JIT_HELPER_ADDR(GET_YIELD_FROM_ITER);
JIT_HELPER_ADDR(BEFORE_ASYNC_WITH);
JIT_HELPER_ADDR(SETUP_WITH);
JIT_HELPER_ADDR(MAKE_FUNCTION);
JIT_HELPER_ADDR(FORMAT_VALUE);
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 8
JIT_HELPER_ADDR(BUILD_LIST_UNPACK);
JIT_HELPER_ADDR(BUILD_MAP_UNPACK);
JIT_HELPER_ADDR(BUILD_MAP_UNPACK_WITH_CALL);
JIT_HELPER_ADDR(BUILD_SET_UNPACK);
JIT_HELPER_ADDR(BUILD_TUPLE_UNPACK_WITH_CALL);
JIT_HELPER_ADDR(BUILD_TUPLE_UNPACK);
JIT_HELPER_ADDR(WITH_CLEANUP_START);
JIT_HELPER_ADDR(WITH_CLEANUP_FINISH);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8
JIT_HELPER_ADDR(POP_FINALLY);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8
JIT_HELPER_ADDR(END_ASYNC_FOR);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9
JIT_HELPER_ADDR(WITH_EXCEPT_START);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 10
JIT_HELPER_ADDR(GET_LEN);
JIT_HELPER_ADDR(MATCH_CLASS);
JIT_HELPER_ADDR(MATCH_MAPPING);
JIT_HELPER_ADDR(MATCH_SEQUENCE);
JIT_HELPER_ADDR(MATCH_KEYS);
JIT_HELPER_ADDR(COPY_DICT_WITHOUT_KEYS);
JIT_HELPER_ADDR(ROT_N);
#endif
case UNPACK_SEQUENCE:
if (oparg == 2) return JIT_HELPER_UNPACK_SEQUENCE2;
if (oparg == 3) return JIT_HELPER_UNPACK_SEQUENCE3;
return JIT_HELPER_UNPACK_SEQUENCE;
case CALL_FUNCTION_EX:
if (oparg == 0) return JIT_HELPER_CALL_FUNCTION_EX_NOKWARGS;
if (oparg == 1) return JIT_HELPER_CALL_FUNCTION_EX_KWARGS;
printf("could not find helper for opcode: %d oparg: %d\n", opcode, oparg);
abort();
default:
printf("could not find helper for opcode: %d oparg: %d\n", opcode, oparg);
abort();
}
#undef JIT_HELPER_ADDR
}
static void* __attribute__ ((const)) get_addr_of_aot_func(int opcode, int oparg, int opcache_available) {
#define OPCODE_STATIC(x, func) if (opcode == x) return (func)
#define _OPCODE_PROFILE(x, func) OPCODE_STATIC(x, jit_use_aot ? func##Profile : func)
#ifdef PYSTON_LITE
#define OPCODE_PROFILE(x, func) OPCODE_STATIC(x, func)
#define OPCODE_PROFILE_LITE(x, func) _OPCODE_PROFILE(x, func)
#else
#define OPCODE_PROFILE(x, func) _OPCODE_PROFILE(x, func)
#define OPCODE_PROFILE_LITE(x, func) _OPCODE_PROFILE(x, func)
#endif
OPCODE_PROFILE(UNARY_POSITIVE, PyNumber_Positive);
OPCODE_PROFILE(UNARY_NEGATIVE, PyNumber_Negative);
OPCODE_PROFILE(UNARY_INVERT, PyNumber_Invert);
OPCODE_PROFILE(UNARY_NOT, PyObject_IsTrue);
OPCODE_PROFILE(GET_ITER, PyObject_GetIter);
OPCODE_PROFILE(BINARY_MULTIPLY, PyNumber_Multiply);
OPCODE_PROFILE(BINARY_MATRIX_MULTIPLY, PyNumber_MatrixMultiply);
OPCODE_PROFILE(BINARY_TRUE_DIVIDE, PyNumber_TrueDivide);
OPCODE_PROFILE(BINARY_FLOOR_DIVIDE, PyNumber_FloorDivide);
OPCODE_PROFILE(BINARY_MODULO, PyNumber_Remainder);
OPCODE_PROFILE(BINARY_ADD, PyNumber_Add);
OPCODE_PROFILE(BINARY_SUBTRACT, PyNumber_Subtract);
OPCODE_PROFILE(BINARY_LSHIFT, PyNumber_Lshift);
OPCODE_PROFILE(BINARY_RSHIFT, PyNumber_Rshift);
OPCODE_PROFILE(BINARY_AND, PyNumber_And);
OPCODE_PROFILE(BINARY_XOR, PyNumber_Xor);
OPCODE_PROFILE(BINARY_OR, PyNumber_Or);
OPCODE_PROFILE(INPLACE_MULTIPLY, PyNumber_InPlaceMultiply);
OPCODE_PROFILE(INPLACE_MATRIX_MULTIPLY, PyNumber_InPlaceMatrixMultiply);
OPCODE_PROFILE(INPLACE_TRUE_DIVIDE, PyNumber_InPlaceTrueDivide);
OPCODE_PROFILE(INPLACE_FLOOR_DIVIDE, PyNumber_InPlaceFloorDivide);
OPCODE_PROFILE(INPLACE_MODULO, PyNumber_InPlaceRemainder);
OPCODE_PROFILE(INPLACE_ADD, PyNumber_InPlaceAdd);
OPCODE_PROFILE(INPLACE_SUBTRACT, PyNumber_InPlaceSubtract);
OPCODE_PROFILE(INPLACE_LSHIFT, PyNumber_InPlaceLshift);
OPCODE_PROFILE(INPLACE_RSHIFT, PyNumber_InPlaceRshift);
OPCODE_PROFILE(INPLACE_AND, PyNumber_InPlaceAnd);
OPCODE_PROFILE(INPLACE_XOR, PyNumber_InPlaceXor);
OPCODE_PROFILE(INPLACE_OR, PyNumber_InPlaceOr);
// the normaly have 3 args but we created special versions because last is always None
OPCODE_PROFILE(BINARY_POWER, PyNumber_PowerNone);
OPCODE_PROFILE(INPLACE_POWER, PyNumber_InPlacePowerNone);
OPCODE_PROFILE_LITE(CALL_FUNCTION, call_function_ceval_no_kw);
OPCODE_PROFILE_LITE(CALL_METHOD, call_function_ceval_no_kw);
OPCODE_PROFILE(CALL_FUNCTION_KW, call_function_ceval_kw);
OPCODE_PROFILE(STORE_SUBSCR, PyObject_SetItem);
OPCODE_PROFILE(BINARY_SUBSCR, PyObject_GetItem);
OPCODE_PROFILE(DELETE_SUBSCR, PyObject_DelItem);
OPCODE_STATIC(LOAD_GLOBAL, JIT_HELPER_LOAD_GLOBAL);
if (opcache_available) {
OPCODE_STATIC(LOAD_ATTR, JIT_HELPER_LOAD_ATTR_CACHED);
OPCODE_STATIC(STORE_ATTR, JIT_HELPER_STORE_ATTR_CACHED);
OPCODE_STATIC(LOAD_METHOD, JIT_HELPER_LOAD_METHOD_CACHED);
} else {
OPCODE_STATIC(LOAD_ATTR, JIT_HELPER_LOAD_ATTR);
OPCODE_STATIC(STORE_ATTR, JIT_HELPER_STORE_ATTR);
OPCODE_STATIC(LOAD_METHOD, JIT_HELPER_LOAD_METHOD);
}
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 8
if (opcode == COMPARE_OP) {
#ifndef PYSTON_LITE
if (jit_use_aot) {
switch (oparg) {
case PyCmp_LT: return cmp_outcomePyCmp_LTProfile;
case PyCmp_LE: return cmp_outcomePyCmp_LEProfile;
case PyCmp_EQ: return cmp_outcomePyCmp_EQProfile;
case PyCmp_NE: return cmp_outcomePyCmp_NEProfile;
case PyCmp_GT: return cmp_outcomePyCmp_GTProfile;
case PyCmp_GE: return cmp_outcomePyCmp_GEProfile;
case PyCmp_IN: return cmp_outcomePyCmp_INProfile;
case PyCmp_NOT_IN: return cmp_outcomePyCmp_NOT_INProfile;
}
}
#endif
switch (oparg) {
case PyCmp_LT: return cmp_outcomePyCmp_LT;
case PyCmp_LE: return cmp_outcomePyCmp_LE;
case PyCmp_EQ: return cmp_outcomePyCmp_EQ;
case PyCmp_NE: return cmp_outcomePyCmp_NE;
case PyCmp_GT: return cmp_outcomePyCmp_GT;
case PyCmp_GE: return cmp_outcomePyCmp_GE;
case PyCmp_IN: return cmp_outcomePyCmp_IN;
case PyCmp_NOT_IN: return cmp_outcomePyCmp_NOT_IN;
// we don't create type specific version for those so use non Profile final versions
case PyCmp_BAD: return cmp_outcomePyCmp_BAD;
case PyCmp_EXC_MATCH: return cmp_outcomePyCmp_EXC_MATCH;
case PyCmp_IS:
case PyCmp_IS_NOT:
printf("unreachable: PyCmp_IS and PyCmp_IS_NOT are inlined\n");
abort();
}
}
#endif
#undef OPCODE_STATIC
#undef OPCODE_PROFILE
printf("could not find aot func for opcode: %d oparg: %d\n", opcode, oparg);
abort();
return 0;
}
static const char* get_opcode_name(int opcode) {
#define OPCODE_NAME(op) case op: return #op
switch (opcode) {
OPCODE_NAME(POP_TOP);
OPCODE_NAME(ROT_TWO);
OPCODE_NAME(ROT_THREE);
OPCODE_NAME(DUP_TOP);
OPCODE_NAME(DUP_TOP_TWO);
OPCODE_NAME(NOP);
OPCODE_NAME(UNARY_POSITIVE);
OPCODE_NAME(UNARY_NEGATIVE);
OPCODE_NAME(UNARY_NOT);
OPCODE_NAME(UNARY_INVERT);
OPCODE_NAME(BINARY_MATRIX_MULTIPLY);
OPCODE_NAME(INPLACE_MATRIX_MULTIPLY);
OPCODE_NAME(BINARY_POWER);
OPCODE_NAME(BINARY_MULTIPLY);
OPCODE_NAME(BINARY_MODULO);
OPCODE_NAME(BINARY_ADD);
OPCODE_NAME(BINARY_SUBTRACT);
OPCODE_NAME(BINARY_SUBSCR);
OPCODE_NAME(BINARY_FLOOR_DIVIDE);
OPCODE_NAME(BINARY_TRUE_DIVIDE);
OPCODE_NAME(INPLACE_FLOOR_DIVIDE);
OPCODE_NAME(INPLACE_TRUE_DIVIDE);
OPCODE_NAME(GET_AITER);
OPCODE_NAME(GET_ANEXT);
OPCODE_NAME(BEFORE_ASYNC_WITH);
OPCODE_NAME(INPLACE_ADD);
OPCODE_NAME(INPLACE_SUBTRACT);
OPCODE_NAME(INPLACE_MULTIPLY);
OPCODE_NAME(INPLACE_MODULO);
OPCODE_NAME(STORE_SUBSCR);
OPCODE_NAME(DELETE_SUBSCR);
OPCODE_NAME(BINARY_LSHIFT);
OPCODE_NAME(BINARY_RSHIFT);
OPCODE_NAME(BINARY_AND);
OPCODE_NAME(BINARY_XOR);
OPCODE_NAME(BINARY_OR);
OPCODE_NAME(INPLACE_POWER);
OPCODE_NAME(GET_ITER);
OPCODE_NAME(GET_YIELD_FROM_ITER);
OPCODE_NAME(PRINT_EXPR);
OPCODE_NAME(LOAD_BUILD_CLASS);
OPCODE_NAME(YIELD_FROM);
OPCODE_NAME(GET_AWAITABLE);
OPCODE_NAME(INPLACE_LSHIFT);
OPCODE_NAME(INPLACE_RSHIFT);
OPCODE_NAME(INPLACE_AND);
OPCODE_NAME(INPLACE_XOR);
OPCODE_NAME(INPLACE_OR);
OPCODE_NAME(RETURN_VALUE);
OPCODE_NAME(IMPORT_STAR);
OPCODE_NAME(SETUP_ANNOTATIONS);
OPCODE_NAME(YIELD_VALUE);
OPCODE_NAME(POP_BLOCK);
OPCODE_NAME(POP_EXCEPT);
OPCODE_NAME(STORE_NAME);
OPCODE_NAME(DELETE_NAME);
OPCODE_NAME(UNPACK_SEQUENCE);
OPCODE_NAME(FOR_ITER);
OPCODE_NAME(UNPACK_EX);
OPCODE_NAME(STORE_ATTR);
OPCODE_NAME(DELETE_ATTR);
OPCODE_NAME(STORE_GLOBAL);
OPCODE_NAME(DELETE_GLOBAL);
OPCODE_NAME(LOAD_CONST);
OPCODE_NAME(LOAD_NAME);
OPCODE_NAME(BUILD_TUPLE);
OPCODE_NAME(BUILD_LIST);
OPCODE_NAME(BUILD_SET);
OPCODE_NAME(BUILD_MAP);
OPCODE_NAME(LOAD_ATTR);
OPCODE_NAME(COMPARE_OP);
OPCODE_NAME(IMPORT_NAME);
OPCODE_NAME(IMPORT_FROM);
OPCODE_NAME(JUMP_FORWARD);
OPCODE_NAME(JUMP_IF_FALSE_OR_POP);
OPCODE_NAME(JUMP_IF_TRUE_OR_POP);
OPCODE_NAME(JUMP_ABSOLUTE);
OPCODE_NAME(POP_JUMP_IF_FALSE);
OPCODE_NAME(POP_JUMP_IF_TRUE);
OPCODE_NAME(LOAD_GLOBAL);
OPCODE_NAME(SETUP_FINALLY);
OPCODE_NAME(LOAD_FAST);
OPCODE_NAME(STORE_FAST);
OPCODE_NAME(DELETE_FAST);
OPCODE_NAME(RAISE_VARARGS);
OPCODE_NAME(CALL_FUNCTION);
OPCODE_NAME(MAKE_FUNCTION);
OPCODE_NAME(BUILD_SLICE);
OPCODE_NAME(LOAD_CLOSURE);
OPCODE_NAME(LOAD_DEREF);
OPCODE_NAME(STORE_DEREF);
OPCODE_NAME(DELETE_DEREF);
OPCODE_NAME(CALL_FUNCTION_KW);
OPCODE_NAME(CALL_FUNCTION_EX);
OPCODE_NAME(SETUP_WITH);
OPCODE_NAME(EXTENDED_ARG);
OPCODE_NAME(LIST_APPEND);
OPCODE_NAME(SET_ADD);
OPCODE_NAME(MAP_ADD);
OPCODE_NAME(LOAD_CLASSDEREF);
OPCODE_NAME(SETUP_ASYNC_WITH);
OPCODE_NAME(FORMAT_VALUE);
OPCODE_NAME(BUILD_CONST_KEY_MAP);
OPCODE_NAME(BUILD_STRING);
OPCODE_NAME(LOAD_METHOD);
OPCODE_NAME(CALL_METHOD);
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 7
OPCODE_NAME(CONTINUE_LOOP);
OPCODE_NAME(BREAK_LOOP);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8
OPCODE_NAME(BEGIN_FINALLY);
OPCODE_NAME(CALL_FINALLY);
OPCODE_NAME(POP_FINALLY);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8
OPCODE_NAME(ROT_FOUR);
OPCODE_NAME(END_ASYNC_FOR);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 8
OPCODE_NAME(WITH_CLEANUP_START);
OPCODE_NAME(WITH_CLEANUP_FINISH);
OPCODE_NAME(END_FINALLY);
OPCODE_NAME(BUILD_LIST_UNPACK);
OPCODE_NAME(BUILD_MAP_UNPACK);
OPCODE_NAME(BUILD_MAP_UNPACK_WITH_CALL);
OPCODE_NAME(BUILD_TUPLE_UNPACK);
OPCODE_NAME(BUILD_TUPLE_UNPACK_WITH_CALL);
OPCODE_NAME(BUILD_SET_UNPACK);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9
OPCODE_NAME(CONTAINS_OP);
OPCODE_NAME(DICT_MERGE);
OPCODE_NAME(DICT_UPDATE);
OPCODE_NAME(IS_OP);
OPCODE_NAME(JUMP_IF_NOT_EXC_MATCH);
OPCODE_NAME(LIST_EXTEND);
OPCODE_NAME(LIST_TO_TUPLE);
OPCODE_NAME(LOAD_ASSERTION_ERROR);
OPCODE_NAME(RERAISE);
OPCODE_NAME(SET_UPDATE);
OPCODE_NAME(WITH_EXCEPT_START);
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 10
OPCODE_NAME(GEN_START);
OPCODE_NAME(GET_LEN);
OPCODE_NAME(MATCH_CLASS);
OPCODE_NAME(MATCH_MAPPING);
OPCODE_NAME(MATCH_SEQUENCE);
OPCODE_NAME(MATCH_KEYS);
OPCODE_NAME(COPY_DICT_WITHOUT_KEYS);
OPCODE_NAME(ROT_N);
#endif
};
#undef OPCODE_NAME
return "UNKNOWN";
}
#define IS_16BIT_VAL(x) ((unsigned long)(x) <= UINT16_MAX)
#define IS_32BIT_VAL(x) ((unsigned long)(x) <= UINT32_MAX)
#define IS_32BIT_SIGNED_VAL(x) ((int32_t)(x) == (int64_t)(x))
// looks which instruction can be reached by jumps
// this is important for the deferred stack operations because
// if a instruction can be reached by a jump we can't use this optimization.
// which means we have make sure to call deferred_vs_apply.
//
// result must be freed()
static char* calculate_jmp_targets(Jit* Dst) {
// TODO: could be a bit vector
char* is_jmp_target = malloc(Dst->num_opcodes);
memset(is_jmp_target, 0, Dst->num_opcodes);
// first instruction is always a jump target because entry can reach it
if (Dst->num_opcodes > 0)
is_jmp_target[0] = 1;
int oldoparg = 0;
for (int inst_idx = 0; inst_idx < Dst->num_opcodes; ++inst_idx) {
_Py_CODEUNIT word = Dst->first_instr[inst_idx];
int opcode = _Py_OPCODE(word);
int oparg = _Py_OPARG(word);
// this is used for the special EXTENDED_ARG opcode
oparg |= oldoparg;
oldoparg = 0;
switch (opcode) {
case JUMP_ABSOLUTE:
case POP_JUMP_IF_FALSE:
case POP_JUMP_IF_TRUE:
case JUMP_IF_FALSE_OR_POP:
case JUMP_IF_TRUE_OR_POP:
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9
case JUMP_IF_NOT_EXC_MATCH:
#endif
is_jmp_target[oparg/INST_IDX_TO_LASTI_FACTOR] = 1;
break;
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 7
case BREAK_LOOP:
case CONTINUE_LOOP:
is_jmp_target[inst_idx + 1] = 1;
is_jmp_target[oparg/INST_IDX_TO_LASTI_FACTOR] = 1;
break;
#endif
case JUMP_FORWARD:
case FOR_ITER:
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8
case END_ASYNC_FOR:
#endif
is_jmp_target[oparg/INST_IDX_TO_LASTI_FACTOR + inst_idx + 1] = 1;
break;
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8
case CALL_FINALLY:
is_jmp_target[inst_idx + 1] = 1;
is_jmp_target[oparg/INST_IDX_TO_LASTI_FACTOR + inst_idx + 1] = 1;
break;
#endif
// this opcodes use PyFrame_BlockSetup which is similar to a jump in case of exception
case SETUP_ASYNC_WITH:
case SETUP_FINALLY:
case SETUP_WITH:
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 7
case SETUP_LOOP:
case SETUP_EXCEPT:
#endif
is_jmp_target[inst_idx + 1] = 1;
is_jmp_target[oparg/INST_IDX_TO_LASTI_FACTOR + inst_idx + 1] = 1;
break;
case YIELD_FROM:
is_jmp_target[inst_idx + 0] = 1;
is_jmp_target[inst_idx + 1] = 1;
break;
case YIELD_VALUE:
is_jmp_target[inst_idx + 1] = 1;
break;
case EXTENDED_ARG:
oldoparg = oparg << 8;
break;
}
}
return is_jmp_target;
}
#if ENABLE_DEFINED_TRACKING
// returns if any of the functions arguments get deleted (checks for DELETE_FAST)
static int check_func_args_never_deleted(Jit* Dst) {
const int num_args = Dst->co->co_argcount;
int oldoparg = 0;
for (int inst_idx = 0; inst_idx < Dst->num_opcodes; ++inst_idx) {
_Py_CODEUNIT word = Dst->first_instr[inst_idx];
int opcode = _Py_OPCODE(word);
int oparg = _Py_OPARG(word);
// this is used for the special EXTENDED_ARG opcode
oparg |= oldoparg;
oldoparg = 0;
switch (opcode) {
case DELETE_FAST:
if (oparg < num_args)
return 0; // this is deleting a function arg!
break;
case EXTENDED_ARG:
oldoparg = oparg << 8;
break;
}
}
return 1;
}
#endif
static int8_t* mem_chunk = NULL;
static size_t mem_chunk_bytes_remaining = 0;
static long mem_bytes_allocated = 0, mem_bytes_used = 0;
static long mem_bytes_used_max = 100*1000*1000; // will stop emitting code after that many bytes
static int jit_num_funcs = 0, jit_num_failed = 0;
static long total_compilation_time_in_us = 0;
static int jit_stats_enabled = 0;
static unsigned long jit_stat_load_attr_hit, jit_stat_load_attr_miss, jit_stat_load_attr_inline, jit_stat_load_attr_total;
static unsigned long jit_stat_store_attr_hit, jit_stat_store_attr_miss, jit_stat_store_attr_inline, jit_stat_store_attr_total;
static unsigned long jit_stat_load_method_hit, jit_stat_load_method_miss, jit_stat_load_method_inline, jit_stat_load_method_total;
static unsigned long jit_stat_load_global_hit, jit_stat_load_global_miss, jit_stat_load_global_inline, jit_stat_load_global_total;
static unsigned long jit_stat_call_method_hit, jit_stat_call_method_miss, jit_stat_call_method_inline, jit_stat_call_method_total;
static unsigned long jit_stat_getitemlong, jit_stat_getitemlong_inlined, jit_stat_setitemlong_inlined;
static unsigned long jit_stat_load_attr_poly, jit_stat_load_attr_poly_entries;
static unsigned long jit_stat_load_method_poly, jit_stat_load_method_poly_entries;
static unsigned long jit_stat_binary_op_inplace, jit_stat_binary_op_inplace_miss, jit_stat_binary_op_inplace_hit;
static unsigned long jit_stat_concat_inplace, jit_stat_concat_inplace_miss, jit_stat_concat_inplace_hit;
#define ENABLE_DEFERRED_RES_PUSH 1
#define ENABLE_AVOID_SIG_TRACE_CHECK 1
@ARM|.arch arm64
@X86|.arch x64
// section layout is same as specified here from left to right
|.section entry, code, cold, deopt, opcode_addr
////////////////////////////////
// REGISTER DEFINITIONS
|.macro define_reg, name, name_idx, reg_amd64, reg_amd64_idx, reg_arm64, reg_arm64_idx
@ARM| .define name, reg_arm64
@ARM|| #define name_idx reg_arm64_idx
@X86| .define name, reg_amd64
@X86|| #define name_idx reg_amd64_idx
|.endmacro
// all this values are in callee saved registers
// NOTE: r13 and rbp need 1 byte more to encode a direct memory access without offset
// e.g. mov rax, [rbp] is encoded as mov rax, [rbp + 0]
| define_reg f, f_idx, r13, 13, x19, 19 // PyFrameObject*
// this register gets used when we have to make a call but preserve a value across it.
// It can never get used in the deferred_vs / will never get used across bytecode instructions
// One has to manually check the surrounding code if it's safe to use this register.
// This register will not automatically get xdecrefed on error / return
// so no need to clear it after use.
| define_reg tmp_preserved_reg, tmp_preserved_reg_idx, rbp, 5, x20, 20 // PyFrameObject*
// this register gets mainly used by deferred_vs when we have to make a call
// but preserve a value which is inside the 'res' register (same as stack slot entry but faster).
// Code needs to always check Dst->deferred_vs_preserved_reg_used to see if it's available.
// On error or return we will always xdecref this register which means that
// code must manually clear the register if it does not want the decref.
| define_reg vs_preserved_reg, vs_preserved_reg_idx, r14, 14, x21, 21 // PyFrameObject*
| define_reg tstate, tstate_idx, r15, 15, x22, 22 // PyThreadState*
| define_reg vsp, vsp_idx, r12, 12, x23, 23 // PyObject** - python value stack pointer
// Python <= 3.9
// pointer to ceval->tracing_possible
| define_reg interrupt, interrupt_idx, rbx, 3, x24, 24 // if you change this you may have to adjust jmp_to_inst_idx
// Pyton >= 3.10
| define_reg trace_info, trace_info_idx, rbx, 3, x24, 24 // if you change this you may have to adjust jmp_to_inst_idx
// follow AMD64 calling convention
// instruction indices can be found here: https://corsix.github.io/dynasm-doc/instructions.html
// function arguments
| define_reg arg1, arg1_idx, rdi, 7, x0, 0
| define_reg arg2, arg2_idx, rsi, 6, x1, 1
| define_reg arg3, arg3_idx, rdx, 2, x2, 2
| define_reg arg4, arg4_idx, rcx, 1, x3, 3
| define_reg arg5, arg5_idx, r8, 8, x4, 4
| define_reg arg6, arg6_idx, r9, 9, x5, 5 // careful same as register 'tmp'
// return values
| define_reg res, res_idx, rax, 0, x7, 7 // on arm this is a dummy reg
| define_reg res2, res2_idx, rdx, 2, x1, 1 // second return value
// Our JIT code assumes that 'arg1' and 'res' are not the same but on ARM64 they are.
// We can work around this by using a temporary register for 'res' and copying
// the real return value of a call to it (and the value we like to return from compiled code).
// This has the cost of a few unnecessary 'mov reg, regs' but they should be super cheap.
// On x86 this is not needed and res and real_res will be the same.
| define_reg real_res, real_res_idx, res, res_idx, x0, 0
// will be used by macros
|.define tmp, arg6
#define tmp_idx arg6_idx
// cpu stack pointer
| define_reg sp_reg, sp_reg_idx, rsp, 4, sp, 31
@ARM_START
// ARM64 requires one more temporary reg because it needs an additional temporary for many operations
// e.g. when comparing 64bit immediate with a memory location we need to load the imm into a reg and the
// memory value in a different one and then compare it.
|.define tmp2, x6
#define tmp2_idx 6
// this is currently only used in deferred_vs_emit() which requires a temporary reg which is different from the two other we already have
|.define tmp_pair, x8
#define tmp_pair_idx 8
|.define zero_reg, xzr // this register is always 0 - nice for clearing memory
#define zero_reg_idx 31
@ARM_END
// GET_DEFERRED[-1] == top deferred stack entry
// GET_DEFERRED[-2] == second deferred stack entry..
#define GET_DEFERRED (&Dst->deferred_vs[Dst->deferred_vs_next])
static void deferred_vs_apply(Jit* Dst);
static void switch_section(Jit* Dst, Section new_section) {
JIT_ASSERT(Dst->current_section != new_section, "safe todo but may be sign of a bug");
Dst->current_section = new_section;
if (new_section == SECTION_CODE) {
|.code
} else if (new_section == SECTION_COLD) {
|.cold
} else if (new_section == SECTION_DEOPT) {
|.deopt
} else if (new_section == SECTION_ENTRY) {
|.entry
} else if (new_section == SECTION_OPCODE_ADDR) {
|.opcode_addr
} else {
JIT_ASSERT(0, "unknwon section");
}
}
|.macro branch, dst
@ARM| b dst
@X86| jmp dst
|.endmacro
|.macro branch_reg, dst
@ARM| br Rx(dst)
@X86| jmp Rq(dst)
|.endmacro
|.macro branch_eq, dst
@ARM| beq dst
@X86| je dst
|.endmacro
|.macro branch_z, dst
| branch_eq dst
|.endmacro
|.macro branch_ne, dst
@ARM| bne dst
@X86| jne dst
|.endmacro
|.macro branch_nz, dst
| branch_ne dst
|.endmacro
|.macro branch_lt, dst
@ARM| blt dst
@X86| jl dst
|.endmacro
|.macro branch_gt, dst
@ARM| bgt dst
@X86| jg dst
|.endmacro
|.macro branch_ge, dst
@ARM| bge dst
@X86| jge dst
|.endmacro
|.macro branch_le, dst
@ARM| ble dst