pub struct Probability { /* private fields */ }Expand description
How likely one edge out of a block is taken, and how much that is worth believing.
Held as parts of Probability::SCALE, which is ten thousand, so a hit rate written as a
whole percent is exact and one written to two decimal places is too. GCC’s REG_BR_PROB_BASE
is the same idea at the same size.
Implementations§
Source§impl Probability
impl Probability
Sourcepub const fn new(parts: u32, quality: Quality) -> Self
pub const fn new(parts: u32, quality: Quality) -> Self
A probability of parts out of Probability::SCALE, believed this much.
There is no constructor that does not say where the number came from, which is section 11.6’s second failure mode closed off at the type. More than the scale is not a probability, and it is clamped rather than refused, because the callers that can produce one are all doing arithmetic where the answer is certainty.
Sourcepub const fn percent(percent: u32, quality: Quality) -> Self
pub const fn percent(percent: u32, quality: Quality) -> Self
A hit rate written as a whole percentage, which is how section 11.2 writes all of them.
Sourcepub const fn always() -> Self
pub const fn always() -> Self
The edge is always taken, and that is arithmetic rather than a guess.
Sourcepub const fn even() -> Self
pub const fn even() -> Self
Nothing is known about this edge, so it is even and says so.
The starting point for a two way branch no predictor matched. Even and guessed is a different statement from even and measured, and the second one is a real fact about a branch that is genuinely unpredictable.
Sourcepub const fn parts(self) -> u32
pub const fn parts(self) -> u32
The parts out of Probability::SCALE.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The other edge out of the same branch.
Sourcepub fn and(self, other: Self) -> Self
pub fn and(self, other: Self) -> Self
Both, for an edge reached by taking this one and then that one.
The quality is the worse of the two, which is the whole reason these are not bare numbers.
Sourcepub fn is_predictable(self) -> bool
pub fn is_predictable(self) -> bool
Whether a branch this likely one way is one a machine will predict correctly.
Section 40.5, and the part of it that matters is not the threshold. A probability a static predictor guessed never counts as predictable however extreme it is, because the branch predictor in the machine is looking at what the program does and the predictor here is looking at what the program says. Guessing that a loop exit is not taken 89 times in 100 is not evidence about any particular branch.
Trait Implementations§
Source§impl Clone for Probability
impl Clone for Probability
Source§fn clone(&self) -> Probability
fn clone(&self) -> Probability
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more