-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use TCO of C compiler to speed up emulation
We need to modify the function emulate into a recursive version for meeting the requirement of tail-call optimization(TCO). To achieve this, I add a variable is_tail to the struct rv_insn_t to help us determine whether the basic block is terminate or not. As a result, we can use this variable to rewrite function emulate into a self-recursive function. Running coremark benchmark now produces faster results than it did previously, and the test results show below. Test environment1: Ubuntu Linux 20.04 on Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz Compiler: gcc 9.4.0 Coremark test result: Previous: 870.317612 Iterations/Sec Now: 920.675364 Iterations/Sec ----------------------------------------------------------------------- Test environment2: Ubuntu Linux 20.04 on Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz Compiler: clang-16 Coremark test result: Previous: 805.702322 Iterations/Sec Now: 849.445119 Iterations/Sec ----------------------------------------------------------------------- Test environment3: Ubuntu Linux on eMAG Compiler: gcc 11.3.0 Coremark test result: Previous: 311.436129 Iterations/Sec Now: 313.900684 Iterations/Sec ----------------------------------------------------------------------- Test environment4: Ubuntu Linux on eMAG Compiler: clang-16 Coremark test result: Previous: 273.265220 Iterations/Sec Now: 297.255706 Iterations/Sec Previously, when the function emulate terminated, it returned to function block_emulate because the previous calling route was rv_step -> block_emulate -> emulate -> block_emulate -> emulate -> ... . So, each time the function emulate was called, a function stack frame was created. However, the current calling route is rv_step -> emulate -> emulate -> ..., so function emulate can now use the same function stack frame because of TCO. That is, any instructions in a basic block can execute function emulate by using the same function stack frame and save the overhead of creating function stack frame.
- Loading branch information
Showing
4 changed files
with
48 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters