Skip to content

[Bug?] DCache AMO store_data Returns Wrong Value #3768

@canxin121

Description

@canxin121

Summary:

In the DCache module, the io.cpu.resp.bits.store_data field incorrectly returns the original store input data for Atomic Memory Operations (AMOs), instead of returning the computed result from the AMOALU.

Technical Details:

When an AMO instruction executes (e.g., amoadd, amoswap), the AMOALU computes the result and stores it in pstore1_storegen_data. However, the response field store_data was unconditionally assigned from pstore1_data (the original input from the CPU register), ignoring the AMO computation.

Location:

  • File: src/main/scala/rocket/DCache.scala
  • Line: ~975 (in unfixed version)

Impact:

This bug is latent in the current codebase because store_data is not actively used by downstream logic. However, it becomes visible when:

  • Logging or tracing AMO operations that read this field
  • Future features that rely on store_data to retrieve the actual stored value

Root Cause:

Missing runtime multiplexer to distinguish between AMO operations (which need the computed result) and regular STORE operations (which use the input data).

Fix:

Replace the unconditional assignment:

io.cpu.resp.bits.store_data := pstore1_data

With a conditional assignment based on operation type:

io.cpu.resp.bits.store_data := Mux(isAMO(pstore1_cmd), pstore1_storegen_data, pstore1_data)

This ensures AMO operations return the computed result while regular stores continue to return the input data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions