mirror of
https://review.haiku-os.org/buildtools
synced 2024-11-23 07:18:49 +01:00
Redo Update MPFR to 4.1.0
GCC had a horrible .gitignore, untracked files were not applied
This commit is contained in:
parent
4389066602
commit
0af6003997
77
gcc/mpfr/doc/mini-gmp
Normal file
77
gcc/mpfr/doc/mini-gmp
Normal file
@ -0,0 +1,77 @@
|
||||
How to compile GNU MPFR with mini-gmp
|
||||
=====================================
|
||||
|
||||
To build and test MPFR against mini-gmp:
|
||||
|
||||
./configure --with-mini-gmp=DIR [other configure options]
|
||||
make
|
||||
make check
|
||||
|
||||
where DIR is the directory that contains mini-gmp
|
||||
(for example .../gmp-6.2.0/mini-gmp).
|
||||
|
||||
"make" will build mini-gmp with the same compiler as for MPFR.
|
||||
|
||||
For "make check", tests that use features not supported by mini-gmp
|
||||
(mpq_t, mpf_t, and the gmp_*printf functions) are skipped.
|
||||
|
||||
Note: To use this version of the MPFR library, you need to define
|
||||
the MPFR_USE_MINI_GMP macro before including mpfr.h (alternatively,
|
||||
you can modify mpfr.h to define this macro at the beginning, though
|
||||
this is discouraged). And since mini-gmp currently does not provide
|
||||
random functions, you also need to define the gmp_randstate_t type
|
||||
with
|
||||
|
||||
typedef long int gmp_randstate_t[1];
|
||||
|
||||
before including mpfr.h (or you may want to modify mini-gmp.h).
|
||||
|
||||
Remark: The random functions provided by MPFR configured with mini-gmp
|
||||
use the POSIX lrand48() and srand48() functions (the platform needs to
|
||||
provide them), thus one should avoid mini-gmp if one needs some really
|
||||
serious random functions. Another consequence is that these functions
|
||||
are not thread-safe.
|
||||
|
||||
This was tested with MPFR svn r13974 and GMP 6.2.0 on x86_64 GNU/Linux:
|
||||
============================================================================
|
||||
Testsuite summary for MPFR 4.1.0-dev
|
||||
============================================================================
|
||||
# TOTAL: 183
|
||||
# PASS: 172
|
||||
# SKIP: 11
|
||||
# XFAIL: 0
|
||||
# FAIL: 0
|
||||
# XPASS: 0
|
||||
# ERROR: 0
|
||||
============================================================================
|
||||
|
||||
How to use mini-gmp with reduced limb size
|
||||
==========================================
|
||||
|
||||
Following the idea of Micro-GMP [1], the GMP developers have adapted mini-gmp
|
||||
so that it can be used with a reduced limb size. For that, you need GMP 6.2.0
|
||||
(or later) and define the MINI_GMP_LIMB_TYPE macro with the associated base
|
||||
type, e.g.
|
||||
|
||||
-DMINI_GMP_LIMB_TYPE=char (in practice, 8 bits)
|
||||
-DMINI_GMP_LIMB_TYPE=short (in practice, 16 bits)
|
||||
-DMINI_GMP_LIMB_TYPE=int (in practice, 32 bits)
|
||||
|
||||
For example:
|
||||
|
||||
./configure --with-mini-gmp=DIR CFLAGS="-DMINI_GMP_LIMB_TYPE=int"
|
||||
|
||||
This was tested with MPFR svn r13974 and GMP 6.2.0 on x86_64 GNU/Linux:
|
||||
============================================================================
|
||||
Testsuite summary for MPFR 4.1.0-dev
|
||||
============================================================================
|
||||
# TOTAL: 183
|
||||
# PASS: 172
|
||||
# SKIP: 11
|
||||
# XFAIL: 0
|
||||
# FAIL: 0
|
||||
# XPASS: 0
|
||||
# ERROR: 0
|
||||
============================================================================
|
||||
|
||||
[1] https://members.loria.fr/PZimmermann/talks/microgmp.pdf
|
90
gcc/mpfr/examples/threads.c
Normal file
90
gcc/mpfr/examples/threads.c
Normal file
@ -0,0 +1,90 @@
|
||||
/* Multithreading test to detect scaling issues with MPFR.
|
||||
|
||||
Define:
|
||||
* the function F;
|
||||
* the precision PREC;
|
||||
* the value V as an expression that will have the type double
|
||||
(it may depend on the thread number i).
|
||||
|
||||
Example:
|
||||
gcc threads.c -lmpfr -lgmp -lpthread -DF=mpfr_sin -DPREC=200 -DV=100
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <mpfr.h>
|
||||
|
||||
#define MAX_THREADS 256
|
||||
|
||||
static int m;
|
||||
|
||||
static void *start_routine (void *arg)
|
||||
{
|
||||
mpfr_t x, y;
|
||||
int i = *(int *) arg, j;
|
||||
|
||||
(void) i; /* avoid a warning if i is not used by V */
|
||||
|
||||
mpfr_inits2 (PREC, x, y, (mpfr_ptr) 0);
|
||||
mpfr_set_d (x, (V), MPFR_RNDN);
|
||||
|
||||
for (j = 0; j < m; j++)
|
||||
F (y, x, MPFR_RNDN);
|
||||
|
||||
mpfr_clears (x, y, (mpfr_ptr) 0);
|
||||
pthread_exit (NULL);
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int i, n;
|
||||
pthread_t tid[MAX_THREADS];
|
||||
|
||||
if (argc != 3 ||
|
||||
(m = atoi (argv[1]), m < 1) ||
|
||||
(n = atoi (argv[2]), n < 1 || n > MAX_THREADS))
|
||||
{
|
||||
fprintf (stderr, "Usage: %s <#iterations> <#threads>\n", argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
printf ("%d iteration(s), %d thread(s).\n", m, n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (pthread_create (&tid[i], NULL, start_routine, &i) != 0)
|
||||
{
|
||||
fprintf (stderr, "%s: failed to create thread %d\n", argv[0], i);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (pthread_join (tid[i], NULL) != 0)
|
||||
{
|
||||
fprintf (stderr, "%s: failed to join thread %d\n", argv[0], i);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
363
gcc/mpfr/src/add1sp1_extracted.c
Normal file
363
gcc/mpfr/src/add1sp1_extracted.c
Normal file
@ -0,0 +1,363 @@
|
||||
/* mpfr_add1sp1 -- internal function to perform a "real" addition on one limb
|
||||
This code was extracted by Kremlin from a formal proof in F*
|
||||
done by Jianyang Pan in April-August 2018: do not modify it!
|
||||
|
||||
Source: https://github.com/project-everest/hacl-star/tree/dev_mpfr/code/mpfr
|
||||
|
||||
Copyright 2004-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#define int64_t long
|
||||
#define uint32_t unsigned int
|
||||
#define uint64_t mp_limb_t
|
||||
|
||||
typedef struct MPFR_Add1sp1_state_s
|
||||
{
|
||||
int64_t sh;
|
||||
int64_t bx;
|
||||
uint64_t rb;
|
||||
uint64_t sb;
|
||||
}
|
||||
MPFR_Add1sp1_state;
|
||||
|
||||
static MPFR_Add1sp1_state
|
||||
MPFR_Add1sp1_mk_state(int64_t sh, int64_t bx, uint64_t rb, uint64_t sb)
|
||||
{
|
||||
return ((MPFR_Add1sp1_state){ .sh = sh, .bx = bx, .rb = rb, .sb = sb });
|
||||
}
|
||||
|
||||
typedef struct K___uint64_t_int64_t_s
|
||||
{
|
||||
uint64_t fst;
|
||||
int64_t snd;
|
||||
}
|
||||
K___uint64_t_int64_t;
|
||||
|
||||
typedef struct K___uint64_t_uint64_t_int64_t_s
|
||||
{
|
||||
uint64_t fst;
|
||||
uint64_t snd;
|
||||
int64_t thd;
|
||||
}
|
||||
K___uint64_t_uint64_t_int64_t;
|
||||
|
||||
#define MPFR_Lib_mpfr_struct __mpfr_struct
|
||||
#define MPFR_Lib_mpfr_RET(I) ((I) != 0 ? ((__gmpfr_flags |= MPFR_FLAGS_INEXACT), (I)) : 0)
|
||||
#define MPFR_Exceptions_mpfr_overflow mpfr_overflow
|
||||
#define mpfr_prec _mpfr_prec
|
||||
#define mpfr_exp _mpfr_exp
|
||||
#define mpfr_d _mpfr_d
|
||||
#define mpfr_sign _mpfr_sign
|
||||
#define MPFR_Lib_gmp_NUMB_BITS GMP_NUMB_BITS
|
||||
#define MPFR_Lib_mpfr_EMAX __gmpfr_emax
|
||||
|
||||
#define MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode) (rnd_mode == MPFR_RNDN)
|
||||
#define MPFR_RoundingMode_mpfr_IS_LIKE_RNDZ MPFR_IS_LIKE_RNDZ
|
||||
|
||||
/* same as mpfr_add1sp, but for p < GMP_NUMB_BITS */
|
||||
static int
|
||||
mpfr_add1sp1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode,
|
||||
mpfr_prec_t p)
|
||||
{
|
||||
MPFR_Lib_mpfr_struct a0 = a[0U];
|
||||
MPFR_Lib_mpfr_struct b0 = b[0U];
|
||||
MPFR_Lib_mpfr_struct c0 = c[0U];
|
||||
int64_t bx = b0.mpfr_exp;
|
||||
int64_t cx = c0.mpfr_exp;
|
||||
int64_t sh = MPFR_Lib_gmp_NUMB_BITS - p;
|
||||
MPFR_Add1sp1_state st;
|
||||
if (bx == cx)
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = b0.mpfr_d;
|
||||
uint64_t *cp = c0.mpfr_d;
|
||||
uint64_t a01 = (bp[0U] >> (uint32_t)1U) + (cp[0U] >> (uint32_t)1U);
|
||||
int64_t bx1 = b0.mpfr_exp + (int64_t)1;
|
||||
uint64_t rb = a01 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
ap[0U] = a01 ^ rb;
|
||||
uint64_t sb = (uint64_t)0U;
|
||||
st = MPFR_Add1sp1_mk_state(sh, bx1, rb, sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPFR_Add1sp1_state ite0;
|
||||
if (bx > cx)
|
||||
{
|
||||
int64_t bx1 = b0.mpfr_exp;
|
||||
int64_t cx1 = c0.mpfr_exp;
|
||||
int64_t d = bx1 - cx1;
|
||||
uint64_t mask = ((uint64_t)1U << (uint32_t)sh) - (uint64_t)1U;
|
||||
MPFR_Add1sp1_state ite1;
|
||||
if (d < sh)
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = b0.mpfr_d;
|
||||
uint64_t *cp = c0.mpfr_d;
|
||||
int64_t bx2 = b0.mpfr_exp;
|
||||
uint64_t a01 = bp[0U] + (cp[0U] >> (uint32_t)d);
|
||||
K___uint64_t_int64_t scrut;
|
||||
if (a01 < bp[0U])
|
||||
scrut =
|
||||
(
|
||||
(K___uint64_t_int64_t){
|
||||
.fst = (uint64_t)0x8000000000000000U | a01 >> (uint32_t)1U,
|
||||
.snd = bx2 + (int64_t)1
|
||||
}
|
||||
);
|
||||
else
|
||||
scrut = ((K___uint64_t_int64_t){ .fst = a01, .snd = bx2 });
|
||||
uint64_t a02 = scrut.fst;
|
||||
int64_t bx3 = scrut.snd;
|
||||
uint64_t rb = a02 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb = (a02 & mask) ^ rb;
|
||||
ap[0U] = a02 & ~mask;
|
||||
ite1 = MPFR_Add1sp1_mk_state(sh, bx3, rb, sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPFR_Add1sp1_state ite;
|
||||
if (d < MPFR_Lib_gmp_NUMB_BITS)
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = b0.mpfr_d;
|
||||
uint64_t *cp = c0.mpfr_d;
|
||||
int64_t bx2 = b0.mpfr_exp;
|
||||
uint64_t sb = cp[0U] << (uint32_t)(MPFR_Lib_gmp_NUMB_BITS - d);
|
||||
uint64_t a01 = bp[0U] + (cp[0U] >> (uint32_t)d);
|
||||
K___uint64_t_uint64_t_int64_t scrut;
|
||||
if (a01 < bp[0U])
|
||||
scrut =
|
||||
(
|
||||
(K___uint64_t_uint64_t_int64_t){
|
||||
.fst = sb | (a01 & (uint64_t)1U),
|
||||
.snd = (uint64_t)0x8000000000000000U | a01 >> (uint32_t)1U,
|
||||
.thd = bx2 + (int64_t)1
|
||||
}
|
||||
);
|
||||
else
|
||||
scrut = ((K___uint64_t_uint64_t_int64_t){ .fst = sb, .snd = a01, .thd = bx2 });
|
||||
uint64_t sb1 = scrut.fst;
|
||||
uint64_t a02 = scrut.snd;
|
||||
int64_t bx3 = scrut.thd;
|
||||
uint64_t rb = a02 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb2 = sb1 | ((a02 & mask) ^ rb);
|
||||
ap[0U] = a02 & ~mask;
|
||||
ite = MPFR_Add1sp1_mk_state(sh, bx3, rb, sb2);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = b0.mpfr_d;
|
||||
int64_t bx2 = b0.mpfr_exp;
|
||||
ap[0U] = bp[0U];
|
||||
uint64_t rb = (uint64_t)0U;
|
||||
uint64_t sb = (uint64_t)1U;
|
||||
ite = MPFR_Add1sp1_mk_state(sh, bx2, rb, sb);
|
||||
}
|
||||
ite1 = ite;
|
||||
}
|
||||
ite0 = ite1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t bx1 = c0.mpfr_exp;
|
||||
int64_t cx1 = b0.mpfr_exp;
|
||||
int64_t d = bx1 - cx1;
|
||||
uint64_t mask = ((uint64_t)1U << (uint32_t)sh) - (uint64_t)1U;
|
||||
MPFR_Add1sp1_state ite1;
|
||||
if (d < sh)
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = c0.mpfr_d;
|
||||
uint64_t *cp = b0.mpfr_d;
|
||||
int64_t bx2 = c0.mpfr_exp;
|
||||
uint64_t a01 = bp[0U] + (cp[0U] >> (uint32_t)d);
|
||||
K___uint64_t_int64_t scrut;
|
||||
if (a01 < bp[0U])
|
||||
scrut =
|
||||
(
|
||||
(K___uint64_t_int64_t){
|
||||
.fst = (uint64_t)0x8000000000000000U | a01 >> (uint32_t)1U,
|
||||
.snd = bx2 + (int64_t)1
|
||||
}
|
||||
);
|
||||
else
|
||||
scrut = ((K___uint64_t_int64_t){ .fst = a01, .snd = bx2 });
|
||||
uint64_t a02 = scrut.fst;
|
||||
int64_t bx3 = scrut.snd;
|
||||
uint64_t rb = a02 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb = (a02 & mask) ^ rb;
|
||||
ap[0U] = a02 & ~mask;
|
||||
ite1 = MPFR_Add1sp1_mk_state(sh, bx3, rb, sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPFR_Add1sp1_state ite;
|
||||
if (d < MPFR_Lib_gmp_NUMB_BITS)
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = c0.mpfr_d;
|
||||
uint64_t *cp = b0.mpfr_d;
|
||||
int64_t bx2 = c0.mpfr_exp;
|
||||
uint64_t sb = cp[0U] << (uint32_t)(MPFR_Lib_gmp_NUMB_BITS - d);
|
||||
uint64_t a01 = bp[0U] + (cp[0U] >> (uint32_t)d);
|
||||
K___uint64_t_uint64_t_int64_t scrut;
|
||||
if (a01 < bp[0U])
|
||||
scrut =
|
||||
(
|
||||
(K___uint64_t_uint64_t_int64_t){
|
||||
.fst = sb | (a01 & (uint64_t)1U),
|
||||
.snd = (uint64_t)0x8000000000000000U | a01 >> (uint32_t)1U,
|
||||
.thd = bx2 + (int64_t)1
|
||||
}
|
||||
);
|
||||
else
|
||||
scrut = ((K___uint64_t_uint64_t_int64_t){ .fst = sb, .snd = a01, .thd = bx2 });
|
||||
uint64_t sb1 = scrut.fst;
|
||||
uint64_t a02 = scrut.snd;
|
||||
int64_t bx3 = scrut.thd;
|
||||
uint64_t rb = a02 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb2 = sb1 | ((a02 & mask) ^ rb);
|
||||
ap[0U] = a02 & ~mask;
|
||||
ite = MPFR_Add1sp1_mk_state(sh, bx3, rb, sb2);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap = a0.mpfr_d;
|
||||
uint64_t *bp = c0.mpfr_d;
|
||||
int64_t bx2 = c0.mpfr_exp;
|
||||
ap[0U] = bp[0U];
|
||||
uint64_t rb = (uint64_t)0U;
|
||||
uint64_t sb = (uint64_t)1U;
|
||||
ite = MPFR_Add1sp1_mk_state(sh, bx2, rb, sb);
|
||||
}
|
||||
ite1 = ite;
|
||||
}
|
||||
ite0 = ite1;
|
||||
}
|
||||
st = ite0;
|
||||
}
|
||||
if (st.bx > MPFR_Lib_mpfr_EMAX)
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap = a->mpfr_d;
|
||||
uint64_t a01 = ap[0U];
|
||||
MPFR_Lib_mpfr_struct uu___72_3478 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3478.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3478.mpfr_sign,
|
||||
.mpfr_exp = st.bx,
|
||||
.mpfr_d = uu___72_3478.mpfr_d
|
||||
}
|
||||
);
|
||||
if (st.rb == (uint64_t)0U && st.sb == (uint64_t)0U)
|
||||
return MPFR_Lib_mpfr_RET((int32_t)0);
|
||||
else if (MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode))
|
||||
if
|
||||
(
|
||||
st.rb
|
||||
== (uint64_t)0U
|
||||
|| (st.sb == (uint64_t)0U && (a01 & (uint64_t)1U << (uint32_t)st.sh) == (uint64_t)0U)
|
||||
)
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap1 = a->mpfr_d;
|
||||
ap1[0U] = ap1[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
if (ap1[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap1[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (st.bx + (int64_t)1 <= MPFR_Lib_mpfr_EMAX)
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3574 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3574.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3574.mpfr_sign,
|
||||
.mpfr_exp = st.bx + (int64_t)1,
|
||||
.mpfr_d = uu___72_3574.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
return MPFR_Lib_mpfr_RET(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else if (MPFR_RoundingMode_mpfr_IS_LIKE_RNDZ(rnd_mode, a->mpfr_sign < (int32_t)0))
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap1 = a->mpfr_d;
|
||||
ap1[0U] = ap1[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
if (ap1[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap1[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (st.bx + (int64_t)1 <= MPFR_Lib_mpfr_EMAX)
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3781 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3781.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3781.mpfr_sign,
|
||||
.mpfr_exp = st.bx + (int64_t)1,
|
||||
.mpfr_d = uu___72_3781.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
return MPFR_Lib_mpfr_RET(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
}
|
233
gcc/mpfr/src/amd/mparam.h
Normal file
233
gcc/mpfr/src/amd/mparam.h
Normal file
@ -0,0 +1,233 @@
|
||||
/* Various Thresholds of MPFR, not exported. -*- mode: C -*-
|
||||
|
||||
Copyright 2005-2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* Generated by MPFR's tuneup.c, 2018-02-22, gcc 6.3.0 */
|
||||
/* gcc13.fsffrance.org (Dual-Core AMD Opteron(tm) Processor 2212)
|
||||
with gmp 6.1.2, which uses -m64 -mtune=k8 -march=k8. */
|
||||
|
||||
#define MPFR_MULHIGH_TAB \
|
||||
-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,9,11, \
|
||||
12,13,11,15,14,15,15,16,18,18,19,20,18,19,19,20, \
|
||||
22,23,23,24,26,30,28,24,30,32,30,32,32,30,30,32, \
|
||||
32,30,30,32,32,38,32,40,36,36,40,40,38,38,38,38, \
|
||||
38,40,44,44,46,46,44,46,48,46,52,48,56,56,56,56, \
|
||||
56,56,56,60,60,60,64,64,64,64,64,64,64,64,64,64, \
|
||||
72,72,72,72,72,72,72,72,72,72,72,72,80,80,80,80, \
|
||||
80,80,80,80,80,80,80,80,80,93,80,93,93,80,80,93, \
|
||||
80,80,80,80,80,105,93,93,93,93,93,93,93,93,93,108, \
|
||||
93,93,111,93,105,117,105,117,117,117,111,117,117,105,111,105, \
|
||||
108,105,117,117,117,117,117,117,117,117,117,117,117,117,111,117, \
|
||||
117,117,117,117,129,129,117,129,129,129,135,129,129,129,135,135, \
|
||||
135,141,141,129,129,141,132,141,141,141,141,135,141,141,141,141, \
|
||||
141,141,141,141,141,141,141,159,141,153,141,153,153,165,165,165, \
|
||||
159,165,165,165,165,165,165,165,165,165,165,177,189,189,189,189, \
|
||||
189,189,177,189,189,189,189,189,189,189,189,189,189,189,189,189, \
|
||||
189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189, \
|
||||
189,213,213,189,189,189,189,189,213,213,213,213,213,213,213,213, \
|
||||
213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213, \
|
||||
213,213,213,213,213,213,213,213,213,213,213,213,213,213,225,225, \
|
||||
225,237,225,225,237,237,237,237,237,237,237,237,237,237,237,252, \
|
||||
237,237,252,252,252,252,252,252,252,252,252,252,252,252,252,252, \
|
||||
252,252,284,252,284,284,252,284,284,252,284,284,284,284,284,284, \
|
||||
284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284, \
|
||||
284,284,284,284,284,284,284,284,284,284,284,284,284,300,300,284, \
|
||||
300,300,300,300,300,300,300,300,316,316,315,316,316,315,316,316, \
|
||||
316,316,315,316,316,316,316,316,316,316,316,316,316,316,316,316, \
|
||||
316,314,315,316,316,316,316,314,315,316,316,316,316,316,316,316, \
|
||||
316,316,316,316,316,316,316,316,316,378,378,378,378,378,378,378, \
|
||||
378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378, \
|
||||
378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378, \
|
||||
378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,426, \
|
||||
378,426,378,426,378,378,378,378,426,426,426,426,426,426,426,426, \
|
||||
426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426, \
|
||||
426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426, \
|
||||
426,426,426,426,426,425,426,426,426,426,426,426,426,426,426,425, \
|
||||
426,426,426,426,474,425,474,426,474,474,504,426,474,504,504,504, \
|
||||
504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504, \
|
||||
504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504, \
|
||||
504,504,504,504,504,504,504,504,504,504,504,504,504,503,504,504, \
|
||||
504,504,504,504,504,504,504,503,504,504,503,504,504,504,504,504, \
|
||||
504,504,568,504,568,504,504,504,568,504,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,567,568,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,568,568,567,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,567,568,568,568,567,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,567,568,568,568,568,568,568,568,568,568, \
|
||||
600,568,568,568,600,632,632,568,632,632,632,632,632,600,632,600, \
|
||||
632,632,600,600,632,632,599,600,632,632,632,632,632,632,632,632, \
|
||||
632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632, \
|
||||
632,632,632,632,632,632,631,632,632,632,632,632,630,631,632,632, \
|
||||
632,632,631,632,632,632,632,632,631,632,631,632,632,632,631,632, \
|
||||
632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,631, \
|
||||
632,632,632,632,632,632,631,632,632,632,632,632,632,736,632,736, \
|
||||
736,736,736,736,736,735,736,735,736,736,736,735,736,736,736,735, \
|
||||
735,736,735,736,736,736,736,736,736,736,736,735,736,736,736,736, \
|
||||
736,736,736,736,735,736,736,736,736,736,736,736,736,736,735,736, \
|
||||
736,736,736,736,736,736,735,736,734,736,736,736,736,736,735,736, \
|
||||
735,736,735,736,736,736,736,736,735,736,736,736,736,736,736,736, \
|
||||
736,736,736,736,736,736,736,735,736,736,736,832,736,736,832,832, \
|
||||
736,831,831,832,832,832,832,832,832,832,830,832,832,832,832,832, \
|
||||
832,832,831,832,832,832,832,832,832,832,832,830,831,832,831,832, \
|
||||
831,832,832,832,832,832,831,832,831,831,831,832,832,832,832,832, \
|
||||
832,832,832,832,831,832,832,832,832,832,832,832,831,832,831,832 \
|
||||
|
||||
#define MPFR_SQRHIGH_TAB \
|
||||
-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,9,9,11, \
|
||||
11,11,11,12,13,14,15,15,17,18,18,17,17,18,18,20, \
|
||||
20,18,19,19,20,21,23,23,24,25,23,23,24,25,26,27, \
|
||||
28,27,28,29,28,31,32,31,32,31,32,33,34,34,34,40, \
|
||||
40,40,40,40,40,40,40,40,40,46,46,46,42,46,46,48, \
|
||||
48,48,48,48,48,48,48,48,56,54,56,56,56,48,56,56, \
|
||||
50,50,52,52,62,54,54,56,56,54,58,60,62,62,58,64, \
|
||||
64,62,66,64,64,72,66,68,66,72,72,72,72,72,72,72, \
|
||||
72,72,72,72,80,72,80,72,80,72,80,80,80,80,80,80, \
|
||||
84,80,80,84,80,80,80,80,80,92,92,92,96,92,96,92, \
|
||||
96,92,96,92,96,96,96,96,96,96,96,100,96,96,96,96, \
|
||||
96,96,96,96,100,96,96,112,112,112,96,112,112,112,112,112, \
|
||||
112,112,112,104,112,111,112,112,112,112,112,112,112,112,112,112, \
|
||||
112,112,112,141,112,141,135,135,141,135,128,141,141,141,135,141, \
|
||||
128,141,140,141,141,141,135,135,141,135,141,141,141,141,141,141, \
|
||||
141,141,147,141,141,147,147,141,141,141,159,147,141,147,147,159, \
|
||||
158,159,159,159,159,159,165,159,165,165,159,165,165,159,165,165, \
|
||||
165,171,159,165,165,165,165,165,165,165,171,171,165,171,171,183, \
|
||||
189,189,183,189,189,189,189,189,189,189,189,189,189,189,189,189, \
|
||||
189,189,189,188,189,189,188,171,171,188,189,189,189,189,189,189, \
|
||||
189,189,183,183,183,189,189,183,188,189,189,195,213,189,189,195, \
|
||||
189,189,188,195,189,189,189,195,213,189,189,189,213,213,213,189, \
|
||||
189,213,213,189,189,189,195,189,189,189,195,188,189,213,213,195, \
|
||||
213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213, \
|
||||
213,213,213,212,213,213,237,236,213,237,213,213,213,213,237,237, \
|
||||
237,237,237,237,237,237,237,237,237,237,237,236,237,237,237,237, \
|
||||
237,237,237,237,237,249,237,237,237,237,237,237,237,249,237,237, \
|
||||
237,272,273,236,273,237,273,273,273,285,273,273,249,273,237,285, \
|
||||
273,273,273,273,285,237,285,285,273,285,273,284,285,285,285,285, \
|
||||
285,285,285,285,285,285,285,284,285,285,285,285,285,284,273,284, \
|
||||
285,285,285,284,285,285,285,285,285,285,285,285,285,285,285,285, \
|
||||
285,285,285,285,284,333,333,333,309,333,285,332,333,333,309,333, \
|
||||
333,309,332,333,321,321,333,309,333,333,333,333,333,332,333,332, \
|
||||
333,333,333,333,333,332,333,333,332,333,333,333,333,333,333,333, \
|
||||
333,333,333,333,332,333,333,333,333,333,333,333,333,333,333,333, \
|
||||
333,333,333,333,333,332,333,333,333,332,333,333,333,333,333,333, \
|
||||
333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333, \
|
||||
333,333,333,333,333,420,333,333,333,402,420,420,402,402,420,420, \
|
||||
402,420,420,420,419,402,420,420,420,420,420,420,420,420,420,420, \
|
||||
420,420,420,420,420,420,420,420,420,420,420,419,420,420,420,420, \
|
||||
420,420,419,420,402,420,420,420,420,420,420,420,420,402,401,420, \
|
||||
420,420,402,420,420,402,419,420,420,420,419,420,420,420,420,420, \
|
||||
420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420, \
|
||||
420,420,420,420,420,418,419,420,419,420,420,420,420,420,420,420, \
|
||||
420,420,420,419,420,420,420,420,420,420,402,420,420,417,420,420, \
|
||||
420,420,420,420,420,420,420,420,419,420,420,420,420,420,420,420, \
|
||||
420,420,438,420,438,438,420,420,420,420,419,420,420,474,420,474, \
|
||||
474,474,474,492,492,474,420,474,492,474,420,492,568,473,420,492, \
|
||||
492,492,568,492,568,568,568,568,492,568,568,568,568,568,568,567, \
|
||||
568,568,568,568,568,568,492,568,568,492,568,568,568,492,568,568, \
|
||||
568,568,568,568,568,492,568,568,568,568,568,568,568,568,567,568, \
|
||||
568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
568,568,567,568,568,568,568,568,568,568,567,568,568,568,568,568, \
|
||||
568,568,567,568,568,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,568,568,568,568,567,568,568,568,568, \
|
||||
568,568,568,568,568,568,567,568,566,567,568,568,568,568,568,568, \
|
||||
568,568,568,568,566,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
568,632,568,632,568,568,568,568,568,568,568,568,568,568,568,568, \
|
||||
632,568,568,568,568,568,568,568,568,568,568,568,568,630,568,568, \
|
||||
630,632,568,568,632,632,631,632,630,568,632,632,632,632,632,632, \
|
||||
632,632,632,632,631,632,632,632,632,632,632,632,664,631,632,664, \
|
||||
631,632,632,632,664,628,632,632,662,632,632,632,632,664,664,632, \
|
||||
632,632,632,664,664,632,632,632,664,631,632,632,664,632,632,632 \
|
||||
|
||||
#define MPFR_DIVHIGH_TAB \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*0-15*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*16-31*/ \
|
||||
0,0,22,0,0,0,0,0,26,26,26,27,0,29,30,30, /*32-47*/ \
|
||||
30,30,34,34,0,33,34,0,34,33,0,0,0,0,0,0, /*48-63*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*64-79*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*80-95*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*96-111*/ \
|
||||
0,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0, /*112-127*/ \
|
||||
0,0,0,0,0,0,74,0,0,78,74,78,74,78,78,74, /*128-143*/ \
|
||||
0,0,78,78,78,78,0,78,0,78,0,0,0,0,88,0, /*144-159*/ \
|
||||
0,0,0,0,91,92,91,92,90,88,92,90,92,92,0,112, /*160-175*/ \
|
||||
92,94,96,95,95,112,104,104,112,112,112,112,112,104,112,120, /*176-191*/ \
|
||||
112,112,112,104,112,120,107,112,120,128,112,112,120,120,120,120, /*192-207*/ \
|
||||
112,120,120,120,128,128,128,120,128,128,128,128,128,128,128,128, /*208-223*/ \
|
||||
128,128,120,128,128,128,128,128,128,120,128,128,128,128,128,128, /*224-239*/ \
|
||||
128,128,128,128,136,128,128,128,128,128,148,136,148,128,136,136, /*240-255*/ \
|
||||
136,148,148,148,135,156,148,148,135,156,156,148,156,149,160,160, /*256-271*/ \
|
||||
156,148,156,156,144,160,156,160,148,156,160,156,156,160,156,149, /*272-287*/ \
|
||||
148,160,160,160,156,156,156,156,154,156,156,156,156,156,156,156, /*288-303*/ \
|
||||
156,156,156,160,156,156,157,160,160,160,160,160,160,160,184,184, /*304-319*/ \
|
||||
184,185,184,179,185,184,184,184,184,184,174,174,183,186,184,186, /*320-335*/ \
|
||||
182,184,185,185,186,186,186,184,208,184,192,208,184,184,184,208, /*336-351*/ \
|
||||
184,208,184,208,208,209,192,216,209,208,216,208,210,208,208,224, /*352-367*/ \
|
||||
222,208,208,216,208,224,210,208,222,210,224,224,208,208,210,224, /*368-383*/ \
|
||||
240,232,208,234,206,240,216,208,208,240,240,224,208,208,208,208, /*384-399*/ \
|
||||
208,208,224,224,233,208,224,224,208,216,224,224,208,240,224,222, /*400-415*/ \
|
||||
240,224,224,256,232,216,240,224,234,256,216,256,224,256,256,232, /*416-431*/ \
|
||||
240,240,240,240,255,224,232,256,256,240,256,256,240,256,240,256, /*432-447*/ \
|
||||
240,240,256,256,256,240,256,256,256,256,240,256,256,256,256,256, /*448-463*/ \
|
||||
256,256,256,256,255,256,256,254,256,256,256,256,256,256,256,256, /*464-479*/ \
|
||||
256,256,255,256,256,256,256,256,256,255,256,256,255,256,256,256, /*480-495*/ \
|
||||
256,256,256,256,256,256,256,256,256,256,256,256,256,256,280,272, /*496-511*/ \
|
||||
272,270,280,296,280,276,280,279,280,280,281,280,280,272,272,280, /*512-527*/ \
|
||||
280,272,280,282,312,272,282,312,280,312,280,280,288,280,281,296, /*528-543*/ \
|
||||
312,296,312,312,296,296,312,288,312,312,312,315,316,312,312,312, /*544-559*/ \
|
||||
312,312,312,312,312,318,312,313,312,302,318,312,311,296,312,312, /*560-575*/ \
|
||||
318,312,312,311,312,296,304,311,312,312,312,312,312,312,312,312, /*576-591*/ \
|
||||
313,312,312,312,312,312,312,318,312,312,312,312,312,312,311,312, /*592-607*/ \
|
||||
316,312,320,312,312,312,312,312,312,312,312,312,316,313,313,318, /*608-623*/ \
|
||||
317,316,317,318,320,318,318,318,320,318,348,368,320,336,372,372, /*624-639*/ \
|
||||
372,371,367,368,368,372,371,368,372,336,372,368,372,368,364,372, /*640-655*/ \
|
||||
372,354,384,368,352,368,372,371,348,352,372,366,368,366,372,368, /*656-671*/ \
|
||||
372,365,368,372,368,372,372,371,372,378,369,371,372,372,369,372, /*672-687*/ \
|
||||
372,372,370,378,384,372,370,367,416,384,416,416,371,372,420,424, /*688-703*/ \
|
||||
366,372,372,368,416,420,372,420,432,372,372,416,378,372,416,384, /*704-719*/ \
|
||||
420,416,420,414,416,416,448,416,419,424,425,416,416,425,432,432, /*720-735*/ \
|
||||
432,432,432,432,448,424,448,432,444,432,432,444,432,432,448,448, /*736-751*/ \
|
||||
448,448,448,448,420,416,420,416,448,448,448,420,448,420,432,432, /*752-767*/ \
|
||||
448,426,448,432,416,420,448,432,448,432,414,432,432,420,417,417, /*768-783*/ \
|
||||
420,444,416,444,419,424,420,426,432,420,432,416,480,416,420,424, /*784-799*/ \
|
||||
420,432,419,420,424,424,420,416,425,419,432,448,448,444,448,432, /*800-815*/ \
|
||||
426,420,432,448,448,448,432,448,512,464,444,448,447,448,448,448, /*816-831*/ \
|
||||
432,448,448,464,431,467,448,448,448,444,448,432,448,448,448,504, /*832-847*/ \
|
||||
448,447,432,432,448,512,432,464,448,504,448,448,480,444,448,449, /*848-863*/ \
|
||||
448,512,448,512,480,444,447,448,449,512,480,448,504,480,448,468, /*864-879*/ \
|
||||
448,448,448,467,512,464,463,504,480,504,504,448,480,512,512,504, /*880-895*/ \
|
||||
480,512,503,480,512,480,504,512,512,467,504,512,512,504,512,512, /*896-911*/ \
|
||||
512,512,504,504,462,480,512,504,512,504,504,504,480,464,480,504, /*912-927*/ \
|
||||
504,504,504,512,480,504,504,512,504,512,480,504,512,512,512,512, /*928-943*/ \
|
||||
512,504,480,504,512,504,480,512,512,480,512,480,561,512,504,512, /*944-959*/ \
|
||||
496,504,512,512,504,512,497,512,504,504,504,512,512,512,504,504, /*960-975*/ \
|
||||
504,512,512,512,512,512,512,504,512,512,512,512,504,512,512,512, /*976-991*/ \
|
||||
562,512,504,512,511,512,512,512,512,504,512,512,512,504,512,512, /*992-1007*/ \
|
||||
512,561,512,512,536,512,512,512,512,512,544,559,561,561,563,544 /*1008-1023*/ \
|
||||
|
||||
#define MPFR_MUL_THRESHOLD 17 /* limbs */
|
||||
#define MPFR_SQR_THRESHOLD 16 /* limbs */
|
||||
#define MPFR_DIV_THRESHOLD 3 /* limbs */
|
||||
#define MPFR_EXP_2_THRESHOLD 585 /* bits */
|
||||
#define MPFR_EXP_THRESHOLD 11179 /* bits */
|
||||
#define MPFR_SINCOS_THRESHOLD 30593 /* bits */
|
||||
#define MPFR_AI_THRESHOLD1 -11898 /* threshold for negative input of mpfr_ai */
|
||||
#define MPFR_AI_THRESHOLD2 1175
|
||||
#define MPFR_AI_THRESHOLD3 18856
|
||||
/* Tuneup completed successfully, took 705 seconds */
|
94
gcc/mpfr/src/cmpabs.c
Normal file
94
gcc/mpfr/src/cmpabs.c
Normal file
@ -0,0 +1,94 @@
|
||||
/* mpfr_cmpabs -- compare the absolute values of two FP numbers
|
||||
|
||||
Copyright 1999, 2001-2004, 2006-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
/* Return a positive value if abs(b) > abs(c), 0 if abs(b) = abs(c), and
|
||||
a negative value if abs(b) < abs(c). */
|
||||
|
||||
int
|
||||
mpfr_cmpabs (mpfr_srcptr b, mpfr_srcptr c)
|
||||
{
|
||||
mpfr_exp_t be, ce;
|
||||
mp_size_t bn, cn;
|
||||
mp_limb_t *bp, *cp;
|
||||
|
||||
if (MPFR_ARE_SINGULAR (b, c))
|
||||
{
|
||||
if (MPFR_IS_NAN (b) || MPFR_IS_NAN (c))
|
||||
{
|
||||
MPFR_SET_ERANGEFLAG ();
|
||||
return 0;
|
||||
}
|
||||
else if (MPFR_IS_INF (b))
|
||||
return ! MPFR_IS_INF (c);
|
||||
else if (MPFR_IS_INF (c))
|
||||
return -1;
|
||||
else if (MPFR_IS_ZERO (c))
|
||||
return ! MPFR_IS_ZERO (b);
|
||||
else /* b == 0 */
|
||||
return -1;
|
||||
}
|
||||
|
||||
MPFR_ASSERTD (MPFR_IS_PURE_FP (b));
|
||||
MPFR_ASSERTD (MPFR_IS_PURE_FP (c));
|
||||
|
||||
/* Now that we know that b and c are pure FP numbers (i.e. they have
|
||||
a meaningful exponent), we use MPFR_EXP instead of MPFR_GET_EXP to
|
||||
allow exponents outside the current exponent range. For instance,
|
||||
this is useful for mpfr_pow, which compares values to __gmpfr_one.
|
||||
This is for internal use only! For compatibility with other MPFR
|
||||
versions, the user must still provide values that are representable
|
||||
in the current exponent range. */
|
||||
be = MPFR_EXP (b);
|
||||
ce = MPFR_EXP (c);
|
||||
if (be > ce)
|
||||
return 1;
|
||||
if (be < ce)
|
||||
return -1;
|
||||
|
||||
/* exponents are equal */
|
||||
|
||||
bn = MPFR_LIMB_SIZE(b)-1;
|
||||
cn = MPFR_LIMB_SIZE(c)-1;
|
||||
|
||||
bp = MPFR_MANT(b);
|
||||
cp = MPFR_MANT(c);
|
||||
|
||||
for ( ; bn >= 0 && cn >= 0; bn--, cn--)
|
||||
{
|
||||
if (bp[bn] > cp[cn])
|
||||
return 1;
|
||||
if (bp[bn] < cp[cn])
|
||||
return -1;
|
||||
}
|
||||
|
||||
for ( ; bn >= 0; bn--)
|
||||
if (bp[bn])
|
||||
return 1;
|
||||
|
||||
for ( ; cn >= 0; cn--)
|
||||
if (cp[cn])
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
35
gcc/mpfr/src/cmpabs_ui.c
Normal file
35
gcc/mpfr/src/cmpabs_ui.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* mpfr_cmpabs_ui -- compare the absolute value of FP to an unsigned long
|
||||
|
||||
Copyright 2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
/* Return a positive value if abs(b) > c, 0 if abs(b) = c, and
|
||||
a negative value if abs(b) < c. */
|
||||
|
||||
int
|
||||
mpfr_cmpabs_ui (mpfr_srcptr b, unsigned long c)
|
||||
{
|
||||
mpfr_t absb;
|
||||
|
||||
MPFR_TMP_INIT_ABS (absb, b);
|
||||
return mpfr_cmp_ui (absb, c);
|
||||
}
|
59
gcc/mpfr/src/dot.c
Normal file
59
gcc/mpfr/src/dot.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* mpfr_dot -- dot product of two array of numbers
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
/* FIXME: handle intermediate overflows and underflows. */
|
||||
|
||||
/* res <- a[0]*b[0] + ... + a[n-1]*b[n-1] */
|
||||
int
|
||||
mpfr_dot (mpfr_ptr res, const mpfr_ptr *a, const mpfr_ptr *b,
|
||||
unsigned long n, mpfr_rnd_t rnd)
|
||||
{
|
||||
mpfr_t *c;
|
||||
size_t i;
|
||||
int inex;
|
||||
mpfr_ptr *tab;
|
||||
|
||||
if (MPFR_UNLIKELY (n == 0))
|
||||
{
|
||||
MPFR_SET_ZERO (res);
|
||||
MPFR_SET_POS (res);
|
||||
MPFR_RET (0);
|
||||
}
|
||||
|
||||
c = (mpfr_t *) mpfr_allocate_func (n * sizeof (mpfr_t));
|
||||
tab = (mpfr_ptr *) mpfr_allocate_func (n * sizeof (mpfr_ptr));
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
mpfr_init2 (c[i], mpfr_get_prec (a[i]) + mpfr_get_prec (b[i]));
|
||||
inex = mpfr_mul (c[i], a[i], b[i], MPFR_RNDZ); /* exact except... */
|
||||
MPFR_ASSERTN (inex == 0); /* failure in case of overflow/underflow */
|
||||
tab[i] = c[i];
|
||||
}
|
||||
inex = mpfr_sum (res, tab, n, rnd);
|
||||
for (i = 0; i < n; i++)
|
||||
mpfr_clear (c[i]);
|
||||
mpfr_free_func (c, n * sizeof (mpfr_t));
|
||||
mpfr_free_func (tab, n * sizeof (mpfr_ptr));
|
||||
return inex;
|
||||
}
|
441
gcc/mpfr/src/get_d128.c
Normal file
441
gcc/mpfr/src/get_d128.c
Normal file
@ -0,0 +1,441 @@
|
||||
/* mpfr_get_decimal128 -- convert a multiple precision floating-point number
|
||||
to an IEEE 754-2008 decimal128 float
|
||||
|
||||
See https://gcc.gnu.org/legacy-ml/gcc/2006-06/msg00691.html,
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html,
|
||||
and TR 24732 <http://www.open-std.org/jtc1/sc22/wg14/www/projects#24732>.
|
||||
|
||||
Copyright 2006-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-impl.h"
|
||||
#include "ieee_floats.h"
|
||||
|
||||
#define ISDIGIT(c) ('0' <= c && c <= '9')
|
||||
|
||||
#ifdef MPFR_WANT_DECIMAL_FLOATS
|
||||
|
||||
#ifndef DEC128_MAX
|
||||
# define DEC128_MAX 9.999999999999999999999999999999999E6144dl
|
||||
#endif
|
||||
|
||||
/* construct a decimal128 NaN */
|
||||
static _Decimal128
|
||||
get_decimal128_nan (void)
|
||||
{
|
||||
return (_Decimal128) MPFR_DBL_NAN;
|
||||
}
|
||||
|
||||
/* construct the decimal128 Inf with given sign */
|
||||
static _Decimal128
|
||||
get_decimal128_inf (int negative)
|
||||
{
|
||||
return (_Decimal128) (negative ? MPFR_DBL_INFM : MPFR_DBL_INFP);
|
||||
}
|
||||
|
||||
/* construct the decimal128 zero with given sign */
|
||||
static _Decimal128
|
||||
get_decimal128_zero (int negative)
|
||||
{
|
||||
_Decimal128 zero = 0;
|
||||
return (_Decimal128) (negative ? -zero : zero);
|
||||
}
|
||||
|
||||
/* construct the decimal128 smallest non-zero with given sign:
|
||||
it is 10^emin * 10^(1-p). Since emax = 6144, emin = 1-emax = -6143,
|
||||
and p = 34, we get 10^(-6176) */
|
||||
static _Decimal128
|
||||
get_decimal128_min (int negative)
|
||||
{
|
||||
return negative ? - 1E-6176dl : 1E-6176dl;
|
||||
}
|
||||
|
||||
/* construct the decimal128 largest finite number with given sign */
|
||||
static _Decimal128
|
||||
get_decimal128_max (int negative)
|
||||
{
|
||||
return negative ? - DEC128_MAX : DEC128_MAX;
|
||||
}
|
||||
|
||||
/* one-to-one conversion:
|
||||
s is a decimal string representing a number x = m * 10^e which must be
|
||||
exactly representable in the decimal128 format, i.e.
|
||||
(a) the mantissa m has at most 34 decimal digits
|
||||
(b1) -6143 <= e <= 6144 with m integer multiple of 10^(-33), |m| < 10
|
||||
(b2) or -6176 <= e <= 6111 with m integer, |m| < 10^34.
|
||||
Assumes s is neither NaN nor +Inf nor -Inf.
|
||||
s = [-][0-9]+E[-][0-9]+
|
||||
|
||||
The decimal128 format (cf table 3.6 of IEEE 754-2008) has the following
|
||||
parameters:
|
||||
* k = 128 (number of bits of storage)
|
||||
* p = 34 (precision in digits)
|
||||
* emax = 6144
|
||||
* bias = E-q = 6176
|
||||
* sign bit has 1 bit
|
||||
* w+5 = 17 bits (combination field width)
|
||||
* t = 110 bits (trailing significand width)
|
||||
We have k = 1 + 5 + w + t = 128.
|
||||
*/
|
||||
static _Decimal128
|
||||
string_to_Decimal128 (char *s) /* portable version */
|
||||
{
|
||||
long int exp = 0;
|
||||
char m[35];
|
||||
long n = 0; /* mantissa length */
|
||||
char *endptr[1];
|
||||
_Decimal128 x = 0;
|
||||
int sign = 0;
|
||||
|
||||
/* read sign */
|
||||
if (*s == '-')
|
||||
{
|
||||
sign = 1;
|
||||
s ++;
|
||||
}
|
||||
/* read mantissa */
|
||||
while (ISDIGIT (*s))
|
||||
m[n++] = *s++;
|
||||
|
||||
/* as constructed in mpfr_get_decimal128, s cannot have any '.' separator */
|
||||
|
||||
/* we will consider an integer mantissa m*10^exp */
|
||||
MPFR_ASSERTN(n <= 34);
|
||||
/* s always has an exponent separator 'E' */
|
||||
MPFR_ASSERTN(*s == 'E');
|
||||
exp = strtol (s + 1, endptr, 10);
|
||||
MPFR_ASSERTN(**endptr == '\0');
|
||||
MPFR_ASSERTN(-6176 <= exp && exp <= (long) (6145 - n));
|
||||
while (n < 34)
|
||||
{
|
||||
m[n++] = '0';
|
||||
exp --;
|
||||
}
|
||||
/* now n=34 and -6176 <= exp <= 6111, cf (b2) */
|
||||
m[n] = '\0';
|
||||
|
||||
/* the number to convert is m[] * 10^exp where the mantissa is a 34-digit
|
||||
integer */
|
||||
|
||||
/* compute biased exponent */
|
||||
exp += 6176;
|
||||
|
||||
MPFR_ASSERTN(exp >= -33);
|
||||
if (exp < 0)
|
||||
{
|
||||
int i;
|
||||
n = -exp;
|
||||
/* check the last n digits of the mantissa are zero */
|
||||
for (i = 1; i <= n; i++)
|
||||
MPFR_ASSERTN(m[34 - n] == '0');
|
||||
/* shift the first (34-n) digits to the right */
|
||||
for (i = 34 - n - 1; i >= 0; i--)
|
||||
m[i + n] = m[i];
|
||||
/* zero the first n digits */
|
||||
for (i = 0; i < n; i ++)
|
||||
m[i] = '0';
|
||||
exp = 0;
|
||||
}
|
||||
|
||||
/* the number to convert is m[] * 10^(exp-6176) */
|
||||
exp -= 6176;
|
||||
|
||||
for (n = 0; n < 34; n++)
|
||||
x = (_Decimal128) 10 * x + (_Decimal128) (m[n] - '0');
|
||||
|
||||
/* multiply by 10^exp */
|
||||
if (exp > 0)
|
||||
{
|
||||
_Decimal128 ten = 10;
|
||||
_Decimal128 ten2 = ten * ten;
|
||||
_Decimal128 ten4 = ten2 * ten2;
|
||||
_Decimal128 ten8 = ten4 * ten4;
|
||||
_Decimal128 ten16 = ten8 * ten8;
|
||||
_Decimal128 ten32 = ten16 * ten16;
|
||||
_Decimal128 ten64 = ten32 * ten32;
|
||||
_Decimal128 ten128 = ten64 * ten64;
|
||||
_Decimal128 ten256 = ten128 * ten128;
|
||||
_Decimal128 ten512 = ten256 * ten256;
|
||||
_Decimal128 ten1024 = ten512 * ten512;
|
||||
_Decimal128 ten2048 = ten1024 * ten1024;
|
||||
_Decimal128 ten4096 = ten2048 * ten2048;
|
||||
|
||||
if (exp >= 4096)
|
||||
{
|
||||
x *= ten4096;
|
||||
exp -= 4096;
|
||||
}
|
||||
if (exp >= 2048)
|
||||
{
|
||||
x *= ten2048;
|
||||
exp -= 2048;
|
||||
}
|
||||
if (exp >= 1024)
|
||||
{
|
||||
x *= ten1024;
|
||||
exp -= 1024;
|
||||
}
|
||||
if (exp >= 512)
|
||||
{
|
||||
x *= ten512;
|
||||
exp -= 512;
|
||||
}
|
||||
if (exp >= 256)
|
||||
{
|
||||
x *= ten256;
|
||||
exp -= 256;
|
||||
}
|
||||
if (exp >= 128)
|
||||
{
|
||||
x *= ten128;
|
||||
exp -= 128;
|
||||
}
|
||||
if (exp >= 64)
|
||||
{
|
||||
x *= ten64;
|
||||
exp -= 64;
|
||||
}
|
||||
if (exp >= 32)
|
||||
{
|
||||
x *= ten32;
|
||||
exp -= 32;
|
||||
}
|
||||
if (exp >= 16)
|
||||
{
|
||||
x *= ten16;
|
||||
exp -= 16;
|
||||
}
|
||||
if (exp >= 8)
|
||||
{
|
||||
x *= ten8;
|
||||
exp -= 8;
|
||||
}
|
||||
if (exp >= 4)
|
||||
{
|
||||
x *= ten4;
|
||||
exp -= 4;
|
||||
}
|
||||
if (exp >= 2)
|
||||
{
|
||||
x *= ten2;
|
||||
exp -= 2;
|
||||
}
|
||||
if (exp >= 1)
|
||||
{
|
||||
x *= ten;
|
||||
exp -= 1;
|
||||
}
|
||||
}
|
||||
else if (exp < 0)
|
||||
{
|
||||
_Decimal128 ten = 10;
|
||||
_Decimal128 ten2 = ten * ten;
|
||||
_Decimal128 ten4 = ten2 * ten2;
|
||||
_Decimal128 ten8 = ten4 * ten4;
|
||||
_Decimal128 ten16 = ten8 * ten8;
|
||||
_Decimal128 ten32 = ten16 * ten16;
|
||||
_Decimal128 ten64 = ten32 * ten32;
|
||||
_Decimal128 ten128 = ten64 * ten64;
|
||||
_Decimal128 ten256 = ten128 * ten128;
|
||||
_Decimal128 ten512 = ten256 * ten256;
|
||||
_Decimal128 ten1024 = ten512 * ten512;
|
||||
_Decimal128 ten2048 = ten1024 * ten1024;
|
||||
_Decimal128 ten4096 = ten2048 * ten2048;
|
||||
|
||||
if (exp <= -4096)
|
||||
{
|
||||
x /= ten4096;
|
||||
exp += 4096;
|
||||
}
|
||||
if (exp <= -2048)
|
||||
{
|
||||
x /= ten2048;
|
||||
exp += 2048;
|
||||
}
|
||||
if (exp <= -1024)
|
||||
{
|
||||
x /= ten1024;
|
||||
exp += 1024;
|
||||
}
|
||||
if (exp <= -512)
|
||||
{
|
||||
x /= ten512;
|
||||
exp += 512;
|
||||
}
|
||||
if (exp <= -256)
|
||||
{
|
||||
x /= ten256;
|
||||
exp += 256;
|
||||
}
|
||||
if (exp <= -128)
|
||||
{
|
||||
x /= ten128;
|
||||
exp += 128;
|
||||
}
|
||||
if (exp <= -64)
|
||||
{
|
||||
x /= ten64;
|
||||
exp += 64;
|
||||
}
|
||||
if (exp <= -32)
|
||||
{
|
||||
x /= ten32;
|
||||
exp += 32;
|
||||
}
|
||||
if (exp <= -16)
|
||||
{
|
||||
x /= ten16;
|
||||
exp += 16;
|
||||
}
|
||||
if (exp <= -8)
|
||||
{
|
||||
x /= ten8;
|
||||
exp += 8;
|
||||
}
|
||||
if (exp <= -4)
|
||||
{
|
||||
x /= ten4;
|
||||
exp += 4;
|
||||
}
|
||||
if (exp <= -2)
|
||||
{
|
||||
x /= ten2;
|
||||
exp += 2;
|
||||
}
|
||||
if (exp <= -1)
|
||||
{
|
||||
x /= ten;
|
||||
exp += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sign)
|
||||
x = -x;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
_Decimal128
|
||||
mpfr_get_decimal128 (mpfr_srcptr src, mpfr_rnd_t rnd_mode)
|
||||
{
|
||||
int negative;
|
||||
mpfr_exp_t e;
|
||||
|
||||
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (src)))
|
||||
{
|
||||
if (MPFR_IS_NAN (src))
|
||||
return get_decimal128_nan ();
|
||||
|
||||
negative = MPFR_IS_NEG (src);
|
||||
|
||||
if (MPFR_IS_INF (src))
|
||||
return get_decimal128_inf (negative);
|
||||
|
||||
MPFR_ASSERTD (MPFR_IS_ZERO(src));
|
||||
return get_decimal128_zero (negative);
|
||||
}
|
||||
|
||||
e = MPFR_GET_EXP (src);
|
||||
negative = MPFR_IS_NEG (src);
|
||||
|
||||
MPFR_UPDATE2_RND_MODE (rnd_mode, MPFR_SIGN (src));
|
||||
|
||||
/* now rnd_mode is RNDN, RNDF, RNDA or RNDZ */
|
||||
|
||||
/* the smallest decimal128 number is 10^(-6176),
|
||||
with 2^(-20517) < 10^(-6176) < 2^(-20516) */
|
||||
if (MPFR_UNLIKELY (e < -20517)) /* src <= 2^(-20518) < 1/2*10^(-6176) */
|
||||
{
|
||||
if (rnd_mode != MPFR_RNDA)
|
||||
return get_decimal128_zero (negative);
|
||||
else /* RNDA: return the smallest non-zero number */
|
||||
return get_decimal128_min (negative);
|
||||
}
|
||||
/* the largest decimal128 number is just below 10^6145 < 2^20414 */
|
||||
else if (MPFR_UNLIKELY (e > 20414)) /* then src >= 2^20414 */
|
||||
{
|
||||
if (rnd_mode == MPFR_RNDZ)
|
||||
return get_decimal128_max (negative);
|
||||
else /* RNDN, RNDA, RNDF: round away */
|
||||
return get_decimal128_inf (negative);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* we need to store the sign (1 character), the significand (at most 34
|
||||
characters), the exponent part (at most 6 characters for "E-6176"),
|
||||
and the terminating null character, thus we need at least 42
|
||||
characters in s. */
|
||||
char s[42];
|
||||
mpfr_get_str (s, &e, 10, 34, src, rnd_mode);
|
||||
/* the smallest normal number is 1.000...000E-6143,
|
||||
which corresponds to s=[0.]1000...000 and e=-6142 */
|
||||
if (e < -6142)
|
||||
{
|
||||
/* the smallest subnormal number is 0.000...001E-6143 = 1E-6176,
|
||||
which corresponds to s=[0.]1000...000 and e=-6175 */
|
||||
if (e < -6175)
|
||||
{
|
||||
if (rnd_mode == MPFR_RNDN && e == -6176)
|
||||
{
|
||||
/* If 0.5E-6176 < |src| < 1E-6176 (smallest subnormal),
|
||||
src should round to +/- 1E-6176 in MPFR_RNDN. */
|
||||
mpfr_get_str (s, &e, 10, 1, src, MPFR_RNDA);
|
||||
return e == -6176 && s[negative] <= '5' ?
|
||||
get_decimal128_zero (negative) :
|
||||
get_decimal128_min (negative);
|
||||
}
|
||||
if (rnd_mode == MPFR_RNDZ || rnd_mode == MPFR_RNDN)
|
||||
return get_decimal128_zero (negative);
|
||||
else /* RNDA or RNDF: return the smallest non-zero number */
|
||||
return get_decimal128_min (negative);
|
||||
}
|
||||
else
|
||||
{
|
||||
mpfr_exp_t e2;
|
||||
long digits = 34 - (-6142 - e);
|
||||
/* if e = -6175 then 34 - (-6142 - e) = 1 */
|
||||
mpfr_get_str (s, &e2, 10, digits, src, rnd_mode);
|
||||
/* Warning: we can have e2 = e + 1 here, when rounding to
|
||||
nearest or away from zero. */
|
||||
s[negative + digits] = 'E';
|
||||
sprintf (s + negative + digits + 1, "%ld",
|
||||
(long int)e2 - digits);
|
||||
return string_to_Decimal128 (s);
|
||||
}
|
||||
}
|
||||
/* the largest number is 9.999...999E+6144,
|
||||
which corresponds to s=[0.]9999...999 and e=6145 */
|
||||
else if (e > 6145)
|
||||
{
|
||||
if (rnd_mode == MPFR_RNDZ)
|
||||
return get_decimal128_max (negative);
|
||||
else /* RNDN, RNDA, RNDF: round away */
|
||||
return get_decimal128_inf (negative);
|
||||
}
|
||||
else /* -6142 <= e <= 6145 */
|
||||
{
|
||||
s[34 + negative] = 'E';
|
||||
sprintf (s + 35 + negative, "%ld", (long int) e - 34);
|
||||
return string_to_Decimal128 (s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MPFR_WANT_DECIMAL_FLOATS */
|
325
gcc/mpfr/src/mul_1_extracted.c
Normal file
325
gcc/mpfr/src/mul_1_extracted.c
Normal file
@ -0,0 +1,325 @@
|
||||
/* mpfr_mul_1 -- internal function to perform a one-limb multiplication
|
||||
This code was extracted by Kremlin from a formal proof in F*
|
||||
done by Jianyang Pan in April-August 2018: do not modify it!
|
||||
|
||||
Source: https://github.com/project-everest/hacl-star/tree/dev_mpfr/code/mpfr
|
||||
|
||||
Copyright 2004-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#define int64_t long
|
||||
#define uint32_t unsigned int
|
||||
#define uint64_t mp_limb_t
|
||||
#define bool int
|
||||
|
||||
typedef struct K___int64_t_uint64_t_uint64_t_s
|
||||
{
|
||||
int64_t fst;
|
||||
uint64_t snd;
|
||||
uint64_t thd;
|
||||
}
|
||||
K___int64_t_uint64_t_uint64_t;
|
||||
|
||||
#define MPFR_Lib_mpfr_struct __mpfr_struct
|
||||
#define MPFR_Lib_mpfr_RET(I) (I) != 0 ? ((__gmpfr_flags |= MPFR_FLAGS_INEXACT), (I)) : 0
|
||||
#define MPFR_Exceptions_mpfr_overflow mpfr_overflow
|
||||
#define MPFR_Exceptions_mpfr_underflow mpfr_underflow
|
||||
#define mpfr_prec _mpfr_prec
|
||||
#define mpfr_exp _mpfr_exp
|
||||
#define mpfr_d _mpfr_d
|
||||
#define mpfr_sign _mpfr_sign
|
||||
#define MPFR_Lib_gmp_NUMB_BITS GMP_NUMB_BITS
|
||||
#define MPFR_Lib_mpfr_EMAX __gmpfr_emax
|
||||
#define MPFR_Lib_mpfr_EMIN __gmpfr_emin
|
||||
#define MPFR_RoundingMode_MPFR_RNDZ MPFR_RNDZ
|
||||
|
||||
#define MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode) (rnd_mode == MPFR_RNDN)
|
||||
#define MPFR_RoundingMode_mpfr_IS_LIKE_RNDZ MPFR_IS_LIKE_RNDZ
|
||||
#define MPFR_RoundingMode_mpfr_IS_LIKE_RNDA MPFR_IS_LIKE_RNDA
|
||||
|
||||
/* Special code for prec(a) < GMP_NUMB_BITS and
|
||||
prec(b), prec(c) <= GMP_NUMB_BITS.
|
||||
Note: this code was copied in sqr.c, function mpfr_sqr_1 (this saves a few cycles
|
||||
with respect to have this function exported). As a consequence, any change here
|
||||
should be reported in mpfr_sqr_1. */
|
||||
static int
|
||||
mpfr_mul_1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode,
|
||||
mpfr_prec_t p)
|
||||
{
|
||||
uint64_t *ap = a->mpfr_d;
|
||||
uint64_t *bp = b->mpfr_d;
|
||||
uint64_t *cp = c->mpfr_d;
|
||||
uint64_t b0 = bp[0U];
|
||||
uint64_t c0 = cp[0U];
|
||||
int64_t sh = MPFR_Lib_gmp_NUMB_BITS - p;
|
||||
uint64_t mask = ((uint64_t)1U << (uint32_t)sh) - (uint64_t)1U;
|
||||
int64_t ax = b->mpfr_exp + c->mpfr_exp;
|
||||
//K___uint64_t_uint64_t scrut0 = MPFR_Umul_ppmm_umul_ppmm(b0, c0);
|
||||
//uint64_t a0 = scrut0.fst;
|
||||
//uint64_t sb = scrut0.snd;
|
||||
uint64_t a0, sb;
|
||||
umul_ppmm (a0, sb, b0, c0);
|
||||
K___int64_t_uint64_t_uint64_t scrut;
|
||||
if (a0 < (uint64_t)0x8000000000000000U)
|
||||
scrut =
|
||||
(
|
||||
(K___int64_t_uint64_t_uint64_t){
|
||||
.fst = ax - (int64_t)1,
|
||||
.snd = a0 << (uint32_t)1U | sb >> (uint32_t)(MPFR_Lib_gmp_NUMB_BITS - (int64_t)1),
|
||||
.thd = sb << (uint32_t)1U
|
||||
}
|
||||
);
|
||||
else
|
||||
scrut = ((K___int64_t_uint64_t_uint64_t){ .fst = ax, .snd = a0, .thd = sb });
|
||||
int64_t ax1 = scrut.fst;
|
||||
uint64_t a01 = scrut.snd;
|
||||
uint64_t sb1 = scrut.thd;
|
||||
uint64_t rb = a01 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb2 = sb1 | ((a01 & mask) ^ rb);
|
||||
ap[0U] = a01 & ~mask;
|
||||
MPFR_Lib_mpfr_struct uu___73_2756 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___73_2756.mpfr_prec,
|
||||
.mpfr_sign = b->mpfr_sign * c->mpfr_sign,
|
||||
.mpfr_exp = uu___73_2756.mpfr_exp,
|
||||
.mpfr_d = uu___73_2756.mpfr_d
|
||||
}
|
||||
);
|
||||
uint64_t *ap1 = a->mpfr_d;
|
||||
uint64_t a02 = ap1[0U];
|
||||
if (ax1 > MPFR_Lib_mpfr_EMAX)
|
||||
return MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
else if (ax1 < MPFR_Lib_mpfr_EMIN)
|
||||
{
|
||||
bool aneg = a->mpfr_sign < (int32_t)0;
|
||||
if
|
||||
(
|
||||
ax1
|
||||
== MPFR_Lib_mpfr_EMIN - (int64_t)1
|
||||
&& a02 == ~mask
|
||||
&&
|
||||
((MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode) && rb > (uint64_t)0U)
|
||||
|| ((rb | sb2) > (uint64_t)0U && MPFR_RoundingMode_mpfr_IS_LIKE_RNDA(rnd_mode, aneg)))
|
||||
)
|
||||
{
|
||||
uint64_t *ap2 = a->mpfr_d;
|
||||
uint64_t a03 = ap2[0U];
|
||||
MPFR_Lib_mpfr_struct uu___72_2907 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_2907.mpfr_prec,
|
||||
.mpfr_sign = uu___72_2907.mpfr_sign,
|
||||
.mpfr_exp = ax1,
|
||||
.mpfr_d = uu___72_2907.mpfr_d
|
||||
}
|
||||
);
|
||||
if (rb == (uint64_t)0U && sb2 == (uint64_t)0U)
|
||||
return MPFR_Lib_mpfr_RET((int32_t)0);
|
||||
else if (MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode))
|
||||
if
|
||||
(
|
||||
rb
|
||||
== (uint64_t)0U
|
||||
|| (sb2 == (uint64_t)0U && (a03 & (uint64_t)1U << (uint32_t)sh) == (uint64_t)0U)
|
||||
)
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap3 = a->mpfr_d;
|
||||
ap3[0U] = ap3[0U] + ((uint64_t)1U << (uint32_t)sh);
|
||||
if (ap3[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap3[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (ax1 + (int64_t)1 > MPFR_Lib_mpfr_EMAX)
|
||||
return MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
else
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3047 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3047.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3047.mpfr_sign,
|
||||
.mpfr_exp = ax1 + (int64_t)1,
|
||||
.mpfr_d = uu___72_3047.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else if (MPFR_RoundingMode_mpfr_IS_LIKE_RNDZ(rnd_mode, a->mpfr_sign < (int32_t)0))
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap3 = a->mpfr_d;
|
||||
ap3[0U] = ap3[0U] + ((uint64_t)1U << (uint32_t)sh);
|
||||
if (ap3[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap3[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (ax1 + (int64_t)1 > MPFR_Lib_mpfr_EMAX)
|
||||
return MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
else
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3237 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3237.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3237.mpfr_sign,
|
||||
.mpfr_exp = ax1 + (int64_t)1,
|
||||
.mpfr_d = uu___72_3237.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else if
|
||||
(
|
||||
MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode)
|
||||
&&
|
||||
(ax1
|
||||
< MPFR_Lib_mpfr_EMIN - (int64_t)1
|
||||
|| (a02 == (uint64_t)0x8000000000000000U && (rb | sb2) == (uint64_t)0U))
|
||||
)
|
||||
return MPFR_Exceptions_mpfr_underflow(a, MPFR_RoundingMode_MPFR_RNDZ, a->mpfr_sign);
|
||||
else
|
||||
return MPFR_Exceptions_mpfr_underflow(a, rnd_mode, a->mpfr_sign);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap2 = a->mpfr_d;
|
||||
uint64_t a03 = ap2[0U];
|
||||
MPFR_Lib_mpfr_struct uu___72_3422 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3422.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3422.mpfr_sign,
|
||||
.mpfr_exp = ax1,
|
||||
.mpfr_d = uu___72_3422.mpfr_d
|
||||
}
|
||||
);
|
||||
if (rb == (uint64_t)0U && sb2 == (uint64_t)0U)
|
||||
return MPFR_Lib_mpfr_RET((int32_t)0);
|
||||
else if (MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode))
|
||||
if
|
||||
(
|
||||
rb
|
||||
== (uint64_t)0U
|
||||
|| (sb2 == (uint64_t)0U && (a03 & (uint64_t)1U << (uint32_t)sh) == (uint64_t)0U)
|
||||
)
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap3 = a->mpfr_d;
|
||||
ap3[0U] = ap3[0U] + ((uint64_t)1U << (uint32_t)sh);
|
||||
if (ap3[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap3[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (ax1 + (int64_t)1 > MPFR_Lib_mpfr_EMAX)
|
||||
return MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
else
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3562 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3562.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3562.mpfr_sign,
|
||||
.mpfr_exp = ax1 + (int64_t)1,
|
||||
.mpfr_d = uu___72_3562.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else if (MPFR_RoundingMode_mpfr_IS_LIKE_RNDZ(rnd_mode, a->mpfr_sign < (int32_t)0))
|
||||
{
|
||||
int32_t ite;
|
||||
if (a->mpfr_sign == (int32_t)1)
|
||||
ite = (int32_t)-1;
|
||||
else
|
||||
ite = (int32_t)1;
|
||||
return MPFR_Lib_mpfr_RET(ite);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t *ap3 = a->mpfr_d;
|
||||
ap3[0U] = ap3[0U] + ((uint64_t)1U << (uint32_t)sh);
|
||||
if (ap3[0U] == (uint64_t)0U)
|
||||
{
|
||||
ap3[0U] = (uint64_t)0x8000000000000000U;
|
||||
if (ax1 + (int64_t)1 > MPFR_Lib_mpfr_EMAX)
|
||||
return MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
else
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu___72_3752 = a[0U];
|
||||
a[0U] =
|
||||
(
|
||||
(MPFR_Lib_mpfr_struct){
|
||||
.mpfr_prec = uu___72_3752.mpfr_prec,
|
||||
.mpfr_sign = uu___72_3752.mpfr_sign,
|
||||
.mpfr_exp = ax1 + (int64_t)1,
|
||||
.mpfr_d = uu___72_3752.mpfr_d
|
||||
}
|
||||
);
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else
|
||||
return MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
83
gcc/mpfr/src/nbits_ulong.c
Normal file
83
gcc/mpfr/src/nbits_ulong.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* mpfr_nbits_ulong -- number of significant bits in an unsigned long
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#define MPFR_NEED_LONGLONG_H /* for count_leading_zeros */
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
/* count the number of significant bits of n, i.e.,
|
||||
nbits(unsigned long) - count_leading_zeros (n) */
|
||||
int
|
||||
mpfr_nbits_ulong (unsigned long n)
|
||||
{
|
||||
int cnt;
|
||||
|
||||
MPFR_ASSERTD (n > 0);
|
||||
|
||||
#ifdef MPFR_LONG_WITHIN_LIMB
|
||||
|
||||
count_leading_zeros (cnt, (mp_limb_t) n);
|
||||
cnt = GMP_NUMB_BITS - cnt;
|
||||
|
||||
#else
|
||||
|
||||
cnt = 0;
|
||||
|
||||
while (n >= 0x10000)
|
||||
{
|
||||
n >>= 16;
|
||||
cnt += 16;
|
||||
}
|
||||
|
||||
MPFR_ASSERTD (n <= 0xffff);
|
||||
|
||||
if (n >= 0x100)
|
||||
{
|
||||
n >>= 8;
|
||||
cnt += 8;
|
||||
}
|
||||
|
||||
MPFR_ASSERTD (n <= 0xff);
|
||||
|
||||
if (n >= 0x10)
|
||||
{
|
||||
n >>= 4;
|
||||
cnt += 4;
|
||||
}
|
||||
|
||||
MPFR_ASSERTD (n <= 0xf);
|
||||
|
||||
if (n >= 4)
|
||||
{
|
||||
n >>= 2;
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
MPFR_ASSERTD (n <= 3);
|
||||
|
||||
/* now n = 1, 2, or 3 */
|
||||
cnt += 1 + (n >= 2);
|
||||
|
||||
#endif
|
||||
|
||||
MPFR_ASSERTD (cnt >= 0);
|
||||
return cnt;
|
||||
}
|
495
gcc/mpfr/src/set_d128.c
Normal file
495
gcc/mpfr/src/set_d128.c
Normal file
@ -0,0 +1,495 @@
|
||||
/* mpfr_set_decimal128 -- convert a IEEE 754r decimal128 float to
|
||||
a multiple precision floating-point number
|
||||
|
||||
See https://gcc.gnu.org/legacy-ml/gcc/2006-06/msg00691.html,
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html,
|
||||
and TR 24732 <http://www.open-std.org/jtc1/sc22/wg14/www/projects#24732>.
|
||||
|
||||
Copyright 2006-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramel projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#define MPFR_NEED_LONGLONG_H
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
#ifdef MPFR_WANT_DECIMAL_FLOATS
|
||||
|
||||
#if HAVE_DECIMAL128_IEEE && \
|
||||
(GMP_NUMB_BITS == 32 || GMP_NUMB_BITS == 64) && \
|
||||
!defined(DECIMAL_GENERIC_CODE)
|
||||
|
||||
#ifdef DECIMAL_DPD_FORMAT
|
||||
/* conversion 10-bits to 3 digits */
|
||||
static unsigned int T[1024] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 80, 81, 800, 801, 880, 881, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 90, 91, 810, 811, 890, 891, 20, 21, 22, 23, 24, 25,
|
||||
26, 27, 28, 29, 82, 83, 820, 821, 808, 809, 30, 31, 32, 33, 34, 35, 36, 37,
|
||||
38, 39, 92, 93, 830, 831, 818, 819, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
|
||||
84, 85, 840, 841, 88, 89, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 94, 95,
|
||||
850, 851, 98, 99, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 86, 87, 860, 861,
|
||||
888, 889, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 96, 97, 870, 871, 898,
|
||||
899, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 180, 181, 900, 901,
|
||||
980, 981, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 190, 191, 910,
|
||||
911, 990, 991, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 182, 183,
|
||||
920, 921, 908, 909, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 192,
|
||||
193, 930, 931, 918, 919, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
|
||||
184, 185, 940, 941, 188, 189, 150, 151, 152, 153, 154, 155, 156, 157, 158,
|
||||
159, 194, 195, 950, 951, 198, 199, 160, 161, 162, 163, 164, 165, 166, 167,
|
||||
168, 169, 186, 187, 960, 961, 988, 989, 170, 171, 172, 173, 174, 175, 176,
|
||||
177, 178, 179, 196, 197, 970, 971, 998, 999, 200, 201, 202, 203, 204, 205,
|
||||
206, 207, 208, 209, 280, 281, 802, 803, 882, 883, 210, 211, 212, 213, 214,
|
||||
215, 216, 217, 218, 219, 290, 291, 812, 813, 892, 893, 220, 221, 222, 223,
|
||||
224, 225, 226, 227, 228, 229, 282, 283, 822, 823, 828, 829, 230, 231, 232,
|
||||
233, 234, 235, 236, 237, 238, 239, 292, 293, 832, 833, 838, 839, 240, 241,
|
||||
242, 243, 244, 245, 246, 247, 248, 249, 284, 285, 842, 843, 288, 289, 250,
|
||||
251, 252, 253, 254, 255, 256, 257, 258, 259, 294, 295, 852, 853, 298, 299,
|
||||
260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 286, 287, 862, 863, 888,
|
||||
889, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 296, 297, 872, 873,
|
||||
898, 899, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 380, 381, 902,
|
||||
903, 982, 983, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 390, 391,
|
||||
912, 913, 992, 993, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 382,
|
||||
383, 922, 923, 928, 929, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339,
|
||||
392, 393, 932, 933, 938, 939, 340, 341, 342, 343, 344, 345, 346, 347, 348,
|
||||
349, 384, 385, 942, 943, 388, 389, 350, 351, 352, 353, 354, 355, 356, 357,
|
||||
358, 359, 394, 395, 952, 953, 398, 399, 360, 361, 362, 363, 364, 365, 366,
|
||||
367, 368, 369, 386, 387, 962, 963, 988, 989, 370, 371, 372, 373, 374, 375,
|
||||
376, 377, 378, 379, 396, 397, 972, 973, 998, 999, 400, 401, 402, 403, 404,
|
||||
405, 406, 407, 408, 409, 480, 481, 804, 805, 884, 885, 410, 411, 412, 413,
|
||||
414, 415, 416, 417, 418, 419, 490, 491, 814, 815, 894, 895, 420, 421, 422,
|
||||
423, 424, 425, 426, 427, 428, 429, 482, 483, 824, 825, 848, 849, 430, 431,
|
||||
432, 433, 434, 435, 436, 437, 438, 439, 492, 493, 834, 835, 858, 859, 440,
|
||||
441, 442, 443, 444, 445, 446, 447, 448, 449, 484, 485, 844, 845, 488, 489,
|
||||
450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 494, 495, 854, 855, 498,
|
||||
499, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 486, 487, 864, 865,
|
||||
888, 889, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 496, 497, 874,
|
||||
875, 898, 899, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 580, 581,
|
||||
904, 905, 984, 985, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 590,
|
||||
591, 914, 915, 994, 995, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529,
|
||||
582, 583, 924, 925, 948, 949, 530, 531, 532, 533, 534, 535, 536, 537, 538,
|
||||
539, 592, 593, 934, 935, 958, 959, 540, 541, 542, 543, 544, 545, 546, 547,
|
||||
548, 549, 584, 585, 944, 945, 588, 589, 550, 551, 552, 553, 554, 555, 556,
|
||||
557, 558, 559, 594, 595, 954, 955, 598, 599, 560, 561, 562, 563, 564, 565,
|
||||
566, 567, 568, 569, 586, 587, 964, 965, 988, 989, 570, 571, 572, 573, 574,
|
||||
575, 576, 577, 578, 579, 596, 597, 974, 975, 998, 999, 600, 601, 602, 603,
|
||||
604, 605, 606, 607, 608, 609, 680, 681, 806, 807, 886, 887, 610, 611, 612,
|
||||
613, 614, 615, 616, 617, 618, 619, 690, 691, 816, 817, 896, 897, 620, 621,
|
||||
622, 623, 624, 625, 626, 627, 628, 629, 682, 683, 826, 827, 868, 869, 630,
|
||||
631, 632, 633, 634, 635, 636, 637, 638, 639, 692, 693, 836, 837, 878, 879,
|
||||
640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 684, 685, 846, 847, 688,
|
||||
689, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 694, 695, 856, 857,
|
||||
698, 699, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 686, 687, 866,
|
||||
867, 888, 889, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 696, 697,
|
||||
876, 877, 898, 899, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 780,
|
||||
781, 906, 907, 986, 987, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719,
|
||||
790, 791, 916, 917, 996, 997, 720, 721, 722, 723, 724, 725, 726, 727, 728,
|
||||
729, 782, 783, 926, 927, 968, 969, 730, 731, 732, 733, 734, 735, 736, 737,
|
||||
738, 739, 792, 793, 936, 937, 978, 979, 740, 741, 742, 743, 744, 745, 746,
|
||||
747, 748, 749, 784, 785, 946, 947, 788, 789, 750, 751, 752, 753, 754, 755,
|
||||
756, 757, 758, 759, 794, 795, 956, 957, 798, 799, 760, 761, 762, 763, 764,
|
||||
765, 766, 767, 768, 769, 786, 787, 966, 967, 988, 989, 770, 771, 772, 773,
|
||||
774, 775, 776, 777, 778, 779, 796, 797, 976, 977, 998, 999 };
|
||||
#endif
|
||||
|
||||
/* Convert d to a decimal string (one-to-one correspondence, no rounding).
|
||||
The string s needs to have at least 44 characters (including the final \0):
|
||||
* 1 for the sign '-'
|
||||
* 2 for the leading '0.'
|
||||
* 34 for the significand
|
||||
* 6 for the exponent (for example 'E-1000')
|
||||
* 1 for the final '\0'
|
||||
|
||||
According to IEEE 754-2008 (page 11), we have k=128, thus w = k/16+4 = 12,
|
||||
t = 15*k/16-10 = 110, p = 9*k/32-2 = 34, emax = 3*2^(w-1) = 6144,
|
||||
emin = 1-emax = -6143, bias = emax+p-2 = 6176.
|
||||
|
||||
The _Decimal128 encoding is:
|
||||
* 1 bit for the sign
|
||||
* a 17-bit (w+5) combination field G
|
||||
* a 110-bit trailing significand field T
|
||||
*/
|
||||
static void
|
||||
decimal128_to_string (char *s, _Decimal128 d)
|
||||
{
|
||||
union ieee_decimal128 x;
|
||||
char *t;
|
||||
int Gh; /* most 5 significant bits from combination field */
|
||||
int exp; /* exponent */
|
||||
unsigned int i;
|
||||
#ifdef DECIMAL_DPD_FORMAT
|
||||
unsigned int D[12]; /* declets */
|
||||
#else /* BID */
|
||||
mp_limb_t rp[4];
|
||||
mp_size_t rn;
|
||||
#endif
|
||||
|
||||
/* now convert BID or DPD to string:
|
||||
the combination field has 17 bits: 5 + 12 */
|
||||
x.d128 = d;
|
||||
Gh = x.s.comb >> 12;
|
||||
if (Gh == 31)
|
||||
{
|
||||
sprintf (s, "NaN");
|
||||
return;
|
||||
}
|
||||
else if (Gh == 30)
|
||||
{
|
||||
if (x.s.sig == 0)
|
||||
sprintf (s, "Inf");
|
||||
else
|
||||
sprintf (s, "-Inf");
|
||||
return;
|
||||
}
|
||||
t = s;
|
||||
if (x.s.sig)
|
||||
*t++ = '-';
|
||||
|
||||
/* both the decimal128 DPD and BID encodings consist of:
|
||||
* a sign bit of 1 bit
|
||||
* a combination field of 17 bits (5 for the combination field and
|
||||
12 remaining bits)
|
||||
* a trailing significand field of 110 bits
|
||||
*/
|
||||
#ifdef DECIMAL_DPD_FORMAT
|
||||
/* page 11 of IEEE 754-2008, case c1) */
|
||||
if (Gh < 24)
|
||||
{
|
||||
exp = Gh >> 3;
|
||||
D[0] = Gh & 7; /* 4G2+2G3+G4 */
|
||||
}
|
||||
else /* case c1i): the most significant five bits of G are 110xx or 1110x */
|
||||
{
|
||||
exp = (Gh >> 1) & 3; /* 2G2+G3 */
|
||||
D[0] = 8 | (Gh & 1); /* leading significant digit, 8 or 9 */
|
||||
}
|
||||
exp = (exp << 12) | (x.s.comb & 0xfff); /* add last 12 bits of biased exp. */
|
||||
D[1] = x.s.t0 >> 4; /* first declet */
|
||||
D[2] = ((x.s.t0 << 6) | (x.s.t1 >> 26)) & 1023;
|
||||
D[3] = (x.s.t1 >> 16) & 1023;
|
||||
D[4] = (x.s.t1 >> 6) & 1023;
|
||||
D[5] = ((x.s.t1 << 4) | (x.s.t2 >> 28)) & 1023;
|
||||
D[6] = (x.s.t2 >> 18) & 1023;
|
||||
D[7] = (x.s.t2 >> 8) & 1023;
|
||||
D[8] = ((x.s.t2 << 2) | (x.s.t3 >> 30)) & 1023;
|
||||
D[9] = (x.s.t3 >> 20) & 1023;
|
||||
D[10] = (x.s.t3 >> 10) & 1023;
|
||||
D[11] = x.s.t3 & 1023;
|
||||
sprintf (t, "%1u%3u%3u%3u%3u%3u%3u%3u%3u%3u%3u%3u", D[0], T[D[1]], T[D[2]],
|
||||
T[D[3]], T[D[4]], T[D[5]], T[D[6]], T[D[7]], T[D[8]], T[D[9]],
|
||||
T[D[10]], T[D[11]]);
|
||||
/* Warning: some characters may be blank */
|
||||
for (i = 0; i < 34; i++)
|
||||
if (t[i] == ' ')
|
||||
t[i] = '0';
|
||||
t += 34;
|
||||
#else /* BID */
|
||||
/* w + 5 = 17, thus w = 12 */
|
||||
/* IEEE 754-2008 specifies that if the decoded significand exceeds the
|
||||
maximum, i.e. here if it is >= 10^34, then the value is zero. */
|
||||
if (Gh < 24)
|
||||
{
|
||||
/* the biased exponent E is formed from G[0] to G[13] and the
|
||||
significant from bits G[14] through the end of the decoding
|
||||
(including the bits of the trailing significand field) */
|
||||
exp = x.s.comb >> 3; /* upper 14 bits, exp <= 12287 */
|
||||
rp[3] = ((x.s.comb & 7) << 14) | x.s.t0;
|
||||
MPFR_ASSERTD (rp[3] < MPFR_LIMB_ONE << 17); /* rp[3] < 2^17 */
|
||||
}
|
||||
else
|
||||
goto zero; /* in that case, the significand would be formed by prefixing
|
||||
(8 + G[16]) to the trailing significand field of 110 bits,
|
||||
which would give a value of at least 2^113 > 10^34-1,
|
||||
and the standard says that any value exceeding the maximum
|
||||
is non-canonical and should be interpreted as 0. */
|
||||
rp[2] = x.s.t1;
|
||||
rp[1] = x.s.t2;
|
||||
rp[0] = x.s.t3;
|
||||
#if GMP_NUMB_BITS == 64
|
||||
rp[0] |= rp[1] << 32;
|
||||
rp[1] = rp[2] | (rp[3] << 32);
|
||||
rn = 2;
|
||||
#else
|
||||
rn = 4;
|
||||
#endif
|
||||
while (rn > 0 && rp[rn - 1] == 0)
|
||||
rn --;
|
||||
if (rn == 0)
|
||||
{
|
||||
zero:
|
||||
t[0] = '0';
|
||||
t[1] = '\0';
|
||||
return;
|
||||
}
|
||||
i = mpn_get_str ((unsigned char *) t, 10, rp, rn);
|
||||
if (i > 34)
|
||||
goto zero;
|
||||
/* convert the values from mpn_get_str (0, 1, ..., 9) to digits: */
|
||||
while (i-- > 0)
|
||||
*t++ += '0';
|
||||
#endif /* DPD or BID */
|
||||
|
||||
exp -= 6176; /* unbiased exponent: emin - (p-1) where
|
||||
emin = 1-emax = 1-6144 = -6143 and p=34 */
|
||||
sprintf (t, "E%d", exp);
|
||||
}
|
||||
|
||||
#else /* portable version */
|
||||
|
||||
#ifndef DEC128_MAX
|
||||
# define DEC128_MAX 9.999999999999999999999999999999999E6144dl
|
||||
#endif
|
||||
|
||||
static void
|
||||
decimal128_to_string (char *s, _Decimal128 d)
|
||||
{
|
||||
int sign = 0, n;
|
||||
int exp = 0;
|
||||
_Decimal128 ten, ten2, ten4, ten8, ten16, ten32, ten64,
|
||||
ten128, ten256, ten512, ten1024, ten2048, ten4096;
|
||||
|
||||
ten = 10;
|
||||
ten2 = 100;
|
||||
ten4 = 10000;
|
||||
ten8 = 100000000;
|
||||
ten16 = ten8 * ten8;
|
||||
ten32 = ten16 * ten16;
|
||||
ten64 = ten32 * ten32;
|
||||
ten128 = ten64 * ten64;
|
||||
ten256 = ten128 * ten128;
|
||||
ten512 = ten256 * ten256;
|
||||
ten1024 = ten512 * ten512;
|
||||
ten2048 = ten1024 * ten1024;
|
||||
ten4096 = ten2048 * ten2048;
|
||||
|
||||
if (MPFR_UNLIKELY (DOUBLE_ISNAN (d))) /* NaN */
|
||||
{
|
||||
sprintf (s, "NaN"); /* sprintf puts a final '\0' */
|
||||
return;
|
||||
}
|
||||
else if (MPFR_UNLIKELY (d > DEC128_MAX)) /* +Inf */
|
||||
{
|
||||
sprintf (s, "Inf");
|
||||
return;
|
||||
}
|
||||
else if (MPFR_UNLIKELY (d < -DEC128_MAX)) /* -Inf */
|
||||
{
|
||||
sprintf (s, "-Inf");
|
||||
return;
|
||||
}
|
||||
|
||||
/* now d is neither NaN nor +Inf nor -Inf */
|
||||
|
||||
if (d < (_Decimal128) 0.0)
|
||||
{
|
||||
sign = 1;
|
||||
d = -d;
|
||||
}
|
||||
else if (d == (_Decimal128) -0.0)
|
||||
{ /* Warning: the comparison d == -0.0 returns true for d = 0.0 too,
|
||||
copy code from set_d.c here. We first compare to the +0.0 bitstring,
|
||||
in case +0.0 and -0.0 are represented identically. */
|
||||
double dd = (double) d, poszero = +0.0, negzero = DBL_NEG_ZERO;
|
||||
if (memcmp (&dd, &poszero, sizeof(double)) != 0 &&
|
||||
memcmp (&dd, &negzero, sizeof(double)) == 0)
|
||||
{
|
||||
sign = 1;
|
||||
d = -d;
|
||||
}
|
||||
}
|
||||
|
||||
/* now normalize d in [0.1, 1[ */
|
||||
if (d >= (_Decimal128) 1.0)
|
||||
{
|
||||
if (d >= ten4096)
|
||||
{
|
||||
d /= ten4096;
|
||||
exp += 4096;
|
||||
}
|
||||
if (d >= ten2048)
|
||||
{
|
||||
d /= ten2048;
|
||||
exp += 2048;
|
||||
}
|
||||
if (d >= ten1024)
|
||||
{
|
||||
d /= ten1024;
|
||||
exp += 1024;
|
||||
}
|
||||
if (d >= ten512)
|
||||
{
|
||||
d /= ten512;
|
||||
exp += 512;
|
||||
}
|
||||
if (d >= ten256)
|
||||
{
|
||||
d /= ten256;
|
||||
exp += 256;
|
||||
}
|
||||
if (d >= ten128)
|
||||
{
|
||||
d /= ten128;
|
||||
exp += 128;
|
||||
}
|
||||
if (d >= ten64)
|
||||
{
|
||||
d /= ten64;
|
||||
exp += 64;
|
||||
}
|
||||
if (d >= ten32)
|
||||
{
|
||||
d /= ten32;
|
||||
exp += 32;
|
||||
}
|
||||
if (d >= ten16)
|
||||
{
|
||||
d /= ten16;
|
||||
exp += 16;
|
||||
}
|
||||
if (d >= ten8)
|
||||
{
|
||||
d /= ten8;
|
||||
exp += 8;
|
||||
}
|
||||
if (d >= ten4)
|
||||
{
|
||||
d /= ten4;
|
||||
exp += 4;
|
||||
}
|
||||
if (d >= ten2)
|
||||
{
|
||||
d /= ten2;
|
||||
exp += 2;
|
||||
}
|
||||
while (d >= 1)
|
||||
{
|
||||
d /= ten;
|
||||
exp += 1;
|
||||
}
|
||||
}
|
||||
else /* d < 1.0 */
|
||||
{
|
||||
if (d < 1 / ten4096)
|
||||
{
|
||||
d *= ten4096;
|
||||
exp -= 4096;
|
||||
}
|
||||
if (d < 1 / ten2048)
|
||||
{
|
||||
d *= ten2048;
|
||||
exp -= 2048;
|
||||
}
|
||||
if (d < 1 / ten1024)
|
||||
{
|
||||
d *= ten1024;
|
||||
exp -= 1024;
|
||||
}
|
||||
if (d < 1 / ten512)
|
||||
{
|
||||
d *= ten512;
|
||||
exp -= 512;
|
||||
}
|
||||
if (d < 1 / ten256)
|
||||
{
|
||||
d *= ten256;
|
||||
exp -= 256;
|
||||
}
|
||||
if (d < 1 / ten128)
|
||||
{
|
||||
d *= ten128;
|
||||
exp -= 128;
|
||||
}
|
||||
if (d < 1 / ten64)
|
||||
{
|
||||
d *= ten64;
|
||||
exp -= 64;
|
||||
}
|
||||
if (d < 1 / ten32)
|
||||
{
|
||||
d *= ten32;
|
||||
exp -= 32;
|
||||
}
|
||||
if (d < 1 / ten16)
|
||||
{
|
||||
d *= ten16;
|
||||
exp -= 16;
|
||||
}
|
||||
if (d < 1 / ten8)
|
||||
{
|
||||
d *= ten8;
|
||||
exp -= 8;
|
||||
}
|
||||
if (d < 1 / ten4)
|
||||
{
|
||||
d *= ten4;
|
||||
exp -= 4;
|
||||
}
|
||||
if (d < 1 / ten2)
|
||||
{
|
||||
d *= ten2;
|
||||
exp -= 2;
|
||||
}
|
||||
if (d < 1 / ten)
|
||||
{
|
||||
d *= ten;
|
||||
exp -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* now 0.1 <= d < 1 */
|
||||
if (sign == 1)
|
||||
*s++ = '-';
|
||||
*s++ = '0';
|
||||
*s++ = '.';
|
||||
for (n = 0; n < 34; n++)
|
||||
{
|
||||
int r;
|
||||
|
||||
MPFR_ASSERTD (d < 1);
|
||||
d *= 10;
|
||||
MPFR_ASSERTD (d < 10);
|
||||
r = (int) d;
|
||||
*s++ = '0' + r;
|
||||
d -= (_Decimal128) r;
|
||||
}
|
||||
MPFR_ASSERTN (d == 0);
|
||||
if (exp != 0)
|
||||
sprintf (s, "E%d", exp); /* adds a final '\0' */
|
||||
else
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
#endif /* definition of decimal128_to_string (DPD, BID, or portable) */
|
||||
|
||||
/* the IEEE754-2008 decimal128 format has 34 digits, with emax=6144,
|
||||
emin=1-emax=-6143 */
|
||||
int
|
||||
mpfr_set_decimal128 (mpfr_ptr r, _Decimal128 d, mpfr_rnd_t rnd_mode)
|
||||
{
|
||||
char s[44]; /* need 1 character for sign,
|
||||
2 characters for '0.'
|
||||
34 characters for significand,
|
||||
1 character for exponent 'E',
|
||||
5 characters for exponent (including sign),
|
||||
1 character for terminating \0. */
|
||||
|
||||
decimal128_to_string (s, d);
|
||||
MPFR_LOG_MSG (("string: %s\n", s));
|
||||
return mpfr_strtofr (r, s, NULL, 10, rnd_mode);
|
||||
}
|
||||
|
||||
#endif /* MPFR_WANT_DECIMAL_FLOATS */
|
530
gcc/mpfr/src/sub1sp1_extracted.c
Normal file
530
gcc/mpfr/src/sub1sp1_extracted.c
Normal file
@ -0,0 +1,530 @@
|
||||
/* mpfr_sub1sp1 -- internal function to perform a "real" subtraction on one limb
|
||||
This code was extracted by Kremlin from a formal proof in F*
|
||||
done by Félix Breton in June-July 2019: do not modify it!
|
||||
|
||||
Source: https://github.com/project-everest/hacl-star/tree/dev_mpfr/code/mpfr
|
||||
|
||||
Copyright 2004-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "stdint.h"
|
||||
#include "inttypes.h" /* for __builtin_clzll */
|
||||
|
||||
/* beginning of manually added declarations */
|
||||
|
||||
#define MPFR_mpfr_sub1sp1 mpfr_sub1sp1
|
||||
#define MPFR_RoundingMode_mpfr_rnd_t mpfr_rnd_t
|
||||
#define MPFR_Lib_mpfr_struct __mpfr_struct
|
||||
#define MPFR_Lib_gmp_NUMB_BITS GMP_NUMB_BITS
|
||||
#define __eq__MPFR_RoundingMode_mpfr_rnd_t(x,y) ((x)==(y))
|
||||
#define MPFR_RoundingMode_MPFR_RNDD MPFR_RNDD
|
||||
#define MPFR_RoundingMode_MPFR_RNDN MPFR_RNDN
|
||||
#define MPFR_RoundingMode_MPFR_RNDZ MPFR_RNDZ
|
||||
#define MPFR_RoundingMode_MPFR_RNDU MPFR_RNDU
|
||||
#define MPFR_Lib_mpfr_SET_EXP MPFR_SET_EXP
|
||||
#define MPFR_Lib_mpfr_RET MPFR_RET
|
||||
#define MPFR_Lib_mpfr_NEG_SIGN(x) (-(x))
|
||||
#define MPFR_Exceptions_mpfr_underflow mpfr_underflow
|
||||
#define MPFR_Exceptions_mpfr_overflow mpfr_overflow
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
/* the original code had mpfr_exp instead of _mpfr_exp */
|
||||
#define mpfr_exp _mpfr_exp
|
||||
/* the original code had mpfr_d instead of _mpfr_d */
|
||||
#define mpfr_d _mpfr_d
|
||||
/* the original code had mpfr_prec instead of _mpfr_prec */
|
||||
#define mpfr_prec _mpfr_prec
|
||||
/* the original code had mpfr_sign instead of _mpfr_sign */
|
||||
#define mpfr_sign _mpfr_sign
|
||||
#define bool int /* to avoid conflict with C++ keyword */
|
||||
|
||||
/* end of manually added declarations */
|
||||
|
||||
static uint32_t MPFR_Lib_Clz_count_leading_zeros (uint64_t a) {
|
||||
return __builtin_clzll(a);
|
||||
}
|
||||
|
||||
typedef struct MPFR_Add1sp1_state_s
|
||||
{
|
||||
int64_t sh;
|
||||
int64_t bx;
|
||||
uint64_t rb;
|
||||
uint64_t sb;
|
||||
}
|
||||
MPFR_Add1sp1_state;
|
||||
|
||||
typedef struct
|
||||
K___MPFR_Lib_mpfr_struct__MPFR_Lib_mpfr_struct__int64_t_int64_t_uint64_t__uint64_t__s
|
||||
{
|
||||
const MPFR_Lib_mpfr_struct *fst; /* added const */
|
||||
const MPFR_Lib_mpfr_struct *snd; /* added const */
|
||||
int64_t thd;
|
||||
int64_t f3;
|
||||
uint64_t *f4;
|
||||
uint64_t *f5;
|
||||
}
|
||||
K___MPFR_Lib_mpfr_struct__MPFR_Lib_mpfr_struct__int64_t_int64_t_uint64_t__uint64_t_;
|
||||
|
||||
static MPFR_Add1sp1_state
|
||||
MPFR_Add1sp1_mk_state(int64_t sh, int64_t bx, uint64_t rb, uint64_t sb)
|
||||
{
|
||||
MPFR_Add1sp1_state lit;
|
||||
lit.sh = sh;
|
||||
lit.bx = bx;
|
||||
lit.rb = rb;
|
||||
lit.sb = sb;
|
||||
return lit;
|
||||
}
|
||||
|
||||
static MPFR_Add1sp1_state
|
||||
MPFR_Sub1sp1_mpfr_sub1sp1_gt_branch_1(
|
||||
MPFR_Lib_mpfr_struct *a,
|
||||
const MPFR_Lib_mpfr_struct *b, /* added const */
|
||||
const MPFR_Lib_mpfr_struct *c, /* added const */
|
||||
uint64_t *ap,
|
||||
uint64_t *bp,
|
||||
uint64_t *cp,
|
||||
int64_t bx,
|
||||
int64_t cx,
|
||||
int64_t p,
|
||||
int64_t sh,
|
||||
uint64_t mask,
|
||||
uint64_t sb_1,
|
||||
uint64_t a0_base
|
||||
)
|
||||
{
|
||||
uint32_t cnt = MPFR_Lib_Clz_count_leading_zeros(a0_base);
|
||||
uint64_t a0;
|
||||
if (cnt == (uint32_t)0U)
|
||||
{
|
||||
a0 = a0_base;
|
||||
}
|
||||
else
|
||||
{
|
||||
a0 = a0_base << cnt | sb_1 >> ((uint32_t)64U - cnt);
|
||||
}
|
||||
{
|
||||
uint64_t sb_2 = sb_1 << cnt;
|
||||
uint64_t rb = a0 & (uint64_t)1U << (uint32_t)(sh - (int64_t)1);
|
||||
uint64_t sb = sb_2 | ((a0 & mask) ^ rb);
|
||||
ap[0U] = a0 & ~mask;
|
||||
return MPFR_Add1sp1_mk_state(sh, bx - (int64_t)cnt, rb, sb);
|
||||
}
|
||||
}
|
||||
|
||||
static bool MPFR_RoundingMode_uu___is_MPFR_RNDN(MPFR_RoundingMode_mpfr_rnd_t projectee)
|
||||
{
|
||||
switch (projectee)
|
||||
{
|
||||
case MPFR_RoundingMode_MPFR_RNDN:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool MPFR_RoundingMode_uu___is_MPFR_RNDZ(MPFR_RoundingMode_mpfr_rnd_t projectee)
|
||||
{
|
||||
switch (projectee)
|
||||
{
|
||||
case MPFR_RoundingMode_MPFR_RNDZ:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool MPFR_RoundingMode_uu___is_MPFR_RNDU(MPFR_RoundingMode_mpfr_rnd_t projectee)
|
||||
{
|
||||
switch (projectee)
|
||||
{
|
||||
case MPFR_RoundingMode_MPFR_RNDU:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool MPFR_RoundingMode_uu___is_MPFR_RNDD(MPFR_RoundingMode_mpfr_rnd_t projectee)
|
||||
{
|
||||
switch (projectee)
|
||||
{
|
||||
case MPFR_RoundingMode_MPFR_RNDD:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t
|
||||
MPFR_Sub1sp1_mpfr_sub1sp1(
|
||||
MPFR_Lib_mpfr_struct *a,
|
||||
const MPFR_Lib_mpfr_struct *b, /* added const */
|
||||
const MPFR_Lib_mpfr_struct *c, /* added const */
|
||||
MPFR_RoundingMode_mpfr_rnd_t rnd_mode,
|
||||
int64_t p
|
||||
)
|
||||
{
|
||||
int64_t bx = b->mpfr_exp;
|
||||
int64_t cx = c->mpfr_exp;
|
||||
uint64_t *ap = a->mpfr_d;
|
||||
uint64_t *bp = b->mpfr_d;
|
||||
uint64_t *cp = c->mpfr_d;
|
||||
int64_t sh = MPFR_Lib_gmp_NUMB_BITS - p;
|
||||
uint64_t bp0ul = bp[0U];
|
||||
uint64_t cp0ul = cp[0U];
|
||||
if (bx == cx && bp0ul == cp0ul)
|
||||
{
|
||||
if (__eq__MPFR_RoundingMode_mpfr_rnd_t(rnd_mode, MPFR_RoundingMode_MPFR_RNDD))
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu____0 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____0.mpfr_prec;
|
||||
lit.mpfr_sign = (int32_t)-1;
|
||||
lit.mpfr_exp = uu____0.mpfr_exp;
|
||||
lit.mpfr_d = uu____0.mpfr_d;
|
||||
a[0U] = lit;
|
||||
}
|
||||
else
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu____1 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____1.mpfr_prec;
|
||||
lit.mpfr_sign = (int32_t)1;
|
||||
lit.mpfr_exp = uu____1.mpfr_exp;
|
||||
lit.mpfr_d = uu____1.mpfr_d;
|
||||
a[0U] = lit;
|
||||
}
|
||||
MPFR_Lib_mpfr_SET_EXP(a, (int64_t)-0x7fffffffffffffff);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET((int32_t)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPFR_Add1sp1_state st;
|
||||
if (bx == cx)
|
||||
{
|
||||
/* Prims_int vb = FStar_UInt64_v(bp[0U]); */ /* unused */
|
||||
/* Prims_int vc = FStar_UInt64_v(cp[0U]); */ /* unused */
|
||||
/* Prims_int vsh = FStar_Int64_v(sh); */ /* unused */
|
||||
if (cp[0U] > bp[0U])
|
||||
{
|
||||
uint64_t a0 = cp[0U] - bp[0U];
|
||||
uint32_t cnt = MPFR_Lib_Clz_count_leading_zeros(a0);
|
||||
int32_t uu____2 = MPFR_Lib_mpfr_NEG_SIGN(b->mpfr_sign);
|
||||
MPFR_Lib_mpfr_struct uu____3 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____3.mpfr_prec;
|
||||
lit.mpfr_sign = uu____2;
|
||||
lit.mpfr_exp = uu____3.mpfr_exp;
|
||||
lit.mpfr_d = uu____3.mpfr_d;
|
||||
a[0U] = lit;
|
||||
ap[0U] = a0 << cnt;
|
||||
{
|
||||
int64_t bx1 = bx - (int64_t)cnt;
|
||||
st = MPFR_Add1sp1_mk_state(sh, bx1, (uint64_t)0U, (uint64_t)0U);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t a0 = bp[0U] - cp[0U];
|
||||
uint32_t cnt = MPFR_Lib_Clz_count_leading_zeros(a0);
|
||||
MPFR_Lib_mpfr_struct uu____4 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____4.mpfr_prec;
|
||||
lit.mpfr_sign = b->mpfr_sign;
|
||||
lit.mpfr_exp = uu____4.mpfr_exp;
|
||||
lit.mpfr_d = uu____4.mpfr_d;
|
||||
a[0U] = lit;
|
||||
ap[0U] = a0 << cnt;
|
||||
{
|
||||
int64_t bx1 = bx - (int64_t)cnt;
|
||||
st = MPFR_Add1sp1_mk_state(sh, bx1, (uint64_t)0U, (uint64_t)0U);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
K___MPFR_Lib_mpfr_struct__MPFR_Lib_mpfr_struct__int64_t_int64_t_uint64_t__uint64_t_ scrut;
|
||||
if (bx >= cx)
|
||||
{
|
||||
MPFR_Lib_mpfr_struct uu____5 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____5.mpfr_prec;
|
||||
lit.mpfr_sign = b->mpfr_sign;
|
||||
lit.mpfr_exp = uu____5.mpfr_exp;
|
||||
lit.mpfr_d = uu____5.mpfr_d;
|
||||
a[0U] = lit;
|
||||
{
|
||||
K___MPFR_Lib_mpfr_struct__MPFR_Lib_mpfr_struct__int64_t_int64_t_uint64_t__uint64_t_ lit0;
|
||||
lit0.fst = b;
|
||||
lit0.snd = c;
|
||||
lit0.thd = bx;
|
||||
lit0.f3 = cx;
|
||||
lit0.f4 = bp;
|
||||
lit0.f5 = cp;
|
||||
scrut = lit0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t uu____6 = MPFR_Lib_mpfr_NEG_SIGN(b->mpfr_sign);
|
||||
MPFR_Lib_mpfr_struct uu____7 = a[0U];
|
||||
MPFR_Lib_mpfr_struct lit;
|
||||
lit.mpfr_prec = uu____7.mpfr_prec;
|
||||
lit.mpfr_sign = uu____6;
|
||||
lit.mpfr_exp = uu____7.mpfr_exp;
|
||||
lit.mpfr_d = uu____7.mpfr_d;
|
||||
a[0U] = lit;
|
||||
{
|
||||
K___MPFR_Lib_mpfr_struct__MPFR_Lib_mpfr_struct__int64_t_int64_t_uint64_t__uint64_t_ lit0;
|
||||
lit0.fst = c;
|
||||
lit0.snd = b;
|
||||
lit0.thd = cx;
|
||||
lit0.f3 = bx;
|
||||
lit0.f4 = cp;
|
||||
lit0.f5 = bp;
|
||||
scrut = lit0;
|
||||
}
|
||||
}
|
||||
{
|
||||
const MPFR_Lib_mpfr_struct *b1 = scrut.fst; /* added const */
|
||||
const MPFR_Lib_mpfr_struct *c1 = scrut.snd; /* added const */
|
||||
int64_t bx1 = scrut.thd;
|
||||
int64_t cx1 = scrut.f3;
|
||||
uint64_t *bp1 = scrut.f4;
|
||||
uint64_t *cp1 = scrut.f5;
|
||||
int64_t d = bx1 - cx1;
|
||||
uint64_t bp0ul1 = bp1[0U];
|
||||
uint64_t cp0ul1 = cp1[0U];
|
||||
uint64_t mask = ((uint64_t)1U << (uint32_t)sh) - (uint64_t)1U;
|
||||
if (d < (int64_t)64)
|
||||
{
|
||||
uint64_t sb_1 = ~(cp0ul1 << (uint32_t)(MPFR_Lib_gmp_NUMB_BITS - d)) + (uint64_t)1U;
|
||||
uint64_t ite;
|
||||
if (sb_1 == (uint64_t)0U)
|
||||
{
|
||||
ite = (uint64_t)0U;
|
||||
}
|
||||
else
|
||||
{
|
||||
ite = (uint64_t)1U;
|
||||
}
|
||||
st =
|
||||
MPFR_Sub1sp1_mpfr_sub1sp1_gt_branch_1(a,
|
||||
b1,
|
||||
c1,
|
||||
ap,
|
||||
bp1,
|
||||
cp1,
|
||||
bx1,
|
||||
cx1,
|
||||
p,
|
||||
sh,
|
||||
mask,
|
||||
sb_1,
|
||||
bp0ul1 - ite - (cp0ul1 >> (uint32_t)d));
|
||||
}
|
||||
else if (bp0ul1 > (uint64_t)0x8000000000000000U)
|
||||
{
|
||||
ap[0U] = bp0ul1 - ((uint64_t)1U << (uint32_t)sh);
|
||||
st = MPFR_Add1sp1_mk_state(sh, bx1, (uint64_t)1U, (uint64_t)1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool
|
||||
rb =
|
||||
sh
|
||||
> (int64_t)1
|
||||
|| d > MPFR_Lib_gmp_NUMB_BITS
|
||||
|| cp0ul1 == (uint64_t)0x8000000000000000U;
|
||||
bool
|
||||
sb =
|
||||
sh
|
||||
> (int64_t)1
|
||||
|| d > MPFR_Lib_gmp_NUMB_BITS
|
||||
|| cp0ul1 != (uint64_t)0x8000000000000000U;
|
||||
ap[0U] = ~mask;
|
||||
{
|
||||
uint64_t ite0;
|
||||
if (rb)
|
||||
{
|
||||
ite0 = (uint64_t)1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
ite0 = (uint64_t)0U;
|
||||
}
|
||||
{
|
||||
uint64_t ite;
|
||||
if (sb)
|
||||
{
|
||||
ite = (uint64_t)1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
ite = (uint64_t)0U;
|
||||
}
|
||||
st = MPFR_Add1sp1_mk_state(sh, bx1 - (int64_t)1, ite0, ite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* the constant (int64_t)-0x000000003fffffff from the original extracted
|
||||
code was manually replaced by __gmpfr_emin */
|
||||
if (st.bx < __gmpfr_emin)
|
||||
{
|
||||
int32_t s = a->mpfr_sign;
|
||||
uint64_t ap0ul = ap[0U];
|
||||
if
|
||||
(
|
||||
__eq__MPFR_RoundingMode_mpfr_rnd_t(rnd_mode,
|
||||
MPFR_RoundingMode_MPFR_RNDN)
|
||||
/* the constant (int64_t)-1073741824 from the original extracted
|
||||
code was manually replaced by __gmpfr_emin-1 */
|
||||
&& (st.bx < __gmpfr_emin - 1 || ap0ul == (uint64_t)0x8000000000000000U)
|
||||
)
|
||||
{
|
||||
MPFR_Lib_mpfr_SET_EXP(a, (int64_t)-0x7fffffffffffffff);
|
||||
return MPFR_Lib_mpfr_NEG_SIGN(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_underflow(a, rnd_mode, s);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t a0 = ap[0U];
|
||||
MPFR_Lib_mpfr_SET_EXP(a, st.bx);
|
||||
if (st.rb == (uint64_t)0U && st.sb == (uint64_t)0U)
|
||||
{
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET((int32_t)0);
|
||||
}
|
||||
else if (MPFR_RoundingMode_uu___is_MPFR_RNDN(rnd_mode))
|
||||
{
|
||||
if
|
||||
(
|
||||
st.rb
|
||||
== (uint64_t)0U
|
||||
|| (st.sb == (uint64_t)0U && (a0 & (uint64_t)1U << (uint32_t)st.sh) == (uint64_t)0U)
|
||||
)
|
||||
{
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(MPFR_Lib_mpfr_NEG_SIGN(a->mpfr_sign));
|
||||
}
|
||||
else if (ap[0U] + ((uint64_t)1U << (uint32_t)st.sh) == (uint64_t)0U)
|
||||
{
|
||||
ap[0U] = ap[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
ap[0U] = (uint64_t)0x8000000000000000U;
|
||||
/* the constant (int64_t)0x000000003fffffff from the original
|
||||
extracted code was replaced by __gmpfr_emax */
|
||||
if (st.bx + (int64_t)1 <= __gmpfr_emax)
|
||||
{
|
||||
MPFR_Lib_mpfr_SET_EXP(a, st.bx + (int64_t)1);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ap[0U] = ap[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool uu____8 = a->mpfr_sign < (int32_t)0;
|
||||
if
|
||||
(
|
||||
MPFR_RoundingMode_uu___is_MPFR_RNDZ(rnd_mode)
|
||||
|| (MPFR_RoundingMode_uu___is_MPFR_RNDU(rnd_mode) && uu____8)
|
||||
|| (MPFR_RoundingMode_uu___is_MPFR_RNDD(rnd_mode) && !uu____8)
|
||||
)
|
||||
{
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(MPFR_Lib_mpfr_NEG_SIGN(a->mpfr_sign));
|
||||
}
|
||||
else if (ap[0U] + ((uint64_t)1U << (uint32_t)st.sh) == (uint64_t)0U)
|
||||
{
|
||||
ap[0U] = ap[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
ap[0U] = (uint64_t)0x8000000000000000U;
|
||||
/* the constant (int64_t)0x000000003fffffff from the original
|
||||
extracted code was replaced by __gmpfr_emax */
|
||||
if (st.bx + (int64_t)1 <= __gmpfr_emax)
|
||||
{
|
||||
MPFR_Lib_mpfr_SET_EXP(a, st.bx + (int64_t)1);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t t = MPFR_Exceptions_mpfr_overflow(a, rnd_mode, a->mpfr_sign);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ap[0U] = ap[0U] + ((uint64_t)1U << (uint32_t)st.sh);
|
||||
/* the following return was commented out from the extracted code */
|
||||
/*return*/ MPFR_Lib_mpfr_RET(a->mpfr_sign);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
(*MPFR_mpfr_sub1sp1)(
|
||||
MPFR_Lib_mpfr_struct *x0,
|
||||
const MPFR_Lib_mpfr_struct *x1, /* added const */
|
||||
const MPFR_Lib_mpfr_struct *x2, /* added const */
|
||||
MPFR_RoundingMode_mpfr_rnd_t x3,
|
||||
int64_t x4
|
||||
) = MPFR_Sub1sp1_mpfr_sub1sp1;
|
||||
|
42
gcc/mpfr/src/total_order.c
Normal file
42
gcc/mpfr/src/total_order.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* mpfr_total_order_p -- total order of two floating-point numbers
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-impl.h"
|
||||
|
||||
/* follows IEEE 754-2008, Section 5.10 */
|
||||
int
|
||||
mpfr_total_order_p (mpfr_srcptr x, mpfr_srcptr y)
|
||||
{
|
||||
if (MPFR_SIGN (x) != MPFR_SIGN (y))
|
||||
return MPFR_IS_POS (y);
|
||||
|
||||
if (MPFR_IS_NAN (x))
|
||||
return MPFR_IS_NAN (y) || MPFR_IS_NEG (x);
|
||||
|
||||
/* Now x is not NaN. */
|
||||
if (MPFR_IS_NAN (y))
|
||||
return MPFR_IS_POS (y); /* x < +NaN, x > -NaN */
|
||||
|
||||
/* Now neither x nor y is NaN, and zeros of different sign have
|
||||
already been taken into account. */
|
||||
return mpfr_lessequal_p (x, y);
|
||||
}
|
233
gcc/mpfr/src/x86_64/mparam.h
Normal file
233
gcc/mpfr/src/x86_64/mparam.h
Normal file
@ -0,0 +1,233 @@
|
||||
/* Various Thresholds of MPFR, not exported. -*- mode: C -*-
|
||||
|
||||
Copyright 2005-2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* Generated by MPFR's tuneup.c, 2018-02-22, gcc 7.3.0 */
|
||||
/* tomate.loria.fr Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz with GMP 6.1.2,
|
||||
where GMP defines -mtune=haswell */
|
||||
|
||||
#define MPFR_MULHIGH_TAB \
|
||||
-1,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0, \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
|
||||
0,0,0,0,0,0,0,0,0,24,26,28,28,28,28,28, \
|
||||
30,30,32,32,30,32,30,34,36,36,38,36,38,38,44,44, \
|
||||
44,44,44,44,44,48,44,44,48,44,48,52,52,48,56,56, \
|
||||
56,56,56,56,56,56,56,56,60,56,60,64,64,64,60,64, \
|
||||
64,68,64,64,64,64,72,68,68,72,63,72,64,64,68,64, \
|
||||
81,72,72,84,81,81,86,81,81,81,87,87,81,87,87,84, \
|
||||
80,84,87,90,87,86,93,87,92,93,93,96,96,93,96,93, \
|
||||
96,93,104,104,105,105,105,105,104,105,105,108,105,108,104,108, \
|
||||
104,108,111,104,117,108,114,116,116,116,117,114,116,129,117,114, \
|
||||
128,129,129,132,132,134,132,117,141,141,132,140,141,132,138,141, \
|
||||
141,141,141,144,140,141,138,141,144,144,141,144,141,141,140,141, \
|
||||
141,141,140,141,141,141,144,165,144,165,165,164,163,165,164,164, \
|
||||
164,168,165,168,164,164,164,165,165,164,165,168,168,165,164,165, \
|
||||
164,164,164,176,165,177,164,165,168,168,165,165,168,168,168,174, \
|
||||
177,176,177,177,177,189,188,189,177,180,177,180,189,187,188,188, \
|
||||
189,189,189,189,189,188,189,192,220,192,220,220,219,220,220,219, \
|
||||
220,219,220,220,220,219,220,220,219,220,220,219,220,219,220,220, \
|
||||
220,220,220,219,220,220,220,224,219,224,220,234,234,236,236,236, \
|
||||
236,235,235,240,235,236,236,236,236,236,235,236,236,251,235,236, \
|
||||
236,252,252,252,252,252,252,252,236,251,251,256,252,252,252,252, \
|
||||
250,251,252,252,251,252,251,252,284,252,264,280,251,252,252,284, \
|
||||
252,284,284,284,284,284,284,283,284,284,284,284,284,283,284,284, \
|
||||
283,284,284,282,284,284,283,306,306,306,306,306,306,330,330,330, \
|
||||
330,330,330,330,330,330,330,329,330,329,330,329,330,330,330,330, \
|
||||
330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330, \
|
||||
330,330,330,330,329,330,354,330,330,330,330,330,354,354,354,353, \
|
||||
354,354,354,353,354,330,354,354,330,354,354,330,330,354,330,378, \
|
||||
330,378,378,330,330,330,378,354,378,378,354,378,378,354,378,377, \
|
||||
378,378,377,378,354,354,354,354,354,354,354,378,354,354,378,378, \
|
||||
378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,440, \
|
||||
440,439,439,378,440,440,440,440,440,440,440,439,440,439,440,440, \
|
||||
439,440,440,440,440,440,440,440,440,440,440,440,440,439,440,439, \
|
||||
439,440,439,440,440,440,440,440,440,440,440,440,440,440,440,440, \
|
||||
440,440,440,440,440,440,439,440,440,440,440,440,440,440,439,440, \
|
||||
440,440,440,472,472,439,440,472,471,472,440,439,440,440,440,472, \
|
||||
472,440,472,472,471,472,472,472,472,472,472,472,472,472,472,472, \
|
||||
504,472,471,504,504,504,472,504,472,472,470,472,472,472,472,472, \
|
||||
504,472,472,504,504,504,503,504,504,504,504,503,504,504,503,504, \
|
||||
504,504,504,504,504,503,504,504,504,504,504,503,504,504,504,504, \
|
||||
504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504, \
|
||||
504,504,504,504,504,504,504,503,503,504,504,504,504,536,536,536, \
|
||||
568,504,568,568,567,568,568,568,567,568,568,567,568,568,568,568, \
|
||||
566,568,568,568,567,568,568,568,567,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,568,568,568,567,568,568,568,568,568,568,568, \
|
||||
568,568,568,568,568,567,568,567,568,568,566,568,568,568,568,568, \
|
||||
640,568,640,639,640,640,568,568,640,640,640,640,640,640,640,640, \
|
||||
639,640,640,640,640,640,640,640,639,640,640,639,640,640,640,640, \
|
||||
640,639,640,640,640,640,640,640,640,640,640,638,640,640,640,640, \
|
||||
640,640,640,640,640,640,640,640,640,640,640,640,664,664,664,639, \
|
||||
639,640,664,640,640,639,640,639,640,640,640,639,640,640,640,640, \
|
||||
640,640,640,639,640,688,688,640,640,688,688,640,687,688,664,663, \
|
||||
640,664,688,688,688,688,663,664,736,663,664,664,663,664,712,664, \
|
||||
664,664,688,664,712,712,736,640,688,736,736,736,736,736,736,736, \
|
||||
688,736,736,736,736,736,736,736,735,736,736,736,736,736,736,736, \
|
||||
736,736,736,736,736,736,736,736,735,735,736,736,736,735,736,736, \
|
||||
735,736,736,736,735,736,736,735,735,736,735,736,736,736,735,736, \
|
||||
736,736,736,736,736,736,735,736,735,736,736,736,736,736,736,736, \
|
||||
736,736,735,736,736,736,736,736,736,736,736,736,736,736,735,736, \
|
||||
736,736,736,735,736,736,736,735,736,736,760,736,734,736,736,736, \
|
||||
832,736,784,760,830,760,832,760,736,832,832,832,736,832,832,832, \
|
||||
832,832,832,831,832,832,831,831,832,831,831,832,832,831,832,831, \
|
||||
832,832,832,832,832,831,736,831,832,832,832,832,832,831,831,832 \
|
||||
|
||||
#define MPFR_SQRHIGH_TAB \
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,7,8,8,9,9, \
|
||||
10,10,12,12,12,12,13,13,14,15,15,16,17,17,18,19, \
|
||||
19,19,19,20,21,22,22,23,23,23,23,23,24,24,26,25, \
|
||||
26,27,28,27,29,29,31,29,31,30,33,32,33,33,33,33, \
|
||||
40,38,40,40,40,44,42,40,42,44,44,46,44,42,48,48, \
|
||||
48,48,50,52,50,50,48,50,50,52,52,56,54,56,58,55, \
|
||||
56,58,58,61,60,61,62,64,64,56,66,68,60,62,58,72, \
|
||||
72,76,76,76,76,72,80,80,80,72,76,76,76,76,76,80, \
|
||||
88,80,76,76,80,76,76,80,88,76,79,84,84,88,84,88, \
|
||||
85,88,92,92,84,92,92,90,91,92,96,92,94,92,94,100, \
|
||||
96,92,92,94,85,100,92,96,88,100,96,96,100,91,94,92, \
|
||||
100,94,95,96,98,96,101,100,100,117,100,100,112,100,104,108, \
|
||||
106,108,111,117,117,117,126,123,120,120,120,117,126,126,123,129, \
|
||||
128,128,128,128,126,131,128,129,132,129,132,135,129,137,136,135, \
|
||||
138,135,132,141,136,144,140,144,141,138,150,147,147,147,142,138, \
|
||||
146,138,147,144,144,150,152,144,147,147,147,162,156,164,165,162, \
|
||||
158,152,162,156,161,162,168,156,168,170,168,171,167,170,171,168, \
|
||||
174,175,174,171,159,164,170,170,150,183,176,176,168,168,177,180, \
|
||||
176,170,160,174,176,171,177,171,176,176,177,183,176,174,177,174, \
|
||||
174,177,176,183,176,177,180,177,180,175,176,183,195,180,194,182, \
|
||||
183,189,192,192,189,177,183,189,195,192,189,201,195,195,186,195, \
|
||||
201,201,201,200,200,198,225,219,224,225,204,213,213,225,213,222, \
|
||||
222,219,227,221,222,212,231,222,228,225,224,224,228,227,228,240, \
|
||||
225,219,225,228,228,224,224,227,237,227,228,228,225,225,225,228, \
|
||||
228,237,231,237,231,236,249,237,249,243,240,240,237,249,249,243, \
|
||||
249,237,261,260,261,261,249,260,249,248,261,249,261,261,261,261, \
|
||||
261,261,260,261,264,272,273,273,236,237,273,261,273,237,273,261, \
|
||||
273,273,273,273,264,240,273,261,273,261,273,273,273,273,261,248, \
|
||||
249,267,273,273,261,261,261,261,261,264,273,264,261,273,270,272, \
|
||||
273,272,273,276,273,272,273,267,273,273,272,276,285,285,285,285, \
|
||||
276,276,285,285,283,288,285,296,296,285,285,273,285,294,297,273, \
|
||||
297,297,296,273,309,297,273,285,297,296,285,308,309,272,285,297, \
|
||||
297,276,309,297,297,321,297,296,297,295,285,297,297,297,297,295, \
|
||||
297,297,309,297,309,309,297,296,321,295,307,321,321,312,348,309, \
|
||||
348,348,309,348,309,347,348,348,324,321,321,363,319,347,364,356, \
|
||||
363,348,333,363,361,348,348,364,364,347,348,362,364,364,380,346, \
|
||||
364,348,347,347,364,348,364,362,364,363,362,364,364,364,363,364, \
|
||||
364,371,364,364,364,363,364,364,363,380,363,377,372,380,380,364, \
|
||||
364,379,371,379,380,364,380,380,379,380,379,380,364,384,363,364, \
|
||||
395,396,395,396,380,395,380,378,396,396,378,396,387,396,396,395, \
|
||||
379,410,396,395,396,395,396,395,411,426,412,412,396,425,396,426, \
|
||||
412,409,410,411,410,450,425,426,394,450,462,419,426,410,431,426, \
|
||||
425,426,432,438,432,450,432,426,432,450,438,449,450,450,456,450, \
|
||||
432,456,456,450,450,461,462,456,474,450,462,450,450,450,474,474, \
|
||||
450,474,474,474,474,474,473,474,474,474,462,474,474,474,474,474, \
|
||||
546,474,474,474,474,474,474,474,486,498,498,498,498,474,497,497, \
|
||||
498,498,498,474,498,522,521,522,522,498,522,522,521,520,521,522, \
|
||||
522,521,522,522,522,522,522,522,522,522,522,522,522,522,522,522, \
|
||||
522,522,522,522,522,545,546,546,546,546,546,545,546,544,522,546, \
|
||||
546,546,567,568,520,567,522,545,567,546,568,545,568,568,568,546, \
|
||||
568,545,546,545,546,546,546,568,568,568,568,567,568,568,568,567, \
|
||||
568,568,568,568,568,568,584,568,567,568,600,568,568,599,600,600, \
|
||||
568,600,600,600,600,600,600,567,600,600,568,600,599,600,600,600, \
|
||||
600,600,600,600,600,600,600,600,600,600,600,600,600,600,632,600, \
|
||||
600,600,632,632,616,632,600,600,600,631,600,632,600,616,600,632, \
|
||||
632,600,600,632,632,600,632,600,632,600,600,600,600,600,600,599, \
|
||||
600,599,600,600,600,599,600,631,600,600,600,600,600,600,600,632, \
|
||||
599,640,600,600,600,632,632,600,600,632,632,631,632,632,632,630, \
|
||||
632,632,632,631,640,696,632,632,632,632,630,631,632,631,648,695, \
|
||||
632,695,696,695,632,631,632,647,648,648,648,696,695,696,696,712, \
|
||||
695,664,695,696,695,695,696,695,696,696,696,696,664,695,696,728, \
|
||||
712,727,728,727,696,728,664,663,696,664,664,728,728,664,696,696, \
|
||||
696,696,696,696,696,695,696,696,696,695,696,696,695,695,696,696, \
|
||||
695,696,695,695,695,696,696,696,696,728,726,728,728,728,727,728 \
|
||||
|
||||
#define MPFR_DIVHIGH_TAB \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*0-15*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*16-31*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*32-47*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*48-63*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*64-79*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*80-95*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*96-111*/ \
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*112-127*/ \
|
||||
68,68,0,0,75,69,0,0,71,78,72,73,74,72,78,74, /*128-143*/ \
|
||||
77,84,78,79,78,84,84,77,80,79,80,82,80,80,88,84, /*144-159*/ \
|
||||
84,84,83,93,84,91,86,92,90,88,92,90,90,94,96,95, /*160-175*/ \
|
||||
94,94,96,96,96,96,98,94,100,98,100,96,97,104,106,100, /*176-191*/ \
|
||||
98,98,102,106,102,106,106,112,109,103,112,112,110,104,112,111, /*192-207*/ \
|
||||
109,112,110,118,110,128,112,116,126,112,128,132,128,128,128,128, /*208-223*/ \
|
||||
124,127,128,122,129,128,125,126,127,125,128,127,128,125,136,128, /*224-239*/ \
|
||||
128,128,136,128,136,128,144,132,130,144,135,132,132,136,136,134, /*240-255*/ \
|
||||
142,144,144,134,144,137,136,150,135,143,136,146,140,144,144,142, /*256-271*/ \
|
||||
144,144,144,143,144,149,162,144,144,162,144,144,156,144,167,146, /*272-287*/ \
|
||||
148,150,162,150,155,150,150,158,154,156,162,168,164,160,168,162, /*288-303*/ \
|
||||
156,168,160,164,160,160,158,158,160,159,160,168,166,166,180,164, /*304-319*/ \
|
||||
168,168,184,180,165,174,174,174,172,179,174,174,190,185,186,180, /*320-335*/ \
|
||||
182,184,185,185,186,186,186,192,192,184,187,200,188,184,184,180, /*336-351*/ \
|
||||
196,180,184,186,186,198,192,189,185,186,192,184,191,186,196,186, /*352-367*/ \
|
||||
189,192,190,216,196,189,195,200,192,197,192,192,192,206,204,196, /*368-383*/ \
|
||||
200,214,210,207,216,198,216,210,198,216,214,216,216,208,216,216, /*384-399*/ \
|
||||
208,216,222,224,228,216,216,216,208,216,216,232,228,214,212,218, /*400-415*/ \
|
||||
216,216,218,220,214,216,221,228,220,224,218,224,220,216,224,232, /*416-431*/ \
|
||||
232,220,228,228,264,233,232,228,228,233,232,256,252,228,228,256, /*432-447*/ \
|
||||
232,264,232,264,256,254,256,232,264,255,252,257,258,264,268,276, /*448-463*/ \
|
||||
254,251,264,268,264,248,256,268,254,264,256,256,252,255,258,256, /*464-479*/ \
|
||||
256,257,264,252,264,256,268,272,256,267,256,276,272,287,272,264, /*480-495*/ \
|
||||
256,257,272,276,268,264,264,264,270,272,288,268,269,280,288,288, /*496-511*/ \
|
||||
280,284,282,288,276,288,279,288,288,281,286,288,280,272,272,280, /*512-527*/ \
|
||||
288,288,294,281,276,288,288,288,288,288,280,288,288,287,288,288, /*528-543*/ \
|
||||
284,288,288,287,288,291,288,288,288,288,324,324,287,288,287,312, /*544-559*/ \
|
||||
288,288,288,305,324,292,309,288,312,328,288,311,336,327,330,300, /*560-575*/ \
|
||||
318,330,312,336,327,321,324,336,330,324,335,327,335,336,336,336, /*576-591*/ \
|
||||
336,324,352,335,360,329,344,329,318,329,336,328,336,336,324,335, /*592-607*/ \
|
||||
323,336,336,336,336,328,336,325,360,324,336,328,316,335,336,332, /*608-623*/ \
|
||||
324,360,334,323,328,360,360,384,328,360,330,336,336,336,368,328, /*624-639*/ \
|
||||
335,371,336,335,372,372,335,336,372,336,336,348,330,356,360,370, /*640-655*/ \
|
||||
336,336,384,336,340,368,336,384,346,360,348,372,348,366,376,368, /*656-671*/ \
|
||||
340,347,368,360,384,384,372,348,384,376,368,360,384,344,369,384, /*672-687*/ \
|
||||
372,360,384,360,366,372,368,352,392,360,377,384,383,368,384,384, /*688-703*/ \
|
||||
384,384,372,369,384,383,384,376,382,364,376,384,378,376,384,384, /*704-719*/ \
|
||||
376,382,372,375,384,383,372,384,408,378,384,384,384,384,416,432, /*720-735*/ \
|
||||
384,384,432,419,384,424,384,440,417,440,392,380,408,376,424,378, /*736-751*/ \
|
||||
432,384,440,392,444,400,440,440,384,384,440,384,448,384,448,432, /*752-767*/ \
|
||||
448,432,432,432,416,440,440,400,440,440,438,432,432,432,448,440, /*768-783*/ \
|
||||
444,444,440,436,440,444,420,436,432,432,440,456,420,443,420,420, /*784-799*/ \
|
||||
456,432,431,432,424,432,464,440,432,466,432,448,456,463,460,448, /*800-815*/ \
|
||||
440,420,448,448,444,431,440,440,416,440,433,439,440,456,440,456, /*816-831*/ \
|
||||
434,454,432,432,431,440,440,440,464,428,428,436,440,440,432,440, /*832-847*/ \
|
||||
432,436,436,439,436,440,432,440,438,445,456,440,456,448,456,440, /*848-863*/ \
|
||||
456,464,464,440,456,448,451,440,447,512,440,440,446,446,448,456, /*864-879*/ \
|
||||
448,456,452,460,453,455,456,456,448,455,463,464,480,464,463,464, /*880-895*/ \
|
||||
480,452,480,528,466,468,456,457,480,467,464,468,504,504,460,467, /*896-911*/ \
|
||||
480,512,464,484,466,468,512,472,504,504,504,504,504,528,478,479, /*912-927*/ \
|
||||
504,480,504,520,504,520,504,504,512,512,472,512,512,528,512,512, /*928-943*/ \
|
||||
528,512,502,528,504,536,536,520,528,528,552,536,512,511,528,512, /*944-959*/ \
|
||||
536,560,512,512,488,528,512,536,552,528,512,576,560,560,576,576, /*960-975*/ \
|
||||
504,560,512,560,560,511,512,552,528,512,512,512,568,576,512,512, /*976-991*/ \
|
||||
512,528,528,568,528,512,504,576,576,528,512,576,544,504,576,512, /*992-1007*/ \
|
||||
512,536,528,560,528,540,536,576,568,536,544,536,536,576,527,544 /*1008-1023*/ \
|
||||
|
||||
#define MPFR_MUL_THRESHOLD 12 /* limbs */
|
||||
#define MPFR_SQR_THRESHOLD 19 /* limbs */
|
||||
#define MPFR_DIV_THRESHOLD 3 /* limbs */
|
||||
#define MPFR_EXP_2_THRESHOLD 894 /* bits */
|
||||
#define MPFR_EXP_THRESHOLD 6522 /* bits */
|
||||
#define MPFR_SINCOS_THRESHOLD 23540 /* bits */
|
||||
#define MPFR_AI_THRESHOLD1 -14260 /* threshold for negative input of mpfr_ai */
|
||||
#define MPFR_AI_THRESHOLD2 1680
|
||||
#define MPFR_AI_THRESHOLD3 24368
|
||||
/* Tuneup completed successfully, took 342 seconds */
|
177
gcc/mpfr/tests/tdot.c
Normal file
177
gcc/mpfr/tests/tdot.c
Normal file
@ -0,0 +1,177 @@
|
||||
/* tdot -- test file for mpfr_dot
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-test.h"
|
||||
|
||||
static void
|
||||
check_simple (void)
|
||||
{
|
||||
mpfr_t tab[3], r;
|
||||
mpfr_ptr tabp[3];
|
||||
int i;
|
||||
|
||||
mpfr_init2 (r, 16);
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
mpfr_init2 (tab[i], 16);
|
||||
mpfr_set_ui (tab[i], 1, MPFR_RNDN);
|
||||
tabp[i] = tab[i];
|
||||
}
|
||||
|
||||
i = mpfr_dot (r, tabp, tabp, 3, MPFR_RNDN);
|
||||
if (mpfr_cmp_ui0 (r, 3) || i != 0)
|
||||
{
|
||||
printf ("Error in check_simple\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_clears (tab[0], tab[1], tab[2], r, (mpfr_ptr) 0);
|
||||
}
|
||||
|
||||
static void
|
||||
check_special (void)
|
||||
{
|
||||
mpfr_t tab[3], r;
|
||||
mpfr_ptr tabp[3];
|
||||
int i;
|
||||
int rnd;
|
||||
|
||||
mpfr_inits2 (53, tab[0], tab[1], tab[2], r, (mpfr_ptr) 0);
|
||||
tabp[0] = tab[0];
|
||||
tabp[1] = tab[1];
|
||||
tabp[2] = tab[2];
|
||||
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 0, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_ZERO (r) || !MPFR_IS_POS (r) || i != 0)
|
||||
{
|
||||
printf ("Special case n==0 failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
mpfr_set_ui (tab[0], 42, MPFR_RNDN);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 1, (mpfr_rnd_t) rnd);
|
||||
if (mpfr_cmp_ui0 (r, 42*42) || i != 0)
|
||||
{
|
||||
printf ("Special case n==1 failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
mpfr_set_ui (tab[1], 17, MPFR_RNDN);
|
||||
MPFR_SET_NAN (tab[2]);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_NAN (r) || i != 0)
|
||||
{
|
||||
printf ("Special case NAN failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
MPFR_SET_INF (tab[2]);
|
||||
MPFR_SET_POS (tab[2]);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_INF (r) || !MPFR_IS_POS (r) || i != 0)
|
||||
{
|
||||
printf ("Special case +INF failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
MPFR_SET_INF (tab[2]);
|
||||
MPFR_SET_NEG (tab[2]);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_INF (r) || !MPFR_IS_POS (r) || i != 0)
|
||||
{
|
||||
printf ("Special case +INF failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
MPFR_SET_ZERO (tab[1]);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 2, (mpfr_rnd_t) rnd);
|
||||
if (mpfr_cmp_ui0 (r, 42*42) || i != 0)
|
||||
{
|
||||
printf ("Special case 42+0 failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
MPFR_SET_NAN (tab[0]);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_NAN (r) || i != 0)
|
||||
{
|
||||
printf ("Special case NAN+0+-INF failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
mpfr_set_inf (tab[0], 1);
|
||||
mpfr_set_inf (tab[0], 1);
|
||||
mpfr_set_inf (tab[2], -1);
|
||||
RND_LOOP (rnd)
|
||||
{
|
||||
i = mpfr_dot (r, tabp, tabp + 1, 2, (mpfr_rnd_t) rnd);
|
||||
if (!MPFR_IS_NAN (r) || i != 0)
|
||||
{
|
||||
printf ("Special case inf*inf-inf*inf failed for %s!\n",
|
||||
mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
mpfr_clears (tab[0], tab[1], tab[2], r, (mpfr_ptr) 0);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
tests_start_mpfr ();
|
||||
|
||||
check_simple ();
|
||||
check_special ();
|
||||
|
||||
tests_end_mpfr ();
|
||||
|
||||
return 0;
|
||||
}
|
595
gcc/mpfr/tests/tget_set_d128.c
Normal file
595
gcc/mpfr/tests/tget_set_d128.c
Normal file
@ -0,0 +1,595 @@
|
||||
/* Test file for mpfr_set_decimal128 and mpfr_get_decimal128.
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* Needed due to the test on MPFR_WANT_DECIMAL_FLOATS */
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef MPFR_WANT_DECIMAL_FLOATS
|
||||
|
||||
#include "mpfr-test.h"
|
||||
|
||||
#ifndef DEC128_MAX
|
||||
# define DEC128_MAX 9.999999999999999999999999999999999E6144dl
|
||||
#endif
|
||||
|
||||
static void
|
||||
print_decimal128 (_Decimal128 d)
|
||||
{
|
||||
if (DOUBLE_ISNAN (d))
|
||||
printf ("NaN");
|
||||
else if (d > DEC128_MAX)
|
||||
printf ("Inf");
|
||||
else if (d < -DEC128_MAX)
|
||||
printf ("-Inf");
|
||||
else if (d == 0)
|
||||
{
|
||||
printf ("%.1f", (double) d);
|
||||
}
|
||||
else /* regular number */
|
||||
{
|
||||
long e = 0;
|
||||
while (d < 1.0dl)
|
||||
{
|
||||
d *= 10.0dl;
|
||||
e --;
|
||||
}
|
||||
/* now d >= 1 */
|
||||
while (d > 10.0dl)
|
||||
{
|
||||
d /= 10.0dl;
|
||||
e ++;
|
||||
}
|
||||
/* now 1 <= d < 10 */
|
||||
printf ("%.33LfE%ld", (long double) d, e);
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
#define PRINT_ERR_MISC(V) \
|
||||
do \
|
||||
{ \
|
||||
printf ("Error in check_misc for %s.\n", V); \
|
||||
printf (" mpfr_get_decimal128() returned: "); \
|
||||
print_decimal128 (d); \
|
||||
printf (" mpfr_set_decimal128() set x to: "); \
|
||||
mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN); \
|
||||
printf (" approx.\n = "); \
|
||||
mpfr_dump (x); \
|
||||
exit (1); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
static void
|
||||
test_set (void)
|
||||
{
|
||||
long v[] = { 1, -1, 2147483647, -2147483647 };
|
||||
mpfr_t x;
|
||||
mpfr_flags_t flags;
|
||||
int i, inex;
|
||||
|
||||
mpfr_init2 (x, 53);
|
||||
for (i = 0; i < numberof (v); i++)
|
||||
{
|
||||
mpfr_clear_flags ();
|
||||
inex = mpfr_set_decimal128 (x, (_Decimal128) v[i], MPFR_RNDN);
|
||||
flags = __gmpfr_flags;
|
||||
if (mpfr_cmp_si (x, v[i]) != 0 || inex != 0 || flags != 0)
|
||||
{
|
||||
printf ("Error in test_set for i=%d\n", i);
|
||||
printf ("Expected %ld\n with inex = 0 and flags =", v[i]);
|
||||
flags_out (0);
|
||||
printf ("Got ");
|
||||
mpfr_dump (x);
|
||||
printf (" with inex = %d and flags =", inex);
|
||||
flags_out (flags);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
mpfr_clear (x);
|
||||
}
|
||||
|
||||
static void
|
||||
powers_of_10 (void)
|
||||
{
|
||||
mpfr_t x1, x2;
|
||||
_Decimal128 d[2];
|
||||
int i, rnd;
|
||||
unsigned int neg;
|
||||
|
||||
mpfr_inits2 (200, x1, x2, (mpfr_ptr) 0);
|
||||
for (i = 0, d[0] = 1, d[1] = 1; i < 150; i++, d[0] *= 10, d[1] /= 10)
|
||||
for (neg = 0; neg <= 3; neg++)
|
||||
RND_LOOP_NO_RNDF (rnd)
|
||||
{
|
||||
int inex1, inex2;
|
||||
mpfr_flags_t flags1, flags2;
|
||||
mpfr_rnd_t rx1;
|
||||
_Decimal128 dd;
|
||||
|
||||
inex1 = mpfr_set_si (x1, (neg >> 1) ? -i : i, MPFR_RNDN);
|
||||
MPFR_ASSERTN (inex1 == 0);
|
||||
|
||||
rx1 = (neg & 1) ?
|
||||
MPFR_INVERT_RND ((mpfr_rnd_t) rnd) : (mpfr_rnd_t) rnd;
|
||||
mpfr_clear_flags ();
|
||||
inex1 = mpfr_exp10 (x1, x1, rx1);
|
||||
flags1 = __gmpfr_flags;
|
||||
|
||||
dd = d[neg >> 1];
|
||||
|
||||
if (neg & 1)
|
||||
{
|
||||
MPFR_SET_NEG (x1);
|
||||
inex1 = -inex1;
|
||||
dd = -dd;
|
||||
}
|
||||
|
||||
mpfr_clear_flags ();
|
||||
inex2 = mpfr_set_decimal128 (x2, dd, (mpfr_rnd_t) rnd);
|
||||
flags2 = __gmpfr_flags;
|
||||
|
||||
if (!(mpfr_equal_p (x1, x2) &&
|
||||
SAME_SIGN (inex1, inex2) &&
|
||||
flags1 == flags2))
|
||||
{
|
||||
printf ("Error in powers_of_10 for i=%d, neg=%d, %s\n",
|
||||
i, neg, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
|
||||
printf ("Expected ");
|
||||
mpfr_dump (x1);
|
||||
printf ("with inex = %d and flags =", inex1);
|
||||
flags_out (flags1);
|
||||
printf ("Got ");
|
||||
mpfr_dump (x2);
|
||||
printf ("with inex = %d and flags =", inex2);
|
||||
flags_out (flags2);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
mpfr_clears (x1, x2, (mpfr_ptr) 0);
|
||||
}
|
||||
|
||||
static void
|
||||
check_misc (void)
|
||||
{
|
||||
mpfr_t x, y;
|
||||
_Decimal128 d;
|
||||
|
||||
mpfr_init2 (x, 123);
|
||||
mpfr_init2 (y, 123);
|
||||
|
||||
#if !defined(MPFR_ERRDIVZERO)
|
||||
mpfr_set_nan (x);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
MPFR_ASSERTN (mpfr_nan_p (x));
|
||||
|
||||
mpfr_set_inf (x, 1);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (! mpfr_inf_p (x) || MPFR_IS_NEG (x))
|
||||
PRINT_ERR_MISC ("+Inf");
|
||||
|
||||
mpfr_set_inf (x, -1);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (! mpfr_inf_p (x) || MPFR_IS_POS (x))
|
||||
PRINT_ERR_MISC ("-Inf");
|
||||
#endif
|
||||
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (MPFR_NOTZERO (x) || MPFR_IS_NEG (x))
|
||||
PRINT_ERR_MISC ("+0");
|
||||
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_neg (x, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (MPFR_NOTZERO (x) || MPFR_IS_POS (x))
|
||||
PRINT_ERR_MISC ("-0");
|
||||
|
||||
mpfr_set_ui (x, 1, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (mpfr_cmp_ui (x, 1) != 0)
|
||||
PRINT_ERR_MISC ("+1");
|
||||
|
||||
mpfr_set_si (x, -1, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (mpfr_cmp_si (x, -1) != 0)
|
||||
PRINT_ERR_MISC ("-1");
|
||||
|
||||
mpfr_set_ui (x, 2, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (mpfr_cmp_ui (x, 2) != 0)
|
||||
PRINT_ERR_MISC ("2");
|
||||
|
||||
mpfr_set_ui (x, 99, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (mpfr_cmp_ui (x, 99) != 0)
|
||||
PRINT_ERR_MISC ("99");
|
||||
|
||||
mpfr_set_str (x, "9999999999999999999999999999999999", 10, MPFR_RNDZ);
|
||||
mpfr_set (y, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("9999999999999999999999999999999999");
|
||||
|
||||
/* smallest normal number */
|
||||
mpfr_set_str (x, "1E-6143", 10, MPFR_RNDU);
|
||||
mpfr_set (y, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDU);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("1E-6143");
|
||||
|
||||
/* smallest subnormal number */
|
||||
mpfr_set_str (x, "1E-6176", 10, MPFR_RNDU);
|
||||
mpfr_set (y, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDU);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("1E-6176");
|
||||
|
||||
/* exercise case e < -20517, i.e., x < 0.5*2^(-20517) */
|
||||
mpfr_set_ui_2exp (x, 1, -20518, MPFR_RNDN);
|
||||
mpfr_nextbelow (x);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
/* d should equal +0 */
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_zero_p (x) && mpfr_signbit (x) == 0);
|
||||
/* check RNDA */
|
||||
mpfr_set_ui_2exp (x, 1, -20518, MPFR_RNDN);
|
||||
mpfr_nextbelow (x);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDA);
|
||||
/* d should equal 1E-6176 */
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
mpfr_set_str (y, "1E-6176", 10, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_equal_p (x, y));
|
||||
/* check negative number */
|
||||
mpfr_set_ui_2exp (x, 1, -20518, MPFR_RNDN);
|
||||
mpfr_nextbelow (x);
|
||||
mpfr_neg (x, x, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
/* d should equal -0 */
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_zero_p (x) && mpfr_signbit (x) == 1);
|
||||
|
||||
/* exercise case e10 < -6175 */
|
||||
mpfr_set_ui_2exp (x, 1, -20517, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_zero_p (x) && mpfr_signbit (x) == 0);
|
||||
mpfr_set_ui_2exp (x, 1, -20517, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDU);
|
||||
mpfr_set_str (y, "1E-6176", 10, MPFR_RNDN);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_equal_p (x, y));
|
||||
mpfr_set_ui_2exp (x, 1, -20517, MPFR_RNDN);
|
||||
/* 2^(-20517) = 5.85570193228610e-6177 thus should be rounded to 1E-6176 */
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_str (y, "1E-6176", 10, MPFR_RNDN);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_equal_p (x, y));
|
||||
|
||||
/* subnormal number with exponent change when we round back
|
||||
from 34 digits to 1 digit */
|
||||
// mpfr_set_str (x, "9.9E-6176", 10, MPFR_RNDN);
|
||||
mpfr_set_str (x, "9.9E-6176", 10, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDU); /* should be 1E-6175 */
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDU);
|
||||
mpfr_set_str (y, "1E-6175", 10, MPFR_RNDN);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("9.9E-6176");
|
||||
|
||||
/* largest number */
|
||||
mpfr_set_str (x, "9.999999999999999999999999999999999E6144", 10, MPFR_RNDZ);
|
||||
mpfr_set (y, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDU);
|
||||
if (d == DEC128_MAX)
|
||||
{
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("DEC128_MAX");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Error in check_misc for DEC128_MAX.\n");
|
||||
printf (" mpfr_get_decimal128() returned: ");
|
||||
print_decimal128 (d);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_set_str (x, "-9.999999999999999999999999999999999E6144", 10, MPFR_RNDZ);
|
||||
mpfr_set (y, x, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDA);
|
||||
if (d == -DEC128_MAX)
|
||||
{
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDZ);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("-DEC128_MAX");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Error in check_misc for -DEC128_MAX.\n");
|
||||
printf (" mpfr_get_decimal128() returned: ");
|
||||
print_decimal128 (d);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* exercise |x| > DEC128_MAX */
|
||||
mpfr_set_str (x, "10E6144", 10, MPFR_RNDU);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
MPFR_ASSERTN(d == DEC128_MAX);
|
||||
mpfr_set_str (x, "-10E6144", 10, MPFR_RNDU);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
MPFR_ASSERTN(d == -DEC128_MAX);
|
||||
|
||||
mpfr_set_prec (x, 53);
|
||||
mpfr_set_prec (y, 53);
|
||||
|
||||
/* largest number */
|
||||
mpfr_set_str (x, "9.999999999999999999999999999999999E6144", 10, MPFR_RNDZ);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (y, d, MPFR_RNDU);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("DEC128_MAX (2)");
|
||||
|
||||
/* since 1+ceil(109*log(2)/log(10)) = 34, the 109-bit value x, when
|
||||
converted to a 34-digit decimal d, gives back x when converted back to
|
||||
binary */
|
||||
mpfr_set_prec (x, 109);
|
||||
mpfr_set_prec (y, 109);
|
||||
mpfr_set_str (x, "1E1793", 10, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
mpfr_set_str (y, "1E1793", 10, MPFR_RNDN);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("1E1793");
|
||||
|
||||
mpfr_set_str (x, "2E4095", 10, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
mpfr_set_str (y, "2E4095", 10, MPFR_RNDN);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("2E4095");
|
||||
|
||||
mpfr_set_str (x, "2E-4096", 10, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
mpfr_set_str (y, "2E-4096", 10, MPFR_RNDN);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("2E-4096");
|
||||
|
||||
mpfr_set_str (x, "2E-6110", 10, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_ui (x, 0, MPFR_RNDZ);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
mpfr_set_str (y, "2E-6110", 10, MPFR_RNDN);
|
||||
if (! mpfr_equal_p (x, y))
|
||||
PRINT_ERR_MISC ("2E-6110");
|
||||
|
||||
/* case where EXP(x) > 20414, thus outside the decimal128 range */
|
||||
mpfr_set_ui_2exp (x, 1, 20414, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
MPFR_ASSERTN(d == DEC128_MAX);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDA);
|
||||
MPFR_ASSERTN(d > DEC128_MAX); /* implies d = +Inf */
|
||||
mpfr_set_si_2exp (x, -1, 20414, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDZ);
|
||||
MPFR_ASSERTN(d == -DEC128_MAX);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDA);
|
||||
MPFR_ASSERTN(d < -DEC128_MAX); /* implies d = -Inf */
|
||||
|
||||
/* case where EXP(x) = 20414, at the limit of the decimal128 range */
|
||||
mpfr_set_ui_2exp (x, 3, 20412, MPFR_RNDN); /* 3*2^20412 > 9.999...E6144 */
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
MPFR_ASSERTN(d > DEC128_MAX); /* implies d = +Inf */
|
||||
mpfr_set_si_2exp (x, -3, 20412, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
MPFR_ASSERTN(d < -DEC128_MAX); /* implies d = -Inf */
|
||||
|
||||
{
|
||||
unsigned long i;
|
||||
for (i = 1; i < 1000; i++)
|
||||
{
|
||||
mpfr_set_ui_2exp (x, i, 20403, MPFR_RNDN);
|
||||
d = mpfr_get_decimal128 (x, MPFR_RNDN);
|
||||
mpfr_set_decimal128 (x, d, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, i, 20403) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
mpfr_clear (x);
|
||||
mpfr_clear (y);
|
||||
}
|
||||
|
||||
static void
|
||||
noncanonical (void)
|
||||
{
|
||||
/* The code below assumes BID. */
|
||||
#if HAVE_DECIMAL128_IEEE && defined(DECIMAL_BID_FORMAT)
|
||||
union ieee_decimal128 x;
|
||||
|
||||
MPFR_ASSERTN (sizeof (x) == 16);
|
||||
/* produce a non-canonical decimal128 with Gh >= 24 */
|
||||
x.d128 = 1;
|
||||
/* if BID, we have sig=0, comb=49408, t0=t1=t2=0, t3=1 */
|
||||
if (x.s.sig == 0 && x.s.comb == 49408 && x.s.t0 == 0 && x.s.t1 == 0 &&
|
||||
x.s.t2 == 0 && x.s.t3 == 1)
|
||||
{
|
||||
/* The volatile below avoids _Decimal128 constant propagation, which is
|
||||
buggy for non-canonical encoding in various GCC versions on the x86
|
||||
and x86_64 targets: failure in the second test below ("Error 2")
|
||||
with gcc (Debian 20190820-1) 10.0.0 20190820 (experimental)
|
||||
[trunk revision 274744]. The MPFR test was not failing with previous
|
||||
GCC versions, not even with gcc (Debian 20190719-1) 10.0.0 20190718
|
||||
(experimental) [trunk revision 273586] (contrary to the similar test
|
||||
in tget_set_d64.c). More information at:
|
||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91226
|
||||
*/
|
||||
volatile _Decimal128 d = 9999999999999999999999999999999999.0dl;
|
||||
mpfr_t y;
|
||||
|
||||
x.s.comb = 98560; /* force Gh >= 24 thus a non-canonical number
|
||||
(significand >= 2^113 > 20^34-1) */
|
||||
mpfr_init2 (y, 113);
|
||||
mpfr_set_decimal128 (y, x.d128, MPFR_RNDN);
|
||||
if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y))
|
||||
{
|
||||
int i;
|
||||
printf ("Error 1 in noncanonical on");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf (" %02X", ((unsigned char *)&x)[i]);
|
||||
printf ("\nExpected +0, got:\n");
|
||||
mpfr_dump (y);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* now construct a case Gh < 24, but where the significand exceeds
|
||||
10^34-1 */
|
||||
x.d128 = d;
|
||||
/* should give sig=0, comb=49415, t0=11529, t1=3199043520,
|
||||
t2=932023907, t3=4294967295 */
|
||||
x.s.t3 ++; /* should give 0 */
|
||||
x.s.t2 += (x.s.t3 == 0);
|
||||
/* now the significand is 10^34 */
|
||||
mpfr_set_decimal128 (y, x.d128, MPFR_RNDN);
|
||||
if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y))
|
||||
{
|
||||
int i;
|
||||
printf ("Error 2 in noncanonical on");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf (" %02X", ((unsigned char *)&x)[i]);
|
||||
printf ("\nExpected +0, got:\n");
|
||||
mpfr_dump (y);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_clear (y);
|
||||
}
|
||||
else
|
||||
printf ("Warning! Unexpected value of x in noncanonical.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* generate random sequences of 16 bytes and interpret them as _Decimal128 */
|
||||
static void
|
||||
check_random_bytes (void)
|
||||
{
|
||||
union {
|
||||
_Decimal128 d;
|
||||
unsigned char c[16];
|
||||
} x;
|
||||
int i;
|
||||
mpfr_t y;
|
||||
_Decimal128 e;
|
||||
|
||||
mpfr_init2 (y, 114); /* 114 = 1 + ceil(34*log(10)/log(2)), thus ensures
|
||||
that if a decimal128 number is converted to a 114-bit
|
||||
value and back, we should get the same value */
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < 16; j++)
|
||||
x.c[j] = randlimb () & 255;
|
||||
mpfr_set_decimal128 (y, x.d, MPFR_RNDN);
|
||||
e = mpfr_get_decimal128 (y, MPFR_RNDN);
|
||||
if (!mpfr_nan_p (y))
|
||||
if (x.d != e)
|
||||
{
|
||||
printf ("check_random_bytes failed\n");
|
||||
printf ("x.d="); print_decimal128 (x.d);
|
||||
printf ("y="); mpfr_dump (y);
|
||||
printf ("e="); print_decimal128 (e);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
mpfr_clear (y);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int verbose = argc > 1;
|
||||
|
||||
tests_start_mpfr ();
|
||||
mpfr_test_init ();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
#ifdef DECIMAL_DPD_FORMAT
|
||||
printf ("Using DPD encoding\n");
|
||||
#endif
|
||||
#ifdef DECIMAL_BID_FORMAT
|
||||
printf ("Using BID encoding\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(MPFR_ERRDIVZERO)
|
||||
check_random_bytes ();
|
||||
#endif
|
||||
test_set ();
|
||||
powers_of_10 ();
|
||||
#if !defined(MPFR_ERRDIVZERO)
|
||||
check_misc ();
|
||||
#endif
|
||||
noncanonical ();
|
||||
|
||||
tests_end_mpfr ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* MPFR_WANT_DECIMAL_FLOATS */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
return 77;
|
||||
}
|
||||
|
||||
#endif /* MPFR_WANT_DECIMAL_FLOATS */
|
121
gcc/mpfr/tests/tprec_round.c
Normal file
121
gcc/mpfr/tests/tprec_round.c
Normal file
@ -0,0 +1,121 @@
|
||||
/* Test file for mpfr_prec_round.
|
||||
|
||||
Copyright 1999-2004, 2006-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-test.h"
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
mpfr_t x;
|
||||
mpfr_exp_t emax;
|
||||
|
||||
tests_start_mpfr ();
|
||||
|
||||
mpfr_init (x);
|
||||
|
||||
mpfr_set_nan (x);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_nan_p (x));
|
||||
|
||||
mpfr_set_inf (x, 1);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
|
||||
|
||||
mpfr_set_inf (x, -1);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
|
||||
|
||||
mpfr_set_ui (x, 0, MPFR_RNDN);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
|
||||
|
||||
mpfr_set_ui (x, 0, MPFR_RNDN);
|
||||
mpfr_neg (x, x, MPFR_RNDN);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG(x));
|
||||
|
||||
emax = mpfr_get_emax ();
|
||||
set_emax (0);
|
||||
mpfr_set_prec (x, 3);
|
||||
mpfr_set_str_binary (x, "0.111");
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
|
||||
set_emax (emax);
|
||||
|
||||
mpfr_set_prec (x, mp_bits_per_limb + 2);
|
||||
mpfr_set_ui (x, 1, MPFR_RNDN);
|
||||
mpfr_nextbelow (x);
|
||||
mpfr_prec_round (x, mp_bits_per_limb + 1, MPFR_RNDN);
|
||||
MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0);
|
||||
|
||||
mpfr_set_prec (x, 3);
|
||||
mpfr_set_ui (x, 5, MPFR_RNDN);
|
||||
mpfr_prec_round (x, 2, MPFR_RNDN);
|
||||
if (mpfr_cmp_ui(x, 4))
|
||||
{
|
||||
printf ("Error in tround: got ");
|
||||
mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
|
||||
printf (" instead of 4\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* check case when reallocation is needed */
|
||||
mpfr_set_prec (x, 3);
|
||||
mpfr_set_ui (x, 5, MPFR_RNDN); /* exact */
|
||||
mpfr_prec_round (x, mp_bits_per_limb + 1, MPFR_RNDN);
|
||||
if (mpfr_cmp_ui(x, 5))
|
||||
{
|
||||
printf ("Error in tround: got ");
|
||||
mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
|
||||
printf (" instead of 5\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_clear(x);
|
||||
mpfr_init2 (x, 3);
|
||||
mpfr_set_si (x, -5, MPFR_RNDN); /* exact */
|
||||
mpfr_prec_round (x, mp_bits_per_limb + 1, MPFR_RNDN);
|
||||
if (mpfr_cmp_si(x, -5))
|
||||
{
|
||||
printf ("Error in tround: got ");
|
||||
mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
|
||||
printf (" instead of -5\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* check case when new precision needs less limbs */
|
||||
mpfr_set_prec (x, mp_bits_per_limb + 1);
|
||||
mpfr_set_ui (x, 5, MPFR_RNDN); /* exact */
|
||||
mpfr_prec_round (x, 3, MPFR_RNDN); /* exact */
|
||||
if (mpfr_cmp_ui(x, 5))
|
||||
{
|
||||
printf ("Error in tround: got ");
|
||||
mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
|
||||
printf (" instead of 5\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_clear(x);
|
||||
|
||||
tests_end_mpfr ();
|
||||
return 0;
|
||||
}
|
111
gcc/mpfr/tests/ttotal_order.c
Normal file
111
gcc/mpfr/tests/ttotal_order.c
Normal file
@ -0,0 +1,111 @@
|
||||
/* Test file for mpfr_total_order_p.
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the AriC and Caramba projects, INRIA.
|
||||
|
||||
This file is part of the GNU MPFR Library.
|
||||
|
||||
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include "mpfr-test.h"
|
||||
|
||||
static void
|
||||
check1 (mpfr_ptr x, mpfr_ptr y)
|
||||
{
|
||||
if (! mpfr_total_order_p (x, x))
|
||||
{
|
||||
printf ("Error on mpfr_total_order_p (x, x) with\n");
|
||||
printf ("x = ");
|
||||
mpfr_dump (x);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
mpfr_set (y, x, MPFR_RNDN);
|
||||
|
||||
if (! mpfr_total_order_p (x, y))
|
||||
{
|
||||
printf ("Error on mpfr_total_order_p (x, y) with\n");
|
||||
printf ("x = ");
|
||||
mpfr_dump (x);
|
||||
printf ("y = ");
|
||||
mpfr_dump (y);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check2 (mpfr_ptr x, mpfr_ptr y)
|
||||
{
|
||||
if (! mpfr_total_order_p (x, y))
|
||||
{
|
||||
printf ("Error on mpfr_total_order_p (x, y) with\n");
|
||||
printf ("x = ");
|
||||
mpfr_dump (x);
|
||||
printf ("y = ");
|
||||
mpfr_dump (y);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (mpfr_total_order_p (y, x))
|
||||
{
|
||||
printf ("Error on mpfr_total_order_p (y, x) with\n");
|
||||
printf ("x = ");
|
||||
mpfr_dump (x);
|
||||
printf ("y = ");
|
||||
mpfr_dump (y);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
mpfr_t x[13];
|
||||
int i, j;
|
||||
|
||||
tests_start_mpfr ();
|
||||
|
||||
for (i = 0; i < 13; i++)
|
||||
mpfr_init2 (x[i], 32);
|
||||
|
||||
mpfr_set_nan (x[1]);
|
||||
MPFR_SET_NEG (x[1]);
|
||||
mpfr_set_inf (x[2], -1);
|
||||
mpfr_set_si (x[3], -3, MPFR_RNDN);
|
||||
mpfr_set_si (x[4], -2, MPFR_RNDN);
|
||||
mpfr_set_si (x[5], -1, MPFR_RNDN);
|
||||
mpfr_set_zero (x[6], -1);
|
||||
mpfr_set_zero (x[7], 1);
|
||||
mpfr_set_si (x[8], 1, MPFR_RNDN);
|
||||
mpfr_set_si (x[9], 2, MPFR_RNDN);
|
||||
mpfr_set_si (x[10], 3, MPFR_RNDN);
|
||||
mpfr_set_inf (x[11], 1);
|
||||
mpfr_set_nan (x[12]);
|
||||
MPFR_SET_POS (x[12]);
|
||||
|
||||
for (i = 1; i <= 12; i++)
|
||||
{
|
||||
check1 (x[i], x[0]);
|
||||
for (j = i+1; j <= 12; j++)
|
||||
check2 (x[i], x[j]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 13; i++)
|
||||
mpfr_clear (x[i]);
|
||||
|
||||
tests_end_mpfr ();
|
||||
return 0;
|
||||
}
|
72
gcc/mpfr/tools/check_mparam.c
Normal file
72
gcc/mpfr/tools/check_mparam.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* check_mparam - check a mparam.h file
|
||||
|
||||
Copyright 2018-2020 Free Software Foundation, Inc.
|
||||
Contributed by the Arenaire and Caramel projects, INRIA.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; see the file COPYING.LESSER. If not, see
|
||||
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* To check some mparam.h tables:
|
||||
1) make a symbolic link to the corresponding mparam.h or
|
||||
provide -DMPARAM='"..."' with a path to the mparam.h
|
||||
file when compiling this program
|
||||
2) compile and run this program */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef MPARAM
|
||||
# define MPARAM "mparam.h"
|
||||
#endif
|
||||
|
||||
#include MPARAM
|
||||
|
||||
#define numberof_const(x) (sizeof (x) / sizeof ((x)[0]))
|
||||
|
||||
static short mulhigh_ktab[] = {MPFR_MULHIGH_TAB};
|
||||
#define MPFR_MULHIGH_TAB_SIZE (numberof_const (mulhigh_ktab))
|
||||
|
||||
static short sqrhigh_ktab[] = {MPFR_SQRHIGH_TAB};
|
||||
#define MPFR_SQRHIGH_TAB_SIZE (numberof_const (sqrhigh_ktab))
|
||||
|
||||
static short divhigh_ktab[] = {MPFR_DIVHIGH_TAB};
|
||||
#define MPFR_DIVHIGH_TAB_SIZE (numberof_const (divhigh_ktab))
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int err = 0, n;
|
||||
|
||||
for (n = 0; n < MPFR_MULHIGH_TAB_SIZE; n++)
|
||||
if (mulhigh_ktab[n] >= n)
|
||||
{
|
||||
printf ("Error, mulhigh_ktab[%d] = %d\n", n, mulhigh_ktab[n]);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
for (n = 0; n < MPFR_SQRHIGH_TAB_SIZE; n++)
|
||||
if (sqrhigh_ktab[n] >= n)
|
||||
{
|
||||
printf ("Error, sqrhigh_ktab[%d] = %d\n", n, sqrhigh_ktab[n]);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
for (n = 2; n < MPFR_DIVHIGH_TAB_SIZE; n++)
|
||||
if (divhigh_ktab[n] >= n-1)
|
||||
{
|
||||
printf ("Error, divhigh_ktab[%d] = %d\n", n, divhigh_ktab[n]);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
42
gcc/mpfr/tools/ck-mparam
Executable file
42
gcc/mpfr/tools/ck-mparam
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Check the mparam.h files. This script is useful as not all mparam.h
|
||||
# files may be tested by our tests.
|
||||
|
||||
# Copyright 2011-2020 Free Software Foundation, Inc.
|
||||
# This script is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
# Note: This script must be run from a writable directory (an executable
|
||||
# check_mparam will be created in it). Moreover, the source tree that is
|
||||
# checked is the one that contains this script, not the one corresponding
|
||||
# to the current working directory (the rule for the other scripts in
|
||||
# the tools directory may be different).
|
||||
|
||||
set -e
|
||||
|
||||
dir=$(dirname "$0")
|
||||
files=$(cd "$dir/.." && find src/*/ -name mparam.h)
|
||||
err=0
|
||||
|
||||
for i in $files
|
||||
do
|
||||
#output=`echo "#include \"$i\"" | gcc -o /dev/null -c -xc - 2>&1`
|
||||
#if [ -n "$output" ]; then
|
||||
# printf "Error for file '%s':\n%s\n" "$i" "$output"
|
||||
# err=1
|
||||
#fi
|
||||
rm -f check_mparam
|
||||
${CC:-cc} "-DMPARAM=\"../$i\"" -o check_mparam "$dir"/check_mparam.c
|
||||
./check_mparam
|
||||
done
|
||||
|
||||
rm -f check_mparam
|
||||
|
||||
exit $err
|
Loading…
Reference in New Issue
Block a user