Skip to content

Commit 3b108e7

Browse files
committed
Merge pull request adafruit#493 from aitjcize/patch
Move entry_table to separated header file.
2 parents 203bc98 + 9413ca0 commit 3b108e7

4 files changed

Lines changed: 104 additions & 105 deletions

File tree

py/mpconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ typedef double mp_float_t;
156156

157157
// Whether to use computed gotos in the VM, or a switch
158158
// 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)
159+
#ifndef MICROPY_USE_COMPUTED_GOTOS
160+
#define MICROPY_USE_COMPUTED_GOTOS (0)
161161
#endif
162162

163163
// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.

py/vm.c

Lines changed: 14 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -167,107 +167,19 @@ 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-
#if MICROPY_USE_COMPUTED_GOTO
171-
172-
# define DISPATCH() do { \
173-
save_ip = ip; \
174-
op = *ip++; \
175-
goto *entry_table[op]; \
170+
#if MICROPY_USE_COMPUTED_GOTOS
171+
#include "vmentrytable.h"
172+
#define DISPATCH() do { \
173+
save_ip = ip; \
174+
op = *ip++; \
175+
goto *entry_table[op]; \
176176
} while(0)
177-
# define ENTRY(op) entry_##op
178-
# define ENTRY_DEFAULT entry_default
179-
180-
static void* entry_table[256] = {
181-
[0 ... 255] = &&entry_default,
182-
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
183-
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,
184-
[MP_BC_LOAD_CONST_TRUE] = &&entry_MP_BC_LOAD_CONST_TRUE,
185-
[MP_BC_LOAD_CONST_ELLIPSIS] = &&entry_MP_BC_LOAD_CONST_ELLIPSIS,
186-
[MP_BC_LOAD_CONST_SMALL_INT] = &&entry_MP_BC_LOAD_CONST_SMALL_INT,
187-
[MP_BC_LOAD_CONST_INT] = &&entry_MP_BC_LOAD_CONST_INT,
188-
[MP_BC_LOAD_CONST_DEC] = &&entry_MP_BC_LOAD_CONST_DEC,
189-
[MP_BC_LOAD_CONST_ID] = &&entry_MP_BC_LOAD_CONST_ID,
190-
[MP_BC_LOAD_CONST_BYTES] = &&entry_MP_BC_LOAD_CONST_BYTES,
191-
[MP_BC_LOAD_CONST_STRING] = &&entry_MP_BC_LOAD_CONST_STRING,
192-
[MP_BC_LOAD_NULL] = &&entry_MP_BC_LOAD_NULL,
193-
[MP_BC_LOAD_FAST_0] = &&entry_MP_BC_LOAD_FAST_0,
194-
[MP_BC_LOAD_FAST_1] = &&entry_MP_BC_LOAD_FAST_1,
195-
[MP_BC_LOAD_FAST_2] = &&entry_MP_BC_LOAD_FAST_2,
196-
[MP_BC_LOAD_FAST_N] = &&entry_MP_BC_LOAD_FAST_N,
197-
[MP_BC_LOAD_DEREF] = &&entry_MP_BC_LOAD_DEREF,
198-
[MP_BC_LOAD_NAME] = &&entry_MP_BC_LOAD_NAME,
199-
[MP_BC_LOAD_GLOBAL] = &&entry_MP_BC_LOAD_GLOBAL,
200-
[MP_BC_LOAD_ATTR] = &&entry_MP_BC_LOAD_ATTR,
201-
[MP_BC_LOAD_METHOD] = &&entry_MP_BC_LOAD_METHOD,
202-
[MP_BC_LOAD_BUILD_CLASS] = &&entry_MP_BC_LOAD_BUILD_CLASS,
203-
[MP_BC_STORE_FAST_0] = &&entry_MP_BC_STORE_FAST_0,
204-
[MP_BC_STORE_FAST_1] = &&entry_MP_BC_STORE_FAST_1,
205-
[MP_BC_STORE_FAST_2] = &&entry_MP_BC_STORE_FAST_2,
206-
[MP_BC_STORE_FAST_N] = &&entry_MP_BC_STORE_FAST_N,
207-
[MP_BC_STORE_DEREF] = &&entry_MP_BC_STORE_DEREF,
208-
[MP_BC_STORE_NAME] = &&entry_MP_BC_STORE_NAME,
209-
[MP_BC_STORE_GLOBAL] = &&entry_MP_BC_STORE_GLOBAL,
210-
[MP_BC_STORE_ATTR] = &&entry_MP_BC_STORE_ATTR,
211-
[MP_BC_STORE_SUBSCR] = &&entry_MP_BC_STORE_SUBSCR,
212-
[MP_BC_DELETE_FAST] = &&entry_MP_BC_DELETE_FAST,
213-
[MP_BC_DELETE_DEREF] = &&entry_MP_BC_DELETE_DEREF,
214-
[MP_BC_DELETE_NAME] = &&entry_MP_BC_DELETE_NAME,
215-
[MP_BC_DELETE_GLOBAL] = &&entry_MP_BC_DELETE_GLOBAL,
216-
[MP_BC_DUP_TOP] = &&entry_MP_BC_DUP_TOP,
217-
[MP_BC_DUP_TOP_TWO] = &&entry_MP_BC_DUP_TOP_TWO,
218-
[MP_BC_POP_TOP] = &&entry_MP_BC_POP_TOP,
219-
[MP_BC_ROT_TWO] = &&entry_MP_BC_ROT_TWO,
220-
[MP_BC_ROT_THREE] = &&entry_MP_BC_ROT_THREE,
221-
[MP_BC_JUMP] = &&entry_MP_BC_JUMP,
222-
[MP_BC_POP_JUMP_IF_TRUE] = &&entry_MP_BC_POP_JUMP_IF_TRUE,
223-
[MP_BC_POP_JUMP_IF_FALSE] = &&entry_MP_BC_POP_JUMP_IF_FALSE,
224-
[MP_BC_JUMP_IF_TRUE_OR_POP] = &&entry_MP_BC_JUMP_IF_TRUE_OR_POP,
225-
[MP_BC_JUMP_IF_FALSE_OR_POP] = &&entry_MP_BC_JUMP_IF_FALSE_OR_POP,
226-
// [MP_BC_SETUP_LOOP] = &&entry_MP_BC_SETUP_LOOP,
227-
[MP_BC_SETUP_WITH] = &&entry_MP_BC_SETUP_WITH,
228-
[MP_BC_WITH_CLEANUP] = &&entry_MP_BC_WITH_CLEANUP,
229-
[MP_BC_UNWIND_JUMP] = &&entry_MP_BC_UNWIND_JUMP,
230-
[MP_BC_SETUP_EXCEPT] = &&entry_MP_BC_SETUP_EXCEPT,
231-
[MP_BC_SETUP_FINALLY] = &&entry_MP_BC_SETUP_FINALLY,
232-
[MP_BC_END_FINALLY] = &&entry_MP_BC_END_FINALLY,
233-
[MP_BC_GET_ITER] = &&entry_MP_BC_GET_ITER,
234-
[MP_BC_FOR_ITER] = &&entry_MP_BC_FOR_ITER,
235-
[MP_BC_POP_BLOCK] = &&entry_MP_BC_POP_BLOCK,
236-
[MP_BC_POP_EXCEPT] = &&entry_MP_BC_POP_EXCEPT,
237-
[MP_BC_NOT] = &&entry_MP_BC_NOT,
238-
[MP_BC_UNARY_OP] = &&entry_MP_BC_UNARY_OP,
239-
[MP_BC_BINARY_OP] = &&entry_MP_BC_BINARY_OP,
240-
[MP_BC_BUILD_TUPLE] = &&entry_MP_BC_BUILD_TUPLE,
241-
[MP_BC_BUILD_LIST] = &&entry_MP_BC_BUILD_LIST,
242-
[MP_BC_LIST_APPEND] = &&entry_MP_BC_LIST_APPEND,
243-
[MP_BC_BUILD_MAP] = &&entry_MP_BC_BUILD_MAP,
244-
[MP_BC_STORE_MAP] = &&entry_MP_BC_STORE_MAP,
245-
[MP_BC_MAP_ADD] = &&entry_MP_BC_MAP_ADD,
246-
[MP_BC_BUILD_SET] = &&entry_MP_BC_BUILD_SET,
247-
[MP_BC_SET_ADD] = &&entry_MP_BC_SET_ADD,
248-
[MP_BC_BUILD_SLICE] = &&entry_MP_BC_BUILD_SLICE,
249-
[MP_BC_UNPACK_SEQUENCE] = &&entry_MP_BC_UNPACK_SEQUENCE,
250-
[MP_BC_UNPACK_EX] = &&entry_MP_BC_UNPACK_EX,
251-
[MP_BC_MAKE_FUNCTION] = &&entry_MP_BC_MAKE_FUNCTION,
252-
[MP_BC_MAKE_FUNCTION_DEFARGS] = &&entry_MP_BC_MAKE_FUNCTION_DEFARGS,
253-
[MP_BC_MAKE_CLOSURE] = &&entry_MP_BC_MAKE_CLOSURE,
254-
[MP_BC_MAKE_CLOSURE_DEFARGS] = &&entry_MP_BC_MAKE_CLOSURE_DEFARGS,
255-
[MP_BC_CALL_FUNCTION] = &&entry_MP_BC_CALL_FUNCTION,
256-
[MP_BC_CALL_FUNCTION_VAR_KW] = &&entry_MP_BC_CALL_FUNCTION_VAR_KW,
257-
[MP_BC_CALL_METHOD] = &&entry_MP_BC_CALL_METHOD,
258-
[MP_BC_CALL_METHOD_VAR_KW] = &&entry_MP_BC_CALL_METHOD_VAR_KW,
259-
[MP_BC_RETURN_VALUE] = &&entry_MP_BC_RETURN_VALUE,
260-
[MP_BC_RAISE_VARARGS] = &&entry_MP_BC_RAISE_VARARGS,
261-
[MP_BC_YIELD_VALUE] = &&entry_MP_BC_YIELD_VALUE,
262-
[MP_BC_YIELD_FROM] = &&entry_MP_BC_YIELD_FROM,
263-
[MP_BC_IMPORT_NAME] = &&entry_MP_BC_IMPORT_NAME,
264-
[MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM,
265-
[MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR,
266-
};
177+
#define ENTRY(op) entry_##op
178+
#define ENTRY_DEFAULT entry_default
267179
#else
268-
# define DISPATCH() break
269-
# define ENTRY(op) case op
270-
# define ENTRY_DEFAULT default
180+
#define DISPATCH() break
181+
#define ENTRY(op) case op
182+
#define ENTRY_DEFAULT default
271183
#endif
272184

273185
int op = 0;
@@ -299,7 +211,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
299211
// loop to execute byte code
300212
for (;;) {
301213
dispatch_loop:
302-
#if MICROPY_USE_COMPUTED_GOTO
214+
#if MICROPY_USE_COMPUTED_GOTOS
303215
DISPATCH();
304216
#else
305217
save_ip = ip;
@@ -1005,8 +917,8 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
1005917
nlr_pop();
1006918
fastn[0] = obj1;
1007919
return MP_VM_RETURN_EXCEPTION;
1008-
#if !MICROPY_USE_COMPUTED_GOTO
1009-
}
920+
#if !MICROPY_USE_COMPUTED_GOTOS
921+
} // switch
1010922
#endif
1011923
}
1012924

