Skip to content

Commit d4d53e9

Browse files
committed
py/emitnative: Access qstr values using indirection table qstr_table.
This changes the native emitter to access qstr values using the qstr indirection table qstr_table, but only when generating native code that will be saved to a .mpy file. This makes the resulting native code fully static, ie it does not require any fix-ups or rewriting when it is imported. The performance of native code is more or less unchanged. Benchmark results on PYBv1.0 (using --via-mpy and --emit native) are: N=100 M=100 baseline -> this-commit diff diff% (error%) bm_chaos.py 407.16 -> 411.85 : +4.69 = +1.152% (+/-0.01%) bm_fannkuch.py 100.89 -> 101.20 : +0.31 = +0.307% (+/-0.01%) bm_fft.py 3521.17 -> 3441.72 : -79.45 = -2.256% (+/-0.00%) bm_float.py 6707.29 -> 6644.83 : -62.46 = -0.931% (+/-0.00%) bm_hexiom.py 55.91 -> 55.41 : -0.50 = -0.894% (+/-0.00%) bm_nqueens.py 5343.54 -> 5326.17 : -17.37 = -0.325% (+/-0.00%) bm_pidigits.py 603.89 -> 632.79 : +28.90 = +4.786% (+/-0.33%) core_qstr.py 64.18 -> 64.09 : -0.09 = -0.140% (+/-0.01%) core_yield_from.py 313.61 -> 311.11 : -2.50 = -0.797% (+/-0.03%) misc_aes.py 654.29 -> 659.75 : +5.46 = +0.834% (+/-0.02%) misc_mandel.py 4205.10 -> 4272.08 : +66.98 = +1.593% (+/-0.01%) misc_pystone.py 3077.79 -> 3128.39 : +50.60 = +1.644% (+/-0.01%) misc_raytrace.py 388.45 -> 393.71 : +5.26 = +1.354% (+/-0.01%) viper_call0.py 576.83 -> 566.76 : -10.07 = -1.746% (+/-0.05%) viper_call1a.py 550.39 -> 540.12 : -10.27 = -1.866% (+/-0.11%) viper_call1b.py 438.32 -> 432.09 : -6.23 = -1.421% (+/-0.11%) viper_call1c.py 442.96 -> 436.11 : -6.85 = -1.546% (+/-0.08%) viper_call2a.py 536.31 -> 527.37 : -8.94 = -1.667% (+/-0.04%) viper_call2b.py 378.99 -> 377.50 : -1.49 = -0.393% (+/-0.08%) Signed-off-by: Damien George <damien@micropython.org>
1 parent 94955e8 commit d4d53e9

12 files changed

Lines changed: 75 additions & 186 deletions

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3323,7 +3323,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
33233323
NULL,
33243324
#if MICROPY_PERSISTENT_CODE_SAVE
33253325
0,
3326-
0, 0, NULL,
3326+
0,
33273327
#endif
33283328
0, comp->scope_cur->num_pos_args, type_sig);
33293329
}

