bridge/class-master/depend/pari/src/modules/mpqs.c
/* returns the FB array pointer for convenience */
returns the FB array pointer for convenience
returns the FB array pointer for convenience
static mpqs_FB_entry_t *
mpqs_create_FB(mpqs_handle_t *h, ulong *f)
{
  const pari_sp av = avma;
  mpqs_int32_t size = h->size_of_FB;
  long i;
  mpqs_uint32_t k = h->_k->k;
  mpqs_FB_entry_t *FB;
  forprime_t S;
  FB = mpqs_FB_ctor(h);
  FB[2].fbe_p = 2;
  FB[2].fbe_flags = MPQS_FBE_CLEAR;
  (void)u_forprime_init(&S, 3, ULONG_MAX);
  for (i = 3; i < h->index0_FB; i++)
  {
    mpqs_uint32_t kp = (ulong)h->_k->kp[i-3];
    if (MPQS_DEBUGLEVEL >= 7) err_printf(",<%lu>", (ulong)kp);
    FB[i].fbe_p = kp;
    FB[i].fbe_flags = MPQS_FBE_CLEAR;
    FB[i].fbe_flogp = (float) log2((double) kp);
    FB[i].fbe_sqrt_kN = 0;
  }
  while (i < size + 2)
  {
    ulong p = u_forprime_next(&S);
    if (p > k || k % p)
    {
      ulong kN_mod_p = umodiu(h->kN, p);
      long kr = krouu(kN_mod_p, p);
      if (kr != -1)
      {
        if (kr == 0) { *f = p; return FB; }
        FB[i].fbe_p = (mpqs_uint32_t) p;
        FB[i].fbe_flags = MPQS_FBE_CLEAR;
        FB[i].fbe_flogp = (float) log2((double)p);
        FB[i++].fbe_sqrt_kN = (mpqs_uint32_t)Fl_sqrt(kN_mod_p, p);
      }
    }
  }
  avma = av;
  if (MPQS_DEBUGLEVEL >= 7)
  {
    err_printf("MPQS: FB [-1,2");
    for (i = 3; i < h->index0_FB; i++) err_printf(",<%lu>", FB[i].fbe_p);
    for (; i < size + 2; i++) err_printf(",%lu", FB[i].fbe_p);
    err_printf("]\n");
  }
  FB[i].fbe_p = 0;              
  h->largest_FB_p = FB[i-1].fbe_p; 
  for (i = h->index0_FB; FB[i].fbe_p != 0; i++)
    if (FB[i].fbe_p >= h->pmin_index1) break;
  h->index1_FB = i;
  *f = 0; return FB;
}
static mpqs_FB_entry_t * mpqs_create_FB ( mpqs_handle_t * h , ulong * f ) { const pari_sp av = avma ; mpqs_int32_t size = h -> size_of_FB ; long i ; mpqs_uint32_t k = h -> _k -> k ; mpqs_FB_entry_t * FB ; forprime_t S ; FB = mpqs_FB_ctor ( h ) ; FB [ 2 ] . fbe_p = 2 ; FB [ 2 ] . fbe_flags = MPQS_FBE_CLEAR ; ( void ) u_forprime_init ( & S , 3 , ULONG_MAX ) ; for ( i = 3 ; i < h -> index0_FB ; i ++ ) { mpqs_uint32_t kp = ( ulong ) h -> _k -> kp [ i - 3 ] ; if ( MPQS_DEBUGLEVEL >= 7 ) err_printf ( " " , ( ulong ) kp ) ; FB [ i ] . fbe_p = kp ; FB [ i ] . fbe_flags = MPQS_FBE_CLEAR ; FB [ i ] . fbe_flogp = ( float ) log2 ( ( double ) kp ) ; FB [ i ] . fbe_sqrt_kN = 0 ; } while ( i < size + 2 ) { ulong p = u_forprime_next ( & S ) ; if ( p > k || k % p ) { ulong kN_mod_p = umodiu ( h -> kN , p ) ; long kr = krouu ( kN_mod_p , p ) ; if ( kr != -1 ) { if ( kr == 0 ) { * f = p ; return FB ; } FB [ i ] . fbe_p = ( mpqs_uint32_t ) p ; FB [ i ] . fbe_flags = MPQS_FBE_CLEAR ; FB [ i ] . fbe_flogp = ( float ) log2 ( ( double ) p ) ; FB [ i ++ ] . fbe_sqrt_kN = ( mpqs_uint32_t ) Fl_sqrt ( kN_mod_p , p ) ; } } } avma = av ; if ( MPQS_DEBUGLEVEL >= 7 ) { err_printf ( " " ) ; for ( i = 3 ; i < h -> index0_FB ; i ++ ) err_printf ( " " , FB [ i ] . fbe_p ) ; for ( ; i < size + 2 ; i ++ ) err_printf ( " " , FB [ i ] . fbe_p ) ; err_printf ( " \n " ) ; } FB [ i ] . fbe_p = 0 ; h -> largest_FB_p = FB [ i - 1 ] . fbe_p ; for ( i = h -> index0_FB ; FB [ i ] . fbe_p != 0 ; i ++ ) if ( FB [ i ] . fbe_p >= h -> pmin_index1 ) break ; h -> index1_FB = i ; * f = 0 ; return FB ; }
returns the FB array pointer for convenience
returns the FB array pointer for convenience
/* the fbe_logval and the fbe_sqrt_kN for 2 are never used */ /* the first loop executes h->_k->omega_k = 0, 1, or 2 times */ /* we *could* flag divisors of k here, but so far I see no need,
     * and no flags bit has been assigned for the purpose */ /* now i == h->index0_FB */ /* dyadic logarithm of p; single precision suffices */ /* cannot yet fill in fbe_logval because the scaling multiplier
         * depends on the largest prime in FB, as yet unknown */ /* x such that x^2 = kN (mod p_i) */ /* sentinel */ /* at subscript size_of_FB + 1 */ /* locate the smallest prime that will be used for sieving */ /* with our parameters this will never fall of the end of the FB */