src/hotspot/cpu/ppc/stubRoutines_ppc_64.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 53483 60add902a57a
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     1
/*
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
     2
 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
     3
 * Copyright (c) 2012, 2019, SAP SE. All rights reserved.
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     5
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     9
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    14
 * accompanied this code).
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    15
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    19
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    22
 * questions.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    23
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    24
 */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    25
48626
9f6f48d4f9a1 8194814: [ppc, s390] A row of minor fixes and cleanups
goetz
parents: 47216
diff changeset
    26
#include "precompiled.hpp"
31861
7efea6fae96b 8131048: ppc: implement CRC32 intrinsic
goetz
parents: 23492
diff changeset
    27
#include "asm/macroAssembler.inline.hpp"
7efea6fae96b 8131048: ppc: implement CRC32 intrinsic
goetz
parents: 23492
diff changeset
    28
#include "runtime/stubRoutines.hpp"
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    29
#include "runtime/vm_version.hpp"
31861
7efea6fae96b 8131048: ppc: implement CRC32 intrinsic
goetz
parents: 23492
diff changeset
    30
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    31
// Implementation of the platform-specific part of StubRoutines - for
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    32
// a description of how to extend it, see the stubRoutines.hpp file.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    33
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    34
31861
7efea6fae96b 8131048: ppc: implement CRC32 intrinsic
goetz
parents: 23492
diff changeset
    35
#define __ masm->
7efea6fae96b 8131048: ppc: implement CRC32 intrinsic
goetz
parents: 23492
diff changeset
    36
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
    37
// CRC constant compute functions
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    38
static juint fold_byte(juint w, juint reverse_poly) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    39
  for (int i = 0; i < 8; i++) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    40
    int poly_if_odd = (-(w & 1)) & reverse_poly;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    41
    w = (w >> 1) ^ poly_if_odd;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    42
  }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    43
  return w;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    44
}
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    45
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    46
static juint fold_word(juint w, juint reverse_poly) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    47
  for (int i = 0; i < 32; i++) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    48
    int poly_if_odd = (-(w & 1)) & reverse_poly;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    49
    w = (w >> 1) ^ poly_if_odd;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    50
  }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    51
  return w;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    52
}
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    53
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    54
static julong numberOfLeadingZeros(julong p) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    55
  julong l = 1ull << 63;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    56
  for (int i = 0; i < 64; ++i) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    57
    if (p & l) return i;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    58
    l >>= 1;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    59
  }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    60
  return 64;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    61
}
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    62
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    63
static julong compute_inverse_poly(julong long_poly) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    64
  // 2^64 / p
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    65
  julong mod = 0, div = 0;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    66
  int d = numberOfLeadingZeros(long_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    67
  int s = d + 1;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    68
  do {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    69
    mod ^= (long_poly << s);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    70
    div |= (1L << s);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    71
    s = d - numberOfLeadingZeros(mod);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    72
  } while (s >= 0);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    73
  return div;
41334
8b28be7b8613 8164920: ppc: enhancement of CRC32 intrinsic
mdoerr
parents: 35594
diff changeset
    74
}
8b28be7b8613 8164920: ppc: enhancement of CRC32 intrinsic
mdoerr
parents: 35594
diff changeset
    75
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    76
#ifndef VM_LITTLE_ENDIAN
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    77
static void reverse_bytes(juint &w) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    78
  w = ((w >> 24) & 0xFF) | (((w >> 16) & 0xFF) << 8) | (((w >> 8) & 0xFF) << 16) | ((w & 0xFF) << 24);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    79
}
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    80
#endif
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    81
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
    82
// Constants to fold n words as needed by macroAssembler.
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    83
address StubRoutines::generate_crc_constants(juint reverse_poly) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    84
  // Layout of constant table:
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    85
  // <= Power7 Little Endian: 4 tables for byte folding
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    86
  // <= Power7 Big Endian: 1 table for single byte folding + 4 tables for multi-byte folding
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    87
  // >= Power8: 1 table for single byte folding + constants for fast vector implementation
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    88
  const bool use_vector = VM_Version::has_vpmsumb();
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    89
  const int vector_size = 16 * (CRC32_UNROLL_FACTOR2 + CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    90
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    91
  const int size = use_vector ? CRC32_TABLE_SIZE + vector_size : (4 BIG_ENDIAN_ONLY(+1)) * CRC32_TABLE_SIZE;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    92
  const address consts = (address)malloc(size);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    93
  if (consts == NULL) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    94
    vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CRC constants: no enough space");
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    95
  }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    96
  juint* ptr = (juint*)consts;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    97
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    98
  // Simple table used for single byte folding
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
    99
  LITTLE_ENDIAN_ONLY(if (use_vector)) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   100
    for (int i = 0; i < 256; ++i) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   101
      ptr[i] = fold_byte(i, reverse_poly);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   102
    }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   103
  }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   104
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   105
  if (!use_vector) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   106
    BIG_ENDIAN_ONLY(ptr = (juint*)(consts + CRC32_TABLE_SIZE);)
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   107
    // <= Power7: 4 tables
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   108
    for (int i = 0; i < 256; ++i) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   109
      juint a = fold_byte(i, reverse_poly),
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   110
            b = fold_byte(a, reverse_poly),
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   111
            c = fold_byte(b, reverse_poly),
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   112
            d = fold_byte(c, reverse_poly);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   113
