< prev index next >

test/compiler/intrinsics/zip/TestCRC32C.java

Print this page

        

*** 25,43 **** --- 25,62 ---- * @test * @bug 8073583 * @summary C2 support for CRC32C on SPARC * * @run main/othervm/timeout=600 -Xbatch compiler.intrinsics.zip.TestCRC32C -m + * @run main/othervm/timeout=600 -Xint -Doffset=1 compiler.intrinsics.zip.TestCRC32C + * @run main/othervm/timeout=600 -Xcomp -XX:+TieredCompilation -Doffset=1 compiler.intrinsics.zip.TestCRC32C + * @run main/othervm/timeout=600 -Xcomp -XX:-TieredCompilation -Doffset=1 compiler.intrinsics.zip.TestCRC32C */ package compiler.intrinsics.zip; import java.nio.ByteBuffer; import java.util.zip.CRC32C; import java.util.zip.Checksum; public class TestCRC32C { + // CRC32C (Castagnoli) polynomial + // coefficients in different forms + // normal: polyBits = 0x1edc6f41 = 0b0001 1110 1101 1100 0110 1111 0100 0001 + // reversed: polybits = 0x82f63b78 = 0b1000 0010 1111 0110 0011 1011 0111 1000 + // reversed reciprocal polybits = 0x8f6e37a0 = 0b1000 1111 0110 1110 0011 0111 1010 0000 + // + // 0 5 9 13 17 21 25 29 + // | | | | | | | | + // reversed shiftL 1 polyBits = 0x105ec76f1L = 0b1 0000 0101 1110 1100 0111 0110 1111 0001 + final static long polyBits = (1L<<(32-32)) + (1L<<(32-28)) + (1L<<(32-27)) + + (1L<<(32-26)) + (1L<<(32-25)) + (1L<<(32-23)) + (1L<<(32-22)) + + (1L<<(32-20)) + (1L<<(32-19)) + (1L<<(32-18)) + (1L<<(32-14)) + + (1L<<(32-13)) + (1L<<(32-11)) + (1L<<(32-10)) + (1L<<(32-9)) + + (1L<<(32-8)) + (1L<<(32-6)) + (1L<<(32-0)); + final static long polyBitsShifted = polyBits>>1; + public static void main(String[] args) { int offset = Integer.getInteger("offset", 0); int msgSize = Integer.getInteger("msgSize", 512); boolean multi = false; int iters = 20000;
*** 63,84 **** --- 82,113 ---- System.out.println("msgSize = " + msgSize + " bytes"); System.out.println(" iters = " + iters); byte[] b = initializedBytes(msgSize, offset); + final long crc_reference = update_byteloop(0, b, offset); + CRC32C crc0 = new CRC32C(); CRC32C crc1 = new CRC32C(); CRC32C crc2 = new CRC32C(); crc0.update(b, offset, msgSize); + if (!check(crc0, crc_reference)) { + System.out.println("CRC32C: crc mismatch during initialization."); + return; + } System.out.println("-------------------------------------------------------"); /* warm up */ for (int i = 0; i < warmupIters; i++) { crc1.reset(); crc1.update(b, offset, msgSize); + if (!check(crc1, crc_reference)) { + System.out.println("CRC32C: crc mismatch during warmup iteration " + i); + break; + } } /* measure performance */ long start = System.nanoTime(); for (int i = 0; i < iters; i++) {
*** 135,144 **** --- 164,197 ---- report("CRCs", crc0, crc2); System.out.println("-------------------------------------------------------"); } + public static long update_byteloop(long crc, byte[] buf, int offset) { + for (int i = offset; i < buf.length; i++) { + crc = update_singlebyte(crc, polyBitsShifted, buf[i]); + } + return crc; + } + + // Straight-forward implementation of CRC update by one byte. + public static long update_singlebyte(long crc, long polynomial, int val) { + crc = (crc ^ -1L) & 0x00000000ffffffffL; // use 1's complement of crc + crc = crc ^ (val&0xff); // XOR in next byte from stream + for (int i = 0; i < 8; i++) { + boolean bitset = (crc & 0x01L) != 0; + + crc = crc>>1; + if (bitset) { + crc = crc ^ polynomial; + crc = crc & 0x00000000ffffffffL; + } + } + crc = (crc ^ -1L) & 0x00000000ffffffffL; // revert taking 1's complement + return crc; + } + private static void report(String s, Checksum crc0, Checksum crc1) { System.out.printf("%s: crc0 = %08x, crc1 = %08x\n", s, crc0.getValue(), crc1.getValue()); }
*** 149,158 **** --- 202,220 ---- return false; } return true; } + private static boolean check(Checksum crc0, long crc_reference) { + if (crc0.getValue() != crc_reference) { + System.err.printf("ERROR: crc0 = %08x, crc_reference = %08x\n", + crc0.getValue(), crc_reference); + return false; + } + return true; + } + private static byte[] initializedBytes(int M, int offset) { byte[] bytes = new byte[M + offset]; for (int i = 0; i < offset; i++) { bytes[i] = (byte) i; }
< prev index next >