summaryrefslogtreecommitdiff
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-19 08:46:01 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-19 12:28:03 +1000
commitadaf0d865cd6c81fb352751566460506392ed55f (patch)
tree0a944ff133a34b0f9ee4c6411144b049fd0ebf52 /py/vm.c
parenta5624bf3818c573611b2b7bfc755e27de97f64e4 (diff)
py: Combine 3 comprehension opcodes (list/dict/set) into 1.
With the previous patch combining 3 emit functions into 1, it now makes sense to also combine the corresponding VM opcodes, which is what this patch does. This eliminates 2 opcodes which simplifies the VM and reduces code size, in bytes: bare-arm:44, minimal:64, unix(NDEBUG,x86-64):272, stmhal:92, esp8266:200. Profiling (with a simple script that creates many list/dict/set comprehensions) shows no measurable change in performance.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/py/vm.c b/py/vm.c
index f9bdedff8..da8697fad 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -777,15 +777,6 @@ unwind_jump:;
DISPATCH();
}
- ENTRY(MP_BC_LIST_APPEND): {
- MARK_EXC_IP_SELECTIVE();
- DECODE_UINT;
- // I think it's guaranteed by the compiler that sp[unum] is a list
- mp_obj_list_append(sp[-unum], sp[0]);
- sp--;
- DISPATCH();
- }
-
ENTRY(MP_BC_BUILD_MAP): {
MARK_EXC_IP_SELECTIVE();
DECODE_UINT;
@@ -799,15 +790,6 @@ unwind_jump:;
mp_obj_dict_store(sp[0], sp[2], sp[1]);
DISPATCH();
- ENTRY(MP_BC_MAP_ADD): {
- MARK_EXC_IP_SELECTIVE();
- DECODE_UINT;
- // I think it's guaranteed by the compiler that sp[-unum - 1] is a map
- mp_obj_dict_store(sp[-unum - 1], sp[0], sp[-1]);
- sp -= 2;
- DISPATCH();
- }
-
#if MICROPY_PY_BUILTINS_SET
ENTRY(MP_BC_BUILD_SET): {
MARK_EXC_IP_SELECTIVE();
@@ -816,15 +798,6 @@ unwind_jump:;
SET_TOP(mp_obj_new_set(unum, sp));
DISPATCH();
}
-
- ENTRY(MP_BC_SET_ADD): {
- MARK_EXC_IP_SELECTIVE();
- DECODE_UINT;
- // I think it's guaranteed by the compiler that sp[-unum] is a set
- mp_obj_set_store(sp[-unum], sp[0]);
- sp--;
- DISPATCH();
- }
#endif
#if MICROPY_PY_BUILTINS_SLICE
@@ -845,6 +818,25 @@ unwind_jump:;
}
#endif
+ ENTRY(MP_BC_STORE_COMP): {
+ MARK_EXC_IP_SELECTIVE();
+ DECODE_UINT;
+ mp_obj_t obj = sp[-(unum >> 2)];
+ if ((unum & 3) == 0) {
+ mp_obj_list_append(obj, sp[0]);
+ sp--;
+ } else if (!MICROPY_PY_BUILTINS_SET || (unum & 3) == 1) {
+ mp_obj_dict_store(obj, sp[0], sp[-1]);
+ sp -= 2;
+ #if MICROPY_PY_BUILTINS_SET
+ } else {
+ mp_obj_set_store(obj, sp[0]);
+ sp--;
+ #endif
+ }
+ DISPATCH();
+ }
+
ENTRY(MP_BC_UNPACK_SEQUENCE): {
MARK_EXC_IP_SELECTIVE();
DECODE_UINT;