#ifndef VM_LITTLE_ENDIAN
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   114
      reverse_bytes(a);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   115
      reverse_bytes(b);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   116
      reverse_bytes(c);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   117
      reverse_bytes(d);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   118
#endif
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   119
      ptr[i         ] = a;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   120
      ptr[i +    256] = b;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   121
      ptr[i + 2* 256] = c;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   122
      ptr[i + 3* 256] = d;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   123
    }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   124
#if 0
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   125
    for (int i = 0; i < 4; ++i) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   126
      tty->print_cr("table %d:", i);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   127
      for (int j = 0; j < 32; ++j) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   128
        for (int k = 0; k < 8; ++k) {
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   129
          tty->print("%08x ", ptr[i*256 + j*8 + k]);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   130
        }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   131
        tty->cr();
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   132
      }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   133
    }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   134
#endif
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   135
    return consts;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   136
  }
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   137
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   138
  // >= Power8: vector constants
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   139
  juint* ptr1 = (juint*)(consts + CRC32_TABLE_SIZE);
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   140
  guarantee(((intptr_t)ptr1 & 0xF) == 0, "16-byte alignment needed");
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   141
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   142
  // Generate constants for outer loop
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   143
  juint v0, v1, v2, v3 = 1;
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   144
  for (int i = 0; i < CRC32_UNROLL_FACTOR2 - 1; ++i) {
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   145
    v0 = fold_word(v3, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   146
    v1 = fold_word(v0, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   147
    v2 = fold_word(v1, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   148
    v3 = fold_word(v2, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   149
#ifdef VM_LITTLE_ENDIAN
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   150
    ptr1[4*i  ] = v3;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   151
    ptr1[4*i+1] = v2;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   152
    ptr1[4*i+2] = v3;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   153
    ptr1[4*i+3] = v2;
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   154
#else
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   155
    ptr1[4*i  ] = v2;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   156
    ptr1[4*i+1] = v3;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   157
    ptr1[4*i+2] = v2;
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   158
    ptr1[4*i+3] = v3;
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   159
#endif
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   160
  }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   161
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   162
  // Generate constants for inner loop
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   163
  juint* ptr2 = ptr1 + 4 * (CRC32_UNROLL_FACTOR2 - 1);
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   164
  v3 = 1; // Restart from scratch.
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   165
  for (int i = 0; i < CRC32_UNROLL_FACTOR; ++i) {
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   166
    v0 = fold_word(v3, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   167
    v1 = fold_word(v0, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   168
    v2 = fold_word(v1, reverse_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   169
    v3 = fold_word(v2, reverse_poly);
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   170
    if (i % CRC32_UNROLL_FACTOR2 == 0) {
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   171
      int idx = CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2 - 1 - i / CRC32_UNROLL_FACTOR2;
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   172
      for (int j = 0; j < 4; ++j) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   173
#ifdef VM_LITTLE_ENDIAN
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   174
        ptr2[4*idx  ] = v3;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   175
        ptr2[4*idx+1] = v2;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   176
        ptr2[4*idx+2] = v1;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   177
        ptr2[4*idx+3] = v0;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   178
#else
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   179
        ptr2[4*idx  ] = v0;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   180
        ptr2[4*idx+1] = v1;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   181
        ptr2[4*idx+2] = v2;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   182
        ptr2[4*idx+3] = v3;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   183
#endif
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   184
      }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   185
    }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   186
  }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   187
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   188
  // Constants to reduce 64 to 32 bit as needed by macroAssembler.
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   189
  juint* ptr3 = ptr2 + 4 * (CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2);
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   190
  julong* c = (julong*)ptr3;
49376
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   191
  julong long_poly = (((julong)reverse_poly) << 1) | 1;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   192
  julong inverse_long_poly = compute_inverse_poly(long_poly);
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   193
#ifdef VM_LITTLE_ENDIAN
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   194
  c[0] = inverse_long_poly;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   195
  c[1] = long_poly;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   196
#else
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   197
  c[0] = long_poly;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   198
  c[1] = inverse_long_poly;
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   199
#endif
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   200
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   201
#ifdef ASSERT
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   202
  if (reverse_poly == REVERSE_CRC32_POLY) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   203
    assert(INVERSE_REVERSE_CRC32_POLY == inverse_long_poly, "sanity");
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   204
  } else if (reverse_poly == REVERSE_CRC32C_POLY) {
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   205
    assert(INVERSE_REVERSE_CRC32C_POLY == inverse_long_poly, "sanity");
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   206
  }
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   207
#endif
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   208
7cd503c499a0 8198894: [PPC64] More generic vector CRC implementation
mdoerr
parents: 48626
diff changeset
   209
  //printf("inv poly: 0x%016llx\n", (long long unsigned int)inverse_long_poly);
53408
e17d7ffad9e3 8216060: [PPC64] Vector CRC implementation should be used by interpreter and be faster for short arrays
mdoerr
parents: 49376
diff changeset
   210
53483
60add902a57a 8217459: [PPC64] Cleanup non-vector version of CRC32
mdoerr
parents: 53408
diff changeset
   211
  return consts;
41334
8b28be7b8613 8164920: ppc: enhancement of CRC32 intrinsic
mdoerr
parents: 35594
diff changeset
   212
}