Redirection and Update Interfaces

Redirection and update requests are the two main types of information sent from the FTQ to the BPU. This section details the specific structure of these request interfaces.

Branch Prediction Redirection(BranchPredictionRedirect)

Interface Definition:src/main/scala/xiangshan/frontend/FrontendBundle.scala

Interface Type:BranchPredictionRedirect

This interface defines the redirection requests from the branch prediction unit, mainly used to redirect the state of the branch predictor.

The BranchPredictionRedirect interface inherits from the Redirect interface and includes many signals, only a subset of which are used by the BPU redirection. The documented structure contains only the interfaces used by the BPU.

Redirection requests have two sources: those generated by comparing IFU pre-decode information and those generated during the backend execution process.

In redirection requests, the key information is cfiUpdate, which corresponds to a control flow instruction. This information pertains to an instruction where the BPU made a prediction error. For example, if the BPU indicates that the third instruction in the prediction block is a normal instruction with no jump, but the pre-decode shows it is an unconditional jump instruction, a prediction error has occurred. In this case, the FTQ generates a redirection request. The cfiUpdate in the redirection request corresponds to this unconditional jump instruction.

The information in cfiUpdate can be broadly classified into three types:

  1. Information about the corresponding instruction and its execution status. This includes the slot (shift) and PC of the instruction in the prediction block, the type-related information of the instruction (pd), and the execution status, such as jump target and whether it jumps.
  2. History maintenance related information. The redirection request contains branch history information corresponding to the prediction block of the instruction to help the BPU restore branch history. folded_hist represents the global folded history, histPtr represents the global history pointer, and other information assists in maintaining branch history. For detailed information, refer to the BPU Top-Level Module.
  3. RAS maintenance related information. For detailed meaning, refer to the RAS sub-predictor documentation.

The meaning of level is whether the redirection includes this instruction. If not included, the redirection request receiver will assume the instruction has been executed, and the next prediction will start from the next instruction. The BPU top-level will default to not including this instruction, and upon receiving a redirection request, it will include the execution status of this instruction in the branch history.

The detailed signal list for the redirection interface is as follows:

  • level: Indicates whether the redirection request includes the current position. Low means redirection after this position, high means redirection at this position.

    • Interface Type: UInt(1.W)
  • cfiUpdate: Control flow instruction update information

    • Interface Type: CfiUpdateInfo

    • Interface List

      • pc: The PC of the instruction corresponding to the redirection request
        • Interface Type: UInt(VaddrBits.W)
      • pd: Pre-decode information of the redirection instruction
        • isRVC: Whether it is a compressed instruction
          • Interface Type: Bool
        • isCall: Whether it is a function call
          • Interface Type: Bool
        • isRet: Whether it is a function return
          • Interface Type: Bool
      • target: Target address of the redirection request instruction
        • Interface Type: UInt(VaddrBits.W)
      • taken: Whether the redirection request instruction is taken
        • Interface Type: Bool
      • shift: Slot in which the redirection request instruction is located, 0 if it is a normal instruction.
        • Interface Type: UInt((log2Ceil(numBr)+1).W)
      • addIntoHist: Whether to include the execution information of the redirection request instruction in the branch history.
        • Interface Type: Bool

      • folded_hist: Folded history corresponding to the redirection request
        • Interface Type: AllFoldedHistories(foldedGHistInfos)
      • afhob: Oldest bit of the branch history corresponding to the redirection request instruction
        • Interface Type: AllAheadFoldedHistoryOldestBits(foldedGHistInfos)
      • lastBrNumOH: Last branch position corresponding to the redirection request
        • Interface Type: UInt((numBr+1).W)
      • histPtr: Global history pointer to be restored by the redirection request
        • Interface Type: CGHPtr

      • ssp: RAS speculative stack top pointer at the commit stack position corresponding to the redirection request instruction
        • Interface Type: UInt(log2Up(RasSize).W)
      • sctr: RAS speculative stack top recursion counter corresponding to the redirection request instruction
        • Interface Type: UInt(log2Up(RasCtrSize).W)
      • TOSW: RAS speculative stack (queue) write pointer corresponding to the redirection request instruction
        • Interface Type: CGHPtr
      • TOSR: RAS speculative stack (queue) read pointer corresponding to the redirection request instruction
        • Interface Type: CGHPtr
      • NOS: RAS stack top counter corresponding to the redirection request instruction
        • Interface Type: CGHPtr

Branch Prediction Update(BranchPredictionUpdate)

Interface Definition: src/main/scala/xiangshan/frontend/FrontendBundle.scala

This interface defines the update requests for the branch predictor, mainly used to update the state of the branch predictor. The document lists only the interfaces used in the BPU.

Update requests correspond to each branch prediction block. When a branch prediction block in the FTQ has been executed, the FTQ generates an update request for this prediction block to train the predictor. Thus, an important role of the update request is to feed back the actual execution status of the instructions to the BPU. Additionally, in the Xiangshan branch prediction unit, the update request is responsible for updating FTB entries.

The information in the update request can be broadly classified into four categories:

  • PC: Indicates the starting address of the prediction block, specifying which prediction block the update request corresponds to
  • FTB Entry Update Information: The update channel contains an FTB entry structure (ftb_entry), outputs the newly generated FTB entry from the FTQ, and indicates whether it is the same as the old FTB entry (old_entry)
  • Actual Execution Status Information of Instructions: The update channel indicates the execution status of branch and unconditional jump instructions in the prediction block, and provides the address and final target of control flow instructions (i.e., instructions that jump)
  • Predictor-Related Data Corresponding to the Prediction Block: Contains spec_info and meta information (refer to the BPU Global Interface Documentation for details)

The interface list of the update request is as follows:

  • pc PC of the update request (starting address of the prediction block)
    • Interface Type:UInt(VAddrBits.W)

  • ftb_entry Updated FTB entry
    • Interface Type:new FTBEntry()
    • Interface List:See(FTBEntry
  • old_entry Whether the updated FTB entry is the same as the old FTB entry
    • Interface Type:Bool()

  • br_taken_mask Mask indicating whether each slot instruction in the prediction block jumps
    • Interface Type:Vec(numBr, Bool())
  • mispred_mask Mask indicating prediction errors in the prediction block. The first and second bits indicate whether the two conditional branch instructions were mispredicted, and the third bit indicates whether the unconditional jump instruction was mispredicted.
    • Interface Type:Vec(numBr+1, Bool())
  • jmp_taken Unconditional jump instruction triggered in the prediction block
    • Interface Type:Bool()
  • cfi_idx Index of the control flow instruction in the prediction block
    • Interface Type:ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
  • full_target Jump target of the prediction block (starting address of the next prediction block)
    • Interface Type:UInt(VAddrBits.W)

  • spec_info Last stage speculative information corresponding to the prediction block
    • Interface Type:new SpeculativeInfo
    • Interface List:(Only foled_hist is used)
      • folded_hist Global folded history
        • Interface Type:AllFolededHistories(foldedGHistInfos)
  • meta Last stage meta information corresponding to the prediction block
    • Interface Type:UInt(MaxMetaLength.W)
Last modified September 13, 2024: Update the picture of BPU Top. (431c050)