Skip to content

Commit e67ed5d

Browse files
committed
Improve configurability for native x64/thumb emitter.
With MICROPY_EMIT_X64 and MICROPY_EMIT_THUMB disabled, the respective emitters and assemblers will not be included in the code. This can significantly reduce binary size for unix version.
1 parent 32f8841 commit e67ed5d

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

py/asmthumb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "mpconfig.h"
88
#include "asmthumb.h"
99

10+
// wrapper around everything in this file
11+
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
12+
1013
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)
1114
#define UNSIGNED_FIT16(x) (((x) & 0xffff0000) == 0)
1215
#define SIGNED_FIT8(x) (((x) & 0xffffff80) == 0) || (((x) & 0xffffff80) == 0xffffff80)
@@ -447,3 +450,5 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp
447450
asm_thumb_write_op16(as, OP_SVC(fun_id));
448451
}
449452
}
453+
454+
#endif // MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB

py/asmx64.c

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

77
#include "misc.h"
88
#include "asmx64.h"
9+
#include "mpconfig.h"
10+
11+
// wrapper around everything in this file
12+
#if MICROPY_EMIT_X64
913

1014
#if defined(__OpenBSD__) || defined(__MACH__)
1115
#define MAP_ANONYMOUS MAP_ANON
@@ -620,3 +624,5 @@ void asm_x64_call_ind(asm_x64_t* as, void *ptr, int temp_r64) {
620624
asm_x64_write_word32(as, ptr - (void*)(as->code_base + as->code_offset + 4));
621625
*/
622626
}
627+
628+
#endif // MICROPY_EMIT_X64

py/compile.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3083,11 +3083,13 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
30833083
// compile pass 2 and 3
30843084
#if !MICROPY_EMIT_CPYTHON
30853085
emit_t *emit_bc = NULL;
3086+
#if MICROPY_EMIT_NATIVE
30863087
emit_t *emit_native = NULL;
30873088
#endif
30883089
#if MICROPY_EMIT_INLINE_THUMB
30893090
emit_inline_asm_t *emit_inline_thumb = NULL;
30903091
#endif
3092+
#endif // !MICROPY_EMIT_CPYTHON
30913093
for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) {
30923094
if (false) {
30933095
// dummy
@@ -3115,6 +3117,8 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
31153117
comp->emit_method_table = &emit_cpython_method_table;
31163118
#else
31173119
switch (s->emit_options) {
3120+
3121+
#if MICROPY_EMIT_NATIVE
31183122
case EMIT_OPT_NATIVE_PYTHON:
31193123
case EMIT_OPT_VIPER:
31203124
#if MICROPY_EMIT_X64
@@ -3131,6 +3135,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
31313135
comp->emit = emit_native;
31323136
comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER);
31333137
break;
3138+
#endif // MICROPY_EMIT_NATIVE
31343139

31353140
default:
31363141
if (emit_bc == NULL) {
@@ -3140,7 +3145,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
31403145
comp->emit_method_table = &emit_bc_method_table;
31413146
break;
31423147
}
3143-
#endif
3148+
#endif // !MICROPY_EMIT_CPYTHON
31443149

31453150
// compile pass 2 and pass 3
31463151
compile_scope(comp, s, PASS_2);

py/emitcpy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "runtime0.h"
1414
#include "emit.h"
1515

16+
// wrapper around everything in this file
1617
#if MICROPY_EMIT_CPYTHON
1718

1819
struct _emit_t {

py/emitnative.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "runtime.h"
3535

3636
// wrapper around everything in this file
37-
#if N_X64 || N_THUMB
37+
#if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)
3838

3939
#if N_X64
4040

@@ -1319,4 +1319,4 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
13191319
emit_native_yield_from,
13201320
};
13211321

1322-
#endif // N_X64 || N_THUMB
1322+
#endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)

unix/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ $(BUILD)/%.o: $(PYSRC)/%.S
8383
$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h
8484
$(CC) $(CFLAGS) -c -o $@ $<
8585

86-
$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h
86+
$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h
8787
$(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
8888

89-
$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h
89+
$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h
9090
$(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
9191

9292
# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)

0 commit comments

Comments
 (0)