Exemple #1
0
void mpn_mul_fft_main(mp_limb_t * r1, mp_limb_t * i1, mp_size_t n1, 
                        mp_limb_t * i2, mp_size_t n2)
{
   mp_size_t off, depth = 6;
   mp_size_t w = 1;
   mp_size_t n = ((mp_size_t) 1 << depth);
   mp_bitcnt_t bits = (n*w - (depth+1))/2;

   mp_bitcnt_t bits1 = n1*FLINT_BITS;
   mp_bitcnt_t bits2 = n2*FLINT_BITS;

   mp_size_t j1 = (bits1 - 1)/bits + 1;
   mp_size_t j2 = (bits2 - 1)/bits + 1;

   FLINT_ASSERT(n1 > 0);
   FLINT_ASSERT(n2 > 0);
   FLINT_ASSERT(j1 + j2 - 1 > 2*n);

   while (j1 + j2 - 1 > 4*n) /* find initial n, w */
   {
      if (w == 1) w = 2;
      else 
      {
         depth++;
         w = 1;
         n *= 2;
      }

      bits = (n*w - (depth+1))/2;
      j1 = (bits1 - 1)/bits + 1;
      j2 = (bits2 - 1)/bits + 1;
   }

   if (depth < 11)
   {
      mp_size_t wadj = 1;
      
      off = fft_tuning_table[depth - 6][w - 1]; /* adjust n and w */
      depth -= off;
      n = ((mp_size_t) 1 << depth);
      w *= ((mp_size_t) 1 << (2*off));
      
      if (depth < 6) wadj = ((mp_size_t) 1 << (6 - depth));

      if (w > wadj)
      {
         do { /* see if a smaller w will work */
            w -= wadj;
            bits = (n*w - (depth+1))/2;
            j1 = (bits1 - 1)/bits + 1;
            j2 = (bits2 - 1)/bits + 1;
         } while (j1 + j2 - 1 <= 4*n && w > wadj);  
         w += wadj;
      }

      mul_truncate_sqrt2(r1, i1, n1, i2, n2, depth, w);
   } else
      mul_mfa_truncate_sqrt2(r1, i1, n1, i2, n2, depth, w);
}
int
main(void)
{
    mp_bitcnt_t depth, w;
    mp_size_t iters, j;
    double truncation;

    FLINT_TEST_INIT(state);

    flint_printf("mul_mfa_truncate_sqrt2....");
    fflush(stdout);

    
    _flint_rand_init_gmp(state);

    depth = 13;
    w = 2;
    iters = 1;
    truncation = 0.5;

    {
       mp_size_t n = (UWORD(1)<<depth);
       mp_bitcnt_t bits1 = (n*w - (depth + 1))/2; 
       mp_bitcnt_t bits = 2*n*bits1;
       mp_size_t int_limbs = ((mp_size_t)(truncation*bits))/FLINT_BITS;
       mp_size_t j;
       mp_limb_t * i1, *i2, *r1, *r2;
        
       flint_printf("limbs = %wd\n", int_limbs);
       
       i1 = flint_malloc(6*int_limbs*sizeof(mp_limb_t));
       i2 = i1 + int_limbs;
       r1 = i2 + int_limbs;
       r2 = r1 + 2*int_limbs;
   
       flint_mpn_urandomb(i1, state->gmp_state, int_limbs*FLINT_BITS);
       flint_mpn_urandomb(i2, state->gmp_state, int_limbs*FLINT_BITS);
  
       for (j = 0; j < iters; j++)
          mul_mfa_truncate_sqrt2(r1, i1, int_limbs, i2, int_limbs, depth, w);
          //mpn_mul(r2, i1, int_limbs, i2, int_limbs);
       
       flint_free(i1);
    }

    flint_randclear(state);
    
    flint_printf("done\n");
    return 0;
}