py/emitglue.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
101101
#if MICROPY_PERSISTENT_CODE_SAVE
102102
size_t n_children,
103103
uint16_t prelude_offset,
104-
uint16_t n_qstr, mp_qstr_link_entry_t *qstr_link,
105104
#endif
106105
mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig) {
107106

@@ -144,8 +143,6 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
144143
#if MICROPY_PERSISTENT_CODE_SAVE
145144
rc->n_children = n_children;
146145
rc->prelude_offset = prelude_offset;
147-
rc->n_qstr = n_qstr;
148-
rc->qstr_link = qstr_link;
149146
#endif
150147

151148
// These two entries are only needed for MP_CODE_NATIVE_ASM.

py/emitglue.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ typedef enum {
4949
MP_CODE_NATIVE_ASM,
5050
} mp_raw_code_kind_t;
5151

52-
typedef struct _mp_qstr_link_entry_t {
53-
uint16_t off;
54-
uint16_t qst;
55-
} mp_qstr_link_entry_t;
56-
5752
// compiled bytecode: instance in RAM, referenced by outer scope, usually freed after first (and only) use
5853
// mpy file: instance in RAM, created when .mpy file is loaded (same comments as above)
5954
// frozen: instance in ROM
@@ -78,8 +73,6 @@ typedef struct _mp_raw_code_t {
7873
#endif
7974
#if MICROPY_EMIT_MACHINE_CODE
8075
uint16_t prelude_offset;
81-
uint16_t n_qstr;
82-
mp_qstr_link_entry_t *qstr_link;
8376
#endif
8477
#endif
8578
#if MICROPY_EMIT_MACHINE_CODE
@@ -104,7 +97,6 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
10497
#if MICROPY_PERSISTENT_CODE_SAVE
10598
size_t n_children,
10699
uint16_t prelude_offset,
107-
uint16_t n_qstr, mp_qstr_link_entry_t *qstr_link,
108100
#endif
109101
mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig);
110102

py/emitnarm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Word indices of REG_LOCAL_x in nlr_buf_t
1212
#define NLR_BUF_IDX_LOCAL_1 (3) // r4
13-
#define NLR_BUF_IDX_LOCAL_2 (4) // r5
14-
#define NLR_BUF_IDX_LOCAL_3 (5) // r6
1513

1614
#define N_ARM (1)
1715
#define EXPORT_FUN(name) emit_native_arm_##name

py/emitnative.c

Lines changed: 64 additions & 61 deletions
Large diffs are not rendered by default.

py/emitnthumb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Word indices of REG_LOCAL_x in nlr_buf_t
1212
#define NLR_BUF_IDX_LOCAL_1 (3) // r4
13-
#define NLR_BUF_IDX_LOCAL_2 (4) // r5
14-
#define NLR_BUF_IDX_LOCAL_3 (5) // r6
1513

1614
#define N_THUMB (1)
1715
#define EXPORT_FUN(name) emit_native_thumb_##name

py/emitnx64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Word indices of REG_LOCAL_x in nlr_buf_t
1212
#define NLR_BUF_IDX_LOCAL_1 (5) // rbx
13-
#define NLR_BUF_IDX_LOCAL_2 (6) // r12
14-
#define NLR_BUF_IDX_LOCAL_3 (7) // r13
1513

1614
#define N_X64 (1)
1715
#define EXPORT_FUN(name) emit_native_x64_##name

py/emitnx86.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
// Word indices of REG_LOCAL_x in nlr_buf_t
1313
#define NLR_BUF_IDX_LOCAL_1 (5) // ebx
14-
#define NLR_BUF_IDX_LOCAL_2 (7) // esi
15-
#define NLR_BUF_IDX_LOCAL_3 (6) // edi
1614

1715
// x86 needs a table to know how many args a given function has
1816
STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {

py/emitnxtensa.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Word indices of REG_LOCAL_x in nlr_buf_t
1212
#define NLR_BUF_IDX_LOCAL_1 (8) // a12
13-
#define NLR_BUF_IDX_LOCAL_2 (9) // a13
14-
#define NLR_BUF_IDX_LOCAL_3 (10) // a14
1513

1614
#define N_XTENSA (1)
1715
#define EXPORT_FUN(name) emit_native_xtensa_##name

py/emitnxtensawin.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
// Word indices of REG_LOCAL_x in nlr_buf_t
1313
#define NLR_BUF_IDX_LOCAL_1 (2 + 4) // a4
14-
#define NLR_BUF_IDX_LOCAL_2 (2 + 5) // a5
15-
#define NLR_BUF_IDX_LOCAL_3 (2 + 6) // a6
1614

1715
#define N_NLR_SETJMP (1)
1816
#define N_XTENSAWIN (1)

0 commit comments

Comments
 (0)