Skip to content

Commit 0bdbf1a

Browse files
committed
performance improvement for N>=32 bit
1 parent 975dac9 commit 0bdbf1a

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public void searchFactors(FactorArguments args, FactorResult result) {
113113
addToMap(p_i_big, exp*Nexp, primeFactors);
114114
if (N.bitLength() < 63) {
115115
// Check if we are done
116-
long p_i_square = p_i *(long)p_i;
116+
long p_i_square = ((long)p_i) * p_i;
117117
if (p_i_square > N.longValue()) {
118-
if (DEBUG) LOG.debug("N=" + N + " < p^2=" + p_i_square);
118+
if (DEBUG) LOG.debug("N=" + N + " < p^2 = " + p_i_square);
119119
// the remaining N is 1 or prime
120120
if (N.compareTo(I_1)>0) addToMap(N, Nexp, primeFactors);
121121
result.smallestPossibleFactor = p_i; // may be helpful in following factor algorithms

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void factor(BigInteger Nbig, SortedMultiset<BigInteger> primeFactors) {
4949
} while (N%p == 0);
5050
primeFactors.add(BigInteger.valueOf(p), exp);
5151
}
52-
if (p*(long)p > N) {
52+
if (((long)p) * p > N) { // move p as long into registers makes a performance difference
5353
if (N>1) primeFactors.add(BigInteger.valueOf(N));
5454
break;
5555
}

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Barrett.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void factor(BigInteger Nbig, int Nexp, SortedMultiset<BigInteger> primeFa
8989
primeFactors.add(BigInteger.valueOf(p), Nexp);
9090
N = q;
9191
}
92-
if (p*(long)p > N) {
92+
if (((long)p) * p > N) { // move p as long into registers makes a performance difference
9393
break;
9494
}
9595
}

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Inverse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void factor(BigInteger Nbig, int Nexp, SortedMultiset<BigInteger> primeFa
8080
primeFactors.add(BigInteger.valueOf(p), Nexp);
8181
N = q; // avoiding a division here by storing q benefits the int version but not the long version
8282
}
83-
if (p*(long)p > N) {
83+
if (((long)p) * p > N) { // move p as long into registers makes a performance difference
8484
break;
8585
}
8686
}

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv63.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void factor(BigInteger Nbig, SortedMultiset<BigInteger> primeFactors) {
6464
} while (N%p == 0);
6565
primeFactors.add(BigInteger.valueOf(p), exp);
6666
}
67-
if (p*(long)p > N) {
67+
if (((long)p) * p > N) { // move p as long into registers makes a performance difference
6868
break;
6969
}
7070
}
@@ -110,7 +110,7 @@ public void searchFactors(FactorArguments args, FactorResult result) {
110110
// At least one division has occurred, add the factor(s) to the result map
111111
addToMap(BigInteger.valueOf(p_i), exp*Nexp, primeFactors);
112112
// Check if we are done
113-
if (p_i *(long)p_i > N) {
113+
if (((long)p_i) * p_i > N) { // move p as long into registers makes a performance difference
114114
// the remaining N is 1 or prime
115115
if (N>1) addToMap(BigInteger.valueOf(N), Nexp, primeFactors);
116116
result.smallestPossibleFactor = p_i; // may be helpful in following factor algorithms

src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv63Inverse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void factor(BigInteger Nbig, SortedMultiset<BigInteger> primeFactors) {
128128
if (exp>0) {
129129
primeFactors.add(BigInteger.valueOf(p), exp);
130130
}
131-
if (p*(long)p > N) {
131+
if (((long)p) * p > N) { // move p as long into registers makes a performance difference
132132
break; // the remaining N is prime
133133
}
134134
}
@@ -176,7 +176,7 @@ public void searchFactors(FactorArguments args, FactorResult result) {
176176
// At least one division has occurred, add the factor(s) to the result map
177177
addToMap(BigInteger.valueOf(p_i), exp*Nexp, primeFactors);
178178
// Check if we are done
179-
if (p_i *(long)p_i > N) {
179+
if (((long)p_i) * p_i > N) { // move p as long into registers makes a performance difference
180180
// the remaining N is 1 or prime
181181
if (N>1) addToMap(BigInteger.valueOf(N), Nexp, primeFactors);
182182
result.smallestPossibleFactor = p_i; // may be helpful in following factor algorithms

0 commit comments

Comments
 (0)