Skip to content

§ 4.6.4. Prediction Recovery

Recovery compares the next PC actually chosen by Execute with the prediction saved for that instruction. Comparing only taken/not-taken is insufficient: the predicted address itself may be wrong, and a taken branch to PC+4 needs no correction.

Component Description Structural Behavioral
RV32IBranchRecovery Full-address comparison and accepted-resolution qualification Yes Yes
RV32IPredictionPath Predictor, saved next-PC values, recovery and PC selection Yes Yes

BranchRecovery

IO pins

Pin Direction Width Description
VALID, PRETERMINAL Input 1 each Execute slot validity and early-terminal status
ADVANCE, KILL Input 1 each EX/MEM will capture; an older terminal/fault instead kills this slot
IS_BRANCH, RST Input 1 each Conditional-branch kind; reset
PREDICTED_PC, FALLTHROUGH_PC, TARGET_PC Input 32 each Saved prediction and the two candidate next addresses
TAKEN Input 1 Select TARGET_PC for a taken branch or jump, otherwise FALLTHROUGH_PC
MISPREDICT Output 1 Eligible valid instruction has unequal addresses
RESOLVE Output 1 Eligible instruction actually leaves Execute without being killed
UPDATE Output 1 RESOLVE and IS_BRANCH; train once at this edge
RECOVERY, BRANCH_MISS Output 1 each Qualified next-PC correction; conditional-branch subset

Behavior and C++ example

MISPREDICT is a request to the coordinator, so it is deliberately not gated by ADVANCE. The coordinator may hold it while an older memory request waits. RESOLVE, UPDATE and the observation pulses are gated by actual advancement and older-instruction priority. This avoids both a combinational dependency loop and repeated table training during a stall.

struct Recovery {bool mispredict,resolve,update,recovery,branch_miss;};
inline Recovery recover(bool valid,bool preterminal,bool advance,bool kill,bool branch,bool reset,
                        uint32_t predicted_pc,uint32_t fallthrough_pc,uint32_t target_pc,bool taken) {
    const bool eligible=valid&&!preterminal&&!reset;
    const bool different=taken ? predicted_pc!=target_pc : predicted_pc!=fallthrough_pc;
    const bool resolve=eligible&&advance&&!kill;
    return {eligible&&different,resolve,resolve&&branch,resolve&&different,resolve&&branch&&different};
}

Implementation

Two structural XOR/reduction networks compare the saved prediction with fallthrough and target in parallel. TAKEN selects the one-bit mismatch. Thus branch resolution does not first wait for a 32-bit next-PC mux and then a comparison. Qualification gates generate the outputs. The behavioral implementation selects the same address predicate. This component stores nothing. If target equals fallthrough, a direction difference alone causes no recovery.

Examples

The table exhausts 256 combinations of validity, terminal status, advancement, kill, instruction kind, reset, selected-address difference and taken direction, followed by two target-equals-fallthrough cases.

All 258 recorded rows of RV32IBranchRecoveryTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.

Default scenario profile: prediction-preview-preview / structural (c00b720a1b70c77a). Changing fidelity or the circuit can change these times.

Checkpointzero-based number · timeline label Timesimulator units ADVANCEInput · 1 bit FALLTHROUGH_PCInput · 32 bit IS_BRANCHInput · 1 bit KILLInput · 1 bit PREDICTED_PCInput · 32 bit PRETERMINALInput · 1 bit RSTInput · 1 bit TAKENInput · 1 bit TARGET_PCInput · 32 bit VALIDInput · 1 bit BRANCH_MISSExpected output · 1 bit MISPREDICTExpected output · 1 bit RECOVERYExpected output · 1 bit RESOLVEExpected output · 1 bit UPDATEExpected output · 1 bit
#0case-010 0 0x00000100 0 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#1case-114 0 0x00000100 0 0 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#2case-218 0 0x00000100 0 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#3case-320 0 0x00000100 0 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#4case-423 1 0x00000100 0 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#5case-529 1 0x00000100 0 0 0x00000100 0 0 0 0x00000200 1 0 0 0 1 0
#6case-635 1 0x00000100 0 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#7case-737 1 0x00000100 0 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#8case-840 0 0x00000100 0 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#9case-944 0 0x00000100 0 1 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#10case-1048 0 0x00000100 0 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#11case-1150 0 0x00000100 0 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#12case-1253 1 0x00000100 0 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#13case-1358 1 0x00000100 0 1 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#14case-1463 1 0x00000100 0 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#15case-1565 1 0x00000100 0 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#16case-1668 0 0x00000100 1 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#17case-1772 0 0x00000100 1 0 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#18case-1876 0 0x00000100 1 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#19case-1978 0 0x00000100 1 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#20case-2081 1 0x00000100 1 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#21case-2187 1 0x00000100 1 0 0x00000100 0 0 0 0x00000200 1 0 0 0 1 1
#22case-2293 1 0x00000100 1 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#23case-2395 1 0x00000100 1 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#24case-2498 0 0x00000100 1 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#25case-25102 0 0x00000100 1 1 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#26case-26106 0 0x00000100 1 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#27case-27108 0 0x00000100 1 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#28case-28111 1 0x00000100 1 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#29case-29116 1 0x00000100 1 1 0x00000100 0 0 0 0x00000200 1 0 0 0 0 0
#30case-30121 1 0x00000100 1 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#31case-31123 1 0x00000100 1 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#32case-32126 0 0x00000100 0 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#33case-33129 0 0x00000100 0 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#34case-34132 0 0x00000100 0 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#35case-35134 0 0x00000100 0 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#36case-36137 1 0x00000100 0 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#37case-37140 1 0x00000100 0 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#38case-38143 1 0x00000100 0 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#39case-39145 1 0x00000100 0 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#40case-40148 0 0x00000100 0 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#41case-41151 0 0x00000100 0 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#42case-42154 0 0x00000100 0 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#43case-43156 0 0x00000100 0 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#44case-44159 1 0x00000100 0 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#45case-45162 1 0x00000100 0 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#46case-46165 1 0x00000100 0 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#47case-47167 1 0x00000100 0 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#48case-48170 0 0x00000100 1 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#49case-49173 0 0x00000100 1 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#50case-50176 0 0x00000100 1 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#51case-51178 0 0x00000100 1 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#52case-52181 1 0x00000100 1 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#53case-53184 1 0x00000100 1 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#54case-54187 1 0x00000100 1 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#55case-55189 1 0x00000100 1 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#56case-56192 0 0x00000100 1 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#57case-57195 0 0x00000100 1 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#58case-58198 0 0x00000100 1 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#59case-59200 0 0x00000100 1 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#60case-60203 1 0x00000100 1 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#61case-61206 1 0x00000100 1 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#62case-62209 1 0x00000100 1 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#63case-63211 1 0x00000100 1 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#64case-64222 0 0x80000100 0 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#65case-65226 0 0x80000100 0 0 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#66case-66230 0 0x80000100 0 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#67case-67232 0 0x80000100 0 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#68case-68235 1 0x80000100 0 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#69case-69242 1 0x80000100 0 0 0x00000100 0 0 0 0x00000200 1 0 1 1 1 0
#70case-70249 1 0x80000100 0 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#71case-71251 1 0x80000100 0 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#72case-72254 0 0x80000100 0 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#73case-73258 0 0x80000100 0 1 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#74case-74262 0 0x80000100 0 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#75case-75264 0 0x80000100 0 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#76case-76267 1 0x80000100 0 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#77case-77272 1 0x80000100 0 1 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#78case-78277 1 0x80000100 0 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#79case-79279 1 0x80000100 0 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#80case-80282 0 0x80000100 1 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#81case-81286 0 0x80000100 1 0 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#82case-82290 0 0x80000100 1 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#83case-83292 0 0x80000100 1 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#84case-84295 1 0x80000100 1 0 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#85case-85302 1 0x80000100 1 0 0x00000100 0 0 0 0x00000200 1 1 1 1 1 1
#86case-86309 1 0x80000100 1 0 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#87case-87311 1 0x80000100 1 0 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#88case-88314 0 0x80000100 1 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#89case-89318 0 0x80000100 1 1 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#90case-90322 0 0x80000100 1 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#91case-91324 0 0x80000100 1 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#92case-92327 1 0x80000100 1 1 0x00000100 0 0 0 0x00000200 0 0 0 0 0 0
#93case-93332 1 0x80000100 1 1 0x00000100 0 0 0 0x00000200 1 0 1 0 0 0
#94case-94337 1 0x80000100 1 1 0x00000100 1 0 0 0x00000200 0 0 0 0 0 0
#95case-95339 1 0x80000100 1 1 0x00000100 1 0 0 0x00000200 1 0 0 0 0 0
#96case-96342 0 0x80000100 0 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#97case-97345 0 0x80000100 0 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#98case-98348 0 0x80000100 0 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#99case-99350 0 0x80000100 0 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#100case-100353 1 0x80000100 0 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#101case-101356 1 0x80000100 0 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#102case-102359 1 0x80000100 0 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#103case-103361 1 0x80000100 0 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#104case-104364 0 0x80000100 0 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#105case-105367 0 0x80000100 0 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#106case-106370 0 0x80000100 0 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#107case-107372 0 0x80000100 0 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#108case-108375 1 0x80000100 0 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#109case-109378 1 0x80000100 0 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#110case-110381 1 0x80000100 0 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#111case-111383 1 0x80000100 0 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#112case-112386 0 0x80000100 1 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#113case-113389 0 0x80000100 1 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#114case-114392 0 0x80000100 1 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#115case-115394 0 0x80000100 1 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#116case-116397 1 0x80000100 1 0 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#117case-117400 1 0x80000100 1 0 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#118case-118403 1 0x80000100 1 0 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#119case-119405 1 0x80000100 1 0 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#120case-120408 0 0x80000100 1 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#121case-121411 0 0x80000100 1 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#122case-122414 0 0x80000100 1 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#123case-123416 0 0x80000100 1 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#124case-124419 1 0x80000100 1 1 0x00000100 0 1 0 0x00000200 0 0 0 0 0 0
#125case-125422 1 0x80000100 1 1 0x00000100 0 1 0 0x00000200 1 0 0 0 0 0
#126case-126425 1 0x80000100 1 1 0x00000100 1 1 0 0x00000200 0 0 0 0 0 0
#127case-127427 1 0x80000100 1 1 0x00000100 1 1 0 0x00000200 1 0 0 0 0 0
#128case-128438 0 0x00000200 0 0 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#129case-129442 0 0x00000200 0 0 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#130case-130446 0 0x00000200 0 0 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#131case-131448 0 0x00000200 0 0 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#132case-132451 1 0x00000200 0 0 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#133case-133457 1 0x00000200 0 0 0x00000100 0 0 1 0x00000100 1 0 0 0 1 0
#134case-134463 1 0x00000200 0 0 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#135case-135465 1 0x00000200 0 0 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#136case-136468 0 0x00000200 0 1 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#137case-137472 0 0x00000200 0 1 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#138case-138476 0 0x00000200 0 1 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#139case-139478 0 0x00000200 0 1 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#140case-140481 1 0x00000200 0 1 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#141case-141486 1 0x00000200 0 1 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#142case-142491 1 0x00000200 0 1 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#143case-143493 1 0x00000200 0 1 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#144case-144496 0 0x00000200 1 0 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#145case-145500 0 0x00000200 1 0 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#146case-146504 0 0x00000200 1 0 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#147case-147506 0 0x00000200 1 0 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#148case-148509 1 0x00000200 1 0 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#149case-149515 1 0x00000200 1 0 0x00000100 0 0 1 0x00000100 1 0 0 0 1 1
#150case-150521 1 0x00000200 1 0 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#151case-151523 1 0x00000200 1 0 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#152case-152526 0 0x00000200 1 1 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#153case-153530 0 0x00000200 1 1 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#154case-154534 0 0x00000200 1 1 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#155case-155536 0 0x00000200 1 1 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#156case-156539 1 0x00000200 1 1 0x00000100 0 0 1 0x00000100 0 0 0 0 0 0
#157case-157544 1 0x00000200 1 1 0x00000100 0 0 1 0x00000100 1 0 0 0 0 0
#158case-158549 1 0x00000200 1 1 0x00000100 1 0 1 0x00000100 0 0 0 0 0 0
#159case-159551 1 0x00000200 1 1 0x00000100 1 0 1 0x00000100 1 0 0 0 0 0
#160case-160554 0 0x00000200 0 0 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#161case-161557 0 0x00000200 0 0 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#162case-162560 0 0x00000200 0 0 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#163case-163562 0 0x00000200 0 0 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#164case-164565 1 0x00000200 0 0 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#165case-165568 1 0x00000200 0 0 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#166case-166571 1 0x00000200 0 0 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#167case-167573 1 0x00000200 0 0 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#168case-168576 0 0x00000200 0 1 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#169case-169579 0 0x00000200 0 1 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#170case-170582 0 0x00000200 0 1 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#171case-171584 0 0x00000200 0 1 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#172case-172587 1 0x00000200 0 1 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#173case-173590 1 0x00000200 0 1 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#174case-174593 1 0x00000200 0 1 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#175case-175595 1 0x00000200 0 1 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#176case-176598 0 0x00000200 1 0 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#177case-177601 0 0x00000200 1 0 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#178case-178604 0 0x00000200 1 0 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#179case-179606 0 0x00000200 1 0 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#180case-180609 1 0x00000200 1 0 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#181case-181612 1 0x00000200 1 0 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#182case-182615 1 0x00000200 1 0 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#183case-183617 1 0x00000200 1 0 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#184case-184620 0 0x00000200 1 1 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#185case-185623 0 0x00000200 1 1 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#186case-186626 0 0x00000200 1 1 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#187case-187628 0 0x00000200 1 1 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#188case-188631 1 0x00000200 1 1 0x00000100 0 1 1 0x00000100 0 0 0 0 0 0
#189case-189634 1 0x00000200 1 1 0x00000100 0 1 1 0x00000100 1 0 0 0 0 0
#190case-190637 1 0x00000200 1 1 0x00000100 1 1 1 0x00000100 0 0 0 0 0 0
#191case-191639 1 0x00000200 1 1 0x00000100 1 1 1 0x00000100 1 0 0 0 0 0
#192case-192650 0 0x00000200 0 0 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#193case-193654 0 0x00000200 0 0 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#194case-194658 0 0x00000200 0 0 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#195case-195660 0 0x00000200 0 0 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#196case-196663 1 0x00000200 0 0 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#197case-197670 1 0x00000200 0 0 0x00000100 0 0 1 0x80000100 1 0 1 1 1 0
#198case-198677 1 0x00000200 0 0 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#199case-199679 1 0x00000200 0 0 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#200case-200682 0 0x00000200 0 1 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#201case-201686 0 0x00000200 0 1 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#202case-202690 0 0x00000200 0 1 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#203case-203692 0 0x00000200 0 1 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#204case-204695 1 0x00000200 0 1 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#205case-205700 1 0x00000200 0 1 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#206case-206705 1 0x00000200 0 1 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#207case-207707 1 0x00000200 0 1 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#208case-208710 0 0x00000200 1 0 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#209case-209714 0 0x00000200 1 0 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#210case-210718 0 0x00000200 1 0 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#211case-211720 0 0x00000200 1 0 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#212case-212723 1 0x00000200 1 0 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#213case-213730 1 0x00000200 1 0 0x00000100 0 0 1 0x80000100 1 1 1 1 1 1
#214case-214737 1 0x00000200 1 0 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#215case-215739 1 0x00000200 1 0 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#216case-216742 0 0x00000200 1 1 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#217case-217746 0 0x00000200 1 1 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#218case-218750 0 0x00000200 1 1 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#219case-219752 0 0x00000200 1 1 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#220case-220755 1 0x00000200 1 1 0x00000100 0 0 1 0x80000100 0 0 0 0 0 0
#221case-221760 1 0x00000200 1 1 0x00000100 0 0 1 0x80000100 1 0 1 0 0 0
#222case-222765 1 0x00000200 1 1 0x00000100 1 0 1 0x80000100 0 0 0 0 0 0
#223case-223767 1 0x00000200 1 1 0x00000100 1 0 1 0x80000100 1 0 0 0 0 0
#224case-224770 0 0x00000200 0 0 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#225case-225773 0 0x00000200 0 0 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#226case-226776 0 0x00000200 0 0 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#227case-227778 0 0x00000200 0 0 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#228case-228781 1 0x00000200 0 0 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#229case-229784 1 0x00000200 0 0 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#230case-230787 1 0x00000200 0 0 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#231case-231789 1 0x00000200 0 0 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#232case-232792 0 0x00000200 0 1 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#233case-233795 0 0x00000200 0 1 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#234case-234798 0 0x00000200 0 1 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#235case-235800 0 0x00000200 0 1 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#236case-236803 1 0x00000200 0 1 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#237case-237806 1 0x00000200 0 1 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#238case-238809 1 0x00000200 0 1 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#239case-239811 1 0x00000200 0 1 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#240case-240814 0 0x00000200 1 0 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#241case-241817 0 0x00000200 1 0 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#242case-242820 0 0x00000200 1 0 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#243case-243822 0 0x00000200 1 0 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#244case-244825 1 0x00000200 1 0 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#245case-245828 1 0x00000200 1 0 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#246case-246831 1 0x00000200 1 0 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#247case-247833 1 0x00000200 1 0 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#248case-248836 0 0x00000200 1 1 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#249case-249839 0 0x00000200 1 1 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#250case-250842 0 0x00000200 1 1 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#251case-251844 0 0x00000200 1 1 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#252case-252847 1 0x00000200 1 1 0x00000100 0 1 1 0x80000100 0 0 0 0 0 0
#253case-253850 1 0x00000200 1 1 0x00000100 0 1 1 0x80000100 1 0 0 0 0 0
#254case-254853 1 0x00000200 1 1 0x00000100 1 1 1 0x80000100 0 0 0 0 0 0
#255case-255855 1 0x00000200 1 1 0x00000100 1 1 1 0x80000100 1 0 0 0 0 0
#256same-address-fallthrough867 1 0x00000004 1 0 0x00000004 0 0 0 0x00000004 1 not checked 0 0 not checked 1
#257same-address-taken870 1 0x00000004 1 0 0x00000004 0 0 1 0x00000004 1 not checked 0 0 not checked 1

Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.

PredictionPath

IO pins

Pin Direction Width Description
CLK, RST, IF_ID_WRITE, ID_EX_WRITE Input 1 each Clock/reset and the actual packet-register enables
FETCH_PC, FETCH_INSTRUCTION Input 32 each Current accepted-candidate fetch
EX_PC, EX_FALLTHROUGH_PC, EX_TARGET_PC Input 32 each Execute instruction identity and candidate next addresses
EX_CONTROL_TAKEN Input 1 Taken conditional branch or jump; selects the actual candidate
EX_VALID, EX_PRETERMINAL, EX_ADVANCE, EX_KILL Input 1 each Recovery qualifications from packet and coordinator
EX_IS_BRANCH, EX_TAKEN Input 1 each Actual conditional-branch kind and outcome
REDIRECT_APPLY Input 1 Coordinator permits correction of Fetch PC
PREDICTED_NEXT_PC, EX_PREDICTED_NEXT_PC Output 32 each Current lookup and saved Execute-slot prediction
FETCH_NEXT_PC Output 32 Corrected address when REDIRECT_APPLY, otherwise current prediction
MISPREDICT, RESOLVE, UPDATE, RECOVERY, BRANCH_MISS Output 1 each BranchRecovery outputs

Behavior and C++ example

The same prediction and prediction_entries configuration applies as for BranchPredictor. Two Register<32> components accompany IF/ID and ID/EX; each captures using its packet's write enable. All captures use pre-edge values. A hold preserves both packet and prediction. A bubble may carry stale metadata because its real VALID bit prevents use; separate prediction-valid registers are unnecessary.

struct PredictionPath {
    Predictor predictor;
    uint32_t if_id_prediction=0,id_ex_prediction=0;
    bool previous_clock=false;
    PredictionPath(Policy p,size_t entries):predictor(p,entries) {}
    void evaluate(bool clk,bool reset,bool if_id_write,bool id_ex_write,
                  uint32_t fetch_pc,uint32_t instruction,bool ex_valid,bool preterminal,
                  bool advance,bool kill,bool branch,uint32_t ex_pc,bool taken) {
        // Compute captures BEFORE changing the table or either packet register.
        const auto lookup=predictor.lookup(fetch_pc,predecode(fetch_pc,instruction)).next_pc;
        const auto old_if_id=if_id_prediction;
        if(reset) if_id_prediction=id_ex_prediction=0;
        else if(!previous_clock&&clk) {
            if(if_id_write) if_id_prediction=lookup;
            if(id_ex_write) id_ex_prediction=old_if_id;
        }
        predictor.evaluate(clk,reset,ex_valid&&!preterminal&&advance&&!kill&&branch,ex_pc,taken);
        previous_clock=clk;
    }
    // After settling: PREDICTED_NEXT_PC = predictor.lookup(...).next_pc;
    // EX_PREDICTED_NEXT_PC = id_ex_prediction;
    // actual_pc = EX_CONTROL_TAKEN ? EX_TARGET_PC : EX_FALLTHROUGH_PC;
    // FETCH_NEXT_PC = REDIRECT_APPLY ? actual_pc : PREDICTED_NEXT_PC;
    // Other outputs = recover(..., id_ex_prediction, EX_FALLTHROUGH_PC, EX_TARGET_PC, EX_CONTROL_TAKEN).
};

Implementation

The structural children are PREDECODE, PREDICTOR, IF_ID_PREDICTION, ID_EX_PREDICTION, RECOVERY, ACTUAL_NEXT_PC, and RECOVERY_PC_SELECT. The address mux supplies correction data but is not ahead of the mismatch comparison. The compact implementation stores only the same table and two metadata words. It has no architectural register file or instruction history.

Example: correction while a load waits

Suppose an older load is in MEM and a branch is in EX. The branch resolves to a different next PC, but the load's response is not ready:

State MISPREDICT EX_ADVANCE UPDATE Effect
Data response pending 1 0 0 Hold packets and prediction; do not redirect or retrain
Successful response arrives 1 1 1 for a conditional branch Advance older work, correct Fetch, flush younger IF/ID and ID/EX
Response is a load fault May be 1 1 with EX_KILL=1 0 Older fault wins; branch cannot advance as valid work or train

Wrong-path instructions never reach an enabled architectural write. A killed instruction-memory request is drained rather than confused with the redirected fetch; that ownership belongs to the requester in 4.6.5.

Examples

All 8 recorded rows of RV32IPredictionPathTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.

Default scenario profile: prediction-preview-preview / structural (c00b720a1b70c77a). Changing fidelity or the circuit can change these times.

Checkpointzero-based number · timeline label Timesimulator units CLKInput · 1 bit EX_ADVANCEInput · 1 bit EX_CONTROL_TAKENInput · 1 bit EX_FALLTHROUGH_PCInput · 32 bit EX_IS_BRANCHInput · 1 bit EX_KILLInput · 1 bit EX_PCInput · 32 bit EX_PRETERMINALInput · 1 bit EX_TAKENInput · 1 bit EX_TARGET_PCInput · 32 bit EX_VALIDInput · 1 bit FETCH_INSTRUCTIONInput · 32 bit FETCH_PCInput · 32 bit ID_EX_WRITEInput · 1 bit IF_ID_WRITEInput · 1 bit REDIRECT_APPLYInput · 1 bit RSTInput · 1 bit BRANCH_MISSExpected output · 1 bit EX_PREDICTED_NEXT_PCExpected output · 32 bit FETCH_NEXT_PCExpected output · 32 bit MISPREDICTExpected output · 1 bit PREDICTED_NEXT_PCExpected output · 32 bit RECOVERYExpected output · 1 bit RESOLVEExpected output · 1 bit UPDATEExpected output · 1 bit
#0reset25 0 0 0 0x00000000 0 0 0x00000000 0 0 0x00000000 0 0x00208463 0x00000000 0 0 0 1 not checked 0x00000000 0x00000008 0 0x00000008 not checked not checked 0
#1capture-if-id33 1 0 0 0x00000000 0 0 0x00000000 0 0 0x00000000 0 0x00208463 0x00000000 1 1 0 0 not checked 0x00000000 not checked not checked not checked not checked not checked not checked
#2capture-id-ex80 1 0 0 0x00000000 0 0 0x00000000 0 0 0x00000000 0 0xFE208EE3 0x00000004 1 1 0 0 not checked 0x00000008 not checked not checked 0x00000000 not checked not checked not checked
#3wait-holds-update86 0 0 0 0x00000004 1 0 0x00000000 0 0 0x00000000 1 0xFE208EE3 0x00000004 0 0 0 0 not checked not checked not checked 1 not checked not checked 0 0
#4held-clock91 1 0 0 0x00000004 1 0 0x00000000 0 0 0x00000000 1 0xFE208EE3 0x00000004 0 0 0 0 not checked 0x00000008 not checked not checked not checked not checked not checked not checked
#5apply-correction96 0 1 0 0x00000004 1 0 0x00000000 0 0 0x00000000 1 0xFE208EE3 0x00000004 0 0 1 0 not checked not checked 0x00000004 not checked not checked not checked not checked 1
#6older-fault-kills-training101 0 1 0 0x00000004 1 1 0x00000000 0 0 0x00000000 1 0xFE208EE3 0x00000004 0 0 1 0 not checked not checked not checked not checked not checked not checked 0 0
#7bubble-does-not-resolve106 0 1 0 0x00000004 1 1 0x00000000 0 0 0x00000000 0 0xFE208EE3 0x00000004 0 0 1 0 not checked not checked not checked 0 not checked not checked not checked not checked

Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.

Tests

RV32IBranchRecoveryTest checks all qualification combinations. RV32IPredictionPathTest checks metadata alignment, holds, correction, killed training and lookup/update collision ordering in both fidelities. Program tests exercise conditional branches, direct jumps and register-indirect jumps. RV32IMemoryMigrationTest combines prediction with delayed ROM/SRAM endpoints, pause/resume, wrong-path store suppression and loops.