Skip to content

Instantly share code, notes, and snippets.

Created June 14, 2020 18:52
What would you like to do?
#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” 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