Skip to content

Commit 3bb8bd8

Browse files
committed
Make USE_COMPUTED_GOTO a config option in mpconfig.h.
Disabled by default. Enabled in unix port.
1 parent 0ae9c70 commit 3bb8bd8

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

py/mpconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ typedef double mp_float_t;
154154
#define MICROPY_PATH_MAX (512)
155155
#endif
156156

157+
// Whether to use computed gotos in the VM, or a switch
158+
// Computed gotos are roughly 10% faster, and increase VM code size by a little
159+
#ifndef MICROPY_USE_COMPUTED_GOTO
160+
#define MICROPY_USE_COMPUTED_GOTO (0)
161+
#endif
162+
157163
// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
158164
#ifndef MICROPY_EXTRA_BUILTINS
159165
#define MICROPY_EXTRA_BUILTINS

py/objstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
662662
if (arg_i > 0) {
663663
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from automatic field numbering to manual field specification"));
664664
}
665-
int index;
665+
int index = 0;
666666
if (str_to_int(vstr_str(field_name), &index) != vstr_len(field_name) - 1) {
667667
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "attributes not supported yet"));
668668
}

py/vm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
167167
volatile mp_obj_t inject_exc) {
168168
// careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think)
169169

170-
#ifdef MICROPY_USE_COMPUTED_GOTO
170+
#if MICROPY_USE_COMPUTED_GOTO
171171

172172
# define DISPATCH() do { \
173173
save_ip = ip; \
@@ -299,7 +299,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
299299
// loop to execute byte code
300300
for (;;) {
301301
dispatch_loop:
302-
#ifdef MICROPY_USE_COMPUTED_GOTO
302+
#if MICROPY_USE_COMPUTED_GOTO
303303
DISPATCH();
304304
#else
305305
save_ip = ip;
@@ -1005,7 +1005,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
10051005
nlr_pop();
10061006
fastn[0] = obj1;
10071007
return MP_VM_RETURN_EXCEPTION;
1008-
#ifndef MICROPY_USE_COMPUTED_GOTO
1008+
#if !MICROPY_USE_COMPUTED_GOTO
10091009
}
10101010
#endif
10111011
}

unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ QSTR_DEFS = qstrdefsport.h
1111
include ../py/py.mk
1212

1313
# compiler settings
14-
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -DMICROPY_USE_COMPUTED_GOTO
14+
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT)
1515

1616
UNAME_S := $(shell uname -s)
1717
ifeq ($(UNAME_S),Darwin)

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
1515
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
1616
#define MICROPY_PATH_MAX (PATH_MAX)
17+
#define MICROPY_USE_COMPUTED_GOTO (1)
1718
#define MICROPY_MOD_SYS_STDFILES (1)
1819

1920
// type definitions for the specific machine

0 commit comments

Comments
 (0)