0 Replies Latest reply on Feb 26, 2013 11:30 PM by briandamgaard

    Serious bug in widely used AMD publication




      AMD Athlon Processor x86 Code Optimization Guide

      Publication  No.: 22007

      Revision: K

      Date: February 2002




      Serious bug in all integer-64 division and remainder assembler routines:

      * _ulldiv

      * _lldiv

      * _ullrem

      * _llrem




      An unsigned division example:

      (2**64 - 1 ) divided by (2**32 + 3):


      18446744073709551615 div 4294967299 = 4294967294 (wrong)

      The correct result: 4294967293


      The problem:


      The problem is that the assembler code doesn't implement the "Hacker's Delight" division correctly. A description of the algorithm can be found here:





      Please note that:

      * The bugs spreads like a virus because many software products and programmers assume the publication it the autoritative implementation of these routines


      * The use of these routines will not die out just because modern 64-bit hardware has native support for 64-integers. Software always need double-integer support and programmers simply change the four routines to operate on whatever the double-integer bit-size is, e..g, 128 bits nowadays.


      For this reason it's imperative to make the public aware of the bug. I hope AMD will take action on this.