Skip to content

Commit 4f040af

Browse files
committed
vm: Make the speed-size trade-off compile time settable
.. and enable for all samd21 boards
1 parent 7b359d7 commit 4f040af

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CIRCUITPY_AUDIOMIXER ?= 0
3636
CIRCUITPY_BINASCII ?= 0
3737
CIRCUITPY_AUDIOMP3 ?= 0
3838
CIRCUITPY_BUILTINS_POW3 ?= 0
39+
CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 1
3940
CIRCUITPY_FREQUENCYIO ?= 0
4041
CIRCUITPY_JSON ?= 0
4142
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#define MICROPY_MODULE_BUILTIN_INIT (1)
7676
#define MICROPY_NONSTANDARD_TYPECODES (0)
7777
#define MICROPY_OPT_COMPUTED_GOTO (1)
78+
#define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE)
7879
#define MICROPY_PERSISTENT_CODE_LOAD (1)
7980

8081
#define MICROPY_PY_ARRAY (1)

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ CFLAGS += -DCIRCUITPY_CANIO=$(CIRCUITPY_CANIO)
130130
CIRCUITPY_DIGITALIO ?= 1
131131
CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO)
132132

133+
CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 0
134+
CFLAGS += -DCIRCUITPY_COMPUTED_GOTO_SAVE_SPACE=$(CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE)
135+
133136
CIRCUITPY_COUNTIO ?= $(CIRCUITPY_FULL_BUILD)
134137
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
135138

py/mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@
413413
#define MICROPY_OPT_COMPUTED_GOTO (0)
414414
#endif
415415

416+
// Whether to save trade flash space for speed in MICROPY_OPT_COMPUTED_GOTO.
417+
// Costs about 3% speed, saves about 1500 bytes space. In addition to the assumptions
418+
// of MICROPY_OPT_COMPUTED_GOTO, also assumes that mp_execute_bytecode is less than
419+
// 32kB in size.
420+
#ifndef MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
421+
#define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (0)
422+
#endif
423+
416424
// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
417425
// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
418426
// uses a bit of extra code ROM, but greatly improves lookup speed.

py/vm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,21 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t *code_sta
129129
#endif
130130
#if MICROPY_OPT_COMPUTED_GOTO
131131
#include "py/vmentrytable.h"
132+
#if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
132133
#define ONE_TRUE_DISPATCH() one_true_dispatch: do { \
133134
TRACE(ip); \
134135
MARK_EXC_IP_GLOBAL(); \
135136
goto *(void*)((char*)&&entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \
136137
} while (0)
137138
#define DISPATCH() do { goto one_true_dispatch; } while(0)
139+
#else
140+
#define DISPATCH() do { \
141+
TRACE(ip); \
142+
MARK_EXC_IP_GLOBAL(); \
143+
goto *entry_table[*ip++]; \
144+
} while (0)
145+
#define ONE_TRUE_DISPATCH() DISPATCH()
146+
#endif
138147
#define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check
139148
#define ENTRY(op) entry_##op
140149
#define ENTRY_DEFAULT entry_default

py/vmentrytable.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131

3232
#include "supervisor/linker.h"
3333

34+
#if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
3435
#define COMPUTE_ENTRY(x) ((char*)(x) - (char*)&&entry_MP_BC_LOAD_CONST_FALSE)
36+
typedef int16_t entry_table_type;
37+
#else
38+
#define COMPUTE_ENTRY(x) (x)
39+
typedef void *entry_table_type;
40+
#endif
3541

36-
static int16_t const PLACE_IN_DTCM_DATA(entry_table[256]) = {
42+
static entry_table_type const PLACE_IN_DTCM_DATA(entry_table[256]) = {
3743
[0 ... 255] = COMPUTE_ENTRY(&&entry_default),
3844
[MP_BC_LOAD_CONST_FALSE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_FALSE),
3945
[MP_BC_LOAD_CONST_NONE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_NONE),

0 commit comments

Comments
 (0)