-
-
Save travisdowns/edb91e38dede70a6fa2b882a3790328e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <inttypes.h> | |
#include <stdbool.h> | |
static inline uint64_t lg(uint64_t x) { | |
return 63U - (uint64_t)__builtin_clzl(x); | |
} | |
static inline uint32_t lg32(uint32_t x) { | |
return 31U - (uint32_t)__builtin_clz(x); | |
} | |
static inline uint64_t divide_chux(uint64_t p, uint64_t q) { | |
bool round_up = p & (q-1); | |
return (p >> lg(q)) + round_up; | |
} | |
static inline uint32_t divide_chux_32(uint32_t p, uint32_t q) { | |
bool round_up = p & (q-1); | |
return (p >> lg32(q)) + round_up; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment