mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8281259: MutableBigInteger subtraction could be simplified
Reviewed-by: bpb
This commit is contained in:
parent
f399ae558e
commit
e73ee0ca10
2 changed files with 16 additions and 5 deletions
|
@ -945,13 +945,13 @@ class MutableBigInteger {
|
||||||
x--; y--;
|
x--; y--;
|
||||||
|
|
||||||
diff = (a.value[x+a.offset] & LONG_MASK) -
|
diff = (a.value[x+a.offset] & LONG_MASK) -
|
||||||
(b.value[y+b.offset] & LONG_MASK) - ((int)-(diff>>32));
|
(b.value[y+b.offset] & LONG_MASK) + (diff >> 32);
|
||||||
result[rstart--] = (int)diff;
|
result[rstart--] = (int)diff;
|
||||||
}
|
}
|
||||||
// Subtract remainder of longer number
|
// Subtract remainder of longer number
|
||||||
while (x > 0) {
|
while (x > 0) {
|
||||||
x--;
|
x--;
|
||||||
diff = (a.value[x+a.offset] & LONG_MASK) - ((int)-(diff>>32));
|
diff = (a.value[x+a.offset] & LONG_MASK) + (diff >> 32);
|
||||||
result[rstart--] = (int)diff;
|
result[rstart--] = (int)diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,13 +986,13 @@ class MutableBigInteger {
|
||||||
while (y > 0) {
|
while (y > 0) {
|
||||||
x--; y--;
|
x--; y--;
|
||||||
diff = (a.value[a.offset+ x] & LONG_MASK) -
|
diff = (a.value[a.offset+ x] & LONG_MASK) -
|
||||||
(b.value[b.offset+ y] & LONG_MASK) - ((int)-(diff>>32));
|
(b.value[b.offset+ y] & LONG_MASK) + (diff >> 32);
|
||||||
a.value[a.offset+x] = (int)diff;
|
a.value[a.offset+x] = (int)diff;
|
||||||
}
|
}
|
||||||
// Subtract remainder of longer number
|
// Subtract remainder of longer number
|
||||||
while (x > 0) {
|
while (diff < 0 && x > 0) {
|
||||||
x--;
|
x--;
|
||||||
diff = (a.value[a.offset+ x] & LONG_MASK) - ((int)-(diff>>32));
|
diff = (a.value[a.offset+ x] & LONG_MASK) + (diff >> 32);
|
||||||
a.value[a.offset+x] = (int)diff;
|
a.value[a.offset+x] = (int)diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,4 +207,15 @@ public class BigIntegers {
|
||||||
bh.consume(tmp);
|
bh.consume(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Invokes the gcd method of BigInteger with different values. */
|
||||||
|
@Benchmark
|
||||||
|
@OperationsPerInvocation(TESTSIZE)
|
||||||
|
public void testGcd(Blackhole bh) {
|
||||||
|
for (int i = 0; i < TESTSIZE; i++) {
|
||||||
|
BigInteger i1 = shiftArray[TESTSIZE - i - 1];
|
||||||
|
BigInteger i2 = shiftArray[i];
|
||||||
|
bh.consume(i2.gcd(i1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue