diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-28 15:04:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-28 15:04:06 +0000 |
commit | 63f3832e813442dcfc88be65d78ce465b053a33b (patch) | |
tree | 1778184b6ce04f808d3d8a068e16cc0848f6b16a /py/emitnative.c | |
parent | 0b2fd918903509d0a5b368d328a9fa837880ff1c (diff) | |
download | micropython-63f3832e813442dcfc88be65d78ce465b053a33b.tar.gz micropython-63f3832e813442dcfc88be65d78ce465b053a33b.zip |
py: Combine emit functions for jump true/false to reduce code size.
Saves 116 bytes for stmhal and 56 bytes for cc3200 port.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r-- | py/emitnative.c | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index dae3d6c1e5..dcf6822ffc 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1744,32 +1744,25 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool pop) { need_stack_settled(emit); } -STATIC void emit_native_pop_jump_if_true(emit_t *emit, mp_uint_t label) { - DEBUG_printf("pop_jump_if_true(label=" UINT_FMT ")\n", label); +STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { + DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, true); - ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); - emit_post(emit); -} - -STATIC void emit_native_pop_jump_if_false(emit_t *emit, mp_uint_t label) { - DEBUG_printf("pop_jump_if_false(label=" UINT_FMT ")\n", label); - emit_native_jump_helper(emit, true); - ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label); - emit_post(emit); -} - -STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) { - DEBUG_printf("jump_if_true_or_pop(label=" UINT_FMT ")\n", label); - emit_native_jump_helper(emit, false); - ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); - adjust_stack(emit, -1); + if (cond) { + ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); + } else { + ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label); + } emit_post(emit); } -STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) { - DEBUG_printf("jump_if_false_or_pop(label=" UINT_FMT ")\n", label); +STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { + DEBUG_printf("jump_if_or_pop(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, false); - ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label); + if (cond) { + ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); + } else { + ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label); + } adjust_stack(emit, -1); emit_post(emit); } @@ -2329,10 +2322,8 @@ const emit_method_table_t EXPORT_FUN(method_table) = { emit_native_rot_two, emit_native_rot_three, emit_native_jump, - emit_native_pop_jump_if_true, - emit_native_pop_jump_if_false, - emit_native_jump_if_true_or_pop, - emit_native_jump_if_false_or_pop, + emit_native_pop_jump_if, + emit_native_jump_if_or_pop, emit_native_break_loop, emit_native_continue_loop, emit_native_setup_with, |