[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Tue Sep 5 18:33:02 CEST 2023
details: /var/hg/gmp/rev/ef441e461f42
changeset: 18452:ef441e461f42
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Sep 05 18:16:53 2023 +0200
description:
mpn/generic/toom*: unsigned to handle sign for evaluated couples
details: /var/hg/gmp/rev/8225bdfc499f
changeset: 18453:8225bdfc499f
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Sep 05 18:32:26 2023 +0200
description:
ChangeLog
diffstat:
ChangeLog | 7 +++++++
gmp-impl.h | 14 +++++++-------
mpn/generic/toom54_mul.c | 2 +-
mpn/generic/toom63_mul.c | 14 ++++++++------
mpn/generic/toom6h_mul.c | 2 +-
mpn/generic/toom8h_mul.c | 2 +-
mpn/generic/toom_couple_handling.c | 2 +-
mpn/generic/toom_eval_dgr3_pm1.c | 8 +++++---
mpn/generic/toom_eval_dgr3_pm2.c | 8 +++++---
mpn/generic/toom_eval_pm1.c | 7 ++++---
mpn/generic/toom_eval_pm2.c | 11 ++++++-----
mpn/generic/toom_eval_pm2exp.c | 7 ++++---
mpn/generic/toom_eval_pm2rexp.c | 7 ++++---
13 files changed, 54 insertions(+), 37 deletions(-)
diffs (truncated from 328 to 300 lines):
diff -r e3cc6f9e9753 -r 8225bdfc499f ChangeLog
--- a/ChangeLog Sun Aug 27 20:47:01 2023 +0200
+++ b/ChangeLog Tue Sep 05 18:32:26 2023 +0200
@@ -1,3 +1,10 @@
+2023-09-05 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mpn/generic/toom{54,63,6h,8h}_mul.c, mpn/generic/toom_couple_handling.c,
+ mpn/generic/toom_eval_{dgr3_pm1,dgr3_pm2,pm1,pm2,pm2exp,pm2rexp}.c:
+ Use unsigned to handle sign for evaluated couples of value in Toom code.
+ * gmp-impl.h: Update prototypes accordingly.
+
2023-08-21 FX Coudert <fxcoudert at gmail.com>
Marc Glisse <marc.glisse at inria.fr>
diff -r e3cc6f9e9753 -r 8225bdfc499f gmp-impl.h
--- a/gmp-impl.h Sun Aug 27 20:47:01 2023 +0200
+++ b/gmp-impl.h Tue Sep 05 18:32:26 2023 +0200
@@ -1481,25 +1481,25 @@
__GMP_DECLSPEC void mpn_toom_interpolate_16pts (mp_ptr, mp_ptr, mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_size_t, int, mp_ptr);
#define mpn_toom_couple_handling __MPN(toom_couple_handling)
-__GMP_DECLSPEC void mpn_toom_couple_handling (mp_ptr, mp_size_t, mp_ptr, int, mp_size_t, int, int);
+__GMP_DECLSPEC void mpn_toom_couple_handling (mp_ptr, mp_size_t, mp_ptr, unsigned, mp_size_t, int, int);
#define mpn_toom_eval_dgr3_pm1 __MPN(toom_eval_dgr3_pm1)
-__GMP_DECLSPEC int mpn_toom_eval_dgr3_pm1 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_dgr3_pm1 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
#define mpn_toom_eval_dgr3_pm2 __MPN(toom_eval_dgr3_pm2)
-__GMP_DECLSPEC int mpn_toom_eval_dgr3_pm2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_dgr3_pm2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
#define mpn_toom_eval_pm1 __MPN(toom_eval_pm1)
-__GMP_DECLSPEC int mpn_toom_eval_pm1 (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_pm1 (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
#define mpn_toom_eval_pm2 __MPN(toom_eval_pm2)
-__GMP_DECLSPEC int mpn_toom_eval_pm2 (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_pm2 (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, mp_ptr);
#define mpn_toom_eval_pm2exp __MPN(toom_eval_pm2exp)
-__GMP_DECLSPEC int mpn_toom_eval_pm2exp (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, unsigned, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_pm2exp (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, unsigned, mp_ptr);
#define mpn_toom_eval_pm2rexp __MPN(toom_eval_pm2rexp)
-__GMP_DECLSPEC int mpn_toom_eval_pm2rexp (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, unsigned, mp_ptr);
+__GMP_DECLSPEC unsigned mpn_toom_eval_pm2rexp (mp_ptr, mp_ptr, unsigned, mp_srcptr, mp_size_t, mp_size_t, unsigned, mp_ptr);
#define mpn_toom22_mul __MPN(toom22_mul)
__GMP_DECLSPEC void mpn_toom22_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr);
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom54_mul.c
--- a/mpn/generic/toom54_mul.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom54_mul.c Tue Sep 05 18:32:26 2023 +0200
@@ -61,7 +61,7 @@
mp_srcptr bp, mp_size_t bn, mp_ptr scratch)
{
mp_size_t n, s, t;
- int sign;
+ unsigned sign;
/***************************** decomposition *******************************/
#define a4 (ap + 4 * n)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom63_mul.c
--- a/mpn/generic/toom63_mul.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom63_mul.c Tue Sep 05 18:32:26 2023 +0200
@@ -37,8 +37,9 @@
#include "gmp-impl.h"
-/* Stores |{ap,n}-{bp,n}| in {rp,n}, returns the sign. */
-static int
+/* Stores |{ap,n}-{bp,n}| in {rp,n}. */
+/* It returns 0 or ~0, depending on the sign of the result. */
+static unsigned
abs_sub_n (mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)
{
mp_limb_t x, y;
@@ -57,7 +58,7 @@
else
{
mpn_sub_n (rp, bp, ap, n);
- return ~0;
+ return ~ (unsigned) 0;
}
}
rp[n] = 0;
@@ -65,9 +66,10 @@
return 0;
}
-static int
+/* It returns 0 or ~0, depending on the sign of the result rm. */
+static unsigned
abs_sub_add_n (mp_ptr rm, mp_ptr rp, mp_srcptr rs, mp_size_t n) {
- int result;
+ unsigned result;
result = abs_sub_n (rm, rp, rs, n);
ASSERT_NOCARRY(mpn_add_n (rp, rp, rs, n));
return result;
@@ -99,7 +101,7 @@
{
mp_size_t n, s, t;
mp_limb_t cy;
- int sign;
+ unsigned sign;
/***************************** decomposition *******************************/
#define a5 (ap + 5 * n)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom6h_mul.c
--- a/mpn/generic/toom6h_mul.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom6h_mul.c Tue Sep 05 18:32:26 2023 +0200
@@ -109,7 +109,7 @@
{
mp_size_t n, s, t;
int p, q, half;
- int sign;
+ unsigned sign;
/***************************** decomposition *******************************/
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom8h_mul.c
--- a/mpn/generic/toom8h_mul.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom8h_mul.c Tue Sep 05 18:32:26 2023 +0200
@@ -119,7 +119,7 @@
{
mp_size_t n, s, t;
int p, q, half;
- int sign;
+ unsigned sign;
/***************************** decomposition *******************************/
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_couple_handling.c
--- a/mpn/generic/toom_couple_handling.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_couple_handling.c Tue Sep 05 18:32:26 2023 +0200
@@ -45,7 +45,7 @@
*/
void
mpn_toom_couple_handling (mp_ptr pp, mp_size_t n, mp_ptr np,
- int nsign, mp_size_t off, int ps, int ns)
+ unsigned nsign, mp_size_t off, int ps, int ns)
{
if (nsign) {
#ifdef HAVE_NATIVE_mpn_rsh1sub_n
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_dgr3_pm1.c
--- a/mpn/generic/toom_eval_dgr3_pm1.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_eval_dgr3_pm1.c Tue Sep 05 18:32:26 2023 +0200
@@ -37,11 +37,13 @@
#include "gmp-impl.h"
-int
+/* Evaluates a polynomial of degree 3, in the points +1 and -1. */
+/* It returns 0 or ~0, depending on the sign of the result xm1. */
+unsigned
mpn_toom_eval_dgr3_pm1 (mp_ptr xp1, mp_ptr xm1,
mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp)
{
- int neg;
+ unsigned neg;
ASSERT (x3n > 0);
ASSERT (x3n <= n);
@@ -49,7 +51,7 @@
xp1[n] = mpn_add_n (xp1, xp, xp + 2*n, n);
tp[n] = mpn_add (tp, xp + n, n, xp + 3*n, x3n);
- neg = (mpn_cmp (xp1, tp, n + 1) < 0) ? ~0 : 0;
+ neg = - (unsigned) (mpn_cmp (xp1, tp, n + 1) < 0);
#if HAVE_NATIVE_mpn_add_n_sub_n
if (neg)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_dgr3_pm2.c
--- a/mpn/generic/toom_eval_dgr3_pm2.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_eval_dgr3_pm2.c Tue Sep 05 18:32:26 2023 +0200
@@ -37,13 +37,15 @@
#include "gmp-impl.h"
+/* Evaluates a polynomial of degree 3, in the points +2 and -2. */
/* Needs n+1 limbs of temporary storage. */
-int
+/* It returns 0 or ~0, depending on the sign of the result xm2. */
+unsigned
mpn_toom_eval_dgr3_pm2 (mp_ptr xp2, mp_ptr xm2,
mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp)
{
mp_limb_t cy;
- int neg;
+ unsigned neg;
ASSERT (x3n > 0);
ASSERT (x3n <= n);
@@ -74,7 +76,7 @@
#endif
mpn_lshift (tp, tp, n+1, 1);
- neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0;
+ neg = - (unsigned) (mpn_cmp (xp2, tp, n + 1) < 0);
#if HAVE_NATIVE_mpn_add_n_sub_n
if (neg)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_pm1.c
--- a/mpn/generic/toom_eval_pm1.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_eval_pm1.c Tue Sep 05 18:32:26 2023 +0200
@@ -38,12 +38,13 @@
#include "gmp-impl.h"
/* Evaluates a polynomial of degree k > 3, in the points +1 and -1. */
-int
+/* It returns 0 or ~0, depending on the sign of the result xm1. */
+unsigned
mpn_toom_eval_pm1 (mp_ptr xp1, mp_ptr xm1, unsigned k,
mp_srcptr xp, mp_size_t n, mp_size_t hn, mp_ptr tp)
{
unsigned i;
- int neg;
+ unsigned neg;
ASSERT (k >= 4);
@@ -66,7 +67,7 @@
else
ASSERT_NOCARRY (mpn_add (xp1, xp1, n+1, xp+k*n, hn));
- neg = (mpn_cmp (xp1, tp, n + 1) < 0) ? ~0 : 0;
+ neg = - (unsigned) (mpn_cmp (xp1, tp, n + 1) < 0);
#if HAVE_NATIVE_mpn_add_n_sub_n
if (neg)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_pm2.c
--- a/mpn/generic/toom_eval_pm2.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_eval_pm2.c Tue Sep 05 18:32:26 2023 +0200
@@ -65,12 +65,13 @@
/* Evaluates a polynomial of degree 2 < k < GMP_NUMB_BITS, in the
points +2 and -2. */
-int
+/* It returns 0 or ~0, depending on the sign of the result xm2. */
+unsigned
mpn_toom_eval_pm2 (mp_ptr xp2, mp_ptr xm2, unsigned k,
mp_srcptr xp, mp_size_t n, mp_size_t hn, mp_ptr tp)
{
int i;
- int neg;
+ unsigned neg;
mp_limb_t cy;
ASSERT (k >= 3);
@@ -103,7 +104,7 @@
else
ASSERT_NOCARRY(mpn_lshift (xp2, xp2, n + 1, 1));
- neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0;
+ neg = (mpn_cmp (xp2, tp, n + 1) < 0);
#if HAVE_NATIVE_mpn_add_n_sub_n
if (neg)
@@ -122,9 +123,9 @@
ASSERT (xp2[n] < (1<<(k+2))-1);
ASSERT (xm2[n] < ((1<<(k+3))-1 - (1^k&1))/3);
- neg ^= ((k & 1) - 1);
+ neg ^= 1 ^ k & 1;
- return neg;
+ return - neg;
}
#undef DO_addlsh2
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_pm2exp.c
--- a/mpn/generic/toom_eval_pm2exp.c Sun Aug 27 20:47:01 2023 +0200
+++ b/mpn/generic/toom_eval_pm2exp.c Tue Sep 05 18:32:26 2023 +0200
@@ -38,13 +38,14 @@
#include "gmp-impl.h"
/* Evaluates a polynomial of degree k > 2, in the points +2^shift and -2^shift. */
-int
+/* It returns 0 or ~0, depending on the sign of the result xm2. */
+unsigned
mpn_toom_eval_pm2exp (mp_ptr xp2, mp_ptr xm2, unsigned k,
mp_srcptr xp, mp_size_t n, mp_size_t hn, unsigned shift,
mp_ptr tp)
{
unsigned i;
- int neg;
+ unsigned neg;
#if HAVE_NATIVE_mpn_addlsh_n
mp_limb_t cy;
#endif
@@ -101,7 +102,7 @@
mpn_add (xp2, xp2, n+1, xm2, hn+1);
#endif /* !HAVE_NATIVE_mpn_addlsh_n */
- neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0;
+ neg = - (unsigned) (mpn_cmp (xp2, tp, n + 1) < 0);
#if HAVE_NATIVE_mpn_add_n_sub_n
if (neg)
diff -r e3cc6f9e9753 -r 8225bdfc499f mpn/generic/toom_eval_pm2rexp.c
More information about the gmp-commit
mailing list