Skip to content

Instantly share code, notes, and snippets.

@dmwit
Last active April 12, 2022 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmwit/c0abc5995739bc750b8e2d85c7166b4e to your computer and use it in GitHub Desktop.
Save dmwit/c0abc5995739bc750b8e2d85c7166b4e to your computer and use it in GitHub Desktop.
#include "32x32to64mul.h"
uint64_t mul64(uint32_t, uint32_t);
inline uint64_t mul64(uint32_t x, uint32_t y) {
uint32_t xlo = x&0xffff, xhi = x>>16, ylo = y&0xffff, yhi = y>>16;
return ((uint64_t)(xhi*yhi) << 32)
+ ((uint64_t)(xhi*ylo) << 16)
+ ((uint64_t)(xlo*yhi) << 16)
+ ((uint64_t)(xlo*ylo) << 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment