NaxRiscv icon indicating copy to clipboard operation
NaxRiscv copied to clipboard

Default branch direction prediction should be TAKEN (currently NOT TAKEN)

Open ronan-lashermes opened this issue 5 months ago • 1 comments

Rationale

Because our programs usually have lots of loops, the cold state of the branch direction predictor (GSHARE for Nax) should be TAKEN. In the current state of affairs, we need to fill the GHB before we get correct TAKEN predictions in a loop.

Implementation

Got a ~2% performance gain on the small program I am actually working on (not a serious test, but an indication nonetheless)

Simulation

In GSharePlugin.scala, l71-73, replace the 0 default value with -1:

if(GenerationFlags.simulation) {
        counter.initBigInt(List.fill(counter.wordCount)(BigInt(- 1)), allowNegative = true)
}

Targeting synthesis

Here I am not sure since we want to initialize a Mem value and I am only simulating. My tentative, in GSharePlugin.scala, l39-41, replace with:

val keys = new AreaRoot {
      val GSHARE_COUNTER = Stageable(Vec.fill(SLICE_COUNT)(U(pow(2, counterWidth).intValue - 1, counterWidth bits)))
}

and add import

import scala.math.pow

What's your opinion on this simple change ? I can create a merge request if need be.

ronan-lashermes avatar Jan 30 '24 13:01 ronan-lashermes