src/hotspot/cpu/s390/stubGenerator_s390.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 54786 ebf733a324d4
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:
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     1
/*
53789
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
     3
 * Copyright (c) 2016, 2019, SAP SE. All rights reserved.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     5
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     9
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    14
 * accompanied this code).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    15
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    19
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    22
 * questions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    23
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    24
 */
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    25
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    26
#include "precompiled.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    27
#include "asm/macroAssembler.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    28
#include "registerSaver_s390.hpp"
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    29
#include "gc/shared/barrierSet.hpp"
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    30
#include "gc/shared/barrierSetAssembler.hpp"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    31
#include "interpreter/interpreter.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    32
#include "interpreter/interp_masm.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 53789
diff changeset
    33
#include "memory/universe.hpp"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    34
#include "nativeInst_s390.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    35
#include "oops/instanceOop.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    36
#include "oops/objArrayKlass.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    37
#include "oops/oop.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    38
#include "prims/methodHandles.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    39
#include "runtime/frame.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    40
#include "runtime/handles.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    41
#include "runtime/sharedRuntime.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    42
#include "runtime/stubCodeGenerator.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    43
#include "runtime/stubRoutines.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    44
#include "runtime/thread.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    45
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    46
// Declaration and definition of StubGenerator (no .hpp file).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    47
// For a more detailed description of the stub routine structure
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    48
// see the comment in stubRoutines.hpp.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    49
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    50
#ifdef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    51
#define __ _masm->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    52
#else
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    53
#define __ (Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    54
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    55
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    56
#define BLOCK_COMMENT(str) if (PrintAssembly) __ block_comment(str)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    57
#define BIND(label)        bind(label); BLOCK_COMMENT(#label ":")
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    58
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    59
// -----------------------------------------------------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    60
// Stub Code definitions
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    61
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    62
class StubGenerator: public StubCodeGenerator {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    63
 private:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    64
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    65
  //----------------------------------------------------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    66
  // Call stubs are used to call Java from C.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    67
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    68
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    69
  // Arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    70
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    71
  //   R2        - call wrapper address     : address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    72
  //   R3        - result                   : intptr_t*
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    73
  //   R4        - result type              : BasicType
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    74
  //   R5        - method                   : method
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    75
  //   R6        - frame mgr entry point    : address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    76
  //   [SP+160]  - parameter block          : intptr_t*
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    77
  //   [SP+172]  - parameter count in words : int
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    78
  //   [SP+176]  - thread                   : Thread*
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    79
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    80
  address generate_call_stub(address& return_address) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    81
    // Set up a new C frame, copy Java arguments, call frame manager
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    82
    // or native_entry, and process result.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    83
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    84
    StubCodeMark mark(this, "StubRoutines", "call_stub");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    85
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    86
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    87
    Register r_arg_call_wrapper_addr   = Z_ARG1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    88
    Register r_arg_result_addr         = Z_ARG2;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    89
    Register r_arg_result_type         = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    90
    Register r_arg_method              = Z_ARG4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    91
    Register r_arg_entry               = Z_ARG5;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    92
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    93
    // offsets to fp
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    94
    #define d_arg_thread 176
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    95
    #define d_arg_argument_addr 160
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    96
    #define d_arg_argument_count 168+4
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    97
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    98
    Register r_entryframe_fp           = Z_tmp_1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    99
    Register r_top_of_arguments_addr   = Z_ARG4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   100
    Register r_new_arg_entry = Z_R14;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   101
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   102
    // macros for frame offsets
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   103
    #define call_wrapper_address_offset \
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   104
               _z_entry_frame_locals_neg(call_wrapper_address)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   105
    #define result_address_offset \
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   106
              _z_entry_frame_locals_neg(result_address)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   107
    #define result_type_offset \
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   108
              _z_entry_frame_locals_neg(result_type)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   109
    #define arguments_tos_address_offset \
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   110
              _z_entry_frame_locals_neg(arguments_tos_address)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   111
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   112
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   113
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   114
      // STACK on entry to call_stub:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   115
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   116
      //     F1      [C_FRAME]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   117
      //            ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   118
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   119
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   120
      Register r_argument_addr              = Z_tmp_3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   121
      Register r_argumentcopy_addr          = Z_tmp_4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   122
      Register r_argument_size_in_bytes     = Z_ARG5;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   123
      Register r_frame_size                 = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   124
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   125
      Label arguments_copied;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   126
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   127
      // Save non-volatile registers to ABI of caller frame.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   128
      BLOCK_COMMENT("save registers, push frame {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   129
      __ z_stmg(Z_R6, Z_R14, 16, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   130
      __ z_std(Z_F8, 96, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   131
      __ z_std(Z_F9, 104, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   132
      __ z_std(Z_F10, 112, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   133
      __ z_std(Z_F11, 120, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   134
      __ z_std(Z_F12, 128, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   135
      __ z_std(Z_F13, 136, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   136
      __ z_std(Z_F14, 144, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   137
      __ z_std(Z_F15, 152, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   138
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   139
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   140
      // Push ENTRY_FRAME including arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   141
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   142
      //     F0      [TOP_IJAVA_FRAME_ABI]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   143
      //             [outgoing Java arguments]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   144
      //             [ENTRY_FRAME_LOCALS]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   145
      //     F1      [C_FRAME]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   146
      //             ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   147
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   148
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   149
      // Calculate new frame size and push frame.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   150
      #define abi_plus_locals_size \
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   151
                (frame::z_top_ijava_frame_abi_size + frame::z_entry_frame_locals_size)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   152
      if (abi_plus_locals_size % BytesPerWord == 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   153
        // Preload constant part of frame size.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   154
        __ load_const_optimized(r_frame_size, -abi_plus_locals_size/BytesPerWord);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   155
        // Keep copy of our frame pointer (caller's SP).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   156
        __ z_lgr(r_entryframe_fp, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   157
        // Add space required by arguments to frame size.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   158
        __ z_slgf(r_frame_size, d_arg_argument_count, Z_R0, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   159
        // Move Z_ARG5 early, it will be used as a local.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   160
        __ z_lgr(r_new_arg_entry, r_arg_entry);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   161
        // Convert frame size from words to bytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   162
        __ z_sllg(r_frame_size, r_frame_size, LogBytesPerWord);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   163
        __ push_frame(r_frame_size, r_entryframe_fp,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   164
                      false/*don't copy SP*/, true /*frame size sign inverted*/);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   165
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   166
        guarantee(false, "frame sizes should be multiples of word size (BytesPerWord)");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   167
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   168
      BLOCK_COMMENT("} save, push");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   169
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   170
      // Load argument registers for call.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   171
      BLOCK_COMMENT("prepare/copy arguments {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   172
      __ z_lgr(Z_method, r_arg_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   173
      __ z_lg(Z_thread, d_arg_thread, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   174
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   175
      // Calculate top_of_arguments_addr which will be tos (not prepushed) later.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   176
      // Wimply use SP + frame::top_ijava_frame_size.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   177
      __ add2reg(r_top_of_arguments_addr,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   178
                 frame::z_top_ijava_frame_abi_size - BytesPerWord, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   179
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   180
      // Initialize call_stub locals (step 1).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   181
      if ((call_wrapper_address_offset + BytesPerWord == result_address_offset) &&
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   182
          (result_address_offset + BytesPerWord == result_type_offset)          &&
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   183
          (result_type_offset + BytesPerWord == arguments_tos_address_offset)) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   184
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   185
        __ z_stmg(r_arg_call_wrapper_addr, r_top_of_arguments_addr,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   186
                  call_wrapper_address_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   187
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   188
        __ z_stg(r_arg_call_wrapper_addr,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   189
                 call_wrapper_address_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   190
        __ z_stg(r_arg_result_addr,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   191
                 result_address_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   192
        __ z_stg(r_arg_result_type,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   193
                 result_type_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   194
        __ z_stg(r_top_of_arguments_addr,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   195
                 arguments_tos_address_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   196
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   197
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   198
      // Copy Java arguments.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   199
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   200
      // Any arguments to copy?
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   201
      __ load_and_test_int2long(Z_R1, Address(r_entryframe_fp, d_arg_argument_count));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   202
      __ z_bre(arguments_copied);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   203
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   204
      // Prepare loop and copy arguments in reverse order.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   205
      {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   206
        // Calculate argument size in bytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   207
        __ z_sllg(r_argument_size_in_bytes, Z_R1, LogBytesPerWord);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   208
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   209
        // Get addr of first incoming Java argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   210
        __ z_lg(r_argument_addr, d_arg_argument_addr, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   211
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   212
        // Let r_argumentcopy_addr point to last outgoing Java argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   213
        __ add2reg(r_argumentcopy_addr, BytesPerWord, r_top_of_arguments_addr); // = Z_SP+160 effectively.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   214
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   215
        // Let r_argument_addr point to last incoming Java argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   216
        __ add2reg_with_index(r_argument_addr, -BytesPerWord,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   217
                              r_argument_size_in_bytes, r_argument_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   218
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   219
        // Now loop while Z_R1 > 0 and copy arguments.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   220
        {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   221
          Label next_argument;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   222
          __ bind(next_argument);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   223
          // Mem-mem move.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   224
          __ z_mvc(0, BytesPerWord-1, r_argumentcopy_addr, 0, r_argument_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   225
          __ add2reg(r_argument_addr,    -BytesPerWord);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   226
          __ add2reg(r_argumentcopy_addr, BytesPerWord);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   227
          __ z_brct(Z_R1, next_argument);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   228
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   229
      }  // End of argument copy loop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   230
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   231
      __ bind(arguments_copied);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   232
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   233
    BLOCK_COMMENT("} arguments");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   234
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   235
    BLOCK_COMMENT("call {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   236
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   237
      // Call frame manager or native entry.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   238
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   239
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   240
      // Register state on entry to frame manager / native entry:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   241
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   242
      //   Z_ARG1 = r_top_of_arguments_addr  - intptr_t *sender tos (prepushed)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   243
      //                                       Lesp = (SP) + copied_arguments_offset - 8
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   244
      //   Z_method                          - method
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   245
      //   Z_thread                          - JavaThread*
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   246
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   247
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   248
      // Here, the usual SP is the initial_caller_sp.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   249
      __ z_lgr(Z_R10, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   250
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   251
      // Z_esp points to the slot below the last argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   252
      __ z_lgr(Z_esp, r_top_of_arguments_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   253
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   254
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   255
      // Stack on entry to frame manager / native entry:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   256
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   257
      //     F0      [TOP_IJAVA_FRAME_ABI]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   258
      //             [outgoing Java arguments]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   259
      //             [ENTRY_FRAME_LOCALS]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   260
      //     F1      [C_FRAME]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   261
      //             ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   262
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   263
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   264
      // Do a light-weight C-call here, r_new_arg_entry holds the address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   265
      // of the interpreter entry point (frame manager or native entry)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   266
      // and save runtime-value of return_pc in return_address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   267
      // (call by reference argument).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   268
      return_address = __ call_stub(r_new_arg_entry);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   269
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   270
    BLOCK_COMMENT("} call");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   271
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   272
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   273
      BLOCK_COMMENT("restore registers {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   274
      // Returned from frame manager or native entry.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   275
      // Now pop frame, process result, and return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   276
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   277
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   278
      // Stack on exit from frame manager / native entry:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   279
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   280
      //     F0      [ABI]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   281
      //             ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   282
      //             [ENTRY_FRAME_LOCALS]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   283
      //     F1      [C_FRAME]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   284
      //             ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   285
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   286
      // Just pop the topmost frame ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   287
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   288
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   289
      // Restore frame pointer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   290
      __ z_lg(r_entryframe_fp, _z_abi(callers_sp), Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   291
      // Pop frame. Done here to minimize stalls.
46726
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
   292
      __ pop_frame();
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   293
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   294
      // Reload some volatile registers which we've spilled before the call
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   295
      // to frame manager / native entry.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   296
      // Access all locals via frame pointer, because we know nothing about
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   297
      // the topmost frame's size.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   298
      __ z_lg(r_arg_result_addr, result_address_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   299
      __ z_lg(r_arg_result_type, result_type_offset, r_entryframe_fp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   300
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   301
      // Restore non-volatiles.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   302
      __ z_lmg(Z_R6, Z_R14, 16, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   303
      __ z_ld(Z_F8, 96, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   304
      __ z_ld(Z_F9, 104, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   305
      __ z_ld(Z_F10, 112, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   306
      __ z_ld(Z_F11, 120, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   307
      __ z_ld(Z_F12, 128, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   308
      __ z_ld(Z_F13, 136, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   309
      __ z_ld(Z_F14, 144, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   310
      __ z_ld(Z_F15, 152, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   311
      BLOCK_COMMENT("} restore");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   312
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   313
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   314
      // Stack on exit from call_stub:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   315
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   316
      //     0       [C_FRAME]
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   317
      //             ...
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   318
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   319
      // No call_stub frames left.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   320
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   321
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   322
      // All non-volatiles have been restored at this point!!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   323
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   324
      //------------------------------------------------------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   325
      // The following code makes some assumptions on the T_<type> enum values.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   326
      // The enum is defined in globalDefinitions.hpp.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   327
      // The validity of the assumptions is tested as far as possible.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   328
      //   The assigned values should not be shuffled
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   329
      //   T_BOOLEAN==4    - lowest used enum value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   330
      //   T_NARROWOOP==16 - largest used enum value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   331
      //------------------------------------------------------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   332
      BLOCK_COMMENT("process result {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   333
      Label firstHandler;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   334
      int   handlerLen= 8;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   335
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   336
      char  assertMsg[] = "check BasicType definition in globalDefinitions.hpp";
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   337
      __ z_chi(r_arg_result_type, T_BOOLEAN);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   338
      __ asm_assert_low(assertMsg, 0x0234);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   339
      __ z_chi(r_arg_result_type, T_NARROWOOP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   340
      __ asm_assert_high(assertMsg, 0x0235);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   341
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   342
      __ add2reg(r_arg_result_type, -T_BOOLEAN);          // Remove offset.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   343
      __ z_larl(Z_R1, firstHandler);                      // location of first handler
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   344
      __ z_sllg(r_arg_result_type, r_arg_result_type, 3); // Each handler is 8 bytes long.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   345
      __ z_bc(MacroAssembler::bcondAlways, 0, r_arg_result_type, Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   346
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   347
      __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   348
      __ bind(firstHandler);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   349
      // T_BOOLEAN:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   350
        guarantee(T_BOOLEAN == 4, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   351
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   352
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   353
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   354
      // T_CHAR:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   355
        guarantee(T_CHAR == T_BOOLEAN+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   356
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   357
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   358
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   359
      // T_FLOAT:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   360
        guarantee(T_FLOAT == T_CHAR+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   361
        __ z_ste(Z_FRET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   362
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   363
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   364
      // T_DOUBLE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   365
        guarantee(T_DOUBLE == T_FLOAT+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   366
        __ z_std(Z_FRET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   367
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   368
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   369
      // T_BYTE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   370
        guarantee(T_BYTE == T_DOUBLE+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   371
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   372
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   373
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   374
      // T_SHORT:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   375
        guarantee(T_SHORT == T_BYTE+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   376
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   377
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   378
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   379
      // T_INT:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   380
        guarantee(T_INT == T_SHORT+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   381
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   382
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   383
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   384
      // T_LONG:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   385
        guarantee(T_LONG == T_INT+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   386
        __ z_stg(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   387
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   388
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   389
      // T_OBJECT:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   390
        guarantee(T_OBJECT == T_LONG+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   391
        __ z_stg(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   392
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   393
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   394
      // T_ARRAY:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   395
        guarantee(T_ARRAY == T_OBJECT+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   396
        __ z_stg(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   397
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   398
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   399
      // T_VOID:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   400
        guarantee(T_VOID == T_ARRAY+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   401
        __ z_stg(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   402
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   403
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   404
      // T_ADDRESS:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   405
        guarantee(T_ADDRESS == T_VOID+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   406
        __ z_stg(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   407
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   408
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   409
      // T_NARROWOOP:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   410
        guarantee(T_NARROWOOP == T_ADDRESS+1, "check BasicType definition in globalDefinitions.hpp");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   411
        __ z_st(Z_RET, 0, r_arg_result_addr);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   412
        __ z_br(Z_R14); // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   413
        __ align(handlerLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   414
      BLOCK_COMMENT("} process result");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   415
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   416
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   417
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   418
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   419
  // Return point for a Java call if there's an exception thrown in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   420
  // Java code. The exception is caught and transformed into a
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   421
  // pending exception stored in JavaThread that can be tested from
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   422
  // within the VM.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   423
  address generate_catch_exception() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   424
    StubCodeMark mark(this, "StubRoutines", "catch_exception");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   425
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   426
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   427
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   428
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   429
    // Registers alive
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   430
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   431
    //   Z_thread
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   432
    //   Z_ARG1 - address of pending exception
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   433
    //   Z_ARG2 - return address in call stub
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   434
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   435
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   436
    const Register exception_file = Z_R0;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   437
    const Register exception_line = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   438
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   439
    __ load_const_optimized(exception_file, (void*)__FILE__);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   440
    __ load_const_optimized(exception_line, (void*)__LINE__);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   441
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   442
    __ z_stg(Z_ARG1, thread_(pending_exception));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   443
    // Store into `char *'.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   444
    __ z_stg(exception_file, thread_(exception_file));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   445
    // Store into `int'.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   446
    __ z_st(exception_line, thread_(exception_line));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   447
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   448
    // Complete return to VM.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   449
    assert(StubRoutines::_call_stub_return_address != NULL, "must have been generated before");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   450
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   451
    // Continue in call stub.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   452
    __ z_br(Z_ARG2);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   453
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   454
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   455
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   456
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   457
  // Continuation point for runtime calls returning with a pending
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   458
  // exception. The pending exception check happened in the runtime
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   459
  // or native call stub. The pending exception in Thread is
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   460
  // converted into a Java-level exception.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   461
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   462
  // Read:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   463
  //   Z_R14: pc the runtime library callee wants to return to.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   464
  //   Since the exception occurred in the callee, the return pc
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   465
  //   from the point of view of Java is the exception pc.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   466
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   467
  // Invalidate:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   468
  //   Volatile registers (except below).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   469
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   470
  // Update:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   471
  //   Z_ARG1: exception
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   472
  //   (Z_R14 is unchanged and is live out).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   473
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   474
  address generate_forward_exception() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   475
    StubCodeMark mark(this, "StubRoutines", "forward_exception");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   476
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   477
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   478
    #define pending_exception_offset in_bytes(Thread::pending_exception_offset())
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   479
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   480
    // Get pending exception oop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   481
    __ z_lg(Z_ARG1, pending_exception_offset, Z_thread);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   482
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   483
    // Make sure that this code is only executed if there is a pending exception.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   484
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   485
      Label L;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   486
      __ z_ltgr(Z_ARG1, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   487
      __ z_brne(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   488
      __ stop("StubRoutines::forward exception: no pending exception (1)");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   489
      __ bind(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   490
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   491
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   492
    __ verify_oop(Z_ARG1, "StubRoutines::forward exception: not an oop");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   493
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   494
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   495
    __ z_lgr(Z_ARG2, Z_R14); // Copy exception pc into Z_ARG2.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   496
    __ save_return_pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   497
    __ push_frame_abi160(0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   498
    // Find exception handler.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   499
    __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   500
                    Z_thread,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   501
                    Z_ARG2);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   502
    // Copy handler's address.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   503
    __ z_lgr(Z_R1, Z_RET);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   504
    __ pop_frame();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   505
    __ restore_return_pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   506
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   507
    // Set up the arguments for the exception handler:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   508
    // - Z_ARG1: exception oop
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   509
    // - Z_ARG2: exception pc
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   510
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   511
    // Load pending exception oop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   512
    __ z_lg(Z_ARG1, pending_exception_offset, Z_thread);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   513
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   514
    // The exception pc is the return address in the caller,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   515
    // must load it into Z_ARG2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   516
    __ z_lgr(Z_ARG2, Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   517
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   518
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   519
    // Make sure exception is set.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   520
    { Label L;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   521
      __ z_ltgr(Z_ARG1, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   522
      __ z_brne(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   523
      __ stop("StubRoutines::forward exception: no pending exception (2)");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   524
      __ bind(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   525
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   526
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   527
    // Clear the pending exception.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   528
    __ clear_mem(Address(Z_thread, pending_exception_offset), sizeof(void *));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   529
    // Jump to exception handler
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   530
    __ z_br(Z_R1 /*handler address*/);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   531
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   532
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   533
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   534
    #undef pending_exception_offset
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   535
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   536
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   537
  // Continuation point for throwing of implicit exceptions that are
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   538
  // not handled in the current activation. Fabricates an exception
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   539
  // oop and initiates normal exception dispatching in this
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   540
  // frame. Only callee-saved registers are preserved (through the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   541
  // normal RegisterMap handling). If the compiler
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   542
  // needs all registers to be preserved between the fault point and
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   543
  // the exception handler then it must assume responsibility for that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   544
  // in AbstractCompiler::continuation_for_implicit_null_exception or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   545
  // continuation_for_implicit_division_by_zero_exception. All other
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   546
  // implicit exceptions (e.g., NullPointerException or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   547
  // AbstractMethodError on entry) are either at call sites or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   548
  // otherwise assume that stack unwinding will be initiated, so
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   549
  // caller saved registers were assumed volatile in the compiler.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   550
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   551
  // Note that we generate only this stub into a RuntimeStub, because
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   552
  // it needs to be properly traversed and ignored during GC, so we
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   553
  // change the meaning of the "__" macro within this method.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   554
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   555
  // Note: the routine set_pc_not_at_call_for_caller in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   556
  // SharedRuntime.cpp requires that this code be generated into a
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   557
  // RuntimeStub.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   558
#undef __
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   559
#define __ masm->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   560
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   561
  address generate_throw_exception(const char* name, address runtime_entry,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   562
                                   bool restore_saved_exception_pc,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   563
                                   Register arg1 = noreg, Register arg2 = noreg) {
46726
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
   564
    assert_different_registers(arg1, Z_R0_scratch);  // would be destroyed by push_frame()
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
   565
    assert_different_registers(arg2, Z_R0_scratch);  // would be destroyed by push_frame()
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
   566
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   567
    int insts_size = 256;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   568
    int locs_size  = 0;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   569
    CodeBuffer      code(name, insts_size, locs_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   570
    MacroAssembler* masm = new MacroAssembler(&code);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   571
    int framesize_in_bytes;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   572
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   573
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   574
    __ save_return_pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   575
    framesize_in_bytes = __ push_frame_abi160(0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   576
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   577
    address frame_complete_pc = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   578
    if (restore_saved_exception_pc) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   579
      __ unimplemented("StubGenerator::throw_exception", 74);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   580
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   581
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   582
    // Note that we always have a runtime stub frame on the top of stack at this point.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   583
    __ get_PC(Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   584
    __ set_last_Java_frame(/*sp*/Z_SP, /*pc*/Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   585
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   586
    // Do the call.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   587
    BLOCK_COMMENT("call runtime_entry");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   588
    __ call_VM_leaf(runtime_entry, Z_thread, arg1, arg2);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   589
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   590
    __ reset_last_Java_frame();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   591
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   592
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   593
    // Make sure that this code is only executed if there is a pending exception.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   594
    { Label L;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   595
      __ z_lg(Z_R0,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   596
                in_bytes(Thread::pending_exception_offset()),
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   597
                Z_thread);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   598
      __ z_ltgr(Z_R0, Z_R0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   599
      __ z_brne(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   600
      __ stop("StubRoutines::throw_exception: no pending exception");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   601
      __ bind(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   602
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   603
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   604
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   605
    __ pop_frame();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   606
    __ restore_return_pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   607
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   608
    __ load_const_optimized(Z_R1, StubRoutines::forward_exception_entry());
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   609
    __ z_br(Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   610
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   611
    RuntimeStub* stub =
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   612
      RuntimeStub::new_runtime_stub(name, &code,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   613
                                    frame_complete_pc - start,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   614
                                    framesize_in_bytes/wordSize,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   615
                                    NULL /*oop_maps*/, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   616
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   617
    return stub->entry_point();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   618
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   619
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   620
#undef __
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   621
#ifdef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   622
#define __ _masm->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   623
#else
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   624
#define __ (Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   625
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   626
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   627
  // Support for uint StubRoutine::zarch::partial_subtype_check(Klass
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   628
  // sub, Klass super);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   629
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   630
  // Arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   631
  //   ret  : Z_RET, returned
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   632
  //   sub  : Z_ARG2, argument, not changed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   633
  //   super: Z_ARG3, argument, not changed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   634
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   635
  //   raddr: Z_R14, blown by call
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   636
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   637
  address generate_partial_subtype_check() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   638
    StubCodeMark mark(this, "StubRoutines", "partial_subtype_check");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   639
    Label miss;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   640
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   641
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   642
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   643
    const Register Rsubklass   = Z_ARG2; // subklass
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   644
    const Register Rsuperklass = Z_ARG3; // superklass
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   645
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   646
    // No args, but tmp registers that are killed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   647
    const Register Rlength     = Z_ARG4; // cache array length
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   648
    const Register Rarray_ptr  = Z_ARG5; // Current value from cache array.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   649
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   650
    if (UseCompressedOops) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   651
      assert(Universe::heap() != NULL, "java heap must be initialized to generate partial_subtype_check stub");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   652
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   653
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   654
    // Always take the slow path (see SPARC).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   655
    __ check_klass_subtype_slow_path(Rsubklass, Rsuperklass,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   656
                                     Rarray_ptr, Rlength, NULL, &miss);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   657
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   658
    // Match falls through here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   659
    __ clear_reg(Z_RET);               // Zero indicates a match. Set EQ flag in CC.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   660
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   661
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   662
    __ BIND(miss);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   663
    __ load_const_optimized(Z_RET, 1); // One indicates a miss.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   664
    __ z_ltgr(Z_RET, Z_RET);           // Set NE flag in CR.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   665
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   666
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   667
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   668
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   669
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   670
  // Return address of code to be called from code generated by
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   671
  // MacroAssembler::verify_oop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   672
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   673
  // Don't generate, rather use C++ code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   674
  address generate_verify_oop_subroutine() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   675
    // Don't generate a StubCodeMark, because no code is generated!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   676
    // Generating the mark triggers notifying the oprofile jvmti agent
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   677
    // about the dynamic code generation, but the stub without
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   678
    // code (code_size == 0) confuses opjitconv
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   679
    // StubCodeMark mark(this, "StubRoutines", "verify_oop_stub");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   680
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   681
    address start = 0;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   682
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   683
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   684
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   685
  // This is to test that the count register contains a positive int value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   686
  // Required because C2 does not respect int to long conversion for stub calls.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   687
  void assert_positive_int(Register count) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   688
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   689
    __ z_srag(Z_R0, count, 31);  // Just leave the sign (must be zero) in Z_R0.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   690
    __ asm_assert_eq("missing zero extend", 0xAFFE);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   691
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   692
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   693
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   694
  //  Generate overlap test for array copy stubs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   695
  //  If no actual overlap is detected, control is transferred to the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   696
  //  "normal" copy stub (entry address passed in disjoint_copy_target).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   697
  //  Otherwise, execution continues with the code generated by the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   698
  //  caller of array_overlap_test.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   699
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   700
  //  Input:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   701
  //    Z_ARG1    - from
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   702
  //    Z_ARG2    - to
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   703
  //    Z_ARG3    - element count
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   704
  void array_overlap_test(address disjoint_copy_target, int log2_elem_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   705
    __ MacroAssembler::compare_and_branch_optimized(Z_ARG2, Z_ARG1, Assembler::bcondNotHigh,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   706
                                                    disjoint_copy_target, /*len64=*/true, /*has_sign=*/false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   707
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   708
    Register index = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   709
    if (log2_elem_size > 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   710
      __ z_sllg(Z_R1, Z_ARG3, log2_elem_size);  // byte count
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   711
      index = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   712
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   713
    __ add2reg_with_index(Z_R1, 0, index, Z_ARG1);  // First byte after "from" range.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   714
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   715
    __ MacroAssembler::compare_and_branch_optimized(Z_R1, Z_ARG2, Assembler::bcondNotHigh,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   716
                                                    disjoint_copy_target, /*len64=*/true, /*has_sign=*/false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   717
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   718
    // Destructive overlap: let caller generate code for that.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   719
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   720
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   721
  //  Generate stub for disjoint array copy. If "aligned" is true, the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   722
  //  "from" and "to" addresses are assumed to be heapword aligned.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   723
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   724
  //  Arguments for generated stub:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   725
  //      from:  Z_ARG1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   726
  //      to:    Z_ARG2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   727
  //      count: Z_ARG3 treated as signed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   728
  void generate_disjoint_copy(bool aligned, int element_size,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   729
                              bool branchToEnd,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   730
                              bool restoreArgs) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   731
    // This is the zarch specific stub generator for general array copy tasks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   732
    // It has the following prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   733
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   734
    // - No destructive overlap allowed (else unpredictable results).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   735
    // - Destructive overlap does not exist if the leftmost byte of the target
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   736
    //   does not coincide with any of the source bytes (except the leftmost).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   737
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   738
    //   Register usage upon entry:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   739
    //      Z_ARG1 == Z_R2 :   address of source array
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   740
    //      Z_ARG2 == Z_R3 :   address of target array
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   741
    //      Z_ARG3 == Z_R4 :   length of operands (# of elements on entry)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   742
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   743
    // Register usage within the generator:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   744
    // - Z_R0 and Z_R1 are KILLed by the stub routine (target addr/len).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   745
    //                 Used as pair register operand in complex moves, scratch registers anyway.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   746
    // - Z_R5 is KILLed by the stub routine (source register pair addr/len) (even/odd reg).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   747
    //                  Same as R0/R1, but no scratch register.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   748
    // - Z_ARG1, Z_ARG2, Z_ARG3 are USEd but preserved by the stub routine,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   749
    //                          but they might get temporarily overwritten.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   750
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   751
    Register  save_reg    = Z_ARG4;   // (= Z_R5), holds original target operand address for restore.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   752
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   753
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   754
      Register   llen_reg = Z_R1;     // Holds left operand len (odd reg).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   755
      Register  laddr_reg = Z_R0;     // Holds left operand addr (even reg), overlaps with data_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   756
      Register   rlen_reg = Z_R5;     // Holds right operand len (odd reg), overlaps with save_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   757
      Register  raddr_reg = Z_R4;     // Holds right operand addr (even reg), overlaps with len_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   758
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   759
      Register   data_reg = Z_R0;     // Holds copied data chunk in alignment process and copy loop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   760
      Register    len_reg = Z_ARG3;   // Holds operand len (#elements at entry, #bytes shortly after).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   761
      Register    dst_reg = Z_ARG2;   // Holds left (target)  operand addr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   762
      Register    src_reg = Z_ARG1;   // Holds right (source) operand addr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   763
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   764
      Label     doMVCLOOP, doMVCLOOPcount, doMVCLOOPiterate;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   765
      Label     doMVCUnrolled;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   766
      NearLabel doMVC,  doMVCgeneral, done;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   767
      Label     MVC_template;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   768
      address   pcMVCblock_b, pcMVCblock_e;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   769
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   770
      bool      usedMVCLE       = true;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   771
      bool      usedMVCLOOP     = true;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   772
      bool      usedMVCUnrolled = false;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   773
      bool      usedMVC         = false;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   774
      bool      usedMVCgeneral  = false;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   775
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   776
      int       stride;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   777
      Register  stride_reg;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   778
      Register  ix_reg;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   779
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   780
      assert((element_size<=256) && (256%element_size == 0), "element size must be <= 256, power of 2");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   781
      unsigned int log2_size = exact_log2(element_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   782
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   783
      switch (element_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   784
        case 1:  BLOCK_COMMENT("ARRAYCOPY DISJOINT byte  {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   785
        case 2:  BLOCK_COMMENT("ARRAYCOPY DISJOINT short {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   786
        case 4:  BLOCK_COMMENT("ARRAYCOPY DISJOINT int   {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   787
        case 8:  BLOCK_COMMENT("ARRAYCOPY DISJOINT long  {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   788
        default: BLOCK_COMMENT("ARRAYCOPY DISJOINT       {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   789
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   790
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   791
      assert_positive_int(len_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   792
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   793
      BLOCK_COMMENT("preparation {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   794
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   795
      // No copying if len <= 0.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   796
      if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   797
        __ compare64_and_branch(len_reg, (intptr_t) 0, Assembler::bcondNotHigh, done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   798
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   799
        if (VM_Version::has_CompareBranch()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   800
          __ z_cgib(len_reg, 0, Assembler::bcondNotHigh, 0, Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   801
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   802
          __ z_ltgr(len_reg, len_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   803
          __ z_bcr(Assembler::bcondNotPositive, Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   804
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   805
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   806
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   807
      // Prefetch just one cache line. Speculative opt for short arrays.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   808
      // Do not use Z_R1 in prefetch. Is undefined here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   809
      if (VM_Version::has_Prefetch()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   810
        __ z_pfd(0x01, 0, Z_R0, src_reg); // Fetch access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   811
        __ z_pfd(0x02, 0, Z_R0, dst_reg); // Store access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   812
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   813
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   814
      BLOCK_COMMENT("} preparation");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   815
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   816
      // Save args only if really needed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   817
      // Keep len test local to branch. Is generated only once.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   818
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   819
      BLOCK_COMMENT("mode selection {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   820
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   821
      // Special handling for arrays with only a few elements.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   822
      // Nothing fancy: just an executed MVC.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   823
      if (log2_size > 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   824
        __ z_sllg(Z_R1, len_reg, log2_size); // Remember #bytes in Z_R1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   825
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   826
      if (element_size != 8) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   827
        __ z_cghi(len_reg, 256/element_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   828
        __ z_brnh(doMVC);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   829
        usedMVC = true;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   830
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   831
      if (element_size == 8) { // Long and oop arrays are always aligned.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   832
        __ z_cghi(len_reg, 256/element_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   833
        __ z_brnh(doMVCUnrolled);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   834
        usedMVCUnrolled = true;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   835
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   836
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   837
      // Prefetch another cache line. We, for sure, have more than one line to copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   838
      if (VM_Version::has_Prefetch()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   839
        __ z_pfd(0x01, 256, Z_R0, src_reg); // Fetch access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   840
        __ z_pfd(0x02, 256, Z_R0, dst_reg); // Store access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   841
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   842
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   843
      if (restoreArgs) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   844
        // Remember entry value of ARG2 to restore all arguments later from that knowledge.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   845
        __ z_lgr(save_reg, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   846
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   847
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   848
      __ z_cghi(len_reg, 4096/element_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   849
      if (log2_size == 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   850
        __ z_lgr(Z_R1, len_reg); // Init Z_R1 with #bytes
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   851
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   852
      __ z_brnh(doMVCLOOP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   853
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   854
      // Fall through to MVCLE case.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   855
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   856
      BLOCK_COMMENT("} mode selection");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   857
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   858
      // MVCLE: for long arrays
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   859
      //   DW aligned: Best performance for sizes > 4kBytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   860
      //   unaligned:  Least complex for sizes > 256 bytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   861
      if (usedMVCLE) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   862
        BLOCK_COMMENT("mode MVCLE {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   863
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   864
        // Setup registers for mvcle.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   865
        //__ z_lgr(llen_reg, len_reg);// r1 <- r4  #bytes already in Z_R1, aka llen_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   866
        __ z_lgr(laddr_reg, dst_reg); // r0 <- r3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   867
        __ z_lgr(raddr_reg, src_reg); // r4 <- r2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   868
        __ z_lgr(rlen_reg, llen_reg); // r5 <- r1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   869
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   870
        __ MacroAssembler::move_long_ext(laddr_reg, raddr_reg, 0xb0);    // special: bypass cache
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   871
        // __ MacroAssembler::move_long_ext(laddr_reg, raddr_reg, 0xb8); // special: Hold data in cache.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   872
        // __ MacroAssembler::move_long_ext(laddr_reg, raddr_reg, 0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   873
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   874
        if (restoreArgs) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   875
          // MVCLE updates the source (Z_R4,Z_R5) and target (Z_R0,Z_R1) register pairs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   876
          // Dst_reg (Z_ARG2) and src_reg (Z_ARG1) are left untouched. No restore required.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   877
          // Len_reg (Z_ARG3) is destroyed and must be restored.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   878
          __ z_slgr(laddr_reg, dst_reg);    // copied #bytes
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   879
          if (log2_size > 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   880
            __ z_srag(Z_ARG3, laddr_reg, log2_size); // Convert back to #elements.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   881
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   882
            __ z_lgr(Z_ARG3, laddr_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   883
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   884
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   885
        if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   886
          __ z_bru(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   887
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   888
          __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   889
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   890
        BLOCK_COMMENT("} mode MVCLE");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   891
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   892
      // No fallthru possible here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   893
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   894
      //  MVCUnrolled: for short, aligned arrays.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   895
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   896
      if (usedMVCUnrolled) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   897
        BLOCK_COMMENT("mode MVC unrolled {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   898
        stride = 8;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   899
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   900
        // Generate unrolled MVC instructions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   901
        for (int ii = 32; ii > 1; ii--) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   902
          __ z_mvc(0, ii * stride-1, dst_reg, 0, src_reg); // ii*8 byte copy
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   903
          if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   904
            __ z_bru(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   905
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   906
            __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   907
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   908
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   909
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   910
        pcMVCblock_b = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   911
        __ z_mvc(0, 1 * stride-1, dst_reg, 0, src_reg); // 8 byte copy
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   912
        if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   913
          __ z_bru(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   914
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   915
          __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   916
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   917
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   918
        pcMVCblock_e = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   919
        Label MVC_ListEnd;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   920
        __ bind(MVC_ListEnd);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   921
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   922
        // This is an absolute fast path:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   923
        // - Array len in bytes must be not greater than 256.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   924
        // - Array len in bytes must be an integer mult of DW
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   925
        //   to save expensive handling of trailing bytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   926
        // - Argument restore is not done,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   927
        //   i.e. previous code must not alter arguments (this code doesn't either).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   928
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   929
        __ bind(doMVCUnrolled);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   930
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   931
        // Avoid mul, prefer shift where possible.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   932
        // Combine shift right (for #DW) with shift left (for block size).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   933
        // Set CC for zero test below (asm_assert).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   934
        // Note: #bytes comes in Z_R1, #DW in len_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   935
        unsigned int MVCblocksize    = pcMVCblock_e - pcMVCblock_b;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   936
        unsigned int logMVCblocksize = 0xffffffffU; // Pacify compiler ("used uninitialized" warning).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   937
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   938
        if (log2_size > 0) { // Len was scaled into Z_R1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   939
          switch (MVCblocksize) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   940
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   941
            case  8: logMVCblocksize = 3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   942
                     __ z_ltgr(Z_R0, Z_R1); // #bytes is index
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   943
                     break;                 // reasonable size, use shift
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   944
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   945
            case 16: logMVCblocksize = 4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   946
                     __ z_slag(Z_R0, Z_R1, logMVCblocksize-log2_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   947
                     break;                 // reasonable size, use shift
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   948
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   949
            default: logMVCblocksize = 0;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   950
                     __ z_ltgr(Z_R0, len_reg); // #DW for mul
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   951
                     break;                 // all other sizes: use mul
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   952
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   953
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   954
          guarantee(log2_size, "doMVCUnrolled: only for DW entities");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   955
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   956
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   957
        // This test (and branch) is redundant. Previous code makes sure that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   958
        //  - element count > 0
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   959
        //  - element size == 8.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   960
        // Thus, len reg should never be zero here. We insert an asm_assert() here,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   961
        // just to double-check and to be on the safe side.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   962
        __ asm_assert(false, "zero len cannot occur", 99);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   963
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   964
        __ z_larl(Z_R1, MVC_ListEnd);        // Get addr of last instr block.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   965
        // Avoid mul, prefer shift where possible.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   966
        if (logMVCblocksize == 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   967
          __ z_mghi(Z_R0, MVCblocksize);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   968
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   969
        __ z_slgr(Z_R1, Z_R0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   970
        __ z_br(Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   971
        BLOCK_COMMENT("} mode MVC unrolled");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   972
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   973
      // No fallthru possible here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   974
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   975
      // MVC execute template
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   976
      // Must always generate. Usage may be switched on below.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   977
      // There is no suitable place after here to put the template.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   978
      __ bind(MVC_template);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   979
      __ z_mvc(0,0,dst_reg,0,src_reg);      // Instr template, never exec directly!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   980
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   981
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   982
      // MVC Loop: for medium-sized arrays
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   983
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   984
      // Only for DW aligned arrays (src and dst).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   985
      // #bytes to copy must be at least 256!!!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   986
      // Non-aligned cases handled separately.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   987
      stride     = 256;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   988
      stride_reg = Z_R1;   // Holds #bytes when control arrives here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   989
      ix_reg     = Z_ARG3; // Alias for len_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   990
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   991
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   992
      if (usedMVCLOOP) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   993
        BLOCK_COMMENT("mode MVC loop {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   994
        __ bind(doMVCLOOP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   995
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   996
        __ z_lcgr(ix_reg, Z_R1);         // Ix runs from -(n-2)*stride to 1*stride (inclusive).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   997
        __ z_llill(stride_reg, stride);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   998
        __ add2reg(ix_reg, 2*stride);    // Thus: increment ix by 2*stride.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   999
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1000
        __ bind(doMVCLOOPiterate);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1001
          __ z_mvc(0, stride-1, dst_reg, 0, src_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1002
          __ add2reg(dst_reg, stride);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1003
          __ add2reg(src_reg, stride);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1004
          __ bind(doMVCLOOPcount);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1005
          __ z_brxlg(ix_reg, stride_reg, doMVCLOOPiterate);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1006
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1007
        // Don 't use add2reg() here, since we must set the condition code!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1008
        __ z_aghi(ix_reg, -2*stride);       // Compensate incr from above: zero diff means "all copied".
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1009
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1010
        if (restoreArgs) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1011
          __ z_lcgr(Z_R1, ix_reg);          // Prepare ix_reg for copy loop, #bytes expected in Z_R1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1012
          __ z_brnz(doMVCgeneral);          // We're not done yet, ix_reg is not zero.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1013
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1014
          // ARG1, ARG2, and ARG3 were altered by the code above, so restore them building on save_reg.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1015
          __ z_slgr(dst_reg, save_reg);     // copied #bytes
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1016
          __ z_slgr(src_reg, dst_reg);      // = ARG1 (now restored)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1017
          if (log2_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1018
            __ z_srag(Z_ARG3, dst_reg, log2_size); // Convert back to #elements to restore ARG3.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1019
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1020
            __ z_lgr(Z_ARG3, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1021
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1022
          __ z_lgr(Z_ARG2, save_reg);       // ARG2 now restored.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1023
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1024
          if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1025
            __ z_bru(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1026
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1027
            __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1028
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1029
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1030
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1031
            if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1032
              __ z_brz(done);                        // CC set by aghi instr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1033
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1034
              __ z_bcr(Assembler::bcondZero, Z_R14); // We're all done if zero.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1035
            }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1036
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1037
          __ z_lcgr(Z_R1, ix_reg);    // Prepare ix_reg for copy loop, #bytes expected in Z_R1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1038
          // __ z_bru(doMVCgeneral);  // fallthru
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1039
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1040
        usedMVCgeneral = true;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1041
        BLOCK_COMMENT("} mode MVC loop");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1042
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1043
      // Fallthru to doMVCgeneral
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1044
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1045
      // MVCgeneral: for short, unaligned arrays, after other copy operations
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1046
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1047
      // Somewhat expensive due to use of EX instruction, but simple.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1048
      if (usedMVCgeneral) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1049
        BLOCK_COMMENT("mode MVC general {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1050
        __ bind(doMVCgeneral);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1051
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1052
        __ add2reg(len_reg, -1, Z_R1);             // Get #bytes-1 for EXECUTE.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1053
        if (VM_Version::has_ExecuteExtensions()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1054
          __ z_exrl(len_reg, MVC_template);        // Execute MVC with variable length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1055
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1056
          __ z_larl(Z_R1, MVC_template);           // Get addr of instr template.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1057
          __ z_ex(len_reg, 0, Z_R0, Z_R1);         // Execute MVC with variable length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1058
        }                                          // penalty: 9 ticks
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1059
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1060
        if (restoreArgs) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1061
          // ARG1, ARG2, and ARG3 were altered by code executed before, so restore them building on save_reg
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1062
          __ z_slgr(dst_reg, save_reg);            // Copied #bytes without the "doMVCgeneral" chunk
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1063
          __ z_slgr(src_reg, dst_reg);             // = ARG1 (now restored), was not advanced for "doMVCgeneral" chunk
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1064
          __ add2reg_with_index(dst_reg, 1, len_reg, dst_reg); // Len of executed MVC was not accounted for, yet.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1065
          if (log2_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1066
            __ z_srag(Z_ARG3, dst_reg, log2_size); // Convert back to #elements to restore ARG3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1067
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1068
             __ z_lgr(Z_ARG3, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1069
          }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1070
          __ z_lgr(Z_ARG2, save_reg);              // ARG2 now restored.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1071
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1072
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1073
        if (usedMVC) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1074
          if (branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1075
            __ z_bru(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1076
          } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1077
            __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1078
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1079
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1080
          if (!branchToEnd) __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1081
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1082
        BLOCK_COMMENT("} mode MVC general");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1083
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1084
      // Fallthru possible if following block not generated.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1085
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1086
      // MVC: for short, unaligned arrays
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1087
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1088
      // Somewhat expensive due to use of EX instruction, but simple. penalty: 9 ticks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1089
      // Differs from doMVCgeneral in reconstruction of ARG2, ARG3, and ARG4.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1090
      if (usedMVC) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1091
        BLOCK_COMMENT("mode MVC {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1092
        __ bind(doMVC);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1093
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1094
        // get #bytes-1 for EXECUTE
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1095
        if (log2_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1096
          __ add2reg(Z_R1, -1);                // Length was scaled into Z_R1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1097
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1098
          __ add2reg(Z_R1, -1, len_reg);       // Length was not scaled.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1099
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1100
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1101
        if (VM_Version::has_ExecuteExtensions()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1102
          __ z_exrl(Z_R1, MVC_template);       // Execute MVC with variable length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1103
        } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1104
          __ z_lgr(Z_R0, Z_R5);                // Save ARG4, may be unnecessary.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1105
          __ z_larl(Z_R5, MVC_template);       // Get addr of instr template.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1106
          __ z_ex(Z_R1, 0, Z_R0, Z_R5);        // Execute MVC with variable length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1107
          __ z_lgr(Z_R5, Z_R0);                // Restore ARG4, may be unnecessary.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1108
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1109
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1110
        if (!branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1111
          __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1112
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1113
        BLOCK_COMMENT("} mode MVC");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1114
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1115
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1116
      __ bind(done);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1117
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1118
      switch (element_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1119
        case 1:  BLOCK_COMMENT("} ARRAYCOPY DISJOINT byte "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1120
        case 2:  BLOCK_COMMENT("} ARRAYCOPY DISJOINT short"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1121
        case 4:  BLOCK_COMMENT("} ARRAYCOPY DISJOINT int  "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1122
        case 8:  BLOCK_COMMENT("} ARRAYCOPY DISJOINT long "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1123
        default: BLOCK_COMMENT("} ARRAYCOPY DISJOINT      "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1124
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1125
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1126
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1127
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1128
  // Generate stub for conjoint array copy. If "aligned" is true, the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1129
  // "from" and "to" addresses are assumed to be heapword aligned.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1130
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1131
  // Arguments for generated stub:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1132
  //   from:  Z_ARG1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1133
  //   to:    Z_ARG2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1134
  //   count: Z_ARG3 treated as signed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1135
  void generate_conjoint_copy(bool aligned, int element_size, bool branchToEnd) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1136
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1137
    // This is the zarch specific stub generator for general array copy tasks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1138
    // It has the following prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1139
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1140
    // - Destructive overlap exists and is handled by reverse copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1141
    // - Destructive overlap exists if the leftmost byte of the target
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1142
    //   does coincide with any of the source bytes (except the leftmost).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1143
    // - Z_R0 and Z_R1 are KILLed by the stub routine (data and stride)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1144
    // - Z_ARG1 and Z_ARG2 are USEd but preserved by the stub routine.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1145
    // - Z_ARG3 is USED but preserved by the stub routine.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1146
    // - Z_ARG4 is used as index register and is thus KILLed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1147
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1148
    {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1149
      Register stride_reg = Z_R1;     // Stride & compare value in loop (negative element_size).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1150
      Register   data_reg = Z_R0;     // Holds value of currently processed element.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1151
      Register     ix_reg = Z_ARG4;   // Holds byte index of currently processed element.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1152
      Register    len_reg = Z_ARG3;   // Holds length (in #elements) of arrays.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1153
      Register    dst_reg = Z_ARG2;   // Holds left  operand addr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1154
      Register    src_reg = Z_ARG1;   // Holds right operand addr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1155
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1156
      assert(256%element_size == 0, "Element size must be power of 2.");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1157
      assert(element_size     <= 8, "Can't handle more than DW units.");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1158
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1159
      switch (element_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1160
        case 1:  BLOCK_COMMENT("ARRAYCOPY CONJOINT byte  {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1161
        case 2:  BLOCK_COMMENT("ARRAYCOPY CONJOINT short {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1162
        case 4:  BLOCK_COMMENT("ARRAYCOPY CONJOINT int   {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1163
        case 8:  BLOCK_COMMENT("ARRAYCOPY CONJOINT long  {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1164
        default: BLOCK_COMMENT("ARRAYCOPY CONJOINT       {"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1165
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1166
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1167
      assert_positive_int(len_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1168
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1169
      if (VM_Version::has_Prefetch()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1170
        __ z_pfd(0x01, 0, Z_R0, src_reg); // Fetch access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1171
        __ z_pfd(0x02, 0, Z_R0, dst_reg); // Store access.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1172
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1173
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1174
      unsigned int log2_size = exact_log2(element_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1175
      if (log2_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1176
        __ z_sllg(ix_reg, len_reg, log2_size);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1177
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1178
        __ z_lgr(ix_reg, len_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1179
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1180
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1181
      // Optimize reverse copy loop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1182
      // Main loop copies DW units which may be unaligned. Unaligned access adds some penalty ticks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1183
      // Unaligned DW access (neither fetch nor store) is DW-atomic, but should be alignment-atomic.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1184
      // Preceding the main loop, some bytes are copied to obtain a DW-multiple remaining length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1185
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1186
      Label countLoop1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1187
      Label copyLoop1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1188
      Label skipBY;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1189
      Label skipHW;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1190
      int   stride = -8;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1191
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1192
      __ load_const_optimized(stride_reg, stride); // Prepare for DW copy loop.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1193
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1194
      if (element_size == 8)    // Nothing to do here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1195
        __ z_bru(countLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1196
      else {                    // Do not generate dead code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1197
        __ z_tmll(ix_reg, 7);   // Check the "odd" bits.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1198
        __ z_bre(countLoop1);   // There are none, very good!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1199
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1200
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1201
      if (log2_size == 0) {     // Handle leftover Byte.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1202
        __ z_tmll(ix_reg, 1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1203
        __ z_bre(skipBY);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1204
        __ z_lb(data_reg,   -1, ix_reg, src_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1205
        __ z_stcy(data_reg, -1, ix_reg, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1206
        __ add2reg(ix_reg, -1); // Decrement delayed to avoid AGI.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1207
        __ bind(skipBY);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1208
        // fallthru
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1209
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1210
      if (log2_size <= 1) {     // Handle leftover HW.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1211
        __ z_tmll(ix_reg, 2);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1212
        __ z_bre(skipHW);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1213
        __ z_lhy(data_reg,  -2, ix_reg, src_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1214
        __ z_sthy(data_reg, -2, ix_reg, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1215
        __ add2reg(ix_reg, -2); // Decrement delayed to avoid AGI.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1216
        __ bind(skipHW);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1217
        __ z_tmll(ix_reg, 4);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1218
        __ z_bre(countLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1219
        // fallthru
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1220
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1221
      if (log2_size <= 2) {     // There are just 4 bytes (left) that need to be copied.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1222
        __ z_ly(data_reg,  -4, ix_reg, src_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1223
        __ z_sty(data_reg, -4, ix_reg, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1224
        __ add2reg(ix_reg, -4); // Decrement delayed to avoid AGI.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1225
        __ z_bru(countLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1226
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1227
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1228
      // Control can never get to here. Never! Never ever!
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1229
      __ z_illtrap(0x99);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1230
      __ bind(copyLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1231
      __ z_lg(data_reg,  0, ix_reg, src_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1232
      __ z_stg(data_reg, 0, ix_reg, dst_reg);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1233
      __ bind(countLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1234
      __ z_brxhg(ix_reg, stride_reg, copyLoop1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1235
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1236
      if (!branchToEnd)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1237
        __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1238
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1239
      switch (element_size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1240
        case 1:  BLOCK_COMMENT("} ARRAYCOPY CONJOINT byte "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1241
        case 2:  BLOCK_COMMENT("} ARRAYCOPY CONJOINT short"); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1242
        case 4:  BLOCK_COMMENT("} ARRAYCOPY CONJOINT int  "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1243
        case 8:  BLOCK_COMMENT("} ARRAYCOPY CONJOINT long "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1244
        default: BLOCK_COMMENT("} ARRAYCOPY CONJOINT      "); break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1245
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1246
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1247
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1248
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1249
  // Generate stub for disjoint byte copy. If "aligned" is true, the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1250
  // "from" and "to" addresses are assumed to be heapword aligned.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1251
  address generate_disjoint_byte_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1252
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1253
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1254
    // This is the zarch specific stub generator for byte array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1255
    // Refer to generate_disjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1256
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1257
    generate_disjoint_copy(aligned, 1, false, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1258
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1259
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1260
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1261
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1262
  address generate_disjoint_short_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1263
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1264
    // This is the zarch specific stub generator for short array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1265
    // Refer to generate_disjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1266
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1267
    generate_disjoint_copy(aligned, 2, false, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1268
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1269
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1270
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1271
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1272
  address generate_disjoint_int_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1273
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1274
    // This is the zarch specific stub generator for int array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1275
    // Refer to generate_disjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1276
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1277
    generate_disjoint_copy(aligned, 4, false, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1278
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1279
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1280
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1281
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1282
  address generate_disjoint_long_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1283
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1284
    // This is the zarch specific stub generator for long array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1285
    // Refer to generate_disjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1286
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1287
    generate_disjoint_copy(aligned, 8, false, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1288
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1289
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1290
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1291
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1292
  address generate_disjoint_oop_copy(bool aligned, const char * name, bool dest_uninitialized) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1293
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1294
    // This is the zarch specific stub generator for oop array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1295
    // Refer to generate_disjoint_copy for a list of prereqs and features.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1296
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1297
    unsigned int size      = UseCompressedOops ? 4 : 8;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1298
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1299
    DecoratorSet decorators = IN_HEAP | IS_ARRAY | ARRAYCOPY_DISJOINT;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1300
    if (dest_uninitialized) {
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1301
      decorators |= IS_DEST_UNINITIALIZED;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1302
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1303
    if (aligned) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1304
      decorators |= ARRAYCOPY_ALIGNED;
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1305
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1306
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49484
diff changeset
  1307
    BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1308
    bs->arraycopy_prologue(_masm, decorators, T_OBJECT, Z_ARG1, Z_ARG2, Z_ARG3);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1309
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1310
    generate_disjoint_copy(aligned, size, true, true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1311
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1312
    bs->arraycopy_epilogue(_masm, decorators, T_OBJECT, Z_ARG2, Z_ARG3, true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1313
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1314
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1315
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1316
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1317
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1318
  address generate_conjoint_byte_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1319
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1320
    // This is the zarch specific stub generator for overlapping byte array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1321
    // Refer to generate_conjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1322
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1323
    address nooverlap_target = aligned ? StubRoutines::arrayof_jbyte_disjoint_arraycopy()
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1324
                                       : StubRoutines::jbyte_disjoint_arraycopy();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1325
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1326
    array_overlap_test(nooverlap_target, 0); // Branch away to nooverlap_target if disjoint.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1327
    generate_conjoint_copy(aligned, 1, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1328
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1329
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1330
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1331
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1332
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1333
  address generate_conjoint_short_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1334
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1335
    // This is the zarch specific stub generator for overlapping short array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1336
    // Refer to generate_conjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1337
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1338
    address nooverlap_target = aligned ? StubRoutines::arrayof_jshort_disjoint_arraycopy()
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1339
                                       : StubRoutines::jshort_disjoint_arraycopy();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1340
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1341
    array_overlap_test(nooverlap_target, 1); // Branch away to nooverlap_target if disjoint.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1342
    generate_conjoint_copy(aligned, 2, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1343
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1344
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1345
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1346
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1347
  address generate_conjoint_int_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1348
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1349
    // This is the zarch specific stub generator for overlapping int array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1350
    // Refer to generate_conjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1351
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1352
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1353
    address nooverlap_target = aligned ? StubRoutines::arrayof_jint_disjoint_arraycopy()
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1354
                                       : StubRoutines::jint_disjoint_arraycopy();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1355
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1356
    array_overlap_test(nooverlap_target, 2); // Branch away to nooverlap_target if disjoint.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1357
    generate_conjoint_copy(aligned, 4, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1358
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1359
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1360
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1361
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1362
  address generate_conjoint_long_copy(bool aligned, const char * name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1363
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1364
    // This is the zarch specific stub generator for overlapping long array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1365
    // Refer to generate_conjoint_copy for a list of prereqs and features:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1366
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1367
    unsigned int start_off   = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1368
    address nooverlap_target = aligned ? StubRoutines::arrayof_jlong_disjoint_arraycopy()
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1369
                                       : StubRoutines::jlong_disjoint_arraycopy();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1370
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1371
    array_overlap_test(nooverlap_target, 3); // Branch away to nooverlap_target if disjoint.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1372
    generate_conjoint_copy(aligned, 8, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1373
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1374
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1375
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1376
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1377
  address generate_conjoint_oop_copy(bool aligned, const char * name, bool dest_uninitialized) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1378
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1379
    // This is the zarch specific stub generator for overlapping oop array copy.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1380
    // Refer to generate_conjoint_copy for a list of prereqs and features.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1381
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1382
    unsigned int size      = UseCompressedOops ? 4 : 8;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1383
    unsigned int shift     = UseCompressedOops ? 2 : 3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1384
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1385
    address nooverlap_target = aligned ? StubRoutines::arrayof_oop_disjoint_arraycopy(dest_uninitialized)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1386
                                       : StubRoutines::oop_disjoint_arraycopy(dest_uninitialized);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1387
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1388
    // Branch to disjoint_copy (if applicable) before pre_barrier to avoid double pre_barrier.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1389
    array_overlap_test(nooverlap_target, shift);  // Branch away to nooverlap_target if disjoint.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1390
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1391
    DecoratorSet decorators = IN_HEAP | IS_ARRAY;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1392
    if (dest_uninitialized) {
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1393
      decorators |= IS_DEST_UNINITIALIZED;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1394
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1395
    if (aligned) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1396
      decorators |= ARRAYCOPY_ALIGNED;
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1397
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1398
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49484
diff changeset
  1399
    BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1400
    bs->arraycopy_prologue(_masm, decorators, T_OBJECT, Z_ARG1, Z_ARG2, Z_ARG3);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1401
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1402
    generate_conjoint_copy(aligned, size, true);  // Must preserve ARG2, ARG3.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1403
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1404
    bs->arraycopy_epilogue(_masm, decorators, T_OBJECT, Z_ARG2, Z_ARG3, true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1405
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1406
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1407
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1408
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1409
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1410
  void generate_arraycopy_stubs() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1411
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1412
    // Note: the disjoint stubs must be generated first, some of
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1413
    // the conjoint stubs use them.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1414
    StubRoutines::_jbyte_disjoint_arraycopy      = generate_disjoint_byte_copy (false, "jbyte_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1415
    StubRoutines::_jshort_disjoint_arraycopy     = generate_disjoint_short_copy(false, "jshort_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1416
    StubRoutines::_jint_disjoint_arraycopy       = generate_disjoint_int_copy  (false, "jint_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1417
    StubRoutines::_jlong_disjoint_arraycopy      = generate_disjoint_long_copy (false, "jlong_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1418
    StubRoutines::_oop_disjoint_arraycopy        = generate_disjoint_oop_copy  (false, "oop_disjoint_arraycopy", false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1419
    StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy  (false, "oop_disjoint_arraycopy_uninit", true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1420
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1421
    StubRoutines::_arrayof_jbyte_disjoint_arraycopy      = generate_disjoint_byte_copy (true, "arrayof_jbyte_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1422
    StubRoutines::_arrayof_jshort_disjoint_arraycopy     = generate_disjoint_short_copy(true, "arrayof_jshort_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1423
    StubRoutines::_arrayof_jint_disjoint_arraycopy       = generate_disjoint_int_copy  (true, "arrayof_jint_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1424
    StubRoutines::_arrayof_jlong_disjoint_arraycopy      = generate_disjoint_long_copy (true, "arrayof_jlong_disjoint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1425
    StubRoutines::_arrayof_oop_disjoint_arraycopy        = generate_disjoint_oop_copy  (true, "arrayof_oop_disjoint_arraycopy", false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1426
    StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy  (true, "arrayof_oop_disjoint_arraycopy_uninit", true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1427
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1428
    StubRoutines::_jbyte_arraycopy           = generate_conjoint_byte_copy (false, "jbyte_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1429
    StubRoutines::_jshort_arraycopy          = generate_conjoint_short_copy(false, "jshort_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1430
    StubRoutines::_jint_arraycopy            = generate_conjoint_int_copy  (false, "jint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1431
    StubRoutines::_jlong_arraycopy           = generate_conjoint_long_copy (false, "jlong_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1432
    StubRoutines::_oop_arraycopy             = generate_conjoint_oop_copy  (false, "oop_arraycopy", false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1433
    StubRoutines::_oop_arraycopy_uninit      = generate_conjoint_oop_copy  (false, "oop_arraycopy_uninit", true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1434
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1435
    StubRoutines::_arrayof_jbyte_arraycopy      = generate_conjoint_byte_copy (true, "arrayof_jbyte_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1436
    StubRoutines::_arrayof_jshort_arraycopy     = generate_conjoint_short_copy(true, "arrayof_jshort_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1437
    StubRoutines::_arrayof_jint_arraycopy       = generate_conjoint_int_copy  (true, "arrayof_jint_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1438
    StubRoutines::_arrayof_jlong_arraycopy      = generate_conjoint_long_copy (true, "arrayof_jlong_arraycopy");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1439
    StubRoutines::_arrayof_oop_arraycopy        = generate_conjoint_oop_copy  (true, "arrayof_oop_arraycopy", false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1440
    StubRoutines::_arrayof_oop_arraycopy_uninit = generate_conjoint_oop_copy  (true, "arrayof_oop_arraycopy_uninit", true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1441
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1442
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1443
  void generate_safefetch(const char* name, int size, address* entry, address* fault_pc, address* continuation_pc) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1444
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1445
    // safefetch signatures:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1446
    //   int      SafeFetch32(int*      adr, int      errValue);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1447
    //   intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1448
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1449
    // arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1450
    //   Z_ARG1 = adr
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1451
    //   Z_ARG2 = errValue
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1452
    //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1453
    // result:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1454
    //   Z_RET  = *adr or errValue
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1455
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1456
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1457
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1458
    // entry point
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1459
    // Load *adr into Z_ARG2, may fault.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1460
    *entry = *fault_pc = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1461
    switch (size) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1462
      case 4:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1463
        // Sign extended int32_t.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1464
        __ z_lgf(Z_ARG2, 0, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1465
        break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1466
      case 8:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1467
        // int64_t
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1468
        __ z_lg(Z_ARG2, 0, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1469
        break;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1470
      default:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1471
        ShouldNotReachHere();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1472
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1473
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1474
    // Return errValue or *adr.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1475
    *continuation_pc = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1476
    __ z_lgr(Z_RET, Z_ARG2);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1477
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1478
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1479
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1480
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1481
  // Call interface for AES_encryptBlock, AES_decryptBlock stubs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1482
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1483
  //   Z_ARG1 - source data block. Ptr to leftmost byte to be processed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1484
  //   Z_ARG2 - destination data block. Ptr to leftmost byte to be stored.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1485
  //            For in-place encryption/decryption, ARG1 and ARG2 can point
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1486
  //            to the same piece of storage.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1487
  //   Z_ARG3 - Crypto key address (expanded key). The first n bits of
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1488
  //            the expanded key constitute the original AES-<n> key (see below).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1489
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1490
  //   Z_RET  - return value. First unprocessed byte offset in src buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1491
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1492
  // Some remarks:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1493
  //   The crypto key, as passed from the caller to these encryption stubs,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1494
  //   is a so-called expanded key. It is derived from the original key
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1495
  //   by the Rijndael key schedule, see http://en.wikipedia.org/wiki/Rijndael_key_schedule
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1496
  //   With the expanded key, the cipher/decipher task is decomposed in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1497
  //   multiple, less complex steps, called rounds. Sun SPARC and Intel
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1498
  //   processors obviously implement support for those less complex steps.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1499
  //   z/Architecture provides instructions for full cipher/decipher complexity.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1500
  //   Therefore, we need the original, not the expanded key here.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1501
  //   Luckily, the first n bits of an AES-<n> expanded key are formed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1502
  //   by the original key itself. That takes us out of trouble. :-)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1503
  //   The key length (in bytes) relation is as follows:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1504
  //     original    expanded   rounds  key bit     keylen
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1505
  //    key bytes   key bytes            length   in words
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1506
  //           16         176       11      128         44
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1507
  //           24         208       13      192         52
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1508
  //           32         240       15      256         60
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1509
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1510
  // The crypto instructions used in the AES* stubs have some specific register requirements.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1511
  //   Z_R0   holds the crypto function code. Please refer to the KM/KMC instruction
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1512
  //          description in the "z/Architecture Principles of Operation" manual for details.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1513
  //   Z_R1   holds the parameter block address. The parameter block contains the cryptographic key
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1514
  //          (KM instruction) and the chaining value (KMC instruction).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1515
  //   dst    must designate an even-numbered register, holding the address of the output message.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1516
  //   src    must designate an even/odd register pair, holding the address/length of the original message
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1517
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1518
  // Helper function which generates code to
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1519
  //  - load the function code in register fCode (== Z_R0).
46726
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
  1520
  //  - load the data block length (depends on cipher function) into register srclen if requested.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1521
  //  - is_decipher switches between cipher/decipher function codes
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1522
  //  - set_len requests (if true) loading the data block length in register srclen
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1523
  void generate_load_AES_fCode(Register keylen, Register fCode, Register srclen, bool is_decipher) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1524
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1525
    BLOCK_COMMENT("Set fCode {"); {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1526
      Label fCode_set;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1527
      int   mode = is_decipher ? VM_Version::CipherMode::decipher : VM_Version::CipherMode::cipher;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1528
      bool  identical_dataBlk_len =  (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES192_dataBlk)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1529
                                  && (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES256_dataBlk);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1530
      // Expanded key length is 44/52/60 * 4 bytes for AES-128/AES-192/AES-256.
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1531
      __ z_cghi(keylen, 52); // Check only once at the beginning. keylen and fCode may share the same register.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1532
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1533
      __ z_lghi(fCode, VM_Version::Cipher::_AES128 + mode);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1534
      if (!identical_dataBlk_len) {
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1535
        __ z_lghi(srclen, VM_Version::Cipher::_AES128_dataBlk);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1536
      }
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1537
      __ z_brl(fCode_set);  // keyLen <  52: AES128
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1538
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1539
      __ z_lghi(fCode, VM_Version::Cipher::_AES192 + mode);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1540
      if (!identical_dataBlk_len) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1541
        __ z_lghi(srclen, VM_Version::Cipher::_AES192_dataBlk);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1542
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1543
      __ z_bre(fCode_set);  // keyLen == 52: AES192
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1544
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1545
      __ z_lghi(fCode, VM_Version::Cipher::_AES256 + mode);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1546
      if (!identical_dataBlk_len) {
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1547
        __ z_lghi(srclen, VM_Version::Cipher::_AES256_dataBlk);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1548
      }
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1549
      // __ z_brh(fCode_set);  // keyLen <  52: AES128           // fallthru
46726
7801367e3cc9 8180659: [s390] micro-optimization in resize_frame_absolute()
lucy
parents: 46315
diff changeset
  1550
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1551
      __ bind(fCode_set);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1552
      if (identical_dataBlk_len) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1553
        __ z_lghi(srclen, VM_Version::Cipher::_AES128_dataBlk);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1554
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1555
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1556
    BLOCK_COMMENT("} Set fCode");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1557
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1558
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1559
  // Push a parameter block for the cipher/decipher instruction on the stack.
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1560
  // Layout of the additional stack space allocated for AES_cipherBlockChaining:
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1561
  //
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1562
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1563
  //   +--------+ <-- SP before expansion
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1564
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1565
  //   :        :  alignment loss, 0..(AES_parmBlk_align-8) bytes
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1566
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1567
  //   +--------+
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1568
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1569
  //   :        :  space for parameter block, size VM_Version::Cipher::_AES*_parmBlk_C
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1570
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1571
  //   +--------+ <-- parmBlk, octoword-aligned, start of parameter block
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1572
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1573
  //   :        :  additional stack space for spills etc., size AES_parmBlk_addspace, DW @ Z_SP not usable!!!
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1574
  //   |        |
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1575
  //   +--------+ <-- Z_SP after expansion
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1576
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1577
  void generate_push_Block(int dataBlk_len, int parmBlk_len, int crypto_fCode,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1578
                           Register parmBlk, Register keylen, Register fCode, Register cv, Register key) {
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1579
    const int AES_parmBlk_align    = 32;  // octoword alignment.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1580
    const int AES_parmBlk_addspace = 24;  // Must be sufficiently large to hold all spilled registers
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1581
                                          // (currently 2) PLUS 1 DW for the frame pointer.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1582
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1583
    const int cv_len     = dataBlk_len;
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1584
    const int key_len    = parmBlk_len - cv_len;
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1585
    // This len must be known at JIT compile time. Only then are we able to recalc the SP before resize.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1586
    // We buy this knowledge by wasting some (up to AES_parmBlk_align) bytes of stack space.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1587
    const int resize_len = cv_len + key_len + AES_parmBlk_align + AES_parmBlk_addspace;
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1588
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1589
    // Use parmBlk as temp reg here to hold the frame pointer.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1590
    __ resize_frame(-resize_len, parmBlk, true);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1591
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1592
    // calculate parmBlk address from updated (resized) SP.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1593
    __ add2reg(parmBlk, resize_len - (cv_len + key_len), Z_SP);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1594
    __ z_nill(parmBlk, (~(AES_parmBlk_align-1)) & 0xffff); // Align parameter block.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1595
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1596
    // There is room for stuff in the range [parmBlk-AES_parmBlk_addspace+8, parmBlk).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1597
    __ z_stg(keylen,  -8, parmBlk);                        // Spill keylen for later use.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1598
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1599
    // calculate (SP before resize) from updated SP.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1600
    __ add2reg(keylen, resize_len, Z_SP);                  // keylen holds prev SP for now.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1601
    __ z_stg(keylen, -16, parmBlk);                        // Spill prev SP for easy revert.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1602
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1603
    __ z_mvc(0,      cv_len-1,  parmBlk, 0, cv);     // Copy cv.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1604
    __ z_mvc(cv_len, key_len-1, parmBlk, 0, key);    // Copy key.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1605
    __ z_lghi(fCode, crypto_fCode);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1606
  }
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1607
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1608
  // NOTE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1609
  //   Before returning, the stub has to copy the chaining value from
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1610
  //   the parmBlk, where it was updated by the crypto instruction, back
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1611
  //   to the chaining value array the address of which was passed in the cv argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1612
  //   As all the available registers are used and modified by KMC, we need to save
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1613
  //   the key length across the KMC instruction. We do so by spilling it to the stack,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1614
  //   just preceding the parmBlk (at (parmBlk - 8)).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1615
  void generate_push_parmBlk(Register keylen, Register fCode, Register parmBlk, Register key, Register cv, bool is_decipher) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1616
    int       mode = is_decipher ? VM_Version::CipherMode::decipher : VM_Version::CipherMode::cipher;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1617
    Label     parmBlk_128, parmBlk_192, parmBlk_256, parmBlk_set;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1618
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1619
    BLOCK_COMMENT("push parmBlk {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1620
    if (VM_Version::has_Crypto_AES()   ) { __ z_cghi(keylen, 52); }
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1621
    if (VM_Version::has_Crypto_AES128()) { __ z_brl(parmBlk_128); }  // keyLen <  52: AES128
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1622
    if (VM_Version::has_Crypto_AES192()) { __ z_bre(parmBlk_192); }  // keyLen == 52: AES192
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1623
    if (VM_Version::has_Crypto_AES256()) { __ z_brh(parmBlk_256); }  // keyLen >  52: AES256
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1624
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1625
    // Security net: requested AES function not available on this CPU.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1626
    // NOTE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1627
    //   As of now (March 2015), this safety net is not required. JCE policy files limit the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1628
    //   cryptographic strength of the keys used to 128 bit. If we have AES hardware support
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1629
    //   at all, we have at least AES-128.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1630
    __ stop_static("AES key strength not supported by CPU. Use -XX:-UseAES as remedy.", 0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1631
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1632
    if (VM_Version::has_Crypto_AES256()) {
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1633
      __ bind(parmBlk_256);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1634
      generate_push_Block(VM_Version::Cipher::_AES256_dataBlk,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1635
                          VM_Version::Cipher::_AES256_parmBlk_C,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1636
                          VM_Version::Cipher::_AES256 + mode,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1637
                          parmBlk, keylen, fCode, cv, key);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1638
      if (VM_Version::has_Crypto_AES128() || VM_Version::has_Crypto_AES192()) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1639
        __ z_bru(parmBlk_set);  // Fallthru otherwise.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1640
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1641
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1642
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1643
    if (VM_Version::has_Crypto_AES192()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1644
      __ bind(parmBlk_192);
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1645
      generate_push_Block(VM_Version::Cipher::_AES192_dataBlk,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1646
                          VM_Version::Cipher::_AES192_parmBlk_C,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1647
                          VM_Version::Cipher::_AES192 + mode,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1648
                          parmBlk, keylen, fCode, cv, key);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1649
      if (VM_Version::has_Crypto_AES128()) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1650
        __ z_bru(parmBlk_set);  // Fallthru otherwise.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1651
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1652
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1653
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1654
    if (VM_Version::has_Crypto_AES128()) {
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1655
      __ bind(parmBlk_128);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1656
      generate_push_Block(VM_Version::Cipher::_AES128_dataBlk,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1657
                          VM_Version::Cipher::_AES128_parmBlk_C,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1658
                          VM_Version::Cipher::_AES128 + mode,
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1659
                          parmBlk, keylen, fCode, cv, key);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1660
      // Fallthru
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1661
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1662
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1663
    __ bind(parmBlk_set);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1664
    BLOCK_COMMENT("} push parmBlk");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1665
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1666
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1667
  // Pop a parameter block from the stack. The chaining value portion of the parameter block
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1668
  // is copied back to the cv array as it is needed for subsequent cipher steps.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1669
  // The keylen value as well as the original SP (before resizing) was pushed to the stack
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1670
  // when pushing the parameter block.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1671
  void generate_pop_parmBlk(Register keylen, Register parmBlk, Register key, Register cv) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1672
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1673
    BLOCK_COMMENT("pop parmBlk {");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1674
    bool identical_dataBlk_len =  (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES192_dataBlk) &&
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1675
                                  (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES256_dataBlk);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1676
    if (identical_dataBlk_len) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1677
      int cv_len = VM_Version::Cipher::_AES128_dataBlk;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1678
      __ z_mvc(0, cv_len-1, cv, 0, parmBlk);  // Copy cv.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1679
    } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1680
      int cv_len;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1681
      Label parmBlk_128, parmBlk_192, parmBlk_256, parmBlk_set;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1682
      __ z_lg(keylen, -8, parmBlk);  // restore keylen
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1683
      __ z_cghi(keylen, 52);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1684
      if (VM_Version::has_Crypto_AES256()) __ z_brh(parmBlk_256);  // keyLen >  52: AES256
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1685
      if (VM_Version::has_Crypto_AES192()) __ z_bre(parmBlk_192);  // keyLen == 52: AES192
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1686
      // if (VM_Version::has_Crypto_AES128()) __ z_brl(parmBlk_128);  // keyLen <  52: AES128  // fallthru
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1687
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1688
      // Security net: there is no one here. If we would need it, we should have
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1689
      // fallen into it already when pushing the parameter block.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1690
      if (VM_Version::has_Crypto_AES128()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1691
        __ bind(parmBlk_128);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1692
        cv_len = VM_Version::Cipher::_AES128_dataBlk;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1693
        __ z_mvc(0, cv_len-1, cv, 0, parmBlk);  // Copy cv.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1694
        if (VM_Version::has_Crypto_AES192() || VM_Version::has_Crypto_AES256()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1695
          __ z_bru(parmBlk_set);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1696
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1697
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1698
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1699
      if (VM_Version::has_Crypto_AES192()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1700
        __ bind(parmBlk_192);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1701
        cv_len = VM_Version::Cipher::_AES192_dataBlk;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1702
        __ z_mvc(0, cv_len-1, cv, 0, parmBlk);  // Copy cv.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1703
        if (VM_Version::has_Crypto_AES256()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1704
          __ z_bru(parmBlk_set);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1705
        }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1706
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1707
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1708
      if (VM_Version::has_Crypto_AES256()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1709
        __ bind(parmBlk_256);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1710
        cv_len = VM_Version::Cipher::_AES256_dataBlk;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1711
        __ z_mvc(0, cv_len-1, cv, 0, parmBlk);  // Copy cv.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1712
        // __ z_bru(parmBlk_set);  // fallthru
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1713
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1714
      __ bind(parmBlk_set);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1715
    }
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1716
    __ z_lg(Z_SP, -16, parmBlk); // Revert resize_frame_absolute. Z_SP saved by push_parmBlk.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1717
    BLOCK_COMMENT("} pop parmBlk");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1718
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1719
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1720
  // Compute AES encrypt/decrypt function.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1721
  void generate_AES_cipherBlock(bool is_decipher) {
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1722
    // Incoming arguments.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1723
    Register       from    = Z_ARG1; // source byte array
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1724
    Register       to      = Z_ARG2; // destination byte array
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1725
    Register       key     = Z_ARG3; // expanded key array
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1726
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1727
    const Register keylen  = Z_R0;   // Temporarily (until fCode is set) holds the expanded key array length.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1728
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1729
    // Register definitions as required by KM instruction.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1730
    const Register fCode   = Z_R0;   // crypto function code
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1731
    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1732
    const Register src     = Z_ARG1; // Must be even reg (KM requirement).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1733
    const Register srclen  = Z_ARG2; // Must be odd reg and pair with src. Overwrites destination address.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1734
    const Register dst     = Z_ARG3; // Must be even reg (KM requirement). Overwrites expanded key address.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1735
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1736
    // Read key len of expanded key (in 4-byte words).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1737
    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1738
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1739
    // Copy arguments to registers as required by crypto instruction.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1740
    __ z_lgr(parmBlk, key);          // crypto key (in T_INT array).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1741
    __ lgr_if_needed(src, from);     // Copy src address. Will not emit, src/from are identical.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1742
    __ z_lgr(dst, to);               // Copy dst address, even register required.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1743
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1744
    // Construct function code into fCode(Z_R0), data block length into srclen(Z_ARG2).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1745
    generate_load_AES_fCode(keylen, fCode, srclen, is_decipher);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1746
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1747
    __ km(dst, src);                 // Cipher the message.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1748
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1749
    __ z_br(Z_R14);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1750
  }
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1751
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1752
  // Compute AES encrypt function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1753
  address generate_AES_encryptBlock(const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1754
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1755
    StubCodeMark mark(this, "StubRoutines", name);
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1756
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1757
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1758
    generate_AES_cipherBlock(false);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1759
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1760
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1761
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1762
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1763
  // Compute AES decrypt function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1764
  address generate_AES_decryptBlock(const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1765
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1766
    StubCodeMark mark(this, "StubRoutines", name);
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1767
    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1768
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1769
    generate_AES_cipherBlock(true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1770
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1771
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1772
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1773
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1774
  // These stubs receive the addresses of the cryptographic key and of the chaining value as two separate
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1775
  // arguments (registers "key" and "cv", respectively). The KMC instruction, on the other hand, requires
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1776
  // chaining value and key to be, in this sequence, adjacent in storage. Thus, we need to allocate some
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1777
  // thread-local working storage. Using heap memory incurs all the hassles of allocating/freeing.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1778
  // Stack space, on the contrary, is deallocated automatically when we return from the stub to the caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1779
  // *** WARNING ***
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1780
  // Please note that we do not formally allocate stack space, nor do we
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1781
  // update the stack pointer. Therefore, no function calls are allowed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1782
  // and nobody else must use the stack range where the parameter block
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1783
  // is located.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1784
  // We align the parameter block to the next available octoword.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1785
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1786
  // Compute chained AES encrypt function.
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1787
  void generate_AES_cipherBlockChaining(bool is_decipher) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1788
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1789
    Register       from    = Z_ARG1; // source byte array (clear text)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1790
    Register       to      = Z_ARG2; // destination byte array (ciphered)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1791
    Register       key     = Z_ARG3; // expanded key array.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1792
    Register       cv      = Z_ARG4; // chaining value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1793
    const Register msglen  = Z_ARG5; // Total length of the msg to be encrypted. Value must be returned
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1794
                                     // in Z_RET upon completion of this stub. Is 32-bit integer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1795
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1796
    const Register keylen  = Z_R0;   // Expanded key length, as read from key array. Temp only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1797
    const Register fCode   = Z_R0;   // crypto function code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1798
    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1799
    const Register src     = Z_ARG1; // is Z_R2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1800
    const Register srclen  = Z_ARG2; // Overwrites destination address.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1801
    const Register dst     = Z_ARG3; // Overwrites key address.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1802
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1803
    // Read key len of expanded key (in 4-byte words).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1804
    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1805
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1806
    // Construct parm block address in parmBlk (== Z_R1), copy cv and key to parm block.
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1807
    // Construct function code in fCode (Z_R0).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1808
    generate_push_parmBlk(keylen, fCode, parmBlk, key, cv, is_decipher);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1809
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1810
    // Prepare other registers for instruction.
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1811
    __ lgr_if_needed(src, from);     // Copy src address. Will not emit, src/from are identical.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1812
    __ z_lgr(dst, to);
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1813
    __ z_llgfr(srclen, msglen);      // We pass the offsets as ints, not as longs as required.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1814
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1815
    __ kmc(dst, src);                // Cipher the message.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1816
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1817
    generate_pop_parmBlk(keylen, parmBlk, key, cv);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1818
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1819
    __ z_llgfr(Z_RET, msglen);       // We pass the offsets as ints, not as longs as required.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1820
    __ z_br(Z_R14);
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1821
  }
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1822
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1823
  // Compute chained AES encrypt function.
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1824
  address generate_cipherBlockChaining_AES_encrypt(const char* name) {
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1825
    __ align(CodeEntryAlignment);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1826
    StubCodeMark mark(this, "StubRoutines", name);
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1827
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1828
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1829
    generate_AES_cipherBlockChaining(false);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1830
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1831
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1832
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1833
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1834
  // Compute chained AES encrypt function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1835
  address generate_cipherBlockChaining_AES_decrypt(const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1836
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1837
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1838
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1839
46733
ff3f9838b730 8180823: [s390] Rework/optimize AES intrinsics
lucy
parents: 46726
diff changeset
  1840
    generate_AES_cipherBlockChaining(true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1841
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1842
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1843
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1844
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1845
53789
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1846
  // Compute GHASH function.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1847
  address generate_ghash_processBlocks() {
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1848
    __ align(CodeEntryAlignment);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1849
    StubCodeMark mark(this, "StubRoutines", "ghash_processBlocks");
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1850
    unsigned int start_off = __ offset();   // Remember stub start address (is rtn value).
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1851
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1852
    const Register state   = Z_ARG1;
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1853
    const Register subkeyH = Z_ARG2;
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1854
    const Register data    = Z_ARG3; // 1st of even-odd register pair.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1855
    const Register blocks  = Z_ARG4;
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1856
    const Register len     = blocks; // 2nd of even-odd register pair.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1857
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1858
    const int param_block_size = 4 * 8;
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1859
    const int frame_resize = param_block_size + 8; // Extra space for copy of fp.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1860
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1861
    // Reserve stack space for parameter block (R1).
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1862
    __ z_lgr(Z_R1, Z_SP);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1863
    __ resize_frame(-frame_resize, Z_R0, true);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1864
    __ z_aghi(Z_R1, -param_block_size);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1865
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1866
    // Fill parameter block.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1867
    __ z_mvc(Address(Z_R1)    , Address(state)  , 16);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1868
    __ z_mvc(Address(Z_R1, 16), Address(subkeyH), 16);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1869
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1870
    // R4+5: data pointer + length
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1871
    __ z_llgfr(len, blocks);  // Cast to 64-bit.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1872
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1873
    // R0: function code
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1874
    __ load_const_optimized(Z_R0, (int)VM_Version::MsgDigest::_GHASH);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1875
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1876
    // Compute.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1877
    __ z_sllg(len, len, 4);  // In bytes.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1878
    __ kimd(data);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1879
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1880
    // Copy back result and free parameter block.
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1881
    __ z_mvc(Address(state), Address(Z_R1), 16);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1882
    __ z_xc(Address(Z_R1), param_block_size, Address(Z_R1));
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1883
    __ z_aghi(Z_SP, frame_resize);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1884
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1885
    __ z_br(Z_R14);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1886
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1887
    return __ addr_at(start_off);
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1888
  }
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1889
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  1890
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1891
  // Call interface for all SHA* stubs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1892
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1893
  //   Z_ARG1 - source data block. Ptr to leftmost byte to be processed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1894
  //   Z_ARG2 - current SHA state. Ptr to state area. This area serves as
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1895
  //            parameter block as required by the crypto instruction.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1896
  //   Z_ARG3 - current byte offset in source data block.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1897
  //   Z_ARG4 - last byte offset in source data block.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1898
  //            (Z_ARG4 - Z_ARG3) gives the #bytes remaining to be processed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1899
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1900
  //   Z_RET  - return value. First unprocessed byte offset in src buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1901
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1902
  //   A few notes on the call interface:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1903
  //    - All stubs, whether they are single-block or multi-block, are assumed to
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1904
  //      digest an integer multiple of the data block length of data. All data
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1905
  //      blocks are digested using the intermediate message digest (KIMD) instruction.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1906
  //      Special end processing, as done by the KLMD instruction, seems to be
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1907
  //      emulated by the calling code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1908
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1909
  //    - Z_ARG1 addresses the first byte of source data. The offset (Z_ARG3) is
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1910
  //      already accounted for.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1911
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1912
  //    - The current SHA state (the intermediate message digest value) is contained
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1913
  //      in an area addressed by Z_ARG2. The area size depends on the SHA variant
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1914
  //      and is accessible via the enum VM_Version::MsgDigest::_SHA<n>_parmBlk_I
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1915
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1916
  //    - The single-block stub is expected to digest exactly one data block, starting
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1917
  //      at the address passed in Z_ARG1.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1918
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1919
  //    - The multi-block stub is expected to digest all data blocks which start in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1920
  //      the offset interval [srcOff(Z_ARG3), srcLimit(Z_ARG4)). The exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1921
  //      (srcLimit-srcOff), rounded up to the next multiple of the data block length,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1922
  //      gives the number of blocks to digest. It must be assumed that the calling code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1923
  //      provides for a large enough source data buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1924
  //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1925
  // Compute SHA-1 function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1926
  address generate_SHA1_stub(bool multiBlock, const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1927
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1928
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1929
    unsigned int start_off = __ offset();   // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1930
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1931
    const Register srcBuff        = Z_ARG1; // Points to first block to process (offset already added).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1932
    const Register SHAState       = Z_ARG2; // Only on entry. Reused soon thereafter for kimd register pairs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1933
    const Register srcOff         = Z_ARG3; // int
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1934
    const Register srcLimit       = Z_ARG4; // Only passed in multiBlock case. int
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1935
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1936
    const Register SHAState_local = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1937
    const Register SHAState_save  = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1938
    const Register srcBufLen      = Z_ARG2; // Destroys state address, must be copied before.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1939
    Label useKLMD, rtn;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1940
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1941
    __ load_const_optimized(Z_R0, (int)VM_Version::MsgDigest::_SHA1);   // function code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1942
    __ z_lgr(SHAState_local, SHAState);                                 // SHAState == parameter block
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1943
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1944
    if (multiBlock) {  // Process everything from offset to limit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1945
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1946
      // The following description is valid if we get a raw (unpimped) source data buffer,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1947
      // spanning the range between [srcOff(Z_ARG3), srcLimit(Z_ARG4)). As detailled above,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1948
      // the calling convention for these stubs is different. We leave the description in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1949
      // to inform the reader what must be happening hidden in the calling code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1950
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1951
      // The data block to be processed can have arbitrary length, i.e. its length does not
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1952
      // need to be an integer multiple of SHA<n>_datablk. Therefore, we need to implement
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1953
      // two different paths. If the length is an integer multiple, we use KIMD, saving us
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1954
      // to copy the SHA state back and forth. If the length is odd, we copy the SHA state
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1955
      // to the stack, execute a KLMD instruction on it and copy the result back to the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1956
      // caller's SHA state location.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1957
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1958
      // Total #srcBuff blocks to process.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1959
      if (VM_Version::has_DistinctOpnds()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1960
        __ z_srk(srcBufLen, srcLimit, srcOff); // exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1961
        __ z_ahi(srcBufLen, VM_Version::MsgDigest::_SHA1_dataBlk-1);   // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1962
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA1_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1963
        __ z_ark(srcLimit, srcOff, srcBufLen); // Srclimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1964
        __ z_llgfr(srcBufLen, srcBufLen);      // Cast to 64-bit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1965
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1966
        __ z_lgfr(srcBufLen, srcLimit);        // Exact difference. srcLimit passed as int.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1967
        __ z_sgfr(srcBufLen, srcOff);          // SrcOff passed as int, now properly casted to long.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1968
        __ z_aghi(srcBufLen, VM_Version::MsgDigest::_SHA1_dataBlk-1);   // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1969
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA1_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1970
        __ z_lgr(srcLimit, srcOff);            // SrcLimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1971
        __ z_agr(srcLimit, srcBufLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1972
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1973
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1974
      // Integral #blocks to digest?
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1975
      // As a result of the calculations above, srcBufLen MUST be an integer
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1976
      // multiple of _SHA1_dataBlk, or else we are in big trouble.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1977
      // We insert an asm_assert into the KLMD case to guard against that.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1978
      __ z_tmll(srcBufLen, VM_Version::MsgDigest::_SHA1_dataBlk-1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1979
      __ z_brc(Assembler::bcondNotAllZero, useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1980
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1981
      // Process all full blocks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1982
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1983
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1984
      __ z_lgr(Z_RET, srcLimit);  // Offset of first unprocessed byte in buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1985
    } else {  // Process one data block only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1986
      __ load_const_optimized(srcBufLen, (int)VM_Version::MsgDigest::_SHA1_dataBlk);   // #srcBuff bytes to process
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1987
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1988
      __ add2reg(Z_RET, (int)VM_Version::MsgDigest::_SHA1_dataBlk, srcOff);            // Offset of first unprocessed byte in buffer. No 32 to 64 bit extension needed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1989
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1990
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1991
    __ bind(rtn);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1992
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1993
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1994
    if (multiBlock) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1995
      __ bind(useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1996
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1997
#if 1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1998
      // Security net: this stub is believed to be called for full-sized data blocks only
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  1999
      // NOTE: The following code is believed to be correct, but is is not tested.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2000
      __ stop_static("SHA128 stub can digest full data blocks only. Use -XX:-UseSHA as remedy.", 0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2001
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2002
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2003
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2004
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2005
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2006
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2007
  // Compute SHA-256 function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2008
  address generate_SHA256_stub(bool multiBlock, const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2009
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2010
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2011
    unsigned int start_off = __ offset();   // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2012
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2013
    const Register srcBuff        = Z_ARG1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2014
    const Register SHAState       = Z_ARG2; // Only on entry. Reused soon thereafter.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2015
    const Register SHAState_local = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2016
    const Register SHAState_save  = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2017
    const Register srcOff         = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2018
    const Register srcLimit       = Z_ARG4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2019
    const Register srcBufLen      = Z_ARG2; // Destroys state address, must be copied before.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2020
    Label useKLMD, rtn;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2021
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2022
    __ load_const_optimized(Z_R0, (int)VM_Version::MsgDigest::_SHA256); // function code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2023
    __ z_lgr(SHAState_local, SHAState);                                 // SHAState == parameter block
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2024
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2025
    if (multiBlock) {  // Process everything from offset to limit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2026
      // The following description is valid if we get a raw (unpimped) source data buffer,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2027
      // spanning the range between [srcOff(Z_ARG3), srcLimit(Z_ARG4)). As detailled above,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2028
      // the calling convention for these stubs is different. We leave the description in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2029
      // to inform the reader what must be happening hidden in the calling code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2030
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2031
      // The data block to be processed can have arbitrary length, i.e. its length does not
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2032
      // need to be an integer multiple of SHA<n>_datablk. Therefore, we need to implement
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2033
      // two different paths. If the length is an integer multiple, we use KIMD, saving us
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2034
      // to copy the SHA state back and forth. If the length is odd, we copy the SHA state
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2035
      // to the stack, execute a KLMD instruction on it and copy the result back to the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2036
      // caller's SHA state location.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2037
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2038
      // total #srcBuff blocks to process
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2039
      if (VM_Version::has_DistinctOpnds()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2040
        __ z_srk(srcBufLen, srcLimit, srcOff);   // exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2041
        __ z_ahi(srcBufLen, VM_Version::MsgDigest::_SHA256_dataBlk-1); // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2042
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA256_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2043
        __ z_ark(srcLimit, srcOff, srcBufLen);   // Srclimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2044
        __ z_llgfr(srcBufLen, srcBufLen);        // Cast to 64-bit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2045
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2046
        __ z_lgfr(srcBufLen, srcLimit);          // exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2047
        __ z_sgfr(srcBufLen, srcOff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2048
        __ z_aghi(srcBufLen, VM_Version::MsgDigest::_SHA256_dataBlk-1); // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2049
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA256_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2050
        __ z_lgr(srcLimit, srcOff);              // Srclimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2051
        __ z_agr(srcLimit, srcBufLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2052
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2053
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2054
      // Integral #blocks to digest?
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2055
      // As a result of the calculations above, srcBufLen MUST be an integer
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2056
      // multiple of _SHA1_dataBlk, or else we are in big trouble.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2057
      // We insert an asm_assert into the KLMD case to guard against that.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2058
      __ z_tmll(srcBufLen, VM_Version::MsgDigest::_SHA256_dataBlk-1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2059
      __ z_brc(Assembler::bcondNotAllZero, useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2060
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2061
      // Process all full blocks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2062
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2063
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2064
      __ z_lgr(Z_RET, srcLimit);  // Offset of first unprocessed byte in buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2065
    } else {  // Process one data block only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2066
      __ load_const_optimized(srcBufLen, (int)VM_Version::MsgDigest::_SHA256_dataBlk); // #srcBuff bytes to process
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2067
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2068
      __ add2reg(Z_RET, (int)VM_Version::MsgDigest::_SHA256_dataBlk, srcOff);          // Offset of first unprocessed byte in buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2069
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2070
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2071
    __ bind(rtn);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2072
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2073
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2074
    if (multiBlock) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2075
      __ bind(useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2076
#if 1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2077
      // Security net: this stub is believed to be called for full-sized data blocks only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2078
      // NOTE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2079
      //   The following code is believed to be correct, but is is not tested.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2080
      __ stop_static("SHA256 stub can digest full data blocks only. Use -XX:-UseSHA as remedy.", 0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2081
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2082
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2083
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2084
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2085
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2086
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2087
  // Compute SHA-512 function.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2088
  address generate_SHA512_stub(bool multiBlock, const char* name) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2089
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2090
    StubCodeMark mark(this, "StubRoutines", name);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2091
    unsigned int start_off = __ offset();   // Remember stub start address (is rtn value).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2092
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2093
    const Register srcBuff        = Z_ARG1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2094
    const Register SHAState       = Z_ARG2; // Only on entry. Reused soon thereafter.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2095
    const Register SHAState_local = Z_R1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2096
    const Register SHAState_save  = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2097
    const Register srcOff         = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2098
    const Register srcLimit       = Z_ARG4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2099
    const Register srcBufLen      = Z_ARG2; // Destroys state address, must be copied before.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2100
    Label useKLMD, rtn;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2101
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2102
    __ load_const_optimized(Z_R0, (int)VM_Version::MsgDigest::_SHA512); // function code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2103
    __ z_lgr(SHAState_local, SHAState);                                 // SHAState == parameter block
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2104
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2105
    if (multiBlock) {  // Process everything from offset to limit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2106
      // The following description is valid if we get a raw (unpimped) source data buffer,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2107
      // spanning the range between [srcOff(Z_ARG3), srcLimit(Z_ARG4)). As detailled above,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2108
      // the calling convention for these stubs is different. We leave the description in
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2109
      // to inform the reader what must be happening hidden in the calling code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2110
      //
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2111
      // The data block to be processed can have arbitrary length, i.e. its length does not
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2112
      // need to be an integer multiple of SHA<n>_datablk. Therefore, we need to implement
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2113
      // two different paths. If the length is an integer multiple, we use KIMD, saving us
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2114
      // to copy the SHA state back and forth. If the length is odd, we copy the SHA state
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2115
      // to the stack, execute a KLMD instruction on it and copy the result back to the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2116
      // caller's SHA state location.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2117
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2118
      // total #srcBuff blocks to process
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2119
      if (VM_Version::has_DistinctOpnds()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2120
        __ z_srk(srcBufLen, srcLimit, srcOff);   // exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2121
        __ z_ahi(srcBufLen, VM_Version::MsgDigest::_SHA512_dataBlk-1); // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2122
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA512_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2123
        __ z_ark(srcLimit, srcOff, srcBufLen);   // Srclimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2124
        __ z_llgfr(srcBufLen, srcBufLen);        // Cast to 64-bit.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2125
      } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2126
        __ z_lgfr(srcBufLen, srcLimit);          // exact difference
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2127
        __ z_sgfr(srcBufLen, srcOff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2128
        __ z_aghi(srcBufLen, VM_Version::MsgDigest::_SHA512_dataBlk-1); // round up
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2129
        __ z_nill(srcBufLen, (~(VM_Version::MsgDigest::_SHA512_dataBlk-1)) & 0xffff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2130
        __ z_lgr(srcLimit, srcOff);              // Srclimit temporarily holds return value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2131
        __ z_agr(srcLimit, srcBufLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2132
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2133
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2134
      // integral #blocks to digest?
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2135
      // As a result of the calculations above, srcBufLen MUST be an integer
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2136
      // multiple of _SHA1_dataBlk, or else we are in big trouble.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2137
      // We insert an asm_assert into the KLMD case to guard against that.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2138
      __ z_tmll(srcBufLen, VM_Version::MsgDigest::_SHA512_dataBlk-1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2139
      __ z_brc(Assembler::bcondNotAllZero, useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2140
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2141
      // Process all full blocks.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2142
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2143
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2144
      __ z_lgr(Z_RET, srcLimit);  // Offset of first unprocessed byte in buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2145
    } else {  // Process one data block only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2146
      __ load_const_optimized(srcBufLen, (int)VM_Version::MsgDigest::_SHA512_dataBlk); // #srcBuff bytes to process
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2147
      __ kimd(srcBuff);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2148
      __ add2reg(Z_RET, (int)VM_Version::MsgDigest::_SHA512_dataBlk, srcOff);          // Offset of first unprocessed byte in buffer.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2149
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2150
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2151
    __ bind(rtn);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2152
    __ z_br(Z_R14);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2153
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2154
    if (multiBlock) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2155
      __ bind(useKLMD);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2156
#if 1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2157
      // Security net: this stub is believed to be called for full-sized data blocks only
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2158
      // NOTE:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2159
      //   The following code is believed to be correct, but is is not tested.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2160
      __ stop_static("SHA512 stub can digest full data blocks only. Use -XX:-UseSHA as remedy.", 0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2161
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2162
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2163
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2164
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2165
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2166
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2167
46315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2168
  /**
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2169
   *  Arguments:
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2170
   *
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2171
   * Inputs:
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2172
   *   Z_ARG1    - int   crc
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2173
   *   Z_ARG2    - byte* buf
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2174
   *   Z_ARG3    - int   length (of buffer)
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2175
   *
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2176
   * Result:
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2177
   *   Z_RET     - int   crc result
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2178
   **/
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2179
  // Compute CRC function (generic, for all polynomials).
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2180
  void generate_CRC_updateBytes(const char* name, Register table, bool invertCRC) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2181
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2182
    // arguments to kernel_crc32:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2183
    Register       crc     = Z_ARG1;  // Current checksum, preset by caller or result from previous call, int.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2184
    Register       data    = Z_ARG2;  // source byte array
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2185
    Register       dataLen = Z_ARG3;  // #bytes to process, int
46315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2186
//    Register       table   = Z_ARG4;  // crc table address. Preloaded and passed in by caller.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2187
    const Register t0      = Z_R10;   // work reg for kernel* emitters
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2188
    const Register t1      = Z_R11;   // work reg for kernel* emitters
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2189
    const Register t2      = Z_R12;   // work reg for kernel* emitters
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2190
    const Register t3      = Z_R13;   // work reg for kernel* emitters
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2191
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2192
    assert_different_registers(crc, data, dataLen, table);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2193
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2194
    // We pass these values as ints, not as longs as required by C calling convention.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2195
    // Crc used as int.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2196
    __ z_llgfr(dataLen, dataLen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2197
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2198
    __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2199
    __ z_stmg(Z_R10, Z_R13, 1*8, Z_SP);  // Spill regs 10..11 to make them available as work registers.
46315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2200
    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, invertCRC);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2201
    __ z_lmg(Z_R10, Z_R13, 1*8, Z_SP);   // Spill regs 10..11 back from stack.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2202
    __ resize_frame(+(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2203
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2204
    __ z_llgfr(Z_RET, crc);  // Updated crc is function result. No copying required, just zero upper 32 bits.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2205
    __ z_br(Z_R14);          // Result already in Z_RET == Z_ARG1.
46315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2206
  }
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2207
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2208
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2209
  // Compute CRC32 function.
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2210
  address generate_CRC32_updateBytes(const char* name) {
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2211
    __ align(CodeEntryAlignment);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2212
    StubCodeMark mark(this, "StubRoutines", name);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2213
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2214
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2215
    assert(UseCRC32Intrinsics, "should not generate this stub (%s) with CRC32 intrinsics disabled", name);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2216
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2217
    BLOCK_COMMENT("CRC32_updateBytes {");
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2218
    Register       table   = Z_ARG4;  // crc32 table address.
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2219
    StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2220
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2221
    generate_CRC_updateBytes(name, table, true);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2222
    BLOCK_COMMENT("} CRC32_updateBytes");
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2223
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2224
    return __ addr_at(start_off);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2225
  }
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2226
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2227
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2228
  // Compute CRC32C function.
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2229
  address generate_CRC32C_updateBytes(const char* name) {
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2230
    __ align(CodeEntryAlignment);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2231
    StubCodeMark mark(this, "StubRoutines", name);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2232
    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2233
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2234
    assert(UseCRC32CIntrinsics, "should not generate this stub (%s) with CRC32C intrinsics disabled", name);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2235
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2236
    BLOCK_COMMENT("CRC32C_updateBytes {");
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2237
    Register       table   = Z_ARG4;  // crc32c table address.
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2238
    StubRoutines::zarch::generate_load_crc32c_table_addr(_masm, table);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2239
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2240
    generate_CRC_updateBytes(name, table, false);
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2241
    BLOCK_COMMENT("} CRC32C_updateBytes");
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2242
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2243
    return __ addr_at(start_off);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2244
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2245
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2246
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2247
  // Arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2248
  //   Z_ARG1    - x address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2249
  //   Z_ARG2    - x length
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2250
  //   Z_ARG3    - y address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2251
  //   Z_ARG4    - y length
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2252
  //   Z_ARG5    - z address
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2253
  //   160[Z_SP] - z length
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2254
  address generate_multiplyToLen() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2255
    __ align(CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2256
    StubCodeMark mark(this, "StubRoutines", "multiplyToLen");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2257
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2258
    address start = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2259
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2260
    const Register x    = Z_ARG1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2261
    const Register xlen = Z_ARG2;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2262
    const Register y    = Z_ARG3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2263
    const Register ylen = Z_ARG4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2264
    const Register z    = Z_ARG5;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2265
    // zlen is passed on the stack:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2266
    // Address zlen(Z_SP, _z_abi(remaining_cargs));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2267
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2268
    // Next registers will be saved on stack in multiply_to_len().
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2269
    const Register tmp1 = Z_tmp_1;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2270
    const Register tmp2 = Z_tmp_2;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2271
    const Register tmp3 = Z_tmp_3;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2272
    const Register tmp4 = Z_tmp_4;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2273
    const Register tmp5 = Z_R9;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2274
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2275
    BLOCK_COMMENT("Entry:");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2276
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2277
    __ z_llgfr(xlen, xlen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2278
    __ z_llgfr(ylen, ylen);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2279
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2280
    __ multiply_to_len(x, xlen, y, ylen, z, tmp1, tmp2, tmp3, tmp4, tmp5);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2281
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2282
    __ z_br(Z_R14);  // Return to caller.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2283
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2284
    return start;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2285
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2286
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2287
  void generate_initial() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2288
    // Generates all stubs and initializes the entry points.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2289
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2290
    // Entry points that exist in all platforms.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2291
    // Note: This is code that could be shared among different
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2292
    // platforms - however the benefit seems to be smaller than the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2293
    // disadvantage of having a much more complicated generator
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2294
    // structure. See also comment in stubRoutines.hpp.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2295
    StubRoutines::_forward_exception_entry                 = generate_forward_exception();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2296
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2297
    StubRoutines::_call_stub_entry                         = generate_call_stub(StubRoutines::_call_stub_return_address);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2298
    StubRoutines::_catch_exception_entry                   = generate_catch_exception();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2299
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2300
    // Build this early so it's available for the interpreter.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2301
    StubRoutines::_throw_StackOverflowError_entry          =
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2302
      generate_throw_exception("StackOverflowError throw_exception",
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2303
                               CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false);
43420
a056d6465ef9 8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents: 42897
diff changeset
  2304
    StubRoutines::_throw_delayed_StackOverflowError_entry  =
a056d6465ef9 8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents: 42897
diff changeset
  2305
      generate_throw_exception("delayed StackOverflowError throw_exception",
a056d6465ef9 8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents: 42897
diff changeset
  2306
                               CAST_FROM_FN_PTR(address, SharedRuntime::throw_delayed_StackOverflowError), false);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2307
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2308
    //----------------------------------------------------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2309
    // Entry points that are platform specific.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2310
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2311
    if (UseCRC32Intrinsics) {
46315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2312
      StubRoutines::_crc_table_adr     = (address)StubRoutines::zarch::_crc_table;
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2313
      StubRoutines::_updateBytesCRC32  = generate_CRC32_updateBytes("CRC32_updateBytes");
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2314
    }
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2315
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2316
    if (UseCRC32CIntrinsics) {
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2317
      StubRoutines::_crc32c_table_addr = (address)StubRoutines::zarch::_crc32c_table;
a796c32af782 8175368: [s390] Provide intrinsic implementation for CRC32C
lucy
parents: 46289
diff changeset
  2318
      StubRoutines::_updateBytesCRC32C = generate_CRC32C_updateBytes("CRC32C_updateBytes");
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2319
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2320
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2321
    // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2322
    StubRoutines::zarch::_trot_table_addr = (address)StubRoutines::zarch::_trot_table;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2323
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2324
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2325
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2326
  void generate_all() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2327
    // Generates all stubs and initializes the entry points.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2328
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2329
    StubRoutines::zarch::_partial_subtype_check            = generate_partial_subtype_check();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2330
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2331
    // These entry points require SharedInfo::stack0 to be set up in non-core builds.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2332
    StubRoutines::_throw_AbstractMethodError_entry         = generate_throw_exception("AbstractMethodError throw_exception",          CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError),  false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2333
    StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError),  false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2334
    StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2335
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2336
    // Support for verify_oop (must happen after universe_init).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2337
    StubRoutines::_verify_oop_subroutine_entry             = generate_verify_oop_subroutine();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2338
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2339
    // Arraycopy stubs used by compilers.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2340
    generate_arraycopy_stubs();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2341
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2342
    // safefetch stubs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2343
    generate_safefetch("SafeFetch32", sizeof(int),      &StubRoutines::_safefetch32_entry, &StubRoutines::_safefetch32_fault_pc, &StubRoutines::_safefetch32_continuation_pc);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2344
    generate_safefetch("SafeFetchN",  sizeof(intptr_t), &StubRoutines::_safefetchN_entry,  &StubRoutines::_safefetchN_fault_pc,  &StubRoutines::_safefetchN_continuation_pc);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2345
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2346
    // Generate AES intrinsics code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2347
    if (UseAESIntrinsics) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2348
      StubRoutines::_aescrypt_encryptBlock = generate_AES_encryptBlock("AES_encryptBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2349
      StubRoutines::_aescrypt_decryptBlock = generate_AES_decryptBlock("AES_decryptBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2350
      StubRoutines::_cipherBlockChaining_encryptAESCrypt = generate_cipherBlockChaining_AES_encrypt("AES_encryptBlock_chaining");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2351
      StubRoutines::_cipherBlockChaining_decryptAESCrypt = generate_cipherBlockChaining_AES_decrypt("AES_decryptBlock_chaining");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2352
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2353
53789
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  2354
    // Generate GHASH intrinsics code
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  2355
    if (UseGHASHIntrinsics) {
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  2356
      StubRoutines::_ghash_processBlocks = generate_ghash_processBlocks();
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  2357
    }
b776653628c5 8218991: s390: Add intrinsic for GHASH algorithm
mdoerr
parents: 51756
diff changeset
  2358
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2359
    // Generate SHA1/SHA256/SHA512 intrinsics code.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2360
    if (UseSHA1Intrinsics) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2361
      StubRoutines::_sha1_implCompress     = generate_SHA1_stub(false,   "SHA1_singleBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2362
      StubRoutines::_sha1_implCompressMB   = generate_SHA1_stub(true,    "SHA1_multiBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2363
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2364
    if (UseSHA256Intrinsics) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2365
      StubRoutines::_sha256_implCompress   = generate_SHA256_stub(false, "SHA256_singleBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2366
      StubRoutines::_sha256_implCompressMB = generate_SHA256_stub(true,  "SHA256_multiBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2367
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2368
    if (UseSHA512Intrinsics) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2369
      StubRoutines::_sha512_implCompress   = generate_SHA512_stub(false, "SHA512_singleBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2370
      StubRoutines::_sha512_implCompressMB = generate_SHA512_stub(true,  "SHA512_multiBlock");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2371
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2372
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2373
#ifdef COMPILER2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2374
    if (UseMultiplyToLenIntrinsic) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2375
      StubRoutines::_multiplyToLen = generate_multiplyToLen();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2376
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2377
    if (UseMontgomeryMultiplyIntrinsic) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2378
      StubRoutines::_montgomeryMultiply
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2379
        = CAST_FROM_FN_PTR(address, SharedRuntime::montgomery_multiply);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2380
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2381
    if (UseMontgomerySquareIntrinsic) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2382
      StubRoutines::_montgomerySquare
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2383
        = CAST_FROM_FN_PTR(address, SharedRuntime::montgomery_square);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2384
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2385
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2386
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2387
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2388
 public:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2389
  StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2390
    // Replace the standard masm with a special one:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2391
    _masm = new MacroAssembler(code);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2392
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2393
    _stub_count = !all ? 0x100 : 0x200;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2394
    if (all) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2395
      generate_all();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2396
    } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2397
      generate_initial();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2398
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2399
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2400
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2401
 private:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2402
  int _stub_count;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2403
  void stub_prolog(StubCodeDesc* cdesc) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2404
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2405
    // Put extra information in the stub code, to make it more readable.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2406
    // Write the high part of the address.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2407
    // [RGV] Check if there is a dependency on the size of this prolog.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2408
    __ emit_32((intptr_t)cdesc >> 32);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2409
    __ emit_32((intptr_t)cdesc);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2410
    __ emit_32(++_stub_count);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2411
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2412
    align(true);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2413
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2414
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2415
  void align(bool at_header = false) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2416
    // z/Architecture cache line size is 256 bytes.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2417
    // There is no obvious benefit in aligning stub
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2418
    // code to cache lines. Use CodeEntryAlignment instead.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2419
    const unsigned int icache_line_size      = CodeEntryAlignment;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2420
    const unsigned int icache_half_line_size = MIN2<unsigned int>(32, CodeEntryAlignment);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2421
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2422
    if (at_header) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2423
      while ((intptr_t)(__ pc()) % icache_line_size != 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2424
        __ emit_16(0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2425
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2426
    } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2427
      while ((intptr_t)(__ pc()) % icache_half_line_size != 0) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2428
        __ z_nop();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2429
      }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2430
    }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2431
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2432
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2433
};
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2434
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2435
void StubGenerator_generate(CodeBuffer* code, bool all) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2436
  StubGenerator g(code, all);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
  2437
}