Fix RV64 Zcmp push/pop offsets - #3564
Open
124107157-KV wants to merge 1 commit into
Open
124107157-KV wants to merge 1 commit into
124107157-KV wants to merge 1 commit into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this PR needed?
The RV64 Zcmp PUSH/POP macro expansion currently uses the RV32 register-slot size when calculating stack offsets.
On RV32, registers occupy 4-byte stack slots, so decrementing the generated offset by 4 bytes is correct. On RV64, however, the generated
SDandLDoperations operate on 8-byte values and therefore the offset must advance in 8-byte steps.The existing implementation continues to decrement offsets by 4 bytes for both XLEN values and compensates for RV64 by forcing immediate bit 2 of generated
SD/LDinstructions to zero. This causes consecutive RV64 register accesses to alias the same stack location.For example:
should expand on RV64 as:
Before this change, the expansion effectively produces overlapping stack accesses:
The same offset problem affects
cm.pop,cm.popret, andcm.popretz.The RV64 path also applies an additional 4-byte correction to the final stack-pointer update. As a result, PUSH adjusts SP by four bytes too much and POP-family instructions adjust SP by four bytes too little.
What does this PR change?
This PR makes the Zcmp register-slot offset dependent on XLEN:
The new XLEN-dependent offset is used throughout the PUSH/POP macro expansion state machine.
The change also:
SDandLDinstructions;PUSH_POP_INSTR_2.Verification
A focused RV64 macro-decoder regression was added.
Before applying the RTL fix, the regression reproduced the issue with the following incorrect behavior:
cm.push {ra,s0-s1}, -32s1:-8(sp)s0:-8(sp)instead of-16(sp)ra:-16(sp)instead of-24(sp)-36instead of-32cm.pop {ra,s0-s1}, 32s1:24(sp)s0:24(sp)instead of16(sp)ra:16(sp)instead of8(sp)28instead of32the maximum-rlist PUSH and POP paths also repeated adjacent stack offsets instead of progressing by 8 bytes.
After the fix, the RV64 regression verifies:
cm.push-8,-16, and-24-32cm.pop24,16, and832cm.popretcm.popretza0maximum-rlist PUSH/POP offset progression through
PUSH_POP_INSTR_2.The existing RV32 macro-decoder regression continues to pass.
The following checks were run successfully:
The full RV64 Verilator build completes successfully.
Related issue
Fixes #3440
Limitations
The new regression tests the macro decoder directly rather than executing the compressed instructions as a full architectural software test.