diff options
author | Alessandro Gatti <a.gatti@frob.it> | 2025-07-10 00:50:15 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-08-11 22:31:13 +1000 |
commit | 0ee3f99da24e678a415a1d0b4575c38ad51430fe (patch) | |
tree | 9ff9c116d3f89bc4934793e7d33a972409dbf25d | |
parent | b1d5c656de3f11fc1729f165c8d9709594ccbfb6 (diff) |
py/asmrv32: Make lt/le comparisons emitter shorter.HEADorigin/masterorigin/HEADmaster
This commit simplifies the emitter code in charge of generating opcodes
performing less-than and less-than-or-equal comparisons.
By rewriting the SLT/SLTU opcode generator (handling less-than
comparisons) and de-inlining the less-than comparison generator call in
the less-than-or-equal generator, the output binary is ~80 bytes smaller
(measurements taken from the QEMU port).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
-rw-r--r-- | py/asmrv32.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/py/asmrv32.c b/py/asmrv32.c index 158b55219..723d32cdd 100644 --- a/py/asmrv32.c +++ b/py/asmrv32.c @@ -573,12 +573,8 @@ void asm_rv32_meta_comparison_ne(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2 } void asm_rv32_meta_comparison_lt(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2, mp_uint_t rd, bool unsigned_comparison) { - // slt(u) rd, rs1, rs2 - if (unsigned_comparison) { - asm_rv32_opcode_sltu(state, rd, rs1, rs2); - } else { - asm_rv32_opcode_slt(state, rd, rs1, rs2); - } + // slt|sltu rd, rs1, rs2 + asm_rv32_emit_word_opcode(state, RV32_ENCODE_TYPE_R(0x33, (0x02 | (unsigned_comparison ? 1 : 0)), 0x00, rd, rs1, rs2)); } void asm_rv32_meta_comparison_le(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2, mp_uint_t rd, bool unsigned_comparison) { @@ -588,11 +584,7 @@ void asm_rv32_meta_comparison_le(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2 // ... ; PC + 8 asm_rv32_opcode_cli(state, rd, 1); asm_rv32_opcode_beq(state, rs1, rs2, 8); - if (unsigned_comparison) { - asm_rv32_opcode_sltu(state, rd, rs1, rs2); - } else { - asm_rv32_opcode_slt(state, rd, rs1, rs2); - } + asm_rv32_meta_comparison_lt(state, rs1, rs2, rd, unsigned_comparison); } #endif // MICROPY_EMIT_RV32 |