Skip to content

sign-extend rs2 for AMOMIN.W/AMOMAX.W operations#267

Open
zyk632 wants to merge 1 commit into
OSCPU:masterfrom
zyk632:fix/amomin-word-sign-extension
Open

sign-extend rs2 for AMOMIN.W/AMOMAX.W operations#267
zyk632 wants to merge 1 commit into
OSCPU:masterfrom
zyk632:fix/amomin-word-sign-extension

Conversation

@zyk632

@zyk632 zyk632 commented Jul 12, 2026

Copy link
Copy Markdown

fix(atomalu): sign-extend rs2 for AMOMIN.W/AMOMAX.W operations

Summary

Fix a hardware bug in AtomALU where rs2 is not properly sign-extended for .W atomic operations.

Background & Changes

In LSU.scala:181 (AtomALU), the following issues were identified:

  • AMOMIN.W / AMOMAX.W: rs2 was not sign-extended from 32-bit to 64-bit
  • AMOMINU.W / AMOMAXU.W: rs2 was not zero-extended for unsigned comparison

Example: 0x00000000ffffffff should be treated as -1 for AMOMIN.W, but the original RTL treated it as a positive 64-bit value (0xffffffff).

Fix applied:

  • Signed word operations (AMOMIN.W/AMOMAX.W): sign-extend lower 32 bits of rs2
  • Unsigned word operations (AMOMINU.W/AMOMAXU.W): zero-extend lower 32 bits of rs2
  • .D operations: unchanged (64-bit behavior)

Test Results

Before fix:
a0 different: right = 0xffffffffffffffff, wrong = 0x0000000000000001
After fix:
HIT GOOD TRAP at pc = 0x800000d2, exit code = 0
All 35 existing NutShell cputest images pass DiffTest (failed=0).

Modified Files

  • src/main/scala/nutcore/backend/fu/LSU.scala: Fix rs2 extension for .W AMO operations

Release Notes

Fix signed/unsigned comparison behavior for AMOMIN.W/AMOMAX.W/AMOMINU.W/AMOMAXU.W operations in AtomALU.

  • I have tested these changes locally

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.

1 participant