-
Notifications
You must be signed in to change notification settings - Fork 99
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
Compare with libriscv #288
Comments
Build libriscv and its command line interface. $ git clone https://github.com/libriscv/libriscv
$ cd libriscv/emulator
$ ./build.sh Since libriscv relies on latest C++ features, recent clang might be required. Consider the following changes:
--- a/emulator/CMakeLists.txt
+++ b/emulator/CMakeLists.txt
@@ -43,7 +43,7 @@ endif()
if (LTO)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=full")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
else()
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
--- a/emulator/build.sh
+++ b/emulator/build.sh
@@ -3,8 +3,8 @@ set -e
mkdir -p .build
pushd .build
-cmake .. -DCMAKE_BUILD_TYPE=Release
-make -j6
+cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++-17
+make -j6 VERBOSE=1
popd
if test -f ".build/rvmicro"; then Use It is important to comprehend the reasons behind libriscv's superior performance compared to rv32emu in pure interpreter mode. |
I conducted experiments comparing the interpreter modes of libriscv and rv32emu. The results are shown in the following chart, where we can clearly observe that libriscv performs better: Furthermore, I observed that the number of executed instructions was nearly identical:
Therefore, I began to examine libriscv's implementation. graph TD
A[Load ELF file] --> C[Generate Decoder Cache]
C --> D[Main loop]
D --> E[Fetch instruction from Decoder Cache]
E --> F[Execute instruction]
F --> G[Update PC]
G --> E
After loading the ELF file, the entire executable segment is pre-decoded to generate a cache. This approach reduces repetitive decoding during execution. |
When rv32emu has a complete MMU, perhaps we can reference some of libriscv's experimental features. |
libriscv is a compact yet comprehensive RISC-V userspace emulator library crafted for effortless embedding and extensive adaptability. It boasts a high-performing interpreter and an experimental binary translator, driven by TinyCC. When binary translation is activated, libtcc seamlessly integrates into the RISC-V emulator, taking on the role of the compiler for binary translation.
Interestingly, both libriscv and rv32emu share some common concepts and objectives. It would be valuable to engage in a comparative analysis to explore aspects such as interpretation and binary translation performance, techniques for ensuring secure sandboxed execution, and strategies for implementing userspace RISC-V emulation.
Expected outcomes:
Reference:
The text was updated successfully, but these errors were encountered: