Skip to content

Commit e5315f7

Browse files
committed
py: Factor some code in inline thumb assembler to reduce code size.
1 parent e41b21c commit e5315f7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

py/emitinlinethumb.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
475475
reg_src = get_arg_reg(emit, op_str, pn_args[1], 7);
476476
asm_thumb_format_4(emit->as, op_code, reg_dest, reg_src);
477477
}
478-
// search table
478+
// search table for ALU ops
479479
for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(format_4_op_table); i++) {
480480
if (strncmp(op_str, format_4_op_table[i].name, 3) == 0 && op_str[3] == '\0') {
481481
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
504504
op_code = ASM_THUMB_FORMAT_3_SUB;
505505
goto op_format_3;
506506
} else if (strcmp(op_str, "movw") == 0) {
507-
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
507+
op_code = ASM_THUMB_OP_MOVW;
508+
mp_uint_t reg_dest;
509+
op_movw_movt:
510+
reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
508511
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff);
509-
asm_thumb_mov_reg_i16(emit->as, ASM_THUMB_OP_MOVW, reg_dest, i_src);
512+
asm_thumb_mov_reg_i16(emit->as, op_code, reg_dest, i_src);
510513
} else if (strcmp(op_str, "movt") == 0) {
511-
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
512-
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff);
513-
asm_thumb_mov_reg_i16(emit->as, ASM_THUMB_OP_MOVT, reg_dest, i_src);
514+
op_code = ASM_THUMB_OP_MOVT;
515+
goto op_movw_movt;
514516
} else if (strcmp(op_str, "movwt") == 0) {
515517
// this is a convenience instruction
516518
// we clear the MSB since it might be set from extracting the small int value

0 commit comments

Comments
 (0)