py/emitnative: Optimise register clearing.

This commit introduces a new generic ASM API function to clear a
register (i.e. clearing all the registers' bits).

The native emitter used to perform a XOR operation to clear a given
register, but different platform have more optimised method to achieve
the same result taking up less space - either for the generated code or
for the code generator itself.

Arm, RV32, X86, and X64 already had an already optimised generator and
generated optimised code.  The code generator when build for Thumb takes
less space generating a constant immediate move rather than a XOR
operation, even though both operations would distill down to a single
narrow opcode.  On Xtensa the situation is almost the same as Thumb,
with the exception that a constant immediate move would take one byte
less than a XOR operation.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2025-11-04 09:46:16 +01:00
committed by Damien George
parent e67d4a2a77
commit f0895f0ea0
8 changed files with 22 additions and 15 deletions

View File

@@ -485,6 +485,8 @@ void asm_thumb_b_rel12(asm_thumb_t *as, int rel);
asm_thumb_str_rlo_rlo_rlo((as), (reg_val), (reg_base), (reg_index)); \
} while (0)
#define ASM_CLR_REG(as, reg_dest) asm_thumb_mov_rlo_i8((as), (reg_dest), 0)
#endif // GENERIC_ASM_API
#endif // MICROPY_INCLUDED_PY_ASMTHUMB_H