Last active
July 19, 2020 10:58
-
-
Save danlark1/fc203457bf604071e128f59b0afd6df3 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
#if defined(__x86_64__) | |
inline uint64_t Divide128Div64To64(uint64_t high, uint64_t low, | |
uint64_t divisor, uint64_t* remainder) { | |
uint64_t result; | |
__asm__("divq %[v]" | |
: "=a"(result), "=d"(*remainder) // Output parametrs, =a for rax, =d for rdx, [v] is an | |
// alias for divisor, input paramters "a" and "d" for low and high. | |
: [v] "r"(divisor), "a"(low), "d"(high)); | |
return result; | |
} | |
#endif | |
tu_int __udivmodti4(tu_int dividend, tu_int divisor, tu_int* remainder) { | |
... | |
#if defined(__x86_64__) | |
if (divisor.high == 0 && dividend.high < divisor) { | |
remainder->high = 0; | |
uint64_t quotient = | |
Divide128Div64To64(dividend.high, dividend.low, | |
divisor.low, &remainder->low); | |
return quotient; | |
} | |
#endif | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment