selectBit static method

Uint64 selectBit(
  1. Uint64 a,
  2. Uint64 b,
  3. Uint64 bit
)

Branch-free select on a 0/1 bit: returns b iff bit == 1, else a. The bit must already be a 0/1 Uint64 (never a bool), so no bool-to-mask conversion — which would itself be a branch — is needed.

Implementation

static Uint64 selectBit(Uint64 a, Uint64 b, Uint64 bit) {
  final m = Uint64.zero - bit;
  return (a & ~m) | (b & m);
}