summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorJeff Epler <jepler@unpythonic.net>2021-03-05 18:29:27 -0600
committerJeff Epler <jepler@unpythonic.net>2021-03-05 18:29:27 -0600
commit4f040af481248ff8161a1be955d22244219411f5 (patch)
tree2c9e23c51ed394cb162bc491ae35e2861351ffb3 /py
parent7b359d7a8add59ebd8e12ec460c8721b783e1ace (diff)
vm: Make the speed-size trade-off compile time settable
.. and enable for all samd21 boards
Diffstat (limited to 'py')
-rw-r--r--py/circuitpy_mpconfig.h1
-rw-r--r--py/circuitpy_mpconfig.mk3
-rwxr-xr-xpy/mpconfig.h8
-rw-r--r--py/vm.c9
-rw-r--r--py/vmentrytable.h8
5 files changed, 28 insertions, 1 deletions
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index 3eda3b004..f61c3959f 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -75,6 +75,7 @@
#define MICROPY_MODULE_BUILTIN_INIT (1)
#define MICROPY_NONSTANDARD_TYPECODES (0)
#define MICROPY_OPT_COMPUTED_GOTO (1)
+#define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
#define MICROPY_PY_ARRAY (1)
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index a5b0ed8a4..496ce918b 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -130,6 +130,9 @@ CFLAGS += -DCIRCUITPY_CANIO=$(CIRCUITPY_CANIO)
CIRCUITPY_DIGITALIO ?= 1
CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO)
+CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 0
+CFLAGS += -DCIRCUITPY_COMPUTED_GOTO_SAVE_SPACE=$(CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE)
+
CIRCUITPY_COUNTIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 034d39d40..1f6f96bd1 100755
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -413,6 +413,14 @@
#define MICROPY_OPT_COMPUTED_GOTO (0)
#endif
+// Whether to save trade flash space for speed in MICROPY_OPT_COMPUTED_GOTO.
+// Costs about 3% speed, saves about 1500 bytes space. In addition to the assumptions
+// of MICROPY_OPT_COMPUTED_GOTO, also assumes that mp_execute_bytecode is less than
+// 32kB in size.
+#ifndef MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
+#define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (0)
+#endif
+
// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
// uses a bit of extra code ROM, but greatly improves lookup speed.
diff --git a/py/vm.c b/py/vm.c
index 283d8e198..890b5f26f 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -129,12 +129,21 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t *code_sta
#endif
#if MICROPY_OPT_COMPUTED_GOTO
#include "py/vmentrytable.h"
+#if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
#define ONE_TRUE_DISPATCH() one_true_dispatch: do { \
TRACE(ip); \
MARK_EXC_IP_GLOBAL(); \
goto *(void*)((char*)&&entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \
} while (0)
#define DISPATCH() do { goto one_true_dispatch; } while(0)
+#else
+ #define DISPATCH() do { \
+ TRACE(ip); \
+ MARK_EXC_IP_GLOBAL(); \
+ goto *entry_table[*ip++]; \
+ } while (0)
+ #define ONE_TRUE_DISPATCH() DISPATCH()
+#endif
#define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check
#define ENTRY(op) entry_##op
#define ENTRY_DEFAULT entry_default
diff --git a/py/vmentrytable.h b/py/vmentrytable.h
index 8d9f00ad8..31832bb58 100644
--- a/py/vmentrytable.h
+++ b/py/vmentrytable.h
@@ -31,9 +31,15 @@
#include "supervisor/linker.h"
+#if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
#define COMPUTE_ENTRY(x) ((char*)(x) - (char*)&&entry_MP_BC_LOAD_CONST_FALSE)
+typedef int16_t entry_table_type;
+#else
+#define COMPUTE_ENTRY(x) (x)
+typedef void *entry_table_type;
+#endif
-static int16_t const PLACE_IN_DTCM_DATA(entry_table[256]) = {
+static entry_table_type const PLACE_IN_DTCM_DATA(entry_table[256]) = {
[0 ... 255] = COMPUTE_ENTRY(&&entry_default),
[MP_BC_LOAD_CONST_FALSE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_FALSE),
[MP_BC_LOAD_CONST_NONE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_NONE),