Skip to content

Commit 569c378

Browse files
committed
Introduce basic block
This commit introduces the basic block in emulator, meaning that it makes emulator decode and execute numerous instructions at a time.
1 parent 2aa7154 commit 569c378

File tree

5 files changed

+197
-92
lines changed

5 files changed

+197
-92
lines changed

src/decode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,9 +1663,9 @@ static inline bool op_unimp(struct rv_insn_t *rv_insn UNUSED,
16631663
typedef bool (*decode_t)(struct rv_insn_t *rv_insn, uint32_t insn);
16641664

16651665
/* decode RISC-V instruction */
1666-
bool rv_decode(struct rv_insn_t *ir, uint32_t insn, uint8_t *insn_len)
1666+
bool rv_decode(struct rv_insn_t *ir, uint32_t insn)
16671667
{
1668-
assert(ir && insn_len);
1668+
assert(ir);
16691669

16701670
#define OP_UNIMP op_unimp
16711671
#define OP(insn) op_##insn
@@ -1704,7 +1704,7 @@ bool rv_decode(struct rv_insn_t *ir, uint32_t insn, uint8_t *insn_len)
17041704
if ((insn & FC_OPCODE) != 3) {
17051705
insn &= 0x0000FFFF;
17061706
const uint16_t c_index = (insn & FC_FUNC3) >> 11 | (insn & FC_OPCODE);
1707-
*insn_len = INSN_16;
1707+
ir->insn_len = INSN_16;
17081708

17091709
/* decode instruction (compressed instructions) */
17101710
const decode_t op = rvc_jump_table[c_index];
@@ -1715,7 +1715,7 @@ bool rv_decode(struct rv_insn_t *ir, uint32_t insn, uint8_t *insn_len)
17151715

17161716
/* standard uncompressed instruction */
17171717
const uint32_t index = (insn & INSN_6_2) >> 2;
1718-
*insn_len = INSN_32;
1718+
ir->insn_len = INSN_32;
17191719

17201720
/* decode instruction */
17211721
const decode_t op = rv_jump_table[index];

src/decode.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ struct rv_insn_t {
236236
#if RV32_HAS(EXT_C)
237237
uint8_t shamt;
238238
#endif
239+
240+
/* instruction length */
241+
uint8_t insn_len;
242+
};
243+
244+
/* a translated basic block */
245+
struct block_t {
246+
/* start of this blocks code */
247+
struct rv_insn_t *ir;
248+
/* index of instructions encompased */
249+
uint32_t index;
250+
/* maximum of instructions encompased */
251+
uint32_t ir_capacity;
239252
};
240253

241254
/* sign extend a 16 bit value */
@@ -251,6 +264,4 @@ static inline uint32_t sign_extend_b(const uint32_t x)
251264
}
252265

253266
/* decode the RISC-V instruction */
254-
bool rv_decode(struct rv_insn_t *rv_insn,
255-
const uint32_t insn,
256-
uint8_t *insn_len);
267+
bool rv_decode(struct rv_insn_t *rv_insn, const uint32_t insn);

0 commit comments

Comments
 (0)