Skip to content

Commit a871e8c

Browse files
committed
Fix immediate decoding
The original decode of `ir->imm` used zero-extension, it should be sign-extension.
1 parent 83b404f commit a871e8c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/decode.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,14 @@ static inline bool op_cfsw(rv_insn_t *ir, const uint32_t insn)
19401940

19411941
#if RV32_HAS(EXT_V) /* (RV32_HAS(EXT_V) */
19421942

1943+
/*
1944+
* Sign extened vector immediate
1945+
*/
1946+
static inline int32_t decode_v_imm(const uint32_t insn)
1947+
{
1948+
return ((int32_t)((insn << 12) & FR4_RS3)) >> 27;
1949+
}
1950+
19431951
/* decode vsetvli zimm[10:0] field
19441952
* zimm = inst[30:20]
19451953
*/
@@ -2048,7 +2056,7 @@ static inline void decode_vvtype(rv_insn_t *ir, const uint32_t insn)
20482056
static inline void decode_vitype(rv_insn_t *ir, const uint32_t insn)
20492057
{
20502058
ir->vs2 = decode_rs2(insn);
2051-
ir->imm = decode_rs1(insn);
2059+
ir->imm = decode_v_imm(insn);
20522060
ir->vd = decode_rd(insn);
20532061
ir->vm = decode_vm(insn);
20542062
}
@@ -4200,18 +4208,14 @@ bool rv_decode(rv_insn_t *ir, uint32_t insn)
42004208
/* Acording to https://github.com/riscvarchive/riscv-v-spec/blob/master/inst-table.adoc this table is for function6. */
42014209
// 000 001 010 011 100 101 110 111
42024210
OP(000000), OP(000001), OP(000010), OP(000011), OP(000100), OP(000101), OP(000110), OP(000111), // 000
4203-
OP(001000), OP(001001), OP(001010), OP(001011), OP(001100), OP(unimp), OP(001110), OP(001111), // 001
4204-
OP(010000), OP(010001), OP(010010), OP(010011), OP(010100), OP(unimp), OP(unimp), OP(010111), // 010
4211+
OP(001000), OP(001001), OP(001010), OP(001011), OP(001100), OP(unimp), OP(001110), OP(001111), // 001
4212+
OP(010000), OP(010001), OP(010010), OP(010011), OP(010100), OP(unimp), OP(unimp), OP(010111), // 010
42054213
OP(011000), OP(011001), OP(011010), OP(011011), OP(011100), OP(011101), OP(011110), OP(011111), // 011
42064214
OP(100000), OP(100001), OP(100010), OP(100011), OP(100100), OP(100101), OP(100110), OP(100111), // 100
42074215
OP(101000), OP(101001), OP(101010), OP(101011), OP(101100), OP(101101), OP(101110), OP(101111), // 101
42084216
OP(110000), OP(110001), OP(110010), OP(110011), OP(110100), OP(110101), OP(110110), OP(110111), // 110
4209-
OP(111000), OP(unimp), OP(111010), OP(111011), OP(111100), OP(111101), OP(111110), OP(111111) // 111
4217+
OP(111000), OP(unimp), OP(111010), OP(111011), OP(111100), OP(111101), OP(111110), OP(111111) // 111
42104218
};
4211-
// /* RVV vector opcode map */
4212-
// static const decode_t MOP_table[] = {
4213-
4214-
// }
42154219
#endif
42164220
/* clang-format on */
42174221

@@ -4255,4 +4259,4 @@ bool rv_decode(rv_insn_t *ir, uint32_t insn)
42554259

42564260
#undef OP_UNIMP
42574261
#undef OP
4258-
}
4262+
}

src/emulate.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ static void block_translate(riscv_t *rv, block_t *block)
655655
break;
656656
}
657657
ir->impl = dispatch_table[ir->opcode];
658-
ir->pc = block->pc_end;
659-
660-
/* compute the end of pc */
658+
ir->pc = block->pc_end; /* compute the end of pc */
661659
block->pc_end += is_compressed(insn) ? 2 : 4;
662660
block->n_insn++;
663661
prev_ir = ir;

0 commit comments

Comments
 (0)