Skip to content

Commit 928c716

Browse files
agattidpgeorge
authored andcommitted
py/asmarm: Fix locals address loading code generation with large imm.
This commit fixes code generation for loading a local's address if its index is greater than 63. The old code blindly encoded the offset into an `ADD Rd, Rn, #imm` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then an `ADD Rd, Rn, R8` opcode. This fixes `tests/float/math_domain.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <[email protected]>
1 parent e84c9ab commit 928c716

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

py/asmarm.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,15 @@ void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) {
292292
}
293293

294294
void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num) {
295-
// add rd, sp, #local_num*4
296-
emit_al(as, asm_arm_op_add_imm(rd, ASM_ARM_REG_SP, local_num << 2));
295+
if (local_num >= 0x40) {
296+
// mov r8, #local_num*4
297+
// add rd, sp, r8
298+
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, local_num << 2);
299+
emit_al(as, asm_arm_op_add_reg(rd, ASM_ARM_REG_SP, ASM_ARM_REG_R8));
300+
} else {
301+
// add rd, sp, #local_num*4
302+
emit_al(as, asm_arm_op_add_imm(rd, ASM_ARM_REG_SP, local_num << 2));
303+
}
297304
}
298305

299306
void asm_arm_mov_reg_pcrel(asm_arm_t *as, uint reg_dest, uint label) {

0 commit comments

Comments
 (0)