Skip to content

Commit

Permalink
Remove warnings from factor.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldesnogu committed Sep 7, 2024
1 parent 7cf3bc7 commit f2da3bd
Showing 1 changed file with 53 additions and 27 deletions.
80 changes: 53 additions & 27 deletions src/factor.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ int main(int argc, char *argv[])
static struct fac_thread_data_t *tdat = 0x0;
int thr_id;
// For Threadpool-based dispatch:
static int main_work_units = 0, pool_work_units = 0;
static int /* main_work_units = 0, */ pool_work_units = 0;
static struct threadpool *tpool = 0x0;
static int task_is_blocking = TRUE;
static thread_control_t thread_control = {0,0,0};
Expand Down Expand Up @@ -628,7 +628,10 @@ int main(int argc, char *argv[])
*/
uint32 itmp32, pdiff_8[8] = {2,1,2,1,2,3,1,3}, pdsum_8[8] = { 0, 2, 6, 8,12,18,20,26};
uint64 itmp64;
uint32 pmodNC,kmodNC,incr[TF_PASSES];
uint32 pmodNC,incr[TF_PASSES];
#ifdef FAC_DEBUG
uint32 kmodNC;
#endif
uint64 two64modp;
uint32 bit,curr_p,i,ihi,m,ncopies,qmod8,regs_todo;
uint32 l,i64,nfactor,word;
Expand Down Expand Up @@ -670,9 +673,9 @@ int main(int argc, char *argv[])
warning from the compiler, we know we've done something wrong in the code logic.
*/
int incomplete_run = FALSE;
int curr_line;
//int curr_line;
double bmin_file, bmax_file;
uint64 tf_passes_file, kmin_file, know_file = 0, kmax_file = 0;
uint64 kmin_file, know_file = 0, kmax_file = 0;
uint32 passmin_file = 0, passnow_file = 0, passmax_file = 0;

uint64 interval_lo,interval_now,interval_hi,ninterval;
Expand All @@ -693,7 +696,6 @@ int main(int argc, char *argv[])

#ifdef P1WORD
double twop_float = 0,fqlo,fqhi;
uint128 p128,q128,t128; // Despite the naming, these are needed for nominal 1-word runs with moduli exceeding 64 bits
#endif
#ifdef P3WORD
uint192 p192,q192,t192;
Expand All @@ -716,7 +718,6 @@ int main(int argc, char *argv[])
#if TEST_TRIALDIV
double citer;
#endif
char *char_addr;

/* Set == 1 to test the trial-div stuff: */
#define TEST_TRIALDIV 0
Expand Down Expand Up @@ -1019,7 +1020,7 @@ Others are optional and in some cases mutually exclusive:

// Alloc threadpool of NTHREADS threads, which will concurrently/asynchronally
// do TF_PASSES 'work units' (factoring passes for various (k mod TF_CLASSES) k-classes:
main_work_units = 0;
//main_work_units = 0;
pool_work_units = NTHREADS;
ASSERT(0x0 != (tpool = threadpool_init(NTHREADS, MAX_THREADS, pool_work_units, &thread_control)), "threadpool_init failed!");
printf("Factor.c: Init threadpool of %d threads\n", NTHREADS);
Expand Down Expand Up @@ -1832,7 +1833,7 @@ Fermat Fn (n > 0): 0,Acceptable km-values for the ? possible pm (= p%60) values:
pm = 16: 0, 6, 8,14,18,20,24,26,30,36,38,44,48,50,54,56 <*** F36 factor has k = 20 ... why do I miss? ***
pm = 32: 0, 4,10,12,18,22,24,28,30,34,40,42,48,52,54,58
*/
i = CHECK_PKMOD60 (&itmp64,1, k, incr);
i = CHECK_PKMOD60 (&itmp64,1, 0/* k */, incr);
ASSERT(i == TF_PASSES, "CHECK_PKMOD60 returns something other than the expected #TF_PASSES! Exponent not of the required form (odd prime or odd composite == any_of[1,7,11,13,17,19,23,29,31,37,41,43,47,49,53,59] (mod 60).\n");
/*
printf("k mod 60 = [");
Expand All @@ -1844,7 +1845,7 @@ Fermat Fn (n > 0): 0,Acceptable km-values for the ? possible pm (= p%60) values:
exit(0);
*/
#else // 4620 classes:
i = CHECK_PKMOD4620(&itmp64,1, k, incr);
i = CHECK_PKMOD4620(&itmp64,1, 0/* k */, incr);
ASSERT(i == TF_PASSES, "CHECK_PKMOD4620 returns something other than the expected #TF_PASSES! Exponent not of the required form (odd prime or odd composite == any_of[960 possible values] (mod 4620).\n");
#endif

