#include <cstdint> #include <cassert> #include <vector> #include <math.h>
static inline uint32_t fast_max_u32(uint32_t a, uint32_t b) { return a + ((b - a) & -(((uint64_t)a - b) >> 63)); }
int main(void) { std::vector<std::pair<uint32_t, uint32_t>> checks = { { 0, 0}, { 0, 1}, { 1, 0}, { 1, 1}, { 0, UINT32_MAX - 1}, { 0, UINT32_MAX}, { 1, UINT32_MAX - 1}, { 1, UINT32_MAX}, {UINT32_MAX - 1, 0}, {UINT32_MAX - 1, 1}, { UINT32_MAX, 0}, { UINT32_MAX, 1}, {UINT32_MAX - 1, UINT32_MAX - 1}, {UINT32_MAX - 1, UINT32_MAX}, { UINT32_MAX, UINT32_MAX - 1}, { UINT32_MAX, UINT32_MAX}, }; for (auto i: checks) { assert(fast_max_u32(i.first, i.second) == std::max(i.first, i.second)); } return 0; }