From e5315f7ffd7325ffc064393ffb82f378d9655934 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 24 Feb 2015 16:35:37 +0000 Subject: [PATCH] py: Factor some code in inline thumb assembler to reduce code size. --- py/emitinlinethumb.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 3cde20ecc7..05ab8a5d49 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -475,7 +475,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a reg_src = get_arg_reg(emit, op_str, pn_args[1], 7); asm_thumb_format_4(emit->as, op_code, reg_dest, reg_src); } - // search table + // search table for ALU ops for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(format_4_op_table); i++) { if (strncmp(op_str, format_4_op_table[i].name, 3) == 0 && op_str[3] == '\0') { op_code = 0x4000 | (format_4_op_table[i].op << 4); @@ -504,13 +504,15 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a op_code = ASM_THUMB_FORMAT_3_SUB; goto op_format_3; } else if (strcmp(op_str, "movw") == 0) { - mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15); + op_code = ASM_THUMB_OP_MOVW; + mp_uint_t reg_dest; + op_movw_movt: + reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15); int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff); - asm_thumb_mov_reg_i16(emit->as, ASM_THUMB_OP_MOVW, reg_dest, i_src); + asm_thumb_mov_reg_i16(emit->as, op_code, reg_dest, i_src); } else if (strcmp(op_str, "movt") == 0) { - mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15); - int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff); - asm_thumb_mov_reg_i16(emit->as, ASM_THUMB_OP_MOVT, reg_dest, i_src); + op_code = ASM_THUMB_OP_MOVT; + goto op_movw_movt; } else if (strcmp(op_str, "movwt") == 0) { // this is a convenience instruction // we clear the MSB since it might be set from extracting the small int value