AMD K6 assembler GCD bug

Kevin Ryde user42 at
Wed Apr 7 03:18:32 CEST 2004

Alas, a bug in the AMD K6 assembler code has been discovered, causing
wrong results from mpz_gcd and other functions involving GCDs.

Hosts "k6-*-*", "k62-*-*" and "k63-*-*" are affected, dating back to
the introduction of the code in gmp 4.0.

Patch below for mpn/x86/k6/gcd_finda.asm.

The program k6gcd.c below exhibits the bug.  You can use it (or the
numbers in it) to check whether you're affected and/or have
successfully patched.  The gcd of the values is 5, but the bug causes
it to come out as 1.

We believe in general the bug will bite rather rarely, and that the
wrong result will still be a divisor of the inputs, but not the
greatest possible divisor.

All folloups or queries to gmp-discuss at please.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcd_finda.asm.jbe.diff
Type: text/x-patch
Size: 215 bytes
Desc: not available
Url : /list-archives/gmp-announce/attachments/20040407/d5d71e9d/gcd_finda.asm.jbe.bin
-------------- next part --------------
#include "gmp.h"

main (void)
  mpz_t a, b, g;
  mpz_init_set_str (a, "3FFC000007FFFFFFFFFF00000000003F83FFFFFFFFFFFFFFF80000000000000001", 16);
  mpz_init_set_str (b, "1FFE0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC000000000000000000000001", 16);
  mpz_init (g);
  mpz_gcd (g, a, b);
  gmp_printf ("expect result 5, the result is %Zd\n", g);
  return 0;

More information about the gmp-announce mailing list