Arithmetic bug on ARM (STM 32 F4)

Dennis Clarke dclarke at blastwave.org
Fri Jan 22 02:52:09 UTC 2021


On 1/21/21 3:17 PM, Torbjörn Granlund wrote:
>   ttt =
>   3578942983869995381409279381784954092773488221200587338717407747084074518600438737913956360066709506626656635118978526559637095289631190671071178702312877654
> 
>   but ttt should be
>   5247183143879283565064056089869553515440215252945038779070795247972433237341511292686962488915110675351673985513318500576097977116134885013371639187873069514
> 
>   I give the code to reproduce the bug in attachment.
> 
>   GMP is built with the options:
>   CC=/home/titouan/Softs/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc
>   ../configure CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m4"
>   --host=arm-none-eabi --disable-assembly --prefix=YOUR_CHOICE
> 
> As you might guess, GMP's mod operation has been tested a lot during
> GMP's 30 years of existence.  A completely fundamental bug like the one
> you observe is of course still possible, but incredibly unlikely.
> 
> It is much more likely that the compiler you used for compiling GMP is
> buggy.  That's indeed where you should start looking.
> 
> Unfortunatly, we cannot help.  We don't know what compiler you used, and
> even if we did, we don't have access to it.
> 
> 

I just checked on Debian sid with gcc 10.2 and sparc64 and IBM Power9
ppc64le and also on Oracle Fujitsu SPARC64 with Oracle Studio 12.6 as
well as on Debian sid i686 and also FreeBSD UNIX with LLVM/Clang on
amd64 and then a few other sundy systems. All work perfectly.

/*******************************************************************
 * The Open Group Base Specifications Issue 6
 * IEEE Std 1003.1, 2004 Edition
 *
 *  An XSI-conforming application should ensure that the feature
 *  test macro _XOPEN_SOURCE is defined with the value 600 before
 *  inclusion of any header. This is needed to enable the
 *  functionality described in The _POSIX_C_SOURCE Feature Test
 *  Macro and in addition to enable the XSI extension.
 *******************************************************************/
#define _XOPEN_SOURCE 600

#include <errno.h>
#include <inttypes.h>
#include <locale.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <gmp.h>

int main(int argc, char *argv[])
{

    mpz_t t;
    mpz_init(t);
    mpz_t tt;
    mpz_init(tt);
    mpz_t ttt;
    mpz_init(ttt);

    mpz_t result_check, expected_result;
    mpz_init(result_check);
    mpz_init(expected_result);

    mpz_set_str( tt,
"25975415027868818028037643145183730078267964363630309107863975221668725232906664910091356673487591948237515304861352649057814029879720636142810833722202669061030484458925649047021859875730105532595466846094449735851132072400310565642",
10);

    mpz_set_str(t,
"6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449",
10);

    mpz_mod(ttt, tt, t);

    printf("tt = ");
    gmp_printf("%Zd", tt);
    printf("\n");

    printf("t = ");
    gmp_printf("%Zd", t);
    printf("\n");

    printf("ttt = ");
    gmp_printf("%Zd", ttt);
    printf("\n");


    mpz_set_str(expected_result,

"5247183143879283565064056089869553515440215252945038779070795247972433237341511292686962488915110675351673985513318500576097977116134885013371639187873069514",
10);


    mpz_sub(result_check, expected_result, ttt);
    printf("\n check the diff on the expected result = ");
    gmp_printf("%Zd",result_check);
    printf("\n");


    mpz_clear(t);
    mpz_clear(tt);
    mpz_clear(ttt);

    mpz_clear(expected_result);
    mpz_clear(result_check);

    return EXIT_SUCCESS;

}


As soon as I have some arm data I will be sure to pass that along.



-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional


More information about the gmp-bugs mailing list