Skip to main content

Probability

Struct Probability 

Source
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

Source

pub const SCALE: u32 = 10_000

What a probability is out of.

Source

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.

Source

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.

Source

pub const fn always() -> Self

The edge is always taken, and that is arithmetic rather than a guess.

Source

pub const fn never() -> Self

The edge is never taken.

Source

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.

Source

pub const fn parts(self) -> u32

The parts out of Probability::SCALE.

Source

pub const fn quality(self) -> Quality

How much this is worth believing.

Source

pub const fn complement(self) -> Self

The other edge out of the same branch.

Source

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.

Source

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

Source§

fn clone(&self) -> Probability

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Probability

Source§

impl Debug for Probability

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Probability

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

As a percentage, with the two decimal places only when they say something.

Source§

impl Eq for Probability

Source§

impl Hash for Probability

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Probability

Source§

fn cmp(&self, other: &Probability) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Probability

Source§

fn eq(&self, other: &Probability) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Probability

Source§

fn partial_cmp(&self, other: &Probability) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Probability

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.