Skip to content
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

Eliminate redundant register swapping in JIT #384

Merged
merged 1 commit into from
Mar 17, 2024
Merged

Conversation

vacantron
Copy link
Collaborator

In the current register allocation of JIT, we save the host registers before using to keep the consistency of the content between the vm and the host register, even it had not been changed by any other operation after loaded from the stack. This generates lots of redundant store related instructions on the host and reduces the performance of vm.

In this patch, we introduce the dirty flag to record the status of the host register. Once the content of the host register is changed by an operation, the flag is set to 1. The register swapping will only be invoked when the register is dirty in next allocation.

The performance improvement after this patch is shown below:

  • x86-64
Metric Original Improved SpeedUp
dhrystone 0.623 s 0.463 s +25.6%
miniz 3.437 s 2.837 s +17.5%
primes 4.435 s 3.205 s +27.7%
sha512 3.212 s 3.024 s +5.9%
aes 1.708 s 1.545 s +9.5%
qsort 5.236 s 5.219 s +0.3%
  • aarch64
Metric Original Improved SpeedUp
dhrystone 1.003 s 0.897 s +10.6%
miniz 4.312 s 4.107 s +4.8%
primes 9.605 s 8.879 s +7.6%
sha512 5.902 s 5.796 s +1.8%
aes 2.932 s 2.891 s +1.4%
qsort 6.123 s 5.988 s +2.2%

@jserv jserv requested a review from qwe661234 March 13, 2024 11:54
@jserv jserv requested a review from qwe661234 March 16, 2024 01:03
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append "Close #330" at the end of git commit message because the work is considered as completed after RA is refined.

In the current register allocation of JIT, we save the host registers
before using to keep the consistency of the content between the vm and
the host register, even it had not been changed by any other operation
after loaded from the stack. This generates lots of redundant `store`
related instructions on the host and reduces the performance of vm.

In this patch, we introduce the `dirty` flag to record the status of
the host register. Once the content of the host register is changed by
an operation, the flag is set to 1. The register swapping will only be
invoked when the register is dirty in next allocation.

The performance improvement after this patch is shown below:

* x86-64
| Metric    | Original | Improved | SpeedUp |
|-----------+----------+----------+---------|
| dhrystone |  0.623 s |  0.463 s |  +25.6% |
| miniz     |  3.437 s |  2.837 s |  +17.5% |
| primes    |  4.435 s |  3.205 s |  +27.7% |
| sha512    |  3.212 s |  3.024 s |   +5.9% |
| aes       |  1.708 s |  1.545 s |   +9.5% |
| qsort     |  5.236 s |  5.219 s |   +0.3% |

* aarch64
| Metric    | Original | Improved | SpeedUp |
|-----------+----------+----------+---------|
| dhrystone |  1.003 s |  0.897 s |  +10.6% |
| miniz     |  4.312 s |  4.107 s |   +4.8% |
| primes    |  9.605 s |  8.879 s |   +7.6% |
| sha512    |  5.902 s |  5.796 s |   +1.8% |
| aes       |  2.932 s |  2.891 s |   +1.4% |
| qsort     |  6.123 s |  5.988 s |   +2.2% |

Close sysprog21#330
@jserv jserv merged commit e23435e into sysprog21:master Mar 17, 2024
8 checks passed
@jserv
Copy link
Contributor

jserv commented Mar 17, 2024

Thank @vacantron for contributing!

@vacantron vacantron deleted the ra branch March 21, 2024 00:21
@jserv jserv added this to the release-2024.1 milestone Apr 30, 2024
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
Eliminate redundant register swapping in JIT
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.

4 participants