Skip to content

Commit 42e0c59

Browse files
committed
py: Add MICROPY_COMP_{DOUBLE,TRIPLE}_TUPLE_ASSIGN config options.
These allow to fine-tune the compiler to select whether it optimises tuple assignments of the form a, b = c, d and a, b, c = d, e, f. Sensible defaults are provided.
1 parent a77ffe6 commit 42e0c59

8 files changed

Lines changed: 24 additions & 2 deletions

File tree

bare-arm/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define MICROPY_EMIT_INLINE_THUMB (0)
99
#define MICROPY_COMP_MODULE_CONST (0)
1010
#define MICROPY_COMP_CONST (0)
11+
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0)
12+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
1113
#define MICROPY_MEM_STATS (0)
1214
#define MICROPY_DEBUG_PRINTERS (0)
1315
#define MICROPY_ENABLE_GC (0)

minimal/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define MICROPY_EMIT_INLINE_THUMB (0)
99
#define MICROPY_COMP_MODULE_CONST (0)
1010
#define MICROPY_COMP_CONST (0)
11+
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0)
12+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
1113
#define MICROPY_MEM_STATS (0)
1214
#define MICROPY_DEBUG_PRINTERS (0)
1315
#define MICROPY_ENABLE_GC (1)

py/compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,8 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
21652165
}
21662166
} else {
21672167
assert(kind == PN_expr_stmt_assign); // should be
2168-
if (MP_PARSE_NODE_IS_STRUCT_KIND(pns1->nodes[0], PN_testlist_star_expr)
2168+
if (MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
2169+
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns1->nodes[0], PN_testlist_star_expr)
21692170
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_testlist_star_expr)
21702171
&& MP_PARSE_NODE_STRUCT_NUM_NODES((mp_parse_node_struct_t*)pns1->nodes[0]) == 2
21712172
&& MP_PARSE_NODE_STRUCT_NUM_NODES((mp_parse_node_struct_t*)pns->nodes[0]) == 2) {
@@ -2182,7 +2183,8 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
21822183
EMIT(rot_two);
21832184
c_assign(comp, pns0->nodes[0], ASSIGN_STORE); // lhs store
21842185
c_assign(comp, pns0->nodes[1], ASSIGN_STORE); // lhs store
2185-
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pns1->nodes[0], PN_testlist_star_expr)
2186+
} else if (MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
2187+
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns1->nodes[0], PN_testlist_star_expr)
21862188
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_testlist_star_expr)
21872189
&& MP_PARSE_NODE_STRUCT_NUM_NODES((mp_parse_node_struct_t*)pns1->nodes[0]) == 3
21882190
&& MP_PARSE_NODE_STRUCT_NUM_NODES((mp_parse_node_struct_t*)pns->nodes[0]) == 3) {

py/mpconfig.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@
175175
#define MICROPY_COMP_CONST (1)
176176
#endif
177177

178+
// Whether to enable optimisation of: a, b = c, d
179+
// Costs 124 bytes (Thumb2)
180+
#ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
181+
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
182+
#endif
183+
184+
// Whether to enable optimisation of: a, b, c = d, e, f
185+
// Cost 156 bytes (Thumb2)
186+
#ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
187+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
188+
#endif
189+
178190
/*****************************************************************************/
179191
/* Internal debugging stuff */
180192

stmhal/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define MICROPY_EMIT_THUMB (1)
3535
#define MICROPY_EMIT_INLINE_THUMB (1)
3636
#define MICROPY_COMP_MODULE_CONST (1)
37+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
3738
#define MICROPY_ENABLE_GC (1)
3839
#define MICROPY_ENABLE_FINALISER (1)
3940
#define MICROPY_STACK_CHECK (1)

unix-cpy/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// options to control how Micro Python is built
2828

2929
#define MICROPY_EMIT_CPYTHON (1)
30+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
3031
#define MICROPY_HELPER_LEXER_UNIX (1)
3132
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
3233
#define MICROPY_PY_IO (0)

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define MICROPY_EMIT_ARM (1)
4141
#endif
4242
#define MICROPY_COMP_MODULE_CONST (1)
43+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
4344
#define MICROPY_ENABLE_GC (1)
4445
#define MICROPY_ENABLE_FINALISER (1)
4546
#define MICROPY_STACK_CHECK (1)

windows/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define MICROPY_EMIT_THUMB (0)
3737
#define MICROPY_EMIT_INLINE_THUMB (0)
3838
#define MICROPY_COMP_MODULE_CONST (1)
39+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
3940
#define MICROPY_ENABLE_GC (1)
4041
#define MICROPY_ENABLE_FINALISER (1)
4142
#define MICROPY_STACK_CHECK (1)

0 commit comments

Comments
 (0)