From 9b9e996df616e8ba3b175b87783d3a34bc357c6d Mon Sep 17 00:00:00 2001 From: Damien Date: Sun, 3 Nov 2013 14:25:43 +0000 Subject: [PATCH] Support for for-loop in native thumb. --- py/asmthumb.c | 11 +++++++---- py/asmthumb.h | 2 +- py/emitnative.c | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/py/asmthumb.c b/py/asmthumb.c index 18be05bd85..7cfb479b56 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -349,10 +349,13 @@ void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num) { asm_thumb_write_op16(as, OP_LDR_FROM_SP_OFFSET(rlo_dest, word_offset)); } -void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint reg_dest, int local_num) { - assert(0); - // see format 12, load address - asm_thumb_write_op16(as, 0x0000); +#define OP_ADD_REG_SP_OFFSET(rlo_dest, word_offset) (0xa800 | ((rlo_dest) << 8) | ((word_offset) & 0x00ff)) + +void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num) { + assert(rlo_dest < REG_R8); + int word_offset = as->num_locals - local_num - 1; + assert(as->pass < ASM_THUMB_PASS_3 || word_offset >= 0); + asm_thumb_write_op16(as, OP_ADD_REG_SP_OFFSET(rlo_dest, word_offset)); } #define OP_ADD_REG_REG_REG(rlo_dest, rlo_src_a, rlo_src_b) (0x1800 | ((rlo_src_b) << 6) | ((rlo_src_a) << 3) | (rlo_dest)) diff --git a/py/asmthumb.h b/py/asmthumb.h index 22aa4a5f61..dcd9c2e3ad 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -71,7 +71,7 @@ void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32_sr void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src); // convenience void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src); // convenience void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience -void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint reg_dest, int local_num); // convenience +void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience void asm_thumb_add_reg_reg_reg(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b); // convenience ? void asm_thumb_cmp_reg_reg(asm_thumb_t *as, uint rlo_a, uint rlo_b); // convenience ? diff --git a/py/emitnative.c b/py/emitnative.c index cdc97fec06..a23c97b6ad 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -965,10 +965,8 @@ static void emit_native_for_iter(emit_t *emit, int label) { asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1); asm_x64_jcc_label(emit->as, JCC_JE, label); #elif N_THUMB - assert(0); // XXX TODO asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1); - // use it, b? - asm_thumb_b_label(emit->as, label); + asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); #endif emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); }