Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
A Mask type used for constant-time operations. More...
#include <ct_utils.hpp>
Public Member Functions | |
Mask (const Mask< T > &other) noexcept | |
template<typename U > | |
Mask (Mask< U > o) noexcept | |
Derive a Mask from a Mask of a larger type. More... | |
T | if_not_set_return (T x) const noexcept |
Return x if the mask is cleared, or otherwise zero. More... | |
T | if_set_return (T x) const noexcept |
Return x if the mask is set, or otherwise zero. More... | |
void | if_set_zero_out (T buf[], size_t elems) noexcept |
If this mask is set, zero out buf, otherwise do nothing. More... | |
bool | is_set () const noexcept |
Return true iff this mask is set. More... | |
Mask< T > & | operator&= (Mask< T > o) noexcept |
AND-combine two masks. More... | |
Mask< T > & | operator= (const Mask< T > &other) noexcept |
Mask< T > & | operator^= (Mask< T > o) noexcept |
XOR-combine two masks. More... | |
Mask< T > & | operator|= (Mask< T > o) noexcept |
OR-combine two masks. More... | |
Mask< T > | operator~ () const noexcept |
Negate this mask. More... | |
T | select (T x, T y) const noexcept |
If this mask is set, return x, otherwise return y. More... | |
T | select_and_unpoison (T x, T y) const noexcept |
Mask< T > | select_mask (Mask< T > x, Mask< T > y) const noexcept |
If this mask is set, return x, otherwise return y. More... | |
void | select_n (T output[], const T x[], const T y[], size_t len) const noexcept |
Conditionally set output to x or y, depending on if mask is set or cleared (resp) More... | |
T | unpoisoned_value () const noexcept |
Return the value of the mask, unpoisoned. More... | |
T | value () const noexcept |
Return the underlying value of the mask. More... | |
Static Public Member Functions | |
static Mask< T > | cleared () noexcept |
Return a Mask<T> with all bits cleared. More... | |
template<typename U > | |
static Mask< T > | expand (Mask< U > m) noexcept |
Return a Mask<T> which is set if m is set. More... | |
static Mask< T > | expand (T v) noexcept |
Return a Mask<T> which is set if v is != 0. More... | |
static Mask< T > | is_any_of (T v, std::initializer_list< T > accepted) noexcept |
static Mask< T > | is_equal (T x, T y) noexcept |
Return a Mask<T> which is set if x == y. More... | |
static Mask< T > | is_gt (T x, T y) noexcept |
Return a Mask<T> which is set if x > y. More... | |
static Mask< T > | is_gte (T x, T y) noexcept |
Return a Mask<T> which is set if x >= y. More... | |
static Mask< T > | is_lt (T x, T y) noexcept |
Return a Mask<T> which is set if x < y. More... | |
static Mask< T > | is_lte (T x, T y) noexcept |
Return a Mask<T> which is set if x <= y. More... | |
static Mask< T > | is_within_range (T v, T l, T u) noexcept |
static Mask< T > | is_zero (T x) noexcept |
Return a Mask<T> which is set if v is == 0 or cleared otherwise. More... | |
static Mask< T > | set () noexcept |
Return a Mask<T> with all bits set. More... | |
Friends | |
Mask< T > | operator& (Mask< T > x, Mask< T > y) noexcept |
AND-combine two masks. More... | |
Mask< T > | operator^ (Mask< T > x, Mask< T > y) noexcept |
XOR-combine two masks. More... | |
Mask< T > | operator| (Mask< T > x, Mask< T > y) noexcept |
OR-combine two masks. More... | |
A Mask type used for constant-time operations.
A Mask<T> always has value either 0 (all bits cleared) or ~0 (all bits set). All operations in a Mask<T> are intended to compile to code which does not contain conditional jumps. This must be verified with tooling (eg binary disassembly or using valgrind) since you never know what a compiler might do.
T | unsigned integral type |
Definition at line 80 of file ct_utils.hpp.
|
inlinenoexcept |
Definition at line 83 of file ct_utils.hpp.
|
inlinenoexcept |
Derive a Mask from a Mask of a larger type.
Definition at line 95 of file ct_utils.hpp.
|
inlinenoexcept |
Definition at line 86 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> with all bits set.
Definition at line 103 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> with all bits cleared.
Definition at line 111 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if v is != 0.
Definition at line 119 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if m is set.
Definition at line 128 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if v is == 0 or cleared otherwise.
Definition at line 137 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if x == y.
Definition at line 145 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if x < y.
Definition at line 153 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if x > y.
Definition at line 161 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if x <= y.
Definition at line 169 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Return a Mask<T> which is set if x >= y.
Definition at line 177 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Definition at line 182 of file ct_utils.hpp.
|
inlinestaticnoexcept |
Definition at line 192 of file ct_utils.hpp.
|
inlinenoexcept |
AND-combine two masks.
Definition at line 209 of file ct_utils.hpp.
|
inlinenoexcept |
XOR-combine two masks.
Definition at line 218 of file ct_utils.hpp.
|
inlinenoexcept |
OR-combine two masks.
Definition at line 227 of file ct_utils.hpp.
|
inlinenoexcept |
Negate this mask.
Definition at line 260 of file ct_utils.hpp.
|
inlinenoexcept |
Return x if the mask is set, or otherwise zero.
Definition at line 268 of file ct_utils.hpp.
|
inlinenoexcept |
Return x if the mask is cleared, or otherwise zero.
Definition at line 276 of file ct_utils.hpp.
|
inlinenoexcept |
If this mask is set, return x, otherwise return y.
Definition at line 284 of file ct_utils.hpp.
|
inlinenoexcept |
Definition at line 289 of file ct_utils.hpp.
|
inlinenoexcept |
If this mask is set, return x, otherwise return y.
Definition at line 299 of file ct_utils.hpp.
|
inlinenoexcept |
Conditionally set output to x or y, depending on if mask is set or cleared (resp)
Definition at line 308 of file ct_utils.hpp.
|
inlinenoexcept |
If this mask is set, zero out buf, otherwise do nothing.
Definition at line 317 of file ct_utils.hpp.
|
inlinenoexcept |
Return the value of the mask, unpoisoned.
Definition at line 328 of file ct_utils.hpp.
|
inlinenoexcept |
Return true iff this mask is set.
Definition at line 338 of file ct_utils.hpp.
|
inlinenoexcept |
Return the underlying value of the mask.
Definition at line 346 of file ct_utils.hpp.
|
friend |
AND-combine two masks.
Definition at line 236 of file ct_utils.hpp.
|
friend |
XOR-combine two masks.
Definition at line 244 of file ct_utils.hpp.
|
friend |
OR-combine two masks.
Definition at line 252 of file ct_utils.hpp.