hotspot/src/cpu/x86/vm/crc32c.h
author twisti
Fri, 18 Dec 2015 12:39:02 -0800
changeset 35135 dd2ce9021031
parent 33066 d98eab8215c4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33066
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     1
/*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     4
*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     7
* published by the Free Software Foundation.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     8
*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    13
* accompanied this code).
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    14
*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    18
*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    21
* questions.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    22
*
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    23
*/
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    24
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    25
enum {
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    26
  // S. Gueron / Information Processing Letters 112 (2012) 184
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    27
  // shows than anything above 6K and below 32K is a good choice
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    28
  // 32K does not deliver any further performance gains
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    29
  // 6K=8*256 (*3 as we compute 3 blocks together)
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    30
  //
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    31
  // Thus selecting the smallest value so it could apply to the largest number
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    32
  // of buffer sizes.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    33
  CRC32C_HIGH = 8 * 256,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    34
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    35
  // empirical
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    36
  // based on ubench study using methodology described in
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    37
  // V. Gopal et al. / Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction April 2011 8
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    38
  //
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    39
  // arbitrary value between 27 and 256
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    40
  CRC32C_MIDDLE = 8 * 86,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    41
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    42
  // V. Gopal et al. / Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction April 2011 9
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    43
  // shows that 240 and 1024 are equally good choices as the 216==8*27
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    44
  //
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    45
  // Selecting the smallest value which resulted in a significant performance improvement over
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    46
  // sequential version
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    47
  CRC32C_LOW = 8 * 27,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    48
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    49
  CRC32C_NUM_ChunkSizeInBytes = 3,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    50
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    51
  // We need to compute powers of 64N and 128N for each "chunk" size
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    52
  CRC32C_NUM_PRECOMPUTED_CONSTANTS = ( 2 * CRC32C_NUM_ChunkSizeInBytes )
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    53
};
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    54
// Notes:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    55
// 1. Why we need to choose a "chunk" approach?
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    56
// Overhead of computing a powers and powers of for an arbitrary buffer of size N is significant
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    57
// (implementation approaches a library perf.)
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    58
// 2. Why only 3 "chunks"?
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    59
// Performance experiments results showed that a HIGH+LOW was not delivering a stable speedup
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    60
// curve.
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    61
//
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    62
// Disclaimer:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    63
// If you ever decide to increase/decrease number of "chunks" be sure to modify
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    64
// a) constants table generation (hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp)
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    65
// b) constant fetch from that table (macroAssembler_x86.cpp)
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents:
diff changeset
    66
// c) unrolled for loop (macroAssembler_x86.cpp)