Skip to content

Commit 4565ac2

Browse files
committed
improve comments
1 parent 4dbbee0 commit 4565ac2

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_2LP.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,17 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
223223
BigInteger QRest = QRest0; // keep initial QRest0 for logging below
224224

225225
// Pass 1: Test solution arrays.
226-
// If |x| < p, then no modulus computation is required.
227-
// Otherwise we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
226+
// The performance bottle-neck here is the modulus computation.
227+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
228+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
229+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
228230
// We can use the long-variant here because x*m will never overflow positive long values.
229-
// For some reasons I do not understand, it is faster to divide Q by p in pass 2 only, not here.
230-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
231-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
231+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
232232
int pass2Count = 0;
233233
int pIndex = baseSize-1;
234234
if (x < 0) {
235235
for ( ; pIndex >= p1Index; pIndex--) {
236-
// for pIndex >= p1Index, we know that |x| < sieveArraySize < p
236+
// for pIndex >= p1Index, we know that |x| < p
237237
int xModP = x+pArray[pIndex];
238238
if (xModP==x1Array[pIndex] || xModP==x2Array[pIndex]) {
239239
pass2Primes[pass2Count] = primes[pIndex];
@@ -272,7 +272,7 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
272272
} else {
273273
// x >= 0
274274
for ( ; pIndex >= p1Index; pIndex--) {
275-
// for pIndex > p1Index, we know that |x| < sieveArraySize < p
275+
// for pIndex > p1Index, we know that |x| < p
276276
if (x==x1Array[pIndex] || x==x2Array[pIndex]) {
277277
pass2Primes[pass2Count] = primes[pIndex];
278278
pass2Exponents[pass2Count] = exponents[pIndex];

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_2LP_Full.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,19 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
216216
}
217217

218218
// Pass 1: Test solution arrays.
219-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
220-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
219+
// The performance bottle-neck here is the modulus computation.
220+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
221+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
222+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
223+
// We can use the long-variant here because x*m will never overflow positive long values.
224+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
221225
final int xAbs = x<0 ? -x : x;
222-
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 was already tested
226+
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 has already been tested
223227
int p = pArray[pIndex];
224228
int xModP;
225229
if (xAbs<p) {
226230
xModP = x<0 ? x+p : x;
227231
} else {
228-
// Compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
229-
// We can use the long-variant here because x*m will never overflow positive long values.
230232
final long m = pinvArrayL[pIndex];
231233
final long q = ( ( ((long)x) * m) >>> 32); // first argument long optimizes register usage
232234
xModP = (int) ( ((long)x) - q * p);
@@ -246,7 +248,6 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
246248
pass2Primes[pass2Count] = primes[pIndex];
247249
pass2Exponents[pass2Count] = exponents[pIndex];
248250
pass2Powers[pass2Count++] = p;
249-
// for some reasons I do not understand it is faster to divide Q by p in pass 2 only, not here
250251
}
251252
}
252253
if (ANALYZE) pass1Duration += timer.capture();

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_3LP.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
226226
BigInteger QRest = QRest0; // keep initial QRest0 for logging below
227227

228228
// Pass 1: Test solution arrays.
229-
// If |x| < p, then no modulus computation is required.
230-
// Otherwise we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
229+
// The performance bottle-neck here is the modulus computation.
230+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
231+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
232+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
231233
// We can use the long-variant here because x*m will never overflow positive long values.
232-
// For some reasons I do not understand, it is faster to divide Q by p in pass 2 only, not here.
233-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
234-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
234+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
235235
int pass2Count = 0;
236236
int pIndex = baseSize-1;
237237
if (x < 0) {
238238
for ( ; pIndex >= p1Index; pIndex--) {
239-
// for pIndex >= p1Index, we know that |x| < sieveArraySize < p
239+
// for pIndex >= p1Index, we know that |x| < p
240240
int xModP = x+pArray[pIndex];
241241
if (xModP==x1Array[pIndex] || xModP==x2Array[pIndex]) {
242242
pass2Primes[pass2Count] = primes[pIndex];
@@ -275,7 +275,7 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
275275
} else {
276276
// x >= 0
277277
for ( ; pIndex >= p1Index; pIndex--) {
278-
// for pIndex > p1Index, we know that |x| < sieveArraySize < p
278+
// for pIndex > p1Index, we know that |x| < p
279279
if (x==x1Array[pIndex] || x==x2Array[pIndex]) {
280280
pass2Primes[pass2Count] = primes[pIndex];
281281
pass2Exponents[pass2Count] = exponents[pIndex];

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_Small.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,19 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
192192
}
193193

194194
// Pass 1: Test solution arrays.
195-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
196-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
195+
// The performance bottle-neck here is the modulus computation.
196+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
197+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
198+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
199+
// We can use the long-variant here because x*m will never overflow positive long values.
200+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
197201
final int xAbs = x<0 ? -x : x;
198-
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 was already tested
202+
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 has already been tested
199203
int p = pArray[pIndex];
200204
int xModP;
201205
if (xAbs<p) {
202206
xModP = x<0 ? x+p : x;
203207
} else {
204-
// Compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
205-
// We can use the long-variant here because x*m will never overflow positive long values.
206208
final long m = pinvArrayL[pIndex];
207209
final long q = ( ( ((long)x) * m) >>> 32); // first argument long optimizes register usage
208210
xModP = (int) ( ((long)x) - q * p);
@@ -222,7 +224,6 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
222224
pass2Primes[pass2Count] = primes[pIndex];
223225
pass2Exponents[pass2Count] = exponents[pIndex];
224226
pass2Powers[pass2Count++] = p;
225-
// for some reasons I do not understand it is faster to divide Q by p in pass 2 only, not here
226227
}
227228
}
228229
if (ANALYZE) pass1Duration += timer.capture();

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_nLP.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,17 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
225225
BigInteger QRest = QRest0; // keep initial QRest0 for logging below
226226

227227
// Pass 1: Test solution arrays.
228-
// If |x| < p, then no modulus computation is required.
229-
// Otherwise we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
228+
// The performance bottle-neck here is the modulus computation.
229+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
230+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
231+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
230232
// We can use the long-variant here because x*m will never overflow positive long values.
231-
// For some reasons I do not understand, it is faster to divide Q by p in pass 2 only, not here.
232-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
233-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
233+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
234234
int pass2Count = 0;
235235
int pIndex = baseSize-1;
236236
if (x < 0) {
237237
for ( ; pIndex >= p1Index; pIndex--) {
238-
// for pIndex >= p1Index, we know that |x| < sieveArraySize < p
238+
// for pIndex >= p1Index, we know that |x| < p
239239
int xModP = x+pArray[pIndex];
240240
if (xModP==x1Array[pIndex] || xModP==x2Array[pIndex]) {
241241
pass2Primes[pass2Count] = primes[pIndex];
@@ -274,7 +274,7 @@ private AQPair test(BigInteger A, BigInteger QRest0, int x) {
274274
} else {
275275
// x >= 0
276276
for ( ; pIndex >= p1Index; pIndex--) {
277-
// for pIndex > p1Index, we know that |x| < sieveArraySize < p
277+
// for pIndex > p1Index, we know that |x| < p
278278
if (x==x1Array[pIndex] || x==x2Array[pIndex]) {
279279
pass2Primes[pass2Count] = primes[pIndex];
280280
pass2Exponents[pass2Count] = exponents[pIndex];

src/main/java/de/tilman_neumann/jml/factor/siqs/tdiv/TDiv_QS_nLP_Full.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,19 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
218218
}
219219

220220
// Pass 1: Test solution arrays.
221-
// IMPORTANT: Java gives x % p = x for |x| < p, and we have many p bigger than any sieve array entry.
222-
// IMPORTANT: Not computing the modulus in these cases improves performance by almost factor 2!
221+
// The performance bottle-neck here is the modulus computation.
222+
// The current approach is already quite fast for large N, because then we have pMax > 3*sieveArraySize,
223+
// which means that for ~75% of x-values we can completely omit the mod-computation or replace it by a simple addition.
224+
// For (big |x|, small p) we compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
225+
// We can use the long-variant here because x*m will never overflow positive long values.
226+
// For some reasons I do not understand yet, it is faster to divide Q by p in pass 2 only, not here.
223227
final int xAbs = x<0 ? -x : x;
224-
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 was already tested
228+
for (int pIndex = baseSize-1; pIndex > 0; pIndex--) { // p[0]=2 has already been tested
225229
int p = pArray[pIndex];
226230
int xModP;
227231
if (xAbs<p) {
228232
xModP = x<0 ? x+p : x;
229233
} else {
230-
// Compute x%p using long-valued Barrett reduction, see https://en.wikipedia.org/wiki/Barrett_reduction.
231-
// We can use the long-variant here because x*m will never overflow positive long values.
232234
final long m = pinvArrayL[pIndex];
233235
final long q = ( ( ((long)x) * m) >>> 32); // first argument long optimizes register usage
234236
xModP = (int) ( ((long)x) - q * p);
@@ -248,7 +250,6 @@ private AQPair test(BigInteger A, BigInteger Q, int x) {
248250
pass2Primes[pass2Count] = primes[pIndex];
249251
pass2Exponents[pass2Count] = exponents[pIndex];
250252
pass2Powers[pass2Count++] = p;
251-
// for some reasons I do not understand it is faster to divide Q by p in pass 2 only, not here
252253
}
253254
}
254255
if (ANALYZE) pass1Duration += timer.capture();

0 commit comments

Comments
 (0)