36
36
37
37
#include "py/asmarm.h"
38
38
39
+ #define REG_TEMP ASM_ARM_REG_R8
40
+
39
41
#define SIGNED_FIT24 (x ) (((x) & 0xff800000) == 0) || (((x) & 0xff000000) == 0xff000000)
40
42
41
43
// Insert word into instruction flow
@@ -171,8 +173,8 @@ void asm_arm_entry(asm_arm_t *as, int num_locals) {
171
173
if (as -> stack_adjust < 0x100 ) {
172
174
emit_al (as , asm_arm_op_sub_imm (ASM_ARM_REG_SP , ASM_ARM_REG_SP , as -> stack_adjust ));
173
175
} 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 ));
176
178
}
177
179
}
178
180
}
@@ -182,8 +184,8 @@ void asm_arm_exit(asm_arm_t *as) {
182
184
if (as -> stack_adjust < 0x100 ) {
183
185
emit_al (as , asm_arm_op_add_imm (ASM_ARM_REG_SP , ASM_ARM_REG_SP , as -> stack_adjust ));
184
186
} 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 ));
187
189
}
188
190
}
189
191
@@ -293,10 +295,10 @@ void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) {
293
295
294
296
void asm_arm_mov_reg_local_addr (asm_arm_t * as , uint rd , int local_num ) {
295
297
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 ));
300
302
} else {
301
303
// add rd, sp, #local_num*4
302
304
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
338
340
// ldr rd, [rn, #off]
339
341
emit_al (as , 0x5900000 | (rn << 16 ) | (rd << 12 ) | byte_offset );
340
342
} 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 );
345
347
}
346
348
}
347
349
@@ -352,19 +354,19 @@ void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn) {
352
354
353
355
void asm_arm_ldrh_reg_reg_reg (asm_arm_t * as , uint rd , uint rm , uint rn ) {
354
356
// 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 ];
357
359
}
358
360
359
361
void asm_arm_ldrh_reg_reg_offset (asm_arm_t * as , uint rd , uint rn , uint byte_offset ) {
360
362
if (byte_offset < 0x100 ) {
361
363
// ldrh rd, [rn, #off]
362
364
emit_al (as , 0x1d000b0 | (rn << 16 ) | (rd << 12 ) | ((byte_offset & 0xf0 ) << 4 ) | (byte_offset & 0xf ));
363
365
} 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 );
368
370
}
369
371
}
370
372
@@ -388,10 +390,10 @@ void asm_arm_str_reg_reg_offset(asm_arm_t *as, uint rd, uint rm, uint byte_offse
388
390
// str rd, [rm, #off]
389
391
emit_al (as , 0x5800000 | (rm << 16 ) | (rd << 12 ) | byte_offset );
390
392
} 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 );
395
397
}
396
398
}
397
399
@@ -412,8 +414,8 @@ void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn) {
412
414
413
415
void asm_arm_strh_reg_reg_reg (asm_arm_t * as , uint rd , uint rm , uint rn ) {
414
416
// 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 ]
417
419
}
418
420
419
421
void asm_arm_strb_reg_reg_reg (asm_arm_t * as , uint rd , uint rm , uint rn ) {
0 commit comments