hotspot/test/compiler/intrinsics/crc32/TestCRC32.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 34205 9ec51d30a11e
permissions -rw-r--r--
Merge
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
 *
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    29
 * @run main/othervm/timeout=720 -Xbatch TestCRC32 -m
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    30
 */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    31
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    32
import java.nio.ByteBuffer;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    33
import java.util.zip.Checksum;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    34
import java.util.zip.CRC32;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    35
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    36
public class TestCRC32 {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    37
    public static void main(String[] args) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    38
        int offset = Integer.getInteger("offset", 0);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    39
        int msgSize = Integer.getInteger("msgSize", 512);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    40
        boolean multi = false;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    41
        int iters = 20000;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    42
        int warmupIters = 20000;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    43
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    44
        if (args.length > 0) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    45
            if (args[0].equals("-m")) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    46
                multi = true;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    47
            } else {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    48
                iters = Integer.valueOf(args[0]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    49
            }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    50
            if (args.length > 1) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    51
                warmupIters = Integer.valueOf(args[1]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    52
            }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    53
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    54
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    55
        if (multi) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    56
            test_multi(warmupIters);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    57
            return;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    58
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    59
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    60
        System.out.println(" offset = " + offset);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    61
        System.out.println("msgSize = " + msgSize + " bytes");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    62
        System.out.println("  iters = " + iters);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    63
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    64
        byte[] b = initializedBytes(msgSize, offset);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    65
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    66
        CRC32 crc0 = new CRC32();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    67
        CRC32 crc1 = new CRC32();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    68
        CRC32 crc2 = new CRC32();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    69
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    70
        crc0.update(b, offset, msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    71
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    72
        System.out.println("-------------------------------------------------------");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    73
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    74
        /* warm up */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    75
        for (int i = 0; i < warmupIters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    76
            crc1.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    77
            crc1.update(b, offset, msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    78
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    79
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    80
        /* measure performance */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    81
        long start = System.nanoTime();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    82
        for (int i = 0; i < iters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    83
            crc1.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    84
            crc1.update(b, offset, msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    85
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    86
        long end = System.nanoTime();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    87
        double total = (double)(end - start)/1e9;         // in seconds
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    88
        double thruput = (double)msgSize*iters/1e6/total; // in MB/s
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    89
        System.out.println("CRC32.update(byte[]) runtime = " + total + " seconds");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    90
        System.out.println("CRC32.update(byte[]) throughput = " + thruput + " MB/s");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    91
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    92
        /* check correctness */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    93
        for (int i = 0; i < iters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    94
            crc1.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    95
            crc1.update(b, offset, msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    96
            if (!check(crc0, crc1)) break;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    97
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    98
        report("CRCs", crc0, crc1);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
    99
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   100
        System.out.println("-------------------------------------------------------");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   101
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   102
        ByteBuffer buf = ByteBuffer.allocateDirect(msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   103
        buf.put(b, offset, msgSize);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   104
        buf.flip();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   105
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   106
        /* warm up */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   107
        for (int i = 0; i < warmupIters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   108
            crc2.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   109
            crc2.update(buf);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   110
            buf.rewind();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   111
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   112
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   113
        /* measure performance */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   114
        start = System.nanoTime();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   115
        for (int i = 0; i < iters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   116
            crc2.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   117
            crc2.update(buf);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   118
            buf.rewind();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   119
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   120
        end = System.nanoTime();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   121
        total = (double)(end - start)/1e9;         // in seconds
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   122
        thruput = (double)msgSize*iters/1e6/total; // in MB/s
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   123
        System.out.println("CRC32.update(ByteBuffer) runtime = " + total + " seconds");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   124
        System.out.println("CRC32.update(ByteBuffer) throughput = " + thruput + " MB/s");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   125
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   126
        /* check correctness */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   127
        for (int i = 0; i < iters; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   128
            crc2.reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   129
            crc2.update(buf);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   130
            buf.rewind();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   131
            if (!check(crc0, crc2)) break;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   132
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   133
        report("CRCs", crc0, crc2);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   134
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   135
        System.out.println("-------------------------------------------------------");
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   136
    }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   137
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   138
    private static void report(String s, Checksum crc0, Checksum crc1) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   139
        System.out.printf("%s: crc0 = %08x, crc1 = %08x\n",
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   140
                          s, crc0.getValue(), crc1.getValue());
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   141
    }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   142
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   143
    private static boolean check(Checksum crc0, Checksum crc1) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   144
        if (crc0.getValue() != crc1.getValue()) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   145
            System.err.printf("ERROR: crc0 = %08x, crc1 = %08x\n",
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   146
                              crc0.getValue(), crc1.getValue());
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   147
            return false;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   148
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   149
        return true;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   150
    }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   151
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   152
    private static byte[] initializedBytes(int M, int offset) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   153
        byte[] bytes = new byte[M + offset];
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   154
        for (int i = 0; i < offset; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   155
            bytes[i] = (byte) i;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   156
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   157
        for (int i = offset; i < bytes.length; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   158
            bytes[i] = (byte) (i - offset);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   159
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   160
        return bytes;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   161
    }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   162
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   163
    private static void test_multi(int iters) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   164
        int len1 = 8;    // the  8B/iteration loop
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   165
        int len2 = 32;   // the 32B/iteration loop
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   166
        int len3 = 4096; // the 4KB/iteration loop
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   167
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   168
        byte[] b = initializedBytes(len3*16, 0);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   169
        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
   170
        int[] sizes = { 0, 1, 2, 3, 4, 5, 6, 7,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   171
                        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
   172
                        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
   173
                        len2, len2+1, len2+3, len2+5, len2+7,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   174
                        len2*2, len2*4, len2*8, len2*16, len2*32, len2*64,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   175
                        len3, len3+1, len3+3, len3+5, len3+7,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   176
                        len3*2, len3*4, len3*8,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   177
                        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
   178
                        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
   179
                        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
   180
                        len1+len2+len3, len1+len2+len3+1, len1+len2+len3+3,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   181
                        len1+len2+len3+5, len1+len2+len3+7,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   182
                        (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
   183
                        (len1+len2+len3)*2+5, (len1+len2+len3)*2+7,
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   184
                        (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
   185
                        (len1+len2+len3)*3-5, (len1+len2+len3)*3-7 };
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   186
        CRC32[] crc0 = new CRC32[offsets.length*sizes.length];
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   187
        CRC32[] crc1 = new CRC32[offsets.length*sizes.length];
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   188
        int i, j, k;
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   189
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   190
        System.out.printf("testing %d cases ...\n", offsets.length*sizes.length);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   191
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   192
        /* set the result from interpreter as reference */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   193
        for (i = 0; i < offsets.length; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   194
            for (j = 0; j < sizes.length; j++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   195
                crc0[i*sizes.length + j] = new CRC32();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   196
                crc1[i*sizes.length + j] = new CRC32();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   197
                crc0[i*sizes.length + j].update(b, offsets[i], sizes[j]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   198
            }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   199
        }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   200
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   201
        /* warm up the JIT compiler and get result */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   202
        for (k = 0; k < iters; k++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   203
            for (i = 0; i < offsets.length; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   204
                for (j = 0; j < sizes.length; j++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   205
                    crc1[i*sizes.length + j].reset();
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   206
                    crc1[i*sizes.length + j].update(b, offsets[i], sizes[j]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   207
                }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   208
            }
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
        /* check correctness */
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   212
        for (i = 0; i < offsets.length; i++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   213
            for (j = 0; j < sizes.length; j++) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   214
                if (!check(crc0[i*sizes.length + j], crc1[i*sizes.length + j])) {
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   215
                    System.out.printf("offsets[%d] = %d", i, offsets[i]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   216
                    System.out.printf("\tsizes[%d] = %d\n", j, sizes[j]);
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   217
                }
9ec51d30a11e 8143012: CRC32 Intrinsics support on SPARC
kvn
parents:
diff changeset
   218
            }
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
}