diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-06 12:51:39 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-07 21:07:23 +0000 |
commit | 7ee91cf86136f4774a9143a3f745d37f314662da (patch) | |
tree | 87960f9f97d6123aa20f9faf53757482a2db7f64 /py/emitbc.c | |
parent | b4b10fd350852e321624d74983cca286091b55a1 (diff) |
py: Add option to cache map lookup results in bytecode.
This is a simple optimisation inspired by JITing technology: we cache in
the bytecode (using 1 byte) the offset of the last successful lookup in
a map. This allows us next time round to check in that location in the
hash table (mp_map_t) for the desired entry, and if it's there use that
entry straight away. Otherwise fallback to a normal map lookup.
Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes.
On a few tests it gives >90% cache hit and greatly improves speed of
code.
Disabled by default. Enabled for unix and stmhal ports.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r-- | py/emitbc.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index a93c03e7e..4560d1ec6 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -510,16 +510,25 @@ STATIC void emit_bc_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { STATIC void emit_bc_load_name(emit_t *emit, qstr qst) { emit_bc_pre(emit, 1); emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_NAME, qst); + if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) { + emit_write_bytecode_byte(emit, 0); + } } STATIC void emit_bc_load_global(emit_t *emit, qstr qst) { emit_bc_pre(emit, 1); emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_GLOBAL, qst); + if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) { + emit_write_bytecode_byte(emit, 0); + } } STATIC void emit_bc_load_attr(emit_t *emit, qstr qst) { emit_bc_pre(emit, 0); emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_ATTR, qst); + if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) { + emit_write_bytecode_byte(emit, 0); + } } STATIC void emit_bc_load_method(emit_t *emit, qstr qst) { @@ -565,6 +574,9 @@ STATIC void emit_bc_store_global(emit_t *emit, qstr qst) { STATIC void emit_bc_store_attr(emit_t *emit, qstr qst) { emit_bc_pre(emit, -2); emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_ATTR, qst); + if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) { + emit_write_bytecode_byte(emit, 0); + } } STATIC void emit_bc_store_subscr(emit_t *emit) { |