Skip to content
STIMSMITH

Branch prediction

Concept WIKI v12 · 8/1/2026

Branch prediction is a CPU microarchitectural mechanism that predicts the likely direction of conditional branch instructions to support instruction-level parallelism (ILP). The provided evidence covers workload-driven characterization of branch-prediction accuracy, security attacks and mitigations targeting the branch prediction unit (BPU), and the use of branch predictions as microarchitectural feedback exposed by the RISC-V SNAP hardware for fuzzing, including its relationship with the RISC-V Control Transfer Records (CTR) extension. Additional evidence also treats branch-prediction behavior as a target of microprocessor functional verification testcases.

Overview

Branch prediction predicts the likely direction of a conditional branch instruction to support instruction-level parallelism (ILP). The workload-characterization source frames branch prediction as a pattern-recognition problem: a predictor learns a mapping from an execution context to a branch outcome. [C1]

Performance role

Accurate branch prediction reduces the number of instructions executed on the wrong path, which can improve both performance and energy consumption. The same workload-characterization work proposes two workload-driven identifiers for branch-prediction behavior: branch working set size and branch predictability. It reports that these identifiers are highly correlated with the misprediction rates of modern predictor schemes such as TAGE and perceptron. [C2]

That work defines the branch working set of a trace as a group of the most frequently occurring branch contexts, where a branch context is represented as a 3-part tuple containing the branch address and the associated global and local history. The study reports characterizing 2,451 workload traces into seven branch-working-set-size categories and nine predictability categories. [C3]

Role in the CPU pipeline

Branch predictions are part of the microarchitectural state available in the processor pipeline during program execution. In the context of SNAP, branch predictions are described as invisible to software under normal execution, but available to hardware-level tracing mechanisms such as those used by SNAP. [C4]

Use in SNAP fuzzing support

SNAP uses branch-related microarchitectural information to provide fuzzers with richer runtime feedback than code coverage alone. The SNAP paper states that last-executed branches can be expensive to extract in software, while branch predictions are entirely invisible to software; SNAP exposes such microarchitectural information to provide extra execution semantics, including immediate control-flow context and approximated data flows. [C5]

SNAP also uses prediction results associated with recorded branch sequences in the Last Branch Queue (LBQ). The paper states that, given prediction results for the recorded branch sequence in the LBQ, SNAP can infer a much longer branch history than the captured one. Because most branch conditions are data-dependent, if a mutated input byte changes the prediction result of a branch, SNAP treats the branch condition as likely related to that input offset, thereby approximating data flow from the input to the variables that affect the branch decision with near-zero cost. [C6]

Example implementation context: RISC-V BOOM

The SNAP evaluation uses a BOOM processor configuration whose front end is listed as having 8-wide fetch, 16 RAS entries, 512 BTB entries, and a gshare branch predictor. [C7]

Security implications

Branch prediction is security-sensitive because modern processors can suffer threats that exploit branch-instruction collisions inside the branch prediction unit (BPU). The STBPU paper summary identifies such threats as including eavesdropping on secret-related branch operations and triggering malicious speculative executions. [C8]

The same source states that mitigations such as partitioning or flushing the BPU can stop some collision-based exploits only to a limited extent and can negatively affect branch prediction accuracy and CPU performance. STBPU is proposed as a secure BPU design that customizes BPU data representation for each software entity requiring isolation and monitors prediction-related events to preemptively change that representation against brute-force collision attempts. [C9]

Verification: branch mis-prediction as a functional test target

Functional verification of pipelined microprocessors treats branch mis-prediction as an explicit testcase category. The UCI technical report on Architecture Description Language driven functional test program generation lists a Branch Prediction class of testcases whose goal is to generate inputs that cause branch mis-prediction and the resulting pipeline stalls and flushing, so that the committed architectural state in the presence of such hazards can be checked. The report also lists a related Feedback Paths category of testcases that exercises every feedback path in the pipeline, of which the branch-prediction feedback path is one instance, and frames this as part of functional-coverage-driven verification. [C11]

Relationship with RISC-V Control Transfer Records (CTR)

The RISC-V Control Transfer Records (CTR) extension provides hardware CSRs for recording control transfers, including branches, and supports exposing branch-prediction-related information to software. A Linux perf patch adding CTR CSR definitions defines configuration bits including CTRCTL_BPFRZ (BP freeze), CTRCTL_TKBRINH (taken-branch inhibit), CTRCTL_NTBREN (not-taken branch enable), and per-transfer-type inhibit bits such as CTRCTL_INDCALL_INH, CTRCTL_DIRCALL_INH, CTRCTL_INDJUMP_INH, CTRCTL_DIRJUMP_INH, CTRCTL_CORSWAP_INH, CTRCTL_RET_INH, CTRCTL_INDOJUMP_INH, and CTRCTL_DIROJUMP_INH. The patch also defines CTRTARGET_MISP, indicating that CTR records can carry misprediction information from the branch predictor, and CTRDATA_TYPE_TAKEN_BRANCH / CTRDATA_TYPE_NONTAKEN_BRANCH record types that distinguish branch outcomes. CTR is therefore a related mechanism that exposes branch outcomes and misprediction state to privileged software, complementing other software-invisible branch-prediction state used by mechanisms such as SNAP. [C10]

