hotspot/test/compiler/intrinsics/crc32c/TestCRC32C.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 31515 6aed85dadbe6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31515
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     1
/*
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     4
 *
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     8
 *
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    13
 * accompanied this code).
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    14
 *
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    18
 *
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    21
 * questions.
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    22
 */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    23
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    24
/**
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    25
 * @test
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    26
 * @bug 8073583
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    27
 * @summary C2 support for CRC32C on SPARC
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    28
 *
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    29
 * @run main/othervm/timeout=600 -Xbatch TestCRC32C -m
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    30
 */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    31
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    32
import java.nio.ByteBuffer;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    33
import java.util.zip.Checksum;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    34
import java.util.zip.CRC32C;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    35
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    36
public class TestCRC32C {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    37
    public static void main(String[] args) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    38
        int offset = Integer.getInteger("offset", 0);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    39
        int msgSize = Integer.getInteger("msgSize", 512);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    40
        boolean multi = false;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    41
        int iters = 20000;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    42
        int warmupIters = 20000;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    43
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    44
        if (args.length > 0) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    45
            if (args[0].equals("-m")) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    46
                multi = true;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    47
            } else {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    48
                iters = Integer.valueOf(args[0]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    49
            }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    50
            if (args.length > 1) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    51
                warmupIters = Integer.valueOf(args[1]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    52
            }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    53
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    54
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    55
        if (multi) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    56
            test_multi(warmupIters);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    57
            return;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    58
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    59
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    60
        System.out.println(" offset = " + offset);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    61
        System.out.println("msgSize = " + msgSize + " bytes");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    62
        System.out.println("  iters = " + iters);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    63
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    64
        byte[] b = initializedBytes(msgSize, offset);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    65
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    66
        CRC32C crc0 = new CRC32C();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    67
        CRC32C crc1 = new CRC32C();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    68
        CRC32C crc2 = new CRC32C();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    69
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    70
        crc0.update(b, offset, msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    71
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    72
        System.out.println("-------------------------------------------------------");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    73
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    74
        /* warm up */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    75
        for (int i = 0; i < warmupIters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    76
            crc1.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    77
            crc1.update(b, offset, msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    78
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    79
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    80
        /* measure performance */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    81
        long start = System.nanoTime();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    82
        for (int i = 0; i < iters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    83
            crc1.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    84
            crc1.update(b, offset, msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    85
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    86
        long end = System.nanoTime();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    87
        double total = (double)(end - start)/1e9;         // in seconds
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    88
        double thruput = (double)msgSize*iters/1e6/total; // in MB/s
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    89
        System.out.println("CRC32C.update(byte[]) runtime = " + total + " seconds");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    90
        System.out.println("CRC32C.update(byte[]) throughput = " + thruput + " MB/s");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    91
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    92
        /* check correctness */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    93
        for (int i = 0; i < iters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    94
            crc1.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    95
            crc1.update(b, offset, msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    96
            if (!check(crc0, crc1)) break;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    97
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    98
        report("CRCs", crc0, crc1);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
    99
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   100
        System.out.println("-------------------------------------------------------");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   101
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   102
        ByteBuffer buf = ByteBuffer.allocateDirect(msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   103
        buf.put(b, offset, msgSize);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   104
        buf.flip();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   105
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   106
        /* warm up */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   107
        for (int i = 0; i < warmupIters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   108
            crc2.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   109
            crc2.update(buf);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   110
            buf.rewind();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   111
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   112
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   113
        /* measure performance */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   114
        start = System.nanoTime();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   115
        for (int i = 0; i < iters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   116
            crc2.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   117
            crc2.update(buf);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   118
            buf.rewind();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   119
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   120
        end = System.nanoTime();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   121
        total = (double)(end - start)/1e9;         // in seconds
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   122
        thruput = (double)msgSize*iters/1e6/total; // in MB/s
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   123
        System.out.println("CRC32C.update(ByteBuffer) runtime = " + total + " seconds");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   124
        System.out.println("CRC32C.update(ByteBuffer) throughput = " + thruput + " MB/s");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   125
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   126
        /* check correctness */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   127
        for (int i = 0; i < iters; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   128
            crc2.reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   129
            crc2.update(buf);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   130
            buf.rewind();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   131
            if (!check(crc0, crc2)) break;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   132
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   133
        report("CRCs", crc0, crc2);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   134
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   135
        System.out.println("-------------------------------------------------------");
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   136
    }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   137
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   138
    private static void report(String s, Checksum crc0, Checksum crc1) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   139
        System.out.printf("%s: crc0 = %08x, crc1 = %08x\n",
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   140
                          s, crc0.getValue(), crc1.getValue());
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   141
    }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   142
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   143
    private static boolean check(Checksum crc0, Checksum crc1) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   144
        if (crc0.getValue() != crc1.getValue()) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   145
            System.err.printf("ERROR: crc0 = %08x, crc1 = %08x\n",
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   146
                              crc0.getValue(), crc1.getValue());
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   147
            return false;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   148
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   149
        return true;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   150
    }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   151
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   152
    private static byte[] initializedBytes(int M, int offset) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   153
        byte[] bytes = new byte[M + offset];
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   154
        for (int i = 0; i < offset; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   155
            bytes[i] = (byte) i;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   156
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   157
        for (int i = offset; i < bytes.length; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   158
            bytes[i] = (byte) (i - offset);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   159
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   160
        return bytes;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   161
    }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   162
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   163
    private static void test_multi(int iters) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   164
        int len1 = 8;    // the  8B/iteration loop
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   165
        int len2 = 32;   // the 32B/iteration loop
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   166
        int len3 = 4096; // the 4KB/iteration loop
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   167
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   168
        byte[] b = initializedBytes(len3*16, 0);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   169
        int[] offsets = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256, 512 };
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   170
        int[] sizes = { 0, 1, 2, 3, 4, 5, 6, 7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   171
                        len1, len1+1, len1+2, len1+3, len1+4, len1+5, len1+6, len1+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   172
                        len1*2, len1*2+1, len1*2+3, len1*2+5, len1*2+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   173
                        len2, len2+1, len2+3, len2+5, len2+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   174
                        len2*2, len2*4, len2*8, len2*16, len2*32, len2*64,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   175
                        len3, len3+1, len3+3, len3+5, len3+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   176
                        len3*2, len3*4, len3*8,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   177
                        len1+len2, len1+len2+1, len1+len2+3, len1+len2+5, len1+len2+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   178
                        len1+len3, len1+len3+1, len1+len3+3, len1+len3+5, len1+len3+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   179
                        len2+len3, len2+len3+1, len2+len3+3, len2+len3+5, len2+len3+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   180
                        len1+len2+len3, len1+len2+len3+1, len1+len2+len3+3,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   181
                        len1+len2+len3+5, len1+len2+len3+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   182
                        (len1+len2+len3)*2, (len1+len2+len3)*2+1, (len1+len2+len3)*2+3,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   183
                        (len1+len2+len3)*2+5, (len1+len2+len3)*2+7,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   184
                        (len1+len2+len3)*3, (len1+len2+len3)*3-1, (len1+len2+len3)*3-3,
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   185
                        (len1+len2+len3)*3-5, (len1+len2+len3)*3-7 };
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   186
        CRC32C[] crc0 = new CRC32C[offsets.length*sizes.length];
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   187
        CRC32C[] crc1 = new CRC32C[offsets.length*sizes.length];
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   188
        int i, j, k;
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   189
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   190
        System.out.printf("testing %d cases ...\n", offsets.length*sizes.length);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   191
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   192
        /* set the result from interpreter as reference */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   193
        for (i = 0; i < offsets.length; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   194
            for (j = 0; j < sizes.length; j++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   195
                crc0[i*sizes.length + j] = new CRC32C();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   196
                crc1[i*sizes.length + j] = new CRC32C();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   197
                crc0[i*sizes.length + j].update(b, offsets[i], sizes[j]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   198
            }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   199
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   200
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   201
        /* warm up the JIT compiler and get result */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   202
        for (k = 0; k < iters; k++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   203
            for (i = 0; i < offsets.length; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   204
                for (j = 0; j < sizes.length; j++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   205
                    crc1[i*sizes.length + j].reset();
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   206
                    crc1[i*sizes.length + j].update(b, offsets[i], sizes[j]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   207
                }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   208
            }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   209
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   210
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   211
        /* check correctness */
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   212
        for (i = 0; i < offsets.length; i++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   213
            for (j = 0; j < sizes.length; j++) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   214
                if (!check(crc0[i*sizes.length + j], crc1[i*sizes.length + j])) {
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   215
                    System.out.printf("offsets[%d] = %d", i, offsets[i]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   216
                    System.out.printf("\tsizes[%d] = %d\n", j, sizes[j]);
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   217
                }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   218
            }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   219
        }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   220
    }
6aed85dadbe6 8073583: C2 support for CRC32C on SPARC
kvn
parents:
diff changeset
   221
}