Ciao, 4 set 2023, 08:02 da ni...@lysator.liu.se:
> As Vincent suggested, it would be good to document somewhere what the > convention is (values 0 or ~0). > Would a comment "It returns 0 or ~0, depending on the sign of the result" added to all the mpn_toom_eval_ functions suffice? > And maybe change to 0 and 1 convention, > I see a line mpn/generic/toom42_mul.c: vm1_neg = mpn_toom_eval_dgr3_pm1 (as1, asm1, ap, n, s, a0_a2) & 1; where we actually use 0 or 1, and many lines like mpn/generic/toom52_mul.c: flags = (enum toom6_flags) (toom6_vm2_neg & mpn_toom_eval_pm2 (as2, asm2, 4, ap, n, s, a1a3)); where we use the value as a mask: 0 or ~ 0. >From the value in {0,1} we can get mask = -value, and from the mask in {0, ~0} >we can get value = mask & 1. Of course we can switch to a different convention, if someone feels it's important. I don't. > since that fits better with assigning it from the return value from > mpn_sub_n, and it seems generally more consistent with how we handle > We never use mpn_sub_n to assign that value. > boolean values elsewhere. But may need further changes, like to > abs_sub_add_n, also noted by Vincent. > Yes, Vincent is right. New patch. Should the value ~0 be written as ~0U to be correctly assigned to an unsigned? Ĝis, m
diff -r e3cc6f9e9753 gmp-impl.h --- a/gmp-impl.h Sun Aug 27 20:47:01 2023 +0200 +++ b/gmp-impl.h Mon Sep 04 09:40:02 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 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 Mon Sep 04 09:40:02 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 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 Mon Sep 04 09:40:02 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; @@ -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 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 Mon Sep 04 09:40:02 2023 +0200 @@ -109,7 +109,7 @@ { mp_size_t n, s, t; int p, q, half; - int sign; + unsigned sign; /***************************** decomposition *******************************/ diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 2023 +0200 @@ -119,7 +119,7 @@ { mp_size_t n, s, t; int p, q, half; - int sign; + unsigned sign; /***************************** decomposition *******************************/ diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 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 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 Mon Sep 04 09:40:02 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); diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 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); diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 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); diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 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); diff -r e3cc6f9e9753 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 Mon Sep 04 09:40:02 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 diff -r e3cc6f9e9753 mpn/generic/toom_eval_pm2rexp.c --- a/mpn/generic/toom_eval_pm2rexp.c Sun Aug 27 20:47:01 2023 +0200 +++ b/mpn/generic/toom_eval_pm2rexp.c Mon Sep 04 09:40:02 2023 +0200 @@ -54,13 +54,14 @@ #endif /* Evaluates a polynomial of degree k >= 3. */ -int +/* It returns 0 or ~0, depending on the sign of the result rm. */ +unsigned mpn_toom_eval_pm2rexp (mp_ptr rp, mp_ptr rm, unsigned int q, mp_srcptr ap, mp_size_t n, mp_size_t t, unsigned int s, mp_ptr ws) { unsigned int i; - int neg; + unsigned neg; /* {ap,q*n+t} -> {rp,n+1} {rm,n+1} , with {ws, n+1}*/ ASSERT (n >= t); ASSERT (s != 0); /* or _eval_pm1 should be used */
_______________________________________________ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs