Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Data misalignment detection different for LBU vs LB instruction #84

Open
viniul opened this issue Sep 15, 2024 · 1 comment
Open

Data misalignment detection different for LBU vs LB instruction #84

viniul opened this issue Sep 15, 2024 · 1 comment

Comments

@viniul
Copy link

viniul commented Sep 15, 2024

The data misalignment detection is implemented as follows:

   // Data misalignment detection
   // For example, if type is 3 (word), the mask is ~(0b111 << (3 - 1)) = ~0b100 = 0b011.
   val misaligned_mask = Wire(UInt(3.W))
   misaligned_mask := ~(7.U(3.W) << (cs_msk_sel - 1.U)(2, 0))
   data_misaligned := (misaligned_mask & io.dat.mem_address_low).orR && mem_en

where cs_msk_sel is dependent on the instruction and is 5 (MT_BU ) for an LBU instruction, and 0(MT_B) for a LB instruction in the 1-stage Sodor core.

This results in a different misaligned_mask for LBU (mask will be 111) vs. LB (mask will be 000) instructions. Consequentially, some loads being flagged as misaligned for an LBU instruction, but not being flagged as misaligned for an LB instruction.

Consider the instruction sequence:

addi x15, x0, 1
slli x15, x15, 31
lb x1, 1(x15)

which correctly returns 07, but switching from lb to lbu will result in an data misaligned exception.

Is this intentional? If so, what is the rationale behind this choice?

@jerryz123
Copy link
Contributor

This seems like a bug. A PR with the fix would be appreciated.

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

No branches or pull requests

2 participants