CITATIONS

11 sources
11 citations
[1] Branch prediction predicts the likely direction of a conditional branch instruction and can be framed as a pattern-recognition problem that learns a mapping from execution context to branch outcome. Workload Characterization for Branch Predictability
[2] Accurate branch prediction reduces wrong-path instructions, improving performance and energy; branch working set size and branch predictability are workload-driven identifiers highly correlated with misprediction rates of modern schemes such as TAGE and perceptron. Workload Characterization for Branch Predictability
[3] The branch working set of a trace is a group of the most frequently occurring branch contexts, defined as a 3-part tuple of branch address and associated global and local history; 2,451 workload traces were characterized into seven working-set-size and nine predictability categories. Workload Characterization for Branch Predictability
[4] Branch predictions are microarchitectural state available in the processor pipeline during program execution; under normal execution they are invisible to software but can be exposed by hardware-level tracing mechanisms. Hardware Support to Improve Fuzzing Performance and Precision (SNAP)
[5] SNAP exposes branch predictions (which are invisible to software) as extra execution semantics including immediate control-flow context and approximated data flows, alongside code coverage. Hardware Support to Improve Fuzzing Performance and Precision (SNAP)
[6] SNAP uses prediction results for branches recorded in the Last Branch Queue (LBQ) to infer a longer effective branch history, and treats a change in a branch's prediction result caused by a mutated input byte as an approximation of data flow from that input offset to the branch condition. Hardware Support to Improve Fuzzing Performance and Precision (SNAP)
[7] The SNAP BOOM evaluation configuration uses an 8-wide fetch front end with 16 RAS entries, 512 BTB entries, and a gshare branch predictor. Hardware Support to Improve Fuzzing Performance and Precision (SNAP)
[8] Modern processors face threats exploiting branch-instruction collisions inside the branch prediction unit (BPU), including eavesdropping on secret-related branch operations and triggering malicious speculative executions. STBPU: A Reasonably Secure Branch Prediction Unit
[9] Mitigations such as partitioning or flushing the BPU can stop some collision-based exploits only to a limited extent and can negatively affect branch prediction accuracy and CPU performance; STBPU customizes BPU data representation per isolated software entity and proactively changes it on detected prediction events to defend against brute-force collision attempts. STBPU: A Reasonably Secure Branch Prediction Unit
[10] The RISC-V Control Transfer Records (CTR) extension defines CSRs (e.g., CSR_MCTRCTL 0x34e, CSR_SCTRCTL 0x14e, CSR_SCTRSTATUS 0x14f, CSR_SCTRDEPTH 0x15f) and configuration bits such as CTRCTL_BPFRZ, CTRCTL_TKBRINH, CTRCTL_NTBREN and per-transfer-type inhibit bits; CTRTARGET_MISP carries branch misprediction information and CTRDATA_TYPE_TAKEN_BRANCH/CTRDATA_TYPE_NONTAKEN_BRANCH record types distinguish branch outcomes. [PATCH RFC 2/6] riscv: perf: Add Control transfer records CSR definations.
[11] Functional test program generation for pipelined microprocessors treats Branch Prediction as an explicit testcase category that produces branch mis-prediction, stalls, and pipeline flushing, and treats every feedback path in the pipeline (including the branch-prediction feedback path) as a coverage target. Architecture Description Language driven Functional Test Program Generation for Microprocessors using SMV

VERSION HISTORY

v12 · 8/1/2026 · minimax/minimax-m3 (current)
v11 · 7/29/2026 · minimax/minimax-m3
v10 · 7/5/2026 · gpt-5.5
v9 · 7/4/2026 · minimax/minimax-m3
v8 · 6/16/2026 · minimax/minimax-m3
v7 · 6/11/2026 · minimax/minimax-m3
v6 · 6/10/2026 · minimax/minimax-m3
v5 · 6/8/2026 · minimax/minimax-m3
v4 · 6/7/2026 · minimax/minimax-m3
v3 · 6/2/2026 · gpt-5.4
v2 · 5/30/2026 · gpt-5.4
v1 · 5/25/2026 · gpt-5.5