Skip to content

Commit 5b90d6d

Browse files
agattidpgeorge
authored andcommitted
py/asmarm: Give a proper name to the temporary register.
This commit performs a small refactoring on the Arm native emitter, by renaming all but one instance of ASM_ARM_REG_R8 into REG_TEMP. ASM_ARM_REG_R8 is the temporary register used by the emitter when operations cannot overwrite the value of a particular register and some extra storage is needed. Signed-off-by: Alessandro Gatti <[email protected]>
1 parent bbab2e9 commit 5b90d6d

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

py/asmarm.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "py/asmarm.h"
3838

39+
#define REG_TEMP ASM_ARM_REG_R8
40+
3941
#define SIGNED_FIT24(x) (((x) & 0xff800000) == 0) || (((x) & 0xff000000) == 0xff000000)
4042

4143
// Insert word into instruction flow
@@ -171,8 +173,8 @@ void asm_arm_entry(asm_arm_t *as, int num_locals) {
171173
if (as->stack_adjust < 0x100) {
172174
emit_al(as, asm_arm_op_sub_imm(ASM_ARM_REG_SP, ASM_ARM_REG_SP, as->stack_adjust));
173175
} else {
174-
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, as->stack_adjust);
175-
emit_al(as, asm_arm_op_sub_reg(ASM_ARM_REG_SP, ASM_ARM_REG_SP, ASM_ARM_REG_R8));
176+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, as->stack_adjust);
177+
emit_al(as, asm_arm_op_sub_reg(ASM_ARM_REG_SP, ASM_ARM_REG_SP, REG_TEMP));
176178
}
177179
}
178180
}
@@ -182,8 +184,8 @@ void asm_arm_exit(asm_arm_t *as) {
182184
if (as->stack_adjust < 0x100) {
183185
emit_al(as, asm_arm_op_add_imm(ASM_ARM_REG_SP, ASM_ARM_REG_SP, as->stack_adjust));
184186
} else {
185-
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, as->stack_adjust);
186-
emit_al(as, asm_arm_op_add_reg(ASM_ARM_REG_SP, ASM_ARM_REG_SP, ASM_ARM_REG_R8));
187+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, as->stack_adjust);
188+
emit_al(as, asm_arm_op_add_reg(ASM_ARM_REG_SP, ASM_ARM_REG_SP, REG_TEMP));
187189
}
188190
}
189191

@@ -293,10 +295,10 @@ void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) {
293295

294296
void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num) {
295297
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));
298+
// mov temp, #local_num*4
299+
// add rd, sp, temp
300+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, local_num << 2);
301+
emit_al(as, asm_arm_op_add_reg(rd, ASM_ARM_REG_SP, REG_TEMP));
300302
} else {
301303
// add rd, sp, #local_num*4
302304
emit_al(as, asm_arm_op_add_imm(rd, ASM_ARM_REG_SP, local_num << 2));
@@ -338,10 +340,10 @@ void asm_arm_ldr_reg_reg_offset(asm_arm_t *as, uint rd, uint rn, uint byte_offse
338340
// ldr rd, [rn, #off]
339341
emit_al(as, 0x5900000 | (rn << 16) | (rd << 12) | byte_offset);
340342
} else {
341-
// mov r8, #off
342-
// ldr rd, [rn, r8]
343-
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, byte_offset);
344-
emit_al(as, 0x7900000 | (rn << 16) | (rd << 12) | ASM_ARM_REG_R8);
343+
// mov temp, #off
344+
// ldr rd, [rn, temp]
345+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, byte_offset);
346+
emit_al(as, 0x7900000 | (rn << 16) | (rd << 12) | REG_TEMP);
345347
}
346348
}
347349

@@ -352,19 +354,19 @@ void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn) {
352354

353355
void asm_arm_ldrh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn) {
354356
// ldrh doesn't support scaled register index
355-
emit_al(as, 0x1a00080 | (ASM_ARM_REG_R8 << 12) | rn); // mov r8, rn, lsl #1
356-
emit_al(as, 0x19000b0 | (rm << 16) | (rd << 12) | ASM_ARM_REG_R8); // ldrh rd, [rm, r8];
357+
emit_al(as, 0x1a00080 | (REG_TEMP << 12) | rn); // mov temp, rn, lsl #1
358+
emit_al(as, 0x19000b0 | (rm << 16) | (rd << 12) | REG_TEMP); // ldrh rd, [rm, temp];
357359
}
358360

359361
void asm_arm_ldrh_reg_reg_offset(asm_arm_t *as, uint rd, uint rn, uint byte_offset) {
360362
if (byte_offset < 0x100) {
361363
// ldrh rd, [rn, #off]
362364
emit_al(as, 0x1d000b0 | (rn << 16) | (rd << 12) | ((byte_offset & 0xf0) << 4) | (byte_offset & 0xf));
363365
} else {
364-
// mov r8, #off
365-
// ldrh rd, [rn, r8]
366-
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, byte_offset);
367-
emit_al(as, 0x19000b0 | (rn << 16) | (rd << 12) | ASM_ARM_REG_R8);
366+
// mov temp, #off
367+
// ldrh rd, [rn, temp]
368+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, byte_offset);
369+
emit_al(as, 0x19000b0 | (rn << 16) | (rd << 12) | REG_TEMP);
368370
}
369371
}
370372

@@ -388,10 +390,10 @@ void asm_arm_str_reg_reg_offset(asm_arm_t *as, uint rd, uint rm, uint byte_offse
388390
// str rd, [rm, #off]
389391
emit_al(as, 0x5800000 | (rm << 16) | (rd << 12) | byte_offset);
390392
} else {
391-
// mov r8, #off
392-
// str rd, [rm, r8]
393-
asm_arm_mov_reg_i32_optimised(as, ASM_ARM_REG_R8, byte_offset);
394-
emit_al(as, 0x7800000 | (rm << 16) | (rd << 12) | ASM_ARM_REG_R8);
393+
// mov temp, #off
394+
// str rd, [rm, temp]
395+
asm_arm_mov_reg_i32_optimised(as, REG_TEMP, byte_offset);
396+
emit_al(as, 0x7800000 | (rm << 16) | (rd << 12) | REG_TEMP);
395397
}
396398
}
397399

@@ -412,8 +414,8 @@ void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn) {
412414

413415
void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn) {
414416
// strh doesn't support scaled register index
415-
emit_al(as, 0x1a00080 | (ASM_ARM_REG_R8 << 12) | rn); // mov r8, rn, lsl #1
416-
emit_al(as, 0x18000b0 | (rm << 16) | (rd << 12) | ASM_ARM_REG_R8); // strh rd, [rm, r8]
417+
emit_al(as, 0x1a00080 | (REG_TEMP << 12) | rn); // mov temp, rn, lsl #1
418+
emit_al(as, 0x18000b0 | (rm << 16) | (rd << 12) | REG_TEMP); // strh rd, [rm, temp]
417419
}
418420

419421
void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn) {

0 commit comments

Comments
 (0)