Skip to content

Break instruction decoding and emulation into separate stage #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 11, 2022

Conversation

jserv
Copy link
Contributor

@jserv jserv commented Dec 11, 2022

wip/instruction-decode branch breaks RISC-V instruction decoding and emulation into separate stage, meaning that it is feasible to incorporate further IR optimizations and JIT code generation.

Risheng1128 and others added 16 commits November 8, 2022 01:25
This commit breaks RISC-V instruction decoding and emulation into separate
stage, meaning that it is feasible to incorporate further IR optimizations
and JIT code generation.
                                                                                                                                                              
RISC-V Architecture Test: RV32I/M/C/privilege pass.
This commit introduces the basic block in emulator, meaning that
it makes emulator decode and execute numerous instructions at a
time.

Use hash table and block prediction to manage blocks efficiently.

In decode stage, allocate a new block which contains up to 1024
instruction by default, decode the instruction into block until it
is full or the latest instruction is a branch instruction and put
it into the block map.

In execution stage, emulator executes instructions in block. The
number of instructions based on the member insn_num in struct block.

In particular, when an exception/interrupt occurs, emulator will
do the following steps:
1. Execute the exception/interrupt handler that resets a new program
   counter from the register mtvec and function emulate returns false.
2. Enter to the decode stage again, and create new block based on
   the new program counter.
That is, emulator will stop executing old block and create the new
one from new program counter.

On the other hand, the file decode.c includes the header file
riscv_private.h which includes the gdbstub file. It will make emulator
compile failed because the gdbstub is cloned until compiling emulate.c.
To resolve this problem, swapping the compile order between emulate.o
and decode.o .
At present, only object files are tracked at the early build process,
which prevents header files from being manipulated properly. We shall
add several rules in build system accordingly.
The prefix n_ denotes the number of someting we are referring.
This patch resolves misuse of suffix _t, which should be always treated
as the derived types.
In preparation for future enhancements such as computed-goto, there is a
need for flexible RISC-V instruction enumeration along with configurable
features.
To avoid frequent instruction length checking, move checking into
exception handler block.

Previously, we had to check the instruction length each time the
function 'emulate' was called. Actually, we only need to check it when
the exception occurs; otherwise, we can simply set rv->compressed to
the appropriate value before running the exception handler.

By doing so, we can avoid the overhead of checking instruction length if
an exception does not happen.
@jserv jserv merged commit cd5746b into master Dec 11, 2022
@jserv jserv deleted the wip/instruction-decode branch December 11, 2022 15:42
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
Break instruction decoding and emulation into separate stage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants