-
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 and dhrystone benchmark now produces faster results than it did previously, and the test results show below. Test environment: 2020 M1 MacBook Pro 13-inch Coremark test result: Previous: 655.631123 Iterations/Sec Now: 791.928093 Iterations/Sec Dhrystone test result: Previous: 712 DMIPS Now: 851 DMIPS Previously, when the function emulate terminated, it returned to function block_emulate because the previous calling route was rv_step -> block_emulate -> emulate. So, each time the function emulate was called, a function stack frame was created. However, function emulate can now use the same function stack because of TCO. That is, any instructions in a basic block can execute function emulate by using the same function stack frame and we save the overhead of creating function stack frame.
- Loading branch information
Showing
3 changed files
with
44 additions
and
38 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