Expand Down Expand Up @@ -2623,7 +2624,13 @@ candidate factors that survive sieving. */
uint32 pass = targ->pass; // Which factoring pass is the thread doing?
uint64 interval_lo = targ->interval_lo;
uint64 interval_hi = targ->interval_hi;
#if ((TRYQ == 1 && !defined(NWORD) && !defined(P4WORD) && !defined(P3WORD) && !defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT)) \
|| (TRYQ == 4 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT))))\
|| (TRYQ == 8 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !(defined(USE_FLOAT) && defined(USE_SSE2) && (OS_BITS == 64))))))
double fbits_in_2p = targ->fbits_in_2p;
#endif
#ifdef USE_AVX512
uint32 *psmall = targ->psmall;
#endif
Expand All @@ -2646,20 +2653,24 @@ candidate factors that survive sieving. */
uint64*u64_arr = targ->u64_arr;
uint32 lenP = targ->lenP;
uint32 lenQ = targ->lenQ;
uint32*kdeep = targ->kdeep;
//uint32*kdeep = targ->kdeep;
#ifdef NWORD
uint32*ndeep = targ->ndeep;
#endif
uint64 countmask = targ->countmask;
uint32 CMASKBITS = targ->CMASKBITS;
uint32 incr = targ->incr;
uint64 kstart = targ->kstart;
//uint64 kstart = targ->kstart;
uint64*bit_map = targ->bit_map ;
uint64*bit_map2 = targ->bit_map2;
double *tdiff = targ->tdiff;
int MODULUS_TYPE = targ->MODULUS_TYPE;
const char *VERSION = targ->VERSION;
//const char *VERSION = targ->VERSION;
const char *OFILE = targ->OFILE;
#endif
#if 0
int found_pass = FALSE;
#endif
#ifdef MULTITHREAD
// Proper init (as opposed to no-init) key to avoiding deadlock here.
// Started with 2 separate _checkpoint and _foundfactor mutexes here, but since both code sections
Expand All @@ -2668,20 +2679,25 @@ candidate factors that survive sieving. */
mutex_updatecount = PTHREAD_MUTEX_INITIALIZER; // No mi64 calls here.
#endif
FILE *fp = 0x0;
char *char_addr;
//char *char_addr;
#if TF_CLASSES == 60
const uint32 TRYQM1 = TRYQ-1, bit_len = (sieve_len << TF_CLSHIFT)/TF_CLASSES; // 255255*64 / 60 = 272272: Number of bits in each of the 16 mod- 60 sievelets
#else // 4620 classes:
const uint32 TRYQM1 = TRYQ-1, bit_len = (sieve_len << TF_CLSHIFT)/TF_CLASSES; // 255255*64^2/4620 = 226304: Number of bits in each of the 960 mod-4620 sievelets
#endif
int itmp;
uint32 bit,bit_hi,curr_p,i,ihi,idx,j,l,m;
uint64 count = 0ull, itmp64, k = 0ull, sweep, res;
//int itmp;
uint32 bit,bit_hi,curr_p,i,ihi,j,l,m;
uint64 count = 0ull, k = 0ull, sweep, res;
int32 q_index = -1;
#if ((TRYQ == 1 && !defined(NWORD) && !defined(P4WORD) && !defined(P3WORD) && !defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT)) \
|| (TRYQ == 4 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT))))\
|| (TRYQ == 8 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !(defined(USE_FLOAT) && defined(USE_SSE2) && (OS_BITS == 64))))))
double fbits_in_k = 0, fbits_in_q = 0;
#endif
#ifdef P1WORD
double twop_float = 0,fqlo,fqhi;
uint128 p128,q128,t128; // Despite the naming, these are needed for nominal 1-word runs with moduli exceeding 64 bits
//uint128 p128,q128,t128; // Despite the naming, these are needed for nominal 1-word runs with moduli exceeding 64 bits
#endif
#ifdef P3WORD
uint192 p192,q192,t192;
Expand Down Expand Up @@ -3068,11 +3084,17 @@ candidate factors that survive sieving. */
if(sweep == 0) printf("%u ones bits of %u [%6.2f%%] in bit_map set.\n",m,bit_len,100.*(float)m/bit_len);
#endif

#if ((TRYQ == 1 && !defined(NWORD) && !defined(P4WORD) && !defined(P3WORD) && !defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT)) \
|| (TRYQ == 4 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !defined(USE_FMADD) && !defined(USE_FLOAT))))\
|| (TRYQ == 8 && !defined(P3WORD) && ((defined(P2WORD) && USE_128x96 >= 1) \
|| (!defined(P2WORD) && !(defined(USE_FLOAT) && defined(USE_SSE2) && (OS_BITS == 64))))))
// To track lg(q) = lg(2.k.p+1), use approximation q ~= 2.k.p, thus lg(q) ~= lg(2.p) + lg(k).
// At start of each pass through the k-based sieve, use 2.k.p with k = [starting k + sievebits]
// to bound qmax from above, and compute lg(qmax) using the above logarithmic sum.
fbits_in_k = log((double)k + TF_CLASSES*bit_len)*ILG2; // Use k-value at end of upcoming pass thru sieve as upper-bound
fbits_in_q = fbits_in_2p + fbits_in_k;
#endif
// if(fbits_in_q > 64)
// printf("sweep = %" PRIu64 ": fbits_in_q = fbits_in_2p [%10.4f] + fbits_in_k [%10.4f] = %10.4f\n",sweep,fbits_in_2p,fbits_in_k,fbits_in_q);

