Skip to content

Commit 0ee3f99

Browse files
agattidpgeorge
authored andcommitted
py/asmrv32: Make lt/le comparisons emitter shorter.
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>
1 parent b1d5c65 commit 0ee3f99

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

py/asmrv32.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,8 @@ void asm_rv32_meta_comparison_ne(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2
573573
}
574574

575575
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) {
576-
// slt(u) rd, rs1, rs2
577-
if (unsigned_comparison) {
578-
asm_rv32_opcode_sltu(state, rd, rs1, rs2);
579-
} else {
580-
asm_rv32_opcode_slt(state, rd, rs1, rs2);
581-
}
576+
// slt|sltu rd, rs1, rs2
577+
asm_rv32_emit_word_opcode(state, RV32_ENCODE_TYPE_R(0x33, (0x02 | (unsigned_comparison ? 1 : 0)), 0x00, rd, rs1, rs2));
582578
}
583579

584580
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
588584
// ... ; PC + 8
589585
asm_rv32_opcode_cli(state, rd, 1);
590586
asm_rv32_opcode_beq(state, rs1, rs2, 8);
591-
if (unsigned_comparison) {
592-
asm_rv32_opcode_sltu(state, rd, rs1, rs2);
593-
} else {
594-
asm_rv32_opcode_slt(state, rd, rs1, rs2);
595-
}
587+
asm_rv32_meta_comparison_lt(state, rs1, rs2, rd, unsigned_comparison);
596588
}
597589

598590
#endif // MICROPY_EMIT_RV32

0 commit comments

Comments
 (0)