Skip to content

Commit 9b9e996

Browse files
committed
Support for for-loop in native thumb.
1 parent 1a6633a commit 9b9e996

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

py/asmthumb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,13 @@ void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num) {
349349
asm_thumb_write_op16(as, OP_LDR_FROM_SP_OFFSET(rlo_dest, word_offset));
350350
}
351351

352-
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint reg_dest, int local_num) {
353-
assert(0);
354-
// see format 12, load address
355-
asm_thumb_write_op16(as, 0x0000);
352+
#define OP_ADD_REG_SP_OFFSET(rlo_dest, word_offset) (0xa800 | ((rlo_dest) << 8) | ((word_offset) & 0x00ff))
353+
354+
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num) {
355+
assert(rlo_dest < REG_R8);
356+
int word_offset = as->num_locals - local_num - 1;
357+
assert(as->pass < ASM_THUMB_PASS_3 || word_offset >= 0);
358+
asm_thumb_write_op16(as, OP_ADD_REG_SP_OFFSET(rlo_dest, word_offset));
356359
}
357360

358361
#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))

py/asmthumb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32_sr
7171
void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src); // convenience
7272
void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src); // convenience
7373
void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience
74-
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint reg_dest, int local_num); // convenience
74+
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience
7575

7676
void asm_thumb_add_reg_reg_reg(asm_thumb_t *as, uint rlo_dest, uint rlo_src_a, uint rlo_src_b); // convenience ?
7777
void asm_thumb_cmp_reg_reg(asm_thumb_t *as, uint rlo_a, uint rlo_b); // convenience ?

py/emitnative.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,8 @@ static void emit_native_for_iter(emit_t *emit, int label) {
965965
asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
966966
asm_x64_jcc_label(emit->as, JCC_JE, label);
967967
#elif N_THUMB
968-
assert(0); // XXX TODO
969968
asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1);
970-
// use it, b?
971-
asm_thumb_b_label(emit->as, label);
969+
asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
972970
#endif
973971
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
974972
}

0 commit comments

Comments
 (0)