예제 #1
0
t_info		*parseur_argv(int ac, char **av)
{
  t_info	*info;

  if (ac < 5)
    {
      printf("Error : Too few arguments entered\nPlease enter at least 4\n");
      exit (84);
    }
  else
    {
      info = malloc(sizeof(t_info));
      info->flags = get_flags(ac, av);
      info->numbers = get_numbers(ac, av);
      check_ratio(ac, av);
      return (info);
    }
}
예제 #2
0
파일: sieve.c 프로젝트: j0nn9/XPMiner
/**
 * run the sieve
 * primorial is x * 2 * 3 * 5 * 11 * 17 * ...
 *
 * where x is hash / (2 * 3 * 5 * 7)
 *
 * the bit verctor of the sieves H, 2H, 3H, 4H, ... ,nH
 * where H is the primorial
 */
void sieve_run(Sieve *const sieve, const mpz_t mpz_primorial) {

#ifdef PRINT_TIME
  uint64_t start_time = gettime_usec();
#endif

  /* save arrays to local variables for faster access */
  uint32_t *const cc1_muls  = sieve->cc1_muls;
  uint32_t *const cc2_muls  = sieve->cc2_muls;
  sieve_t  *const twn       = sieve->twn;
  sieve_t  *const cc2       = sieve->cc2;
  sieve_t  *const cc1       = sieve->cc1;
  sieve_t  *const all       = sieve->all;
  sieve_t  *const cc1_layer = sieve->cc1_layer;
  sieve_t  *const cc2_layer = sieve->cc2_layer;
  sieve_t  *const ext_twn   = sieve->ext_twn;
  sieve_t  *const ext_cc2   = sieve->ext_cc2;
  sieve_t  *const ext_cc1   = sieve->ext_cc1;
  sieve_t  *const ext_all   = sieve->ext_all;
  
  /* calculate the multipliers first */
  calc_multipliers(sieve, mpz_primorial);

  uint32_t l, w, e;
  uint32_t word_start, word_end, bit_start, bit_end;

  /* calculate the first half of extension 0 */
  if (use_first_half) {
    for (word_start = 0, 
         bit_start  = 0, 
         word_end   = cache_words,
         bit_end    = cache_bits;
         sieve->active && bit_start < bit_half;
         word_start += cache_words,
         word_end   += cache_words,
         bit_start  += cache_bits,
         bit_end    += cache_bits) {
 
      for (l = 0; sieve->active && l < chain_length; l++) {

#ifdef PRINT_CACHE_TIME      
        uint64_t cache_time = gettime_usec();
#endif
        sieve_from_to(cc2_layer, cc2_muls, bit_start, bit_end, l);  
#ifdef PRINT_CACHE_TIME
        error_msg("[DD] cache time: %" PRIu64 "\n", 
                  gettime_usec() - cache_time);
#endif
        sieve_from_to(cc1_layer, cc1_muls, bit_start, bit_end, l);  

        for (w = word_start; w < word_end; w++) {
          cc2[w] |= cc2_layer[w];
          cc1[w] |= cc1_layer[w];
        }
 
        /* copy layers to the twn candidates */
        if (l == twn_cc2_layers) 
          memcpy(twn + word_start, cc2 + word_start, cache_bytes);
 
        /* apply layers to the twn candidates */
        if (l == twn_cc1_layers) 
          for (w = word_start; w < word_end; w++)
            twn[w] |= cc1[w];
      }
    }
  }

  /* sieve the second half of all extensions */
  for (word_start = word_half, 
       bit_start  = bit_half, 
       word_end   = word_half + cache_words,
       bit_end    = bit_half  + cache_bits;
       sieve->active && bit_start < sieve_size;
       word_start += cache_words,
       word_end   += cache_words,
       bit_start  += cache_bits,
       bit_end    += cache_bits) {

    for (l = 0; sieve->active && l < layers; l++) {

      /* sieve cc1 and cc2 layer l */
      sieve_from_to(cc2_layer, cc2_muls, bit_start, bit_end, l);  
      sieve_from_to(cc1_layer, cc1_muls, bit_start, bit_end, l);  

      /* apply the layer to extension 0 (the normal sieve) */
      if (l < chain_length) {

        for (w = word_start; w < word_end; w++) {
          cc2[w] |= cc2_layer[w];
          cc1[w] |= cc1_layer[w];
        }
      }

      /* copy the cc2 layers to the twn candidates */
      if (l == twn_cc2_layers) 
        memcpy(twn + word_start, cc2 + word_start, cache_bytes);

      /* apply the cc1 layers to the twn candidates */
      if (l == twn_cc1_layers) 
        for (w = word_start; w < word_end; w++)
          twn[w] |= cc1[w];


      /* apply layers to the extensions */
      for (e = 0; sieve->active && e < extensions; e++) {
        
        uint32_t ext_offset = e * sieve_words;
        uint32_t ext_layer  = l - (e + 1);
     
        if (e < l && l <= e + chain_length) {
     
          sieve_t *ptr_cc2 = ext_cc2 + ext_offset;
          sieve_t *ptr_cc1 = ext_cc1 + ext_offset;
     
          for (w = word_start; w < word_end; w++) {
            ptr_cc2[w] |= cc2_layer[w];
            ptr_cc1[w] |= cc1_layer[w];
          }
        }

        /* copy layers to the extended twn candidates */
        if (ext_layer == twn_cc2_layers) {
          uint32_t offset = word_start + ext_offset;
          memcpy(ext_twn + offset, ext_cc2 + offset, cache_bytes);
        }

        /* copy layers to the extended twn candidates */ 
        if (ext_layer == twn_cc1_layers) {

          sieve_t *ptr_cc1 = ext_cc1 + ext_offset;
          sieve_t *ptr_twn = ext_twn + ext_offset;
     
          for (w = word_start; w < word_end; w++)
            ptr_twn[w] |= ptr_cc1[w];
        }
      }
    }
  }

  /* check the sieve if DEBUG is enabled */
  check_sieve(cc1,                     
              cc2,                     
              twn,                     
              ext_cc1,                 
              ext_cc2,                 
              ext_twn,                 
              cc1_muls,                
              cc2_muls,                
              chain_length,            
              sieve_words,
              extensions,              
              layers,
              primes,                  
              min_prime_index,               
              max_prime_index,
              mpz_primorial,
              sieve_size,
              use_first_half);

  /* create the final set of candidates */
  uint32_t i;
  for (i = 0; i < sieve_words; i++)
    all[i] = cc1[i] & cc2[i] & twn[i];

  /* mark 0H as composite */
  all[0] |= (sieve_t) 1;


  /* create the final set of extended candidates */
  for (e = 0; sieve->active && e < extensions; e++) {
    
    sieve_t *ptr_cc1 = ext_cc1 + e * sieve_words;
    sieve_t *ptr_cc2 = ext_cc2 + e * sieve_words;
    sieve_t *ptr_twn = ext_twn + e * sieve_words;
    sieve_t *ptr_all = ext_all + e * sieve_words;

    /* create the final set of candidates */
    for (i = sieve_words / 2; i < sieve_words; i++) 
      ptr_all[i] = ptr_cc1[i] & ptr_cc2[i] & ptr_twn[i];

    /* mark factor 0 as composite */
    ptr_all[0] |= (sieve_t) 1;
   }

#ifdef PRINT_TIME
  error_msg("[DD] sieving: %" PRIu64 "\n", gettime_usec() - start_time);
  start_time = gettime_usec();
#endif

  /* check sieve out put if DEBUG is enabled */
  check_candidates(mpz_primorial,     
                   all,               
                   cc1,               
                   twn,               
                   chain_length,      
                   0,         
                   sieve_words,
                   &sieve->test_params);

  /* run the fermat test on the remaining candidates */
  test_candidates(sieve, cc1, twn, all, mpz_primorial, 0); 

  /* test extended candidates */
  for (e = 0; sieve->active && e < extensions; e++) {
    
    sieve_t *ptr_cc1 = ext_cc1 + e * sieve_words;
    sieve_t *ptr_twn = ext_twn + e * sieve_words;
    sieve_t *ptr_all = ext_all + e * sieve_words;

    /* check sieve out put if DEBUG is enabled */
    check_candidates(mpz_primorial, 
                     ptr_all,               
                     ptr_cc1,               
                     ptr_twn,               
                     chain_length,      
                     e + 1,         
                     sieve_words,
                     &sieve->test_params);

    /* run the fermat test on the remaining candidates */
    test_candidates(sieve, ptr_cc1, ptr_twn, ptr_all, mpz_primorial, e + 1);
  }
#ifdef PRINT_TIME
  error_msg("[DD] testing : %" PRIu64 "\n", gettime_usec() - start_time);
#endif

  /* check candidate ratio if DEBUG is enabled */
  check_ratio(&sieve->stats);
}