Hi,

I found a bug when running some tests under Valgrind. The mpz_invert function gives wrong results if its arguments are larger than 64 bits.

GMP version: 6.1.2

Valgrind version: 3.13.0

GCC: gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1~16.04)

Kernel: Linux xlab-jan 4.4.0-128-generic #154-Ubuntu SMP Fri May 25 14:15:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Architecture: skylake-pc-linux-gnu

Code for reproducing: attached (Compile it with /gcc -o g gmp_valgrind.c -lgmp/ and run with /./g/ and /valgrind ./g/, when run normally it should output equal = 1 and under Valgrind equal = 0)


I know it's stated in the GMP Manual that Valgrind might not support instructions recently added to an ISA, but this seems like it should work. I hope I provided enough details to verify and reproduce this.

Best regards,

Jan


#include <gmp.h>

int main() {
    mpz_t g, p, z, i;
    mpz_inits(g, p, z, i, NULL);
    mpz_set_str(g, "164917514854091185926007547162250134788", 10);
    mpz_set_str(p, "297610433467095548694109139968310730599", 10);
    mpz_set_str(i, "227530644042031236994570943278081104642", 10);

    mpz_invert(z, g, p);
    gmp_printf("true inverse = %Zd\ncalculated inverse = %Zd\nequal = %d\n", i, z, !mpz_cmp(i, z));
    
    mpz_clears(g, p, z, i, NULL);
    return 0;
}
_______________________________________________
gmp-bugs mailing list
[email protected]
https://gmplib.org/mailman/listinfo/gmp-bugs

Reply via email to