fix(BPU): btbHit is incorrectly invalidated causing the correct PHT result to be invalidated #147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Behavior
I was trying to implement GShare algorithm on NutShell's BPU(ngc7331@bc7cddf), then I noticed something strange (lines 1, 6 and 7 of the log below).
So I added more logs to the ALU and BPU, giving line 5 and lines 2~4 above, respectively. We can see that:
To sum up, the correct PHT result is invalidated and caused the IFU to operate on the wrong fetch path, reducing branch prediction accuracy and IPC.
The correct log should look like:
The original BPU behaves exactly the same except for the GHR update mechanism, so it's not a bug of my changes on the fork.
Solution
NutShell/src/main/scala/nutcore/frontend/BPU.scala
Line 311 in aeb6019
NutShell/src/main/scala/nutcore/frontend/BPU.scala
Line 320 in aeb6019
Notice the
RegNext(btb.io.r.req.fire, init = false.B)
inbtbHit
. It is only valid for one cycle after the request is valid (io.in.pc.valid = 1
), but the IFU is not guaranteed a successful handshake with the imem in that cycle, causing the problem.On the other hand,
btbRead.valid
seems to be enough to ensure thatbtbHit
is valid.Therefore, a quick solution is to just delete this
RegNext
.The modifications are tested using:
And the result shows a 2%~14% increase on prediction accuracy and 1.5%~7% increase on IPC over baseline (aeb6019).
Note: In the above table, the "right" column in the "IPC" row is the actual IPC value and the "acc" column is the ratio to baseline.