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