Last active
July 9, 2023 01:05
-
-
Save tkoz0/f9ccc791874e6a9bbbd918aafbabc92b to your computer and use it in GitHub Desktop.
64 bit number modulo mersenne number (M61, 2^61-1) compiles with no multiplication or division 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
#include <stdint.h> | |
#define MP(p) ((1uLL << p) - 1) | |
uint64_t mod_m61(uint64_t a) | |
{ | |
uint64_t tmp = (a & MP(61)) + (a >> 61); | |
if (tmp >= MP(61)) | |
tmp -= MP(61); | |
return tmp; | |
} | |
// a simple (a % MP(61)) compiles with a multiplication and longer instruction sequence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment