What is the fastest and cross platform/compiler (GCC and MSVC) way to multiply 64b x 32b divide by 64b integers like:
uint64_t counter;
uint32_t resolution = NANOS_IN_SEC; // NANOS_IN_SEC = 1000000000
uint64_t freq;
uint64_t res = (counter * resolution) / freq; // but without overflow/losing precision
Result is guaranteed to always fit into 64b.
I checked a lot of answers, but all of them solved 64b x 64b multiplication and were quite slow.
Is there a solution how to reduce the code complexity when we can assume the 2nd operand to be 32b only?