We tested the size of the field encoding, not the
actual range of values.
Signed-off-by: Richard Henderson <[email protected]>
---
tcg/riscv64/tcg-target.c.inc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tcg/riscv64/tcg-target.c.inc b/tcg/riscv64/tcg-target.c.inc
index e8e1480016c..c167ff5237a 100644
--- a/tcg/riscv64/tcg-target.c.inc
+++ b/tcg/riscv64/tcg-target.c.inc
@@ -480,7 +480,8 @@ static tcg_insn_unit encode_s(RISCVInsn opc, TCGReg rs1,
static bool encode_bimm12(tcg_insn_unit *insn, tcg_target_long imm)
{
- if ((imm & 1) == 0 && imm == sextract32(imm, 0, 12)) {
+ /* The 13-bit immediate is stored in 12 bits, with bit 0 zero. */
+ if ((imm & 1) == 0 && imm == sextract32(imm, 0, 13)) {
*insn |= ((imm & 0x1000) << 19
| (imm & 0x7e0) << 20
| (imm & 0x1e) << 7
@@ -516,7 +517,8 @@ static tcg_insn_unit encode_u(RISCVInsn opc, TCGReg rd,
tcg_target_long imm)
static bool encode_jimm20(tcg_insn_unit *insn, tcg_target_long imm)
{
- if ((imm & 1) == 0 && imm == sextract32(imm, 0, 20)) {
+ /* The 21-bit immediate is stored in 20 bits, with bit 0 zero. */
+ if ((imm & 1) == 0 && imm == sextract32(imm, 0, 21)) {
*insn |= ((imm & 0x0007fe) << (21 - 1)
| (imm & 0x000800) << (20 - 11)
| (imm & 0x0ff000) << (12 - 12)
--
2.53.0