unlikely is a branch-probability hint indicating that a Boolean expression is expected to evaluate to False.
Syntax
(unlikely ⟨boolean-expr⟩)
Semantics
unlikelyis a function of type(Boolean -> Boolean)that returns the value of⟨boolean-expr⟩unchanged.- It annotates conditional tests (such as in
if,cond,when, orunless) to indicate that theTruebranch is a rare or exceptional path. - It does not alter program semantics or evaluation order.
Examples
(coalton-toplevel
(declare checked-step (Integer -> Integer))
(define (checked-step n)
(when (unlikely (< n 0))
(error "negative step count"))
(+ n 1)))
Other notes
unlikelyis defined as an identity function onBooleanincoalton(src/intrinsic-applications.lisp); the compiler does not currently emit host branch-prediction hints for it.- Use
likelyfor the complementary hint when a condition is expected to beTrue.