Last active
July 9, 2023 01:02
-
-
Save tkoz0/11dc87e7ac8117e888fbfd0f0949a10b to your computer and use it in GitHub Desktop.
64 bit multiply with 128 bit result, compiles to native amd64 x86_64 instruction with gcc 9.4 -O3
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
typedef struct { uint64_t lo, hi; } mul64_t; | |
mul64_t mul64(uint64_t a, uint64_t b) | |
{ | |
mul64_t ret; | |
__uint128_t c = (__uint128_t) a * (__uint128_t) b; | |
ret.hi = c >> 64; | |
ret.lo = c; | |
return ret; | |
} | |
/* | |
mul64(unsigned long, unsigned long): | |
mov rax, rdi | |
mul rsi | |
ret | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment