From b50efbd0e319764dab3f49b64519cfea5f2c2bab Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 12:30:09 +1100 Subject: [PATCH] py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints. Signed-off-by: Damien George --- py/asmxtensa.c | 4 +++- py/asmxtensa.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/py/asmxtensa.c b/py/asmxtensa.c index 84018402f6..0fbe351dcf 100644 --- a/py/asmxtensa.c +++ b/py/asmxtensa.c @@ -185,7 +185,9 @@ size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { } void asm_xtensa_mov_reg_i32_optimised(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { - if (SIGNED_FIT12(i32)) { + if (-32 <= (int)i32 && (int)i32 <= 95) { + asm_xtensa_op_movi_n(as, reg_dest, i32); + } else if (SIGNED_FIT12(i32)) { asm_xtensa_op_movi(as, reg_dest, i32); } else { asm_xtensa_mov_reg_i32(as, reg_dest, i32); diff --git a/py/asmxtensa.h b/py/asmxtensa.h index aef9e74625..f226624a82 100644 --- a/py/asmxtensa.h +++ b/py/asmxtensa.h @@ -203,8 +203,9 @@ static inline void asm_xtensa_op_movi(asm_xtensa_t *as, uint reg_dest, int32_t i asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 10, (imm12 >> 8) & 0xf, reg_dest, imm12 & 0xff)); } -static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm4) { - asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm4)); +// Argument must be in the range (-32 .. 95) inclusive. +static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm7) { + asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm7)); } static inline void asm_xtensa_op_mull(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {