-
-
Save anonymous/5350e5394a379f99774d01dace85f6ef 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
inline uint64_t lg(uint64_t x) { | |
return 63U - (uint64_t)__builtin_clzl(x); | |
} | |
inline uint32_t lg32(uint32_t x) { | |
return 31U - (uint32_t)__builtin_clz(x); | |
} | |
inline uint32_t divide_questionc_32(uint32_t p, uint32_t q) { | |
uint32_t e = lg32(q); | |
return (((int32_t)p - 1) >> e) + 1; | |
} | |
inline uint64_t divide_questionc(uint64_t p, uint64_t q) { | |
uint64_t e = lg(q); | |
return (((int64_t)p - 1) >> e) + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment