Marco Bodrato <bodr...@mail.dm.unipi.it> writes:

  This is not really needed to solve a bug.
  The comment before the mpn_mul_fft_decompose function says "We must
  have nl <= 2*K*l", this means that we should never have ((dif = nl -
  Kl) > Kl), and the code in that branch should never be used.

I noticed that at some point too, and have had a patch lying around for
quite a while:

*** /tmp/extdiff.kfdtyubq/gmp.1cbf890d4bff/mpn/generic/mul_fft.c	Thu Mar  3 21:50:34 2022
--- /home/tege/prec/gmp/mpn/generic/mul_fft.c	Tue Apr  6 10:57:52 2021
***************
*** 59,62 ****
--- 59,65 ----
  */
  
+ #include <stdio.h>
+ 
+ 
  #ifdef TRACE
  #undef TRACE
***************
*** 267,270 ****
--- 270,277 ----
  	  cc = 0;
  	}
+ #if 0
+       /* FIXME: Remove rd assignments above. */
+       rd = ~r[m];
+ #endif
  
        /* now complement {r, m}, subtract cc from r[0], subtract rd from r[m] */
***************
*** 682,726 ****
    TMP_MARK;
  
    if (nl > Kl) /* normalize {n, nl} mod 2^(Kl*GMP_NUMB_BITS)+1 */
      {
        mp_size_t dif = nl - Kl;
!       mp_limb_signed_t cy;
  
        tmp = TMP_BALLOC_LIMBS(Kl + 1);
  
!       if (dif > Kl)
! 	{
! 	  int subp = 0;
! 
! 	  cy = mpn_sub_n (tmp, n, n + Kl, Kl);
! 	  n += 2 * Kl;
! 	  dif -= Kl;
! 
! 	  /* now dif > 0 */
! 	  while (dif > Kl)
! 	    {
! 	      if (subp)
! 		cy += mpn_sub_n (tmp, tmp, n, Kl);
! 	      else
! 		cy -= mpn_add_n (tmp, tmp, n, Kl);
! 	      subp ^= 1;
! 	      n += Kl;
! 	      dif -= Kl;
! 	    }
! 	  /* now dif <= Kl */
! 	  if (subp)
! 	    cy += mpn_sub (tmp, tmp, Kl, n, dif);
! 	  else
! 	    cy -= mpn_add (tmp, tmp, Kl, n, dif);
! 	  if (cy >= 0)
! 	    cy = mpn_add_1 (tmp, tmp, Kl, cy);
! 	  else
! 	    cy = mpn_sub_1 (tmp, tmp, Kl, -cy);
! 	}
!       else /* dif <= Kl, i.e. nl <= 2 * Kl */
! 	{
! 	  cy = mpn_sub (tmp, n, Kl, n + Kl, dif);
! 	  cy = mpn_add_1 (tmp, tmp, Kl, cy);
! 	}
        tmp[Kl] = cy;
        nl = Kl + 1;
--- 689,703 ----
    TMP_MARK;
  
+   ASSERT_ALWAYS (nl <= 2*Kl);
+ 
    if (nl > Kl) /* normalize {n, nl} mod 2^(Kl*GMP_NUMB_BITS)+1 */
      {
        mp_size_t dif = nl - Kl;
!       mp_limb_t cy;
  
        tmp = TMP_BALLOC_LIMBS(Kl + 1);
  
!       cy = mpn_sub (tmp, n, Kl, n + Kl, dif);
!       cy = mpn_add_1 (tmp, tmp, Kl, cy);
        tmp[Kl] = cy;
        nl = Kl + 1;
(Not sure about the separate FIXME change therein; it looks strange to
me now.)

Feel free to clean this up.


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

Reply via email to