Closed kimwalisch closed 5 years ago
The good news is that I was unable to generate a libdivide divisor that would miscalculate even though the internal libdivide_128_div_64_to_64()
helper function was clearly buggy and is used e.g. to generate a u64
libdivide divisor.
Bug report by Stefan Kanthak:
Here is a link to the full blog post: https://skanthak.homepage.t-online.de/division.html
I have written a standalone test program for libdivide's
libdivide_128_div_64_to_64()
function that can be compiled using GCC or Clang on a 64-bit CPU architecture. The test program calculates many combinations of x1/x2 where x1 is of type__uint128_t
and x2 is of typeuint64_t
. The test program always calculates x1/x2 twice, first using the builtin integer division and second using libdivide'slibdivide_128_div_64_to_64()
function and then compares both results for equality.The test program is able to reproduce the reported bug and I can also confirm that the proposed fix below fixes the bug:
And here is my test program:
The above test program can be compiled and run using: