-
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: Intel® Core™ i7-8700 CPU @ 3.20GHz Coremark test result: Previous: 476.792332 Iterations/Sec Now: 911.991797 Iterations/Sec Dhrystone test result: Previous: 414 DMIPS Now: 775 DMIPS 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
3 changed files
with
27 additions
and
23 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