Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created June 14, 2020 18:52
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 danlark1/5afcaba4fdd3e74f0d4a014e332948aa to your computer and use it in GitHub Desktop.
Save danlark1/5afcaba4fdd3e74f0d4a014e332948aa to your computer and use it in GitHub Desktop.
#include <cinttypes>
uint64_t div(uint64_t u1, uint64_t u0, uint64_t v) {
uint64_t result;
uint64_t remainder;
__asm__("divq %[v]" : "=a"(result), "=d"(remainder) : [v] "r"(v), "a"(u0), "d"(u1));
return result;
}
int main() {
div(1, 0, 1); // 2**64 / 1
}
/*
g++ -std=c++17 -O0 main.cpp -o main
./main
“./main” terminated by signal SIGFPE (Floating point exception)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment