chipsalliance / chipsalliance/rocket-chip

[Bug?] DCache AMO store_data Returns Wrong Value

Open
#3,768 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
3.9k
Forks
1.3k
Avg merge
5d 13m
Merged PRs (30d)
1

Description

**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:
```scala
io.cpu.resp.bits.store_data := pstore1_data
```

With a conditional assignment based on operation type:
```scala
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.

Contributor guide

Open the contributing guide

Research direction

Start in src/main/scala/rocket/DCache.scala around line 975 and inspect how pstore1_data, pstore1_storegen_data, and the AMO operation type feed io.cpu.resp.bits.store_data. Verify the behavior for AMO and regular STORE operations, then run the relevant DCache tests to confirm that AMOs report their computed result while regular stores retain their input data.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
embedded-iot
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.