pub fn bounds_mask(index: usize, size: usize) -> usizeExpand description
Branchless bounds mask for Spectre v1 mitigation.
Returns a mask that is all-ones if index < size and all-zeros
otherwise. The comparison is performed without a branch, so
mis-speculation cannot bypass the bounds check.
§Usage
ⓘ
let safe_idx = index & bounds_mask(index, arr.len());
let value = arr[safe_idx]; // safe even under mis-speculation