Skip to content

Commit

Permalink
Merge upstream-jdk
Browse files Browse the repository at this point in the history
  • Loading branch information
corretto-github-robot committed Jun 27, 2024
2 parents 184dcdf + b5fbdb2 commit 63537e8
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 155 deletions.
10 changes: 2 additions & 8 deletions make/jdk/src/classes/build/tools/intpoly/FieldGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ private String generate(FieldParams params) throws IOException {
result.appendLine("}");

result.appendLine("@Override");
result.appendLine("protected int mult(long[] a, long[] b, long[] r) {");
result.appendLine("protected void mult(long[] a, long[] b, long[] r) {");
result.incrIndent();
for (int i = 0; i < 2 * params.getNumLimbs() - 1; i++) {
result.appendIndent();
Expand All @@ -804,9 +804,6 @@ private String generate(FieldParams params) throws IOException {
}
}
result.append(");\n");
result.appendIndent();
result.append("return 0;");
result.appendLine();
result.decrIndent();
result.appendLine("}");

Expand Down Expand Up @@ -836,7 +833,7 @@ private String generate(FieldParams params) throws IOException {
// }
// }
result.appendLine("@Override");
result.appendLine("protected int square(long[] a, long[] r) {");
result.appendLine("protected void square(long[] a, long[] r) {");
result.incrIndent();
for (int i = 0; i < 2 * params.getNumLimbs() - 1; i++) {
result.appendIndent();
Expand Down Expand Up @@ -877,9 +874,6 @@ private String generate(FieldParams params) throws IOException {
}
}
result.append(");\n");
result.appendIndent();
result.append("return 0;");
result.appendLine();
result.decrIndent();
result.appendLine("}");

Expand Down
1 change: 0 additions & 1 deletion src/hotspot/cpu/x86/stubGenerator_x86_64_poly_mont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ address StubGenerator::generate_intpoly_montgomeryMult_P256() {
const Register tmp = r9;

montgomeryMultiply(aLimbs, bLimbs, rLimbs, tmp, _masm);
__ mov64(rax, 0x1); // Return 1 (Fig. 5, Step 6 [1] skipped in montgomeryMultiply)

__ leave();
__ ret(0);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/classfile/vmIntrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ class methodHandle;
/* support for sun.security.util.math.intpoly.MontgomeryIntegerPolynomialP256 */ \
do_class(sun_security_util_math_intpoly_MontgomeryIntegerPolynomialP256, "sun/security/util/math/intpoly/MontgomeryIntegerPolynomialP256") \
do_intrinsic(_intpoly_montgomeryMult_P256, sun_security_util_math_intpoly_MontgomeryIntegerPolynomialP256, intPolyMult_name, intPolyMult_signature, F_R) \
do_name(intPolyMult_name, "mult") \
do_signature(intPolyMult_signature, "([J[J[J)I") \
do_name(intPolyMult_name, "multImpl") \
do_signature(intPolyMult_signature, "([J[J[J)V") \
\
do_class(sun_security_util_math_intpoly_IntegerPolynomial, "sun/security/util/math/intpoly/IntegerPolynomial") \
do_intrinsic(_intpoly_assign, sun_security_util_math_intpoly_IntegerPolynomial, intPolyAssign_name, intPolyAssign_signature, F_S) \
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/opto/library_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7554,8 +7554,6 @@ bool LibraryCallKit::inline_intpoly_montgomeryMult_P256() {
OptoRuntime::intpoly_montgomeryMult_P256_Type(),
stubAddr, stubName, TypePtr::BOTTOM,
a_start, b_start, r_start);
Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
set_result(result);
return true;
}

Expand Down
19 changes: 13 additions & 6 deletions src/hotspot/share/opto/loopopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,18 +795,25 @@ Node *PhaseIdealLoop::conditional_move( Node *region ) {
// Avoid duplicated float compare.
if (phis > 1 && (cmp_op == Op_CmpF || cmp_op == Op_CmpD)) return nullptr;

// Ignore cost if CMOVE can be moved outside the loop.
if (used_inside_loop && cost >= ConditionalMoveLimit) {
return nullptr;
float infrequent_prob = PROB_UNLIKELY_MAG(3);
// Ignore cost and blocks frequency if CMOVE can be moved outside the loop.
if (used_inside_loop) {
if (cost >= ConditionalMoveLimit) return nullptr; // Too much goo

// BlockLayoutByFrequency optimization moves infrequent branch
// from hot path. No point in CMOV'ing in such case (110 is used
// instead of 100 to take into account not exactness of float value).
if (BlockLayoutByFrequency) {
infrequent_prob = MAX2(infrequent_prob, (float)BlockLayoutMinDiamondPercentage/110.0f);
}
}
// Check for highly predictable branch. No point in CMOV'ing if
// we are going to predict accurately all the time.
constexpr float infrequent_prob = PROB_UNLIKELY_MAG(2);
if (C->use_cmove() && (cmp_op == Op_CmpF || cmp_op == Op_CmpD)) {
//keep going
} else if (iff->_prob < infrequent_prob || iff->_prob > (1.0f - infrequent_prob)) {
} else if (iff->_prob < infrequent_prob ||
iff->_prob > (1.0f - infrequent_prob))
return nullptr;
}

// --------------
// Now replace all Phis with CMOV's
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/opto/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,8 @@ const TypeFunc* OptoRuntime::intpoly_montgomeryMult_P256_Type() {

// result type needed
fields = TypeTuple::fields(1);
fields[TypeFunc::Parms + 0] = TypeInt::INT; // carry bits in output
const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
fields[TypeFunc::Parms + 0] = nullptr; // void
const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
return TypeFunc::make(domain, range);
}

Expand All @@ -1434,7 +1434,7 @@ const TypeFunc* OptoRuntime::intpoly_assign_Type() {

// result type needed
fields = TypeTuple::fields(1);
fields[TypeFunc::Parms + 0] = NULL; // void
fields[TypeFunc::Parms + 0] = nullptr; // void
const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
return TypeFunc::make(domain, range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ public abstract sealed class IntegerPolynomial implements IntegerFieldModuloP
* store the result in an IntegerPolynomial representation in a. Requires
* that a.length == numLimbs.
*/
protected int multByInt(long[] a, long b) {
protected void multByInt(long[] a, long b) {
for (int i = 0; i < a.length; i++) {
a[i] *= b;
}
reduce(a);
return 0;
}

/**
Expand All @@ -104,15 +103,15 @@ protected int multByInt(long[] a, long b) {
* a.length == b.length == r.length == numLimbs. It is allowed for a and r
* to be the same array.
*/
protected abstract int mult(long[] a, long[] b, long[] r);
protected abstract void mult(long[] a, long[] b, long[] r);

/**
* Multiply an IntegerPolynomial representation (a) with itself and store
* the result in an IntegerPolynomialRepresentation (r). Requires that
* a.length == r.length == numLimbs. It is allowed for a and r
* to be the same array.
*/
protected abstract int square(long[] a, long[] r);
protected abstract void square(long[] a, long[] r);

IntegerPolynomial(int bitsPerLimb,
int numLimbs,
Expand Down Expand Up @@ -622,8 +621,8 @@ public ImmutableElement multiply(IntegerModuloP genB) {
}

long[] newLimbs = new long[limbs.length];
int numAdds = mult(limbs, b.limbs, newLimbs);
return new ImmutableElement(newLimbs, numAdds);
mult(limbs, b.limbs, newLimbs);
return new ImmutableElement(newLimbs, 0);
}

@Override
Expand All @@ -635,8 +634,8 @@ public ImmutableElement square() {
}

long[] newLimbs = new long[limbs.length];
int numAdds = IntegerPolynomial.this.square(limbs, newLimbs);
return new ImmutableElement(newLimbs, numAdds);
IntegerPolynomial.this.square(limbs, newLimbs);
return new ImmutableElement(newLimbs, 0);
}

public void addModPowerTwo(IntegerModuloP arg, byte[] result) {
Expand Down Expand Up @@ -751,7 +750,8 @@ public MutableElement setProduct(IntegerModuloP genB) {
b.numAdds = 0;
}

numAdds = mult(limbs, b.limbs, limbs);
mult(limbs, b.limbs, limbs);
numAdds = 0;
return this;
}

Expand All @@ -764,7 +764,8 @@ public MutableElement setProduct(SmallValue v) {
}

int value = ((Limb)v).value;
numAdds += multByInt(limbs, value);
multByInt(limbs, value);
numAdds = 0;
return this;
}

Expand Down Expand Up @@ -824,7 +825,8 @@ public MutableElement setSquare() {
numAdds = 0;
}

numAdds = IntegerPolynomial.this.square(limbs, limbs);
IntegerPolynomial.this.square(limbs, limbs);
numAdds = 0;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private IntegerPolynomial1305() {
super(BITS_PER_LIMB, NUM_LIMBS, 1, MODULUS);
}

protected int mult(long[] a, long[] b, long[] r) {
protected void mult(long[] a, long[] b, long[] r) {

// Use grade-school multiplication into primitives to avoid the
// temporary array allocation. This is equivalent to the following
Expand All @@ -73,7 +73,6 @@ protected int mult(long[] a, long[] b, long[] r) {
long c8 = (a[4] * b[4]);

carryReduce(r, c0, c1, c2, c3, c4, c5, c6, c7, c8);
return 0;
}

private void carryReduce(long[] r, long c0, long c1, long c2, long c3,
Expand All @@ -100,7 +99,7 @@ private void carryReduce(long[] r, long c0, long c1, long c2, long c3,
}

@Override
protected int square(long[] a, long[] r) {
protected void square(long[] a, long[] r) {
// Use grade-school multiplication with a simple squaring optimization.
// Multiply into primitives to avoid the temporary array allocation.
// This is equivalent to the following code:
Expand All @@ -123,7 +122,6 @@ protected int square(long[] a, long[] r) {
long c8 = (a[4] * a[4]);

carryReduce(r, c0, c1, c2, c3, c4, c5, c6, c7, c8);
return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ private void multOnly(long[] a, long[] b, long[] c) {
}

@Override
protected int mult(long[] a, long[] b, long[] r) {
protected void mult(long[] a, long[] b, long[] r) {

long[] c = new long[2 * numLimbs];
multOnly(a, b, c);
carryReduce(c, r);
return 0;
}

private void modReduceInBits(long[] limbs, int index, int bits, long x) {
Expand Down Expand Up @@ -189,7 +188,7 @@ protected void reduce(long[] a) {
}

@Override
protected int square(long[] a, long[] r) {
protected void square(long[] a, long[] r) {

long[] c = new long[2 * numLimbs];
for (int i = 0; i < numLimbs; i++) {
Expand All @@ -200,7 +199,6 @@ protected int square(long[] a, long[] r) {
}

carryReduce(c, r);
return 0;
}

/**
Expand Down
Loading

0 comments on commit 63537e8

Please sign in to comment.