Expand All @@ -3088,7 +3110,7 @@ candidate factors that survive sieving. */
*/
if((k <= k_targ) && (k_targ < (k+(sieve_len<<6))))
{
itmp64 = k_targ - k;
uint64 itmp64 = k_targ - k;
ASSERT(itmp64%TF_CLASSES == 0,"(k_targ - k)%TF_CLASSES == 0");
itmp64 /= TF_CLASSES;
i64_targ = itmp64 >> 6;
Expand Down Expand Up @@ -3420,7 +3442,8 @@ candidate factors that survive sieving. */
printf("Do deep sieving for k = %u\n",(uint32)k);
/****** Apr 2105: This all needs to be made thread-safe ******/
ASSERT(0, "This all needs to be made thread-safe!");
kdeep[*ndeep++] = (uint32)k;
//kdeep[*ndeep] = (uint32)k;
*ndeep++;
ASSERT(*ndeep < 1024, "Increase allocation of kdeep[] array or use deeper sieving bound to reduce #candidate k's!");
// itmp64 = factor_qmmp_sieve64((uint32)findex, k, MAX_SIEVING_PRIME+2, 0x0001000000000000ull);
// if(itmp64) {
Expand Down Expand Up @@ -3497,11 +3520,11 @@ candidate factors that survive sieving. */
#else
/* Otherwise use pure-integer-based modmul: */
if(fbits_in_q < 63) {
itmp64 = k*(p[0]<<1) + 1;
uint64 itmp64 = k*(p[0]<<1) + 1;
res = twopmodq63(p[0],itmp64);
res = (res == 1);
} else if(fbits_in_q < 64) {
itmp64 = k*(p[0]<<1) + 1;
uint64 itmp64 = k*(p[0]<<1) + 1;
res = twopmodq64(p[0],itmp64);
res = (res == 1);
}
Expand Down Expand Up @@ -3685,7 +3708,7 @@ candidate factors that survive sieving. */
res = twopmodq128_96_q8 (p[0],k_to_try[0],k_to_try[1],k_to_try[2],k_to_try[3],k_to_try[4],k_to_try[5],k_to_try[6],k_to_try[7]);
#else
/* Use fully 128-bit routines: */
p128.d0 = p[0]; p128.d1 = 0;
//p128.d0 = p[0]; p128.d1 = 0;
res = twopmodq128_q8 (p ,k_to_try[0],k_to_try[1],k_to_try[2],k_to_try[3],k_to_try[4],k_to_try[5],k_to_try[6],k_to_try[7]);
#endif
}
Expand Down Expand Up @@ -4355,8 +4378,11 @@ void get_startval(

uint64 given_b_get_k(double bits, const uint64 two_p[], uint32 len)
{
#ifndef P1WORD
int i,l;
uint64 itmp64, k;
uint64 itmp64;
#endif
uint64 k;
double fqlo, twop_float;
#ifdef P1WORD
/* Find FP approximation to 2*p - can't use this for multiword case, because double approximation tp 2*p may overflow: */
Expand Down Expand Up @@ -4694,8 +4720,8 @@ uint64 kmin, uint64 know, uint64 kmax, uint32 passmin, uint32 passnow, uint32 pa
int write_savefile(const char*fname, const char*pstring, uint32 passnow, uint64 know, uint64 count)
{
int itmp;
uint32 curr_line = 0, nerr = 0, passnow_file;
uint64 know_file, count_file;
uint32 curr_line = 0, nerr = 0, passnow_file = 0;
uint64 know_file;
char *char_addr;
/* TF restart files are in HRF, not binary: */
fp = mlucas_fopen(fname,"r+"); // Open in update ("read plus") mode
Expand Down Expand Up @@ -4800,7 +4826,7 @@ int write_savefile(const char*fname, const char*pstring, uint32 passnow, uint64
++nerr; fprintf(stderr,"ERROR: Line %d of factoring restart file %s lacks the required = sign!\n",curr_line,fname);
}
char_addr++;
count_file = convert_base10_char_uint64(char_addr); // Need to reset == 0 prior to sieving so kvector-fill code works properly
/* uint64 count_file = */ convert_base10_char_uint64(char_addr); // Need to reset == 0 prior to sieving so kvector-fill code works properly
}
++curr_line; itmp = fprintf(fp,"#Q tried = %s\n", &char_buf0[convert_uint64_base10_char (char_buf0, count)]);
if(itmp <= 0) {
Expand Down

0 comments on commit f2da3bd

Please sign in to comment.