test: add valid positive and negative J-type immediate encoding tests to encoder#606
Open
amathxbt wants to merge 1 commit into
Open
test: add valid positive and negative J-type immediate encoding tests to encoder#606amathxbt wants to merge 1 commit into
amathxbt wants to merge 1 commit into
Conversation
test_j_type_jump_boundaries previously used 1048576 (2^20) as both "positive" and "negative" 1 MB jumps. Because 2^20 equals the minimum value in a 21-bit two's-complement immediate field, both op_c values produce the same 32-bit encoding (0x800000EF), so the test did not exercise the encoder's handling of any valid negative offset. Replace the ambiguous test cases with: - JAL x1, +16 (valid positive) -> 0x10000EF - JAL x1, -8 (valid negative) -> 0xFF9FF0EF The expected values are derived from the RISC-V J-type bit-field layout and confirmed manually. The original ±1 MB case is retained with a comment explaining the two's-complement identity.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Problem
test_j_type_jump_boundariesusesop_c = 1048576(2^20) for the “positive” case andop_c = -1048576i32 as u32for the “negative” case, then asserts both produce0x800000EF.This is not a sign error — it is a two’s-complement identity: 2^20 equals the minimum representable value in a 21-bit signed immediate field (the J-type field width), so the two
op_cvalues are bit-for-bit identical. The test never exercises any valid negative jump offset, leaving the encoder’s negative-immediate path entirely untested.The B-type test (
test_b_type_branch_offsets) correctly tests a negative offset (BEQ x1, x2, -16); the J-type test should do the same.Fix
Add two concrete test cases that cover valid positive and negative J-type immediates:
JAL x1, +160x10000EFJAL x1, -8-8i32 as u320xFF9FF0EFExpected values are derived from the RISC-V J-type bit-field layout (spec §2.5) and verified manually. The original ±1 MB case is retained with a comment explaining the two’s-complement identity.