/* * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @library /test/lib * @build jdk.test.lib.RandomFactory * @run main MultiplicationTests * @bug 5100935 8188044 * @summary Tests for multiplication methods (use -Dseed=X to set PRNG seed) * @key randomness
*/
// Number of random products to test. privatestaticfinalint COUNT = 1 << 16;
// Initialize shared random number generator privatestatic java.util.Random rnd = RandomFactory.getRandom();
// Calculate high 64 bits of 128 product using BigInteger. privatestaticlong multiplyHighBigInt(long x, long y) { return BigInteger.valueOf(x).multiply(BigInteger.valueOf(y))
.shiftRight(64).longValue();
}
// Calculate high 64 bits of unsigned 128 product using signed multiply privatestaticlong unsignedMultiplyHigh(long x, long y) { long x0 = x & 0xffffffffL; long x1 = x >>> 32; long y0 = y & 0xffffffffL; long y1 = y >>> 32;
long t = x1 * y0 + ((x0 * y0) >>> 32); long z0 = x0 * y1 + (t & 0xffffffffL); long z1 = t >>> 32;
return x1 * y1 + z1 + (z0 >>> 32);
}
// Compare results of two functions for a pair of values privatestaticboolean check(BiFunction<Long,Long,Long> reference,
BiFunction<Long,Long,Long> multiply, long x, long y) { long p1 = reference.apply(x, y); long p2 = multiply.apply(x, y); if (p1 != p2) {
System.err.printf("Error - x:%d y:%d p1:%d p2:%d\n", x, y, p1, p2); returnfalse;
} else { returntrue;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.