Re: Arithmetic bug on ARM (STM 32 F4)

2021-01-22 Thread Titouan Coladon
Hi,

I cannot run make check because of the cross-compilation.

I also noticed that the GMP function "mpz_probab_prime_p" fail when GMP
is built with the latest versions (after 7) of gcc-arm-none-eabi.


Titouan Coladon


Le 22/01/2021 à 12:33, Vincent Lefevre a écrit :
> Hi,
>
> On 2021-01-22 11:59:43 +0100, Titouan Coladon wrote:
>> it's indeed, gcc that must have a bug.
>>
>> The older bare metal version: gcc-arm-none-eabi-7-2017-q4-major-linux is
>> working properly.
>>
>> Then the latest version : gcc-arm-none-eabi-8-2018-q4-major-linux,
>> gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux and
>> gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux all have the issue.
> Does "make check" fail? If it doesn't, perhaps a new test could be
> added.
>
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Arithmetic bug on ARM (STM 32 F4)

2021-01-22 Thread Vincent Lefevre
On 2021-01-22 13:29:13 +0100, Titouan Coladon wrote:
> I cannot run make check because of the cross-compilation.

I think that it would be a good idea to use an emulator to check the
GMP build. This should always be done. Compiler bugs are common.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Arithmetic bug on ARM (STM 32 F4)

2021-01-22 Thread Vincent Lefevre
Hi,

On 2021-01-22 11:59:43 +0100, Titouan Coladon wrote:
> it's indeed, gcc that must have a bug.
> 
> The older bare metal version: gcc-arm-none-eabi-7-2017-q4-major-linux is
> working properly.
> 
> Then the latest version : gcc-arm-none-eabi-8-2018-q4-major-linux,
> gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux and
> gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux all have the issue.

Does "make check" fail? If it doesn't, perhaps a new test could be
added.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Arithmetic bug on ARM (STM 32 F4)

2021-01-21 Thread Dennis Clarke
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 
#include 
#include 
#include 
#include 
#include 

#include 

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
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Arithmetic bug on ARM (STM 32 F4)

2021-01-21 Thread Torbjörn Granlund
  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.


-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs