#include <stdint.h> | |
// 0xff if MSB(x) = 1 else 0x00 | |
uint8_t msb(uint8_t x) { | |
return 0 - (x >> (8 * sizeof(x) - 1)); | |
} | |
// 0xff if a < b else 0x00 | |
uint8_t lt(uint8_t a, uint8_t b) { | |
return msb(a ^ ((a ^ b) | ((a - b) ^ b))); | |
} | |
uint8_t add(uint8_t a, uint8_t b) { | |
return (a + b) | lt(a + b, a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment