Fix: RV32 SLL/SRL/SRA mask shift amount#18
Conversation
Shift counts >= 32 gave wrong results; add edge-case tests for masking
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis pull request changes RV32 register-shift semantics to mask the shift amount to rs2[4:0] (0x1f) for SLL, SRL, and SRA; implementations perform shifts on 32-bit-cast operands and return int64 results. Tests for SLL/SRL/SRA are expanded with edge-case shift amounts above 31. ChangesRV32 Shift Instruction Masking
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ExecuteI.fs (2)
302-304: ⚡ Quick winUpdate or remove misplaced comment block.
This comment describes shift instruction behavior but appears inside the
execSLTfunction (Set Less Than), not inside a shift function. It should either be moved to the appropriate shift instruction or removed from this location.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ExecuteI.fs` around lines 302 - 304, The comment about SLL, SRL, and SRA (logical left/right and arithmetic right shifts using low 6 bits of rs2 in RV64I) is misplaced inside execSLT; move that comment to the shift-instruction handler(s) (e.g., the functions handling SLL, SRL, SRA) or remove it here so execSLT contains only relevant commentary about set-less-than semantics; ensure the relocated comment accompanies the shift implementation (references: execSLT, SLL, SRL, SRA, rs1, rs2, RV64I).
329-331: ⚡ Quick winUpdate comments to document RV32I masking behavior.
These comments currently state "In RV64I, only the low 6 bits of rs2 are considered for the shift amount" but omit the RV32I behavior. Now that the implementation correctly masks to the low 5 bits for RV32I, the comments should reflect both modes.
📝 Suggested comment update
-// SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register -// rs1 by the shift amount held in register rs2. In RV64I, only the low 6 bits of rs2 are considered for the -// shift amount. +// SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register +// rs1 by the shift amount held in register rs2. In RV32I, only the low 5 bits of rs2 are considered for the +// shift amount. In RV64I, only the low 6 bits of rs2 are considered for the shift amount.Also applies to: 346-348
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ExecuteI.fs` around lines 329 - 331, Update the block comments that describe SLL, SRL, and SRA to document both RV64I and RV32I masking rules: state that in RV64I only the low 6 bits of rs2 are used as the shift amount and in RV32I only the low 5 bits are used; apply this change to the comment blocks around the SLL/SRL/SRA descriptions (the ExecuteI implementation comments) and also update the corresponding comment at the other occurrence noted (the second block around the same SLL/SRL/SRA descriptions).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ExecuteI.fs`:
- Around line 302-304: The comment about SLL, SRL, and SRA (logical left/right
and arithmetic right shifts using low 6 bits of rs2 in RV64I) is misplaced
inside execSLT; move that comment to the shift-instruction handler(s) (e.g., the
functions handling SLL, SRL, SRA) or remove it here so execSLT contains only
relevant commentary about set-less-than semantics; ensure the relocated comment
accompanies the shift implementation (references: execSLT, SLL, SRL, SRA, rs1,
rs2, RV64I).
- Around line 329-331: Update the block comments that describe SLL, SRL, and SRA
to document both RV64I and RV32I masking rules: state that in RV64I only the low
6 bits of rs2 are used as the shift amount and in RV32I only the low 5 bits are
used; apply this change to the comment blocks around the SLL/SRL/SRA
descriptions (the ExecuteI implementation comments) and also update the
corresponding comment at the other occurrence noted (the second block around the
same SLL/SRL/SRA descriptions).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 66a9dc1b-4fc5-4634-9328-94d1a7b952b6
📒 Files selected for processing (2)
ExecuteI.fsTests/rv32i/alu.fs
Summary by CodeRabbit
Bug Fixes
Tests