Commit e67ed5d2 authored by Damien George's avatar Damien George
Browse files

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.
parent 32f88410
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "mpconfig.h" #include "mpconfig.h"
#include "asmthumb.h" #include "asmthumb.h"
// wrapper around everything in this file
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0) #define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)
#define UNSIGNED_FIT16(x) (((x) & 0xffff0000) == 0) #define UNSIGNED_FIT16(x) (((x) & 0xffff0000) == 0)
#define SIGNED_FIT8(x) (((x) & 0xffffff80) == 0) || (((x) & 0xffffff80) == 0xffffff80) #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 ...@@ -447,3 +450,5 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp
asm_thumb_write_op16(as, OP_SVC(fun_id)); asm_thumb_write_op16(as, OP_SVC(fun_id));
} }
} }
#endif // MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "misc.h" #include "misc.h"
#include "asmx64.h" #include "asmx64.h"
#include "mpconfig.h"
// wrapper around everything in this file
#if MICROPY_EMIT_X64
#if defined(__OpenBSD__) || defined(__MACH__) #if defined(__OpenBSD__) || defined(__MACH__)
#define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
...@@ -620,3 +624,5 @@ void asm_x64_call_ind(asm_x64_t* as, void *ptr, int temp_r64) { ...@@ -620,3 +624,5 @@ void asm_x64_call_ind(asm_x64_t* as, void *ptr, int temp_r64) {
asm_x64_write_word32(as, ptr - (void*)(as->code_base + as->code_offset + 4)); asm_x64_write_word32(as, ptr - (void*)(as->code_base + as->code_offset + 4));
*/ */
} }
#endif // MICROPY_EMIT_X64
...@@ -3083,11 +3083,13 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { ...@@ -3083,11 +3083,13 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
// compile pass 2 and 3 // compile pass 2 and 3
#if !MICROPY_EMIT_CPYTHON #if !MICROPY_EMIT_CPYTHON
emit_t *emit_bc = NULL; emit_t *emit_bc = NULL;
#if MICROPY_EMIT_NATIVE
emit_t *emit_native = NULL; emit_t *emit_native = NULL;
#endif #endif
#if MICROPY_EMIT_INLINE_THUMB #if MICROPY_EMIT_INLINE_THUMB
emit_inline_asm_t *emit_inline_thumb = NULL; emit_inline_asm_t *emit_inline_thumb = NULL;
#endif #endif
#endif // !MICROPY_EMIT_CPYTHON
for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) { for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) {
if (false) { if (false) {
// dummy // dummy
...@@ -3115,6 +3117,8 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { ...@@ -3115,6 +3117,8 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
comp->emit_method_table = &emit_cpython_method_table; comp->emit_method_table = &emit_cpython_method_table;
#else #else
switch (s->emit_options) { switch (s->emit_options) {
#if MICROPY_EMIT_NATIVE
case EMIT_OPT_NATIVE_PYTHON: case EMIT_OPT_NATIVE_PYTHON:
case EMIT_OPT_VIPER: case EMIT_OPT_VIPER:
#if MICROPY_EMIT_X64 #if MICROPY_EMIT_X64
...@@ -3131,6 +3135,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { ...@@ -3131,6 +3135,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
comp->emit = emit_native; comp->emit = emit_native;
comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER); comp->emit_method_table->set_native_types(comp->emit, s->emit_options == EMIT_OPT_VIPER);
break; break;
#endif // MICROPY_EMIT_NATIVE
default: default:
if (emit_bc == NULL) { if (emit_bc == NULL) {
...@@ -3140,7 +3145,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { ...@@ -3140,7 +3145,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
comp->emit_method_table = &emit_bc_method_table; comp->emit_method_table = &emit_bc_method_table;
break; break;
} }
#endif #endif // !MICROPY_EMIT_CPYTHON
// compile pass 2 and pass 3 // compile pass 2 and pass 3
compile_scope(comp, s, PASS_2); compile_scope(comp, s, PASS_2);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "runtime0.h" #include "runtime0.h"
#include "emit.h" #include "emit.h"
// wrapper around everything in this file
#if MICROPY_EMIT_CPYTHON #if MICROPY_EMIT_CPYTHON
struct _emit_t { struct _emit_t {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "runtime.h" #include "runtime.h"
// wrapper around everything in this file // wrapper around everything in this file
#if N_X64 || N_THUMB #if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)
#if N_X64 #if N_X64
...@@ -1319,4 +1319,4 @@ const emit_method_table_t EXPORT_FUN(method_table) = { ...@@ -1319,4 +1319,4 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_yield_from, emit_native_yield_from,
}; };
#endif // N_X64 || N_THUMB #endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)
...@@ -83,10 +83,10 @@ $(BUILD)/%.o: $(PYSRC)/%.S ...@@ -83,10 +83,10 @@ $(BUILD)/%.o: $(PYSRC)/%.S
$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h $(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h $(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h
$(CC) $(CFLAGS) -DN_X64 -c -o $@ $< $(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h $(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h
$(CC) $(CFLAGS) -DN_THUMB -c -o $@ $< $(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster) # optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment