1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Small utilities for Hopper program authors.
//!
//! The line for inclusion is narrow: a helper lands here when it is
//! too small to justify its own module and too broadly useful to
//! leave as a local copy in three places. At the moment that means
//! branch-prediction hints; future additions fit the same rule or
//! they do not fit at all.
/// Branch-prediction hints for hot handlers.
///
/// Both functions are identity over `bool` on every supported
/// target. The call site cost is zero: the compiler inlines them
/// into the containing branch with no runtime effect. What they
/// communicate is intent. A handler that expects the fast path to
/// win 99% of the time writes
///
/// ```ignore
/// if hopper::utils::hint::likely(is_cached) {
/// return fast_path(ctx);
/// }
/// slow_path(ctx)
/// ```
///
/// and the compiler keeps the fast path straight-line, pushing the
/// spill into the cold branch. Same story for [`unlikely`] in the
/// opposite direction.
///
/// On host targets (tests, off-chain tooling) future versions may
/// route through `core::intrinsics::likely` when that intrinsic is
/// stabilized; the API shape stays identical so user code never
/// needs to change. On SBF the Solana runtime does not expose a
/// branch-weight hint today, so the hint compiles out entirely.
/// Leaving the calls in the code path is safe and free.