Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid generating machine code repeatly for same basic block #378

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

qwe661234
Copy link
Collaborator

@qwe661234 qwe661234 commented Mar 11, 2024

Originally, every execution path had its own machine code. Therefore, even if some basic blocks had been traced in other execution paths, we still generated a new copy of machine code. To use the code cache space more efficiently, we modified the recorded table to be global, allowing every execution path to share the machine code. This modification ensures that every basic block has only one copy of machine code, thus saving code cache space.

For example, the code cache stored 1,926,471 (1.9 MB) bytes of machine code for AES previously. After the modification, the code cache stored 182,730 (0.18 MB) bytes of machine code.

@jserv jserv requested review from vacantron and henrybear327 March 11, 2024 07:30
src/jit.c Outdated Show resolved Hide resolved
@qwe661234 qwe661234 force-pushed the save_code_cache branch 2 times, most recently from 172daff to eb9221c Compare March 11, 2024 12:01
@qwe661234 qwe661234 requested a review from jserv March 11, 2024 12:02
@@ -56,7 +56,8 @@
#define JIT_OP_MOD_REG (JIT_CLS_ALU | JIT_SRC_REG | 0x90)

#define STACK_SIZE 512
#define MAX_INSNS 1024
#define MAX_JUMPS 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you show empirical adjustments for both MAX_JUMPS and MAX_INSNS. I wonder how they can be calculated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The MAX_JUMPS means the number of host branch instructions within a chained block collection need to be resolved.

Copy link
Collaborator Author

@qwe661234 qwe661234 Mar 12, 2024

Choose a reason for hiding this comment

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

I modified MAX_INSNS into MAX_BLOCKS because it refers to the total number of basic blocks within our code cache. Considering that our block cache size is 4096 and some blocks may be replaced, I set MAX_BLOCKS to 8192.

src/jit.c Outdated Show resolved Hide resolved
src/jit.c Outdated Show resolved Hide resolved
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.

Drop the trailing dot in the subject of git commit messages.
See https://cbea.ms/git-commit/

@qwe661234 qwe661234 requested a review from jserv March 12, 2024 02:29
src/jit.c Outdated Show resolved Hide resolved
We set 256 as the threshold because we recorded 16 indirect jumps, and
the threshold for launching T1C is 4096. This modification also saves
code cache space by avoiding storing the machine code with less usage.
Originally, every execution path had its own machine code. Therefore,
even if some basic blocks had been traced in other execution paths, we
still generated a new copy of machine code. To use the code cache space
more efficiently, we modified the recorded table to be global, allowing
every execution path to share the machine code. This modification
ensures that every basic block has only one copy of machine code, thus
saving code cache space.

For example, the code cache stored 1,926,471 (1.9 MB) bytes of machine
code for AES previously. After the modification, the code cache stored
182,730 (0.18 MB) bytes of machine code.
@qwe661234 qwe661234 requested a review from jserv March 12, 2024 03:18
@jserv jserv merged commit 2935d30 into sysprog21:master Mar 12, 2024
8 checks passed
@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
Avoid generating machine code repeatly for same basic block
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants