From 67c5f89af539e0778155dcd35b58c32af64debec Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 2 Mar 2015 17:51:32 +0000 Subject: [PATCH] py: In inline assembler, fix branch out-of-range error reporting. Should only give an error on the last pass of the assembler, since that's when we are certain about the branch size. --- py/asmthumb.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/py/asmthumb.c b/py/asmthumb.c index ad67000888..5bf2d80bb4 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -297,12 +297,8 @@ bool asm_thumb_b_n_label(asm_thumb_t *as, uint label) { mp_uint_t dest = get_label_dest(as, label); mp_int_t rel = dest - as->code_offset; rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction - if (SIGNED_FIT12(rel)) { - asm_thumb_op16(as, OP_B_N(rel)); - return true; - } else { - return false; - } + asm_thumb_op16(as, OP_B_N(rel)); + return as->pass != ASM_THUMB_PASS_EMIT || SIGNED_FIT12(rel); } #define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff)) @@ -316,12 +312,8 @@ bool asm_thumb_bcc_nw_label(asm_thumb_t *as, int cond, uint label, bool wide) { mp_int_t rel = dest - as->code_offset; rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction if (!wide) { - if (SIGNED_FIT9(rel)) { - asm_thumb_op16(as, OP_BCC_N(cond, rel)); - return true; - } else { - return false; - } + asm_thumb_op16(as, OP_BCC_N(cond, rel)); + return as->pass != ASM_THUMB_PASS_EMIT || SIGNED_FIT9(rel); } else { asm_thumb_op32(as, OP_BCC_W_HI(cond, rel), OP_BCC_W_LO(rel)); return true; @@ -335,12 +327,8 @@ bool asm_thumb_bl_label(asm_thumb_t *as, uint label) { mp_uint_t dest = get_label_dest(as, label); mp_int_t rel = dest - as->code_offset; rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction - if (SIGNED_FIT23(rel)) { - asm_thumb_op32(as, OP_BL_HI(rel), OP_BL_LO(rel)); - return true; - } else { - return false; - } + asm_thumb_op32(as, OP_BL_HI(rel), OP_BL_LO(rel)); + return as->pass != ASM_THUMB_PASS_EMIT || SIGNED_FIT23(rel); } void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, mp_uint_t i32) {