py/vmentrytable.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
static void* entry_table[256] = {
2+
[0 ... 255] = &&entry_default,
3+
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
4+
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,
5+
[MP_BC_LOAD_CONST_TRUE] = &&entry_MP_BC_LOAD_CONST_TRUE,
6+
[MP_BC_LOAD_CONST_ELLIPSIS] = &&entry_MP_BC_LOAD_CONST_ELLIPSIS,
7+
[MP_BC_LOAD_CONST_SMALL_INT] = &&entry_MP_BC_LOAD_CONST_SMALL_INT,
8+
[MP_BC_LOAD_CONST_INT] = &&entry_MP_BC_LOAD_CONST_INT,
9+
[MP_BC_LOAD_CONST_DEC] = &&entry_MP_BC_LOAD_CONST_DEC,
10+
[MP_BC_LOAD_CONST_ID] = &&entry_MP_BC_LOAD_CONST_ID,
11+
[MP_BC_LOAD_CONST_BYTES] = &&entry_MP_BC_LOAD_CONST_BYTES,
12+
[MP_BC_LOAD_CONST_STRING] = &&entry_MP_BC_LOAD_CONST_STRING,
13+
[MP_BC_LOAD_NULL] = &&entry_MP_BC_LOAD_NULL,
14+
[MP_BC_LOAD_FAST_0] = &&entry_MP_BC_LOAD_FAST_0,
15+
[MP_BC_LOAD_FAST_1] = &&entry_MP_BC_LOAD_FAST_1,
16+
[MP_BC_LOAD_FAST_2] = &&entry_MP_BC_LOAD_FAST_2,
17+
[MP_BC_LOAD_FAST_N] = &&entry_MP_BC_LOAD_FAST_N,
18+
[MP_BC_LOAD_DEREF] = &&entry_MP_BC_LOAD_DEREF,
19+
[MP_BC_LOAD_NAME] = &&entry_MP_BC_LOAD_NAME,
20+
[MP_BC_LOAD_GLOBAL] = &&entry_MP_BC_LOAD_GLOBAL,
21+
[MP_BC_LOAD_ATTR] = &&entry_MP_BC_LOAD_ATTR,
22+
[MP_BC_LOAD_METHOD] = &&entry_MP_BC_LOAD_METHOD,
23+
[MP_BC_LOAD_BUILD_CLASS] = &&entry_MP_BC_LOAD_BUILD_CLASS,
24+
[MP_BC_STORE_FAST_0] = &&entry_MP_BC_STORE_FAST_0,
25+
[MP_BC_STORE_FAST_1] = &&entry_MP_BC_STORE_FAST_1,
26+
[MP_BC_STORE_FAST_2] = &&entry_MP_BC_STORE_FAST_2,
27+
[MP_BC_STORE_FAST_N] = &&entry_MP_BC_STORE_FAST_N,
28+
[MP_BC_STORE_DEREF] = &&entry_MP_BC_STORE_DEREF,
29+
[MP_BC_STORE_NAME] = &&entry_MP_BC_STORE_NAME,
30+
[MP_BC_STORE_GLOBAL] = &&entry_MP_BC_STORE_GLOBAL,
31+
[MP_BC_STORE_ATTR] = &&entry_MP_BC_STORE_ATTR,
32+
[MP_BC_STORE_SUBSCR] = &&entry_MP_BC_STORE_SUBSCR,
33+
[MP_BC_DELETE_FAST] = &&entry_MP_BC_DELETE_FAST,
34+
[MP_BC_DELETE_DEREF] = &&entry_MP_BC_DELETE_DEREF,
35+
[MP_BC_DELETE_NAME] = &&entry_MP_BC_DELETE_NAME,
36+
[MP_BC_DELETE_GLOBAL] = &&entry_MP_BC_DELETE_GLOBAL,
37+
[MP_BC_DUP_TOP] = &&entry_MP_BC_DUP_TOP,
38+
[MP_BC_DUP_TOP_TWO] = &&entry_MP_BC_DUP_TOP_TWO,
39+
[MP_BC_POP_TOP] = &&entry_MP_BC_POP_TOP,
40+
[MP_BC_ROT_TWO] = &&entry_MP_BC_ROT_TWO,
41+
[MP_BC_ROT_THREE] = &&entry_MP_BC_ROT_THREE,
42+
[MP_BC_JUMP] = &&entry_MP_BC_JUMP,
43+
[MP_BC_POP_JUMP_IF_TRUE] = &&entry_MP_BC_POP_JUMP_IF_TRUE,
44+
[MP_BC_POP_JUMP_IF_FALSE] = &&entry_MP_BC_POP_JUMP_IF_FALSE,
45+
[MP_BC_JUMP_IF_TRUE_OR_POP] = &&entry_MP_BC_JUMP_IF_TRUE_OR_POP,
46+
[MP_BC_JUMP_IF_FALSE_OR_POP] = &&entry_MP_BC_JUMP_IF_FALSE_OR_POP,
47+
// [MP_BC_SETUP_LOOP] = &&entry_MP_BC_SETUP_LOOP,
48+
[MP_BC_SETUP_WITH] = &&entry_MP_BC_SETUP_WITH,
49+
[MP_BC_WITH_CLEANUP] = &&entry_MP_BC_WITH_CLEANUP,
50+
[MP_BC_UNWIND_JUMP] = &&entry_MP_BC_UNWIND_JUMP,
51+
[MP_BC_SETUP_EXCEPT] = &&entry_MP_BC_SETUP_EXCEPT,
52+
[MP_BC_SETUP_FINALLY] = &&entry_MP_BC_SETUP_FINALLY,
53+
[MP_BC_END_FINALLY] = &&entry_MP_BC_END_FINALLY,
54+
[MP_BC_GET_ITER] = &&entry_MP_BC_GET_ITER,
55+
[MP_BC_FOR_ITER] = &&entry_MP_BC_FOR_ITER,
56+
[MP_BC_POP_BLOCK] = &&entry_MP_BC_POP_BLOCK,
57+
[MP_BC_POP_EXCEPT] = &&entry_MP_BC_POP_EXCEPT,
58+
[MP_BC_NOT] = &&entry_MP_BC_NOT,
59+
[MP_BC_UNARY_OP] = &&entry_MP_BC_UNARY_OP,
60+
[MP_BC_BINARY_OP] = &&entry_MP_BC_BINARY_OP,
61+
[MP_BC_BUILD_TUPLE] = &&entry_MP_BC_BUILD_TUPLE,
62+
[MP_BC_BUILD_LIST] = &&entry_MP_BC_BUILD_LIST,
63+
[MP_BC_LIST_APPEND] = &&entry_MP_BC_LIST_APPEND,
64+
[MP_BC_BUILD_MAP] = &&entry_MP_BC_BUILD_MAP,
65+
[MP_BC_STORE_MAP] = &&entry_MP_BC_STORE_MAP,
66+
[MP_BC_MAP_ADD] = &&entry_MP_BC_MAP_ADD,
67+
[MP_BC_BUILD_SET] = &&entry_MP_BC_BUILD_SET,
68+
[MP_BC_SET_ADD] = &&entry_MP_BC_SET_ADD,
69+
[MP_BC_BUILD_SLICE] = &&entry_MP_BC_BUILD_SLICE,
70+
[MP_BC_UNPACK_SEQUENCE] = &&entry_MP_BC_UNPACK_SEQUENCE,
71+
[MP_BC_UNPACK_EX] = &&entry_MP_BC_UNPACK_EX,
72+
[MP_BC_MAKE_FUNCTION] = &&entry_MP_BC_MAKE_FUNCTION,
73+
[MP_BC_MAKE_FUNCTION_DEFARGS] = &&entry_MP_BC_MAKE_FUNCTION_DEFARGS,
74+
[MP_BC_MAKE_CLOSURE] = &&entry_MP_BC_MAKE_CLOSURE,
75+
[MP_BC_MAKE_CLOSURE_DEFARGS] = &&entry_MP_BC_MAKE_CLOSURE_DEFARGS,
76+
[MP_BC_CALL_FUNCTION] = &&entry_MP_BC_CALL_FUNCTION,
77+
[MP_BC_CALL_FUNCTION_VAR_KW] = &&entry_MP_BC_CALL_FUNCTION_VAR_KW,
78+
[MP_BC_CALL_METHOD] = &&entry_MP_BC_CALL_METHOD,
79+
[MP_BC_CALL_METHOD_VAR_KW] = &&entry_MP_BC_CALL_METHOD_VAR_KW,
80+
[MP_BC_RETURN_VALUE] = &&entry_MP_BC_RETURN_VALUE,
81+
[MP_BC_RAISE_VARARGS] = &&entry_MP_BC_RAISE_VARARGS,
82+
[MP_BC_YIELD_VALUE] = &&entry_MP_BC_YIELD_VALUE,
83+
[MP_BC_YIELD_FROM] = &&entry_MP_BC_YIELD_FROM,
84+
[MP_BC_IMPORT_NAME] = &&entry_MP_BC_IMPORT_NAME,
85+
[MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM,
86+
[MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR,
87+
};

unix/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +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)
17+
#define MICROPY_USE_COMPUTED_GOTOS (1)
1818
#define MICROPY_MOD_SYS_STDFILES (1)
1919

2020
// type definitions for the specific machine

0 commit comments

Comments
 (0)