src/hotspot/cpu/x86/stubGenerator_x86_32.cpp
author redestad
Tue, 29 Jan 2019 14:34:26 +0100
changeset 53546 63eb7e38ce84
parent 51976 390f529f4f22
child 54534 66f5241da404
permissions -rw-r--r--
8217922: Compiler dead code removal Reviewed-by: thartmann, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53546
63eb7e38ce84 8217922: Compiler dead code removal
redestad
parents: 51976
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    25
#include "precompiled.hpp"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14132
diff changeset
    26
#include "asm/macroAssembler.hpp"
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14132
diff changeset
    27
#include "asm/macroAssembler.inline.hpp"
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    28
#include "gc/shared/barrierSet.hpp"
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    29
#include "gc/shared/barrierSetAssembler.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    30
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    31
#include "nativeInst_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    32
#include "oops/instanceOop.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    33
#include "oops/method.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    34
#include "oops/objArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    35
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    36
#include "prims/methodHandles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    37
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    38
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    39
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    40
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    41
#include "runtime/stubRoutines.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 14132
diff changeset
    42
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    43
#ifdef COMPILER2
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    44
#include "opto/runtime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    45
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// Declaration and definition of StubGenerator (no .hpp file).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// For a more detailed description of the stub routine structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// see the comment in stubRoutines.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
#define __ _masm->
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
    52
#define a__ ((Assembler*)_masm)->
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
#ifdef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
#define BLOCK_COMMENT(str) /* nothing */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
#define BLOCK_COMMENT(str) __ block_comment(str)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
const int MXCSR_MASK  = 0xFFC0;  // Mask out any pending exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
const int FPU_CNTRL_WRD_MASK = 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// -------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// Stub Code definitions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
class StubGenerator: public StubCodeGenerator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
#ifdef PRODUCT
18073
f02460441ddc 8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents: 17622
diff changeset
    72
#define inc_counter_np(counter) ((void)0)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void inc_counter_np_(int& counter) {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
    75
    __ incrementl(ExternalAddress((address)&counter));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
#define inc_counter_np(counter) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  BLOCK_COMMENT("inc_counter " #counter); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  inc_counter_np_(counter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  void inc_copy_counter_np(BasicType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    case T_BYTE:    inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    case T_SHORT:   inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    case T_INT:     inc_counter_np(SharedRuntime::_jint_array_copy_ctr); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    case T_LONG:    inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    case T_OBJECT:  inc_counter_np(SharedRuntime::_oop_array_copy_ctr); return;
51953
3aac38c47955 8211274: x86_32 build failures after JDK-8211029 (Have a common set of enabled warnings for all native libraries)
shade
parents: 50728
diff changeset
    90
    default:        ShouldNotReachHere();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Call stubs are used to call Java from C
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  //    [ return_from_Java     ] <--- rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //    [ argument word n      ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  //      ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // -N [ argument word 1      ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // -7 [ Possible padding for stack alignment ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // -6 [ Possible padding for stack alignment ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // -5 [ Possible padding for stack alignment ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // -4 [ mxcsr save           ] <--- rsp_after_call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // -3 [ saved rbx,            ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // -2 [ saved rsi            ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // -1 [ saved rdi            ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  //  0 [ saved rbp,            ] <--- rbp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  //  1 [ return address       ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  //  2 [ ptr. to call wrapper ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  //  3 [ result               ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  //  4 [ result_type          ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  //  5 [ method               ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  //  6 [ entry_point          ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  //  7 [ parameters           ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  //  8 [ parameter_size       ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  //  9 [ thread               ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  address generate_call_stub(address& return_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    StubCodeMark mark(this, "StubRoutines", "call_stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // stub code parameters / addresses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    bool  sse_save = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_catch_exception()!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    const int     locals_count_in_bytes  (4*wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    const Address mxcsr_save    (rbp, -4 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    const Address saved_rbx     (rbp, -3 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    const Address saved_rsi     (rbp, -2 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    const Address saved_rdi     (rbp, -1 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    const Address result        (rbp,  3 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    const Address result_type   (rbp,  4 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    const Address method        (rbp,  5 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    const Address entry_point   (rbp,  6 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    const Address parameters    (rbp,  7 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    const Address parameter_size(rbp,  8 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    const Address thread        (rbp,  9 * wordSize); // same as in generate_catch_exception()!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    sse_save =  UseSSE > 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // stub code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    __ enter();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   145
    __ movptr(rcx, parameter_size);              // parameter counter
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5252
diff changeset
   146
    __ shlptr(rcx, Interpreter::logStackElementSize); // convert parameter count to bytes
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   147
    __ addptr(rcx, locals_count_in_bytes);       // reserve space for register saves
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   148
    __ subptr(rsp, rcx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   149
    __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    // save rdi, rsi, & rbx, according to C calling conventions
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   152
    __ movptr(saved_rdi, rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   153
    __ movptr(saved_rsi, rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   154
    __ movptr(saved_rbx, rbx);
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 30299
diff changeset
   155
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    // save and initialize %mxcsr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (sse_save) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      Label skip_ldmx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      __ stmxcsr(mxcsr_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      __ movl(rax, mxcsr_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      __ andl(rax, MXCSR_MASK);    // Only check control and mask bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      __ cmp32(rax, mxcsr_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      __ jcc(Assembler::equal, skip_ldmx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      __ ldmxcsr(mxcsr_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      __ bind(skip_ldmx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // make sure the control word is correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // make sure we have no pending exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    { Label L;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   175
      __ movptr(rcx, thread);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   176
      __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      __ stop("StubRoutines::call_stub: entered with pending exception");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // pass parameters if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    BLOCK_COMMENT("pass parameters if any");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    Label parameters_done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    __ movl(rcx, parameter_size);  // parameter counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    __ testl(rcx, rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    __ jcc(Assembler::zero, parameters_done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // parameter passing loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    Label loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // Copy Java parameters in reverse order (receiver last)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // Note that the argument order is inverted in the process
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    // source is rdx[rcx: N-1..0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    // dest   is rsp[rbx: 0..N-1]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   198
    __ movptr(rdx, parameters);          // parameter pointer
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   199
    __ xorptr(rbx, rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    __ BIND(loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    // get parameter
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   204
    __ movptr(rax, Address(rdx, rcx, Interpreter::stackElementScale(), -wordSize));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   205
    __ movptr(Address(rsp, rbx, Interpreter::stackElementScale(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                    Interpreter::expr_offset_in_bytes(0)), rax);          // store parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    __ increment(rbx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    __ decrement(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    __ jcc(Assembler::notZero, loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    // call Java function
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    __ BIND(parameters_done);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   213
    __ movptr(rbx, method);           // get Method*
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   214
    __ movptr(rax, entry_point);      // get entry_point
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   215
    __ mov(rsi, rsp);                 // set sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    BLOCK_COMMENT("call Java function");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    __ call(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    BLOCK_COMMENT("call_stub_return_address:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    return_address = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
8315
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   222
#ifdef COMPILER2
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   223
    {
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   224
      Label L_skip;
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   225
      if (UseSSE >= 2) {
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   226
        __ verify_FPU(0, "call_stub_return");
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   227
      } else {
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   228
        for (int i = 1; i < 8; i++) {
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   229
          __ ffree(i);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   230
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
8315
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   232
        // UseSSE <= 1 so double result should be left on TOS
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   233
        __ movl(rsi, result_type);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   234
        __ cmpl(rsi, T_DOUBLE);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   235
        __ jcc(Assembler::equal, L_skip);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   236
        if (UseSSE == 0) {
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   237
          // UseSSE == 0 so float result should be left on TOS
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   238
          __ cmpl(rsi, T_FLOAT);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   239
          __ jcc(Assembler::equal, L_skip);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   240
        }
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   241
        __ ffree(0);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   242
      }
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   243
      __ BIND(L_skip);
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   244
    }
1503f9d7681f 7009309: JSR 292: compiler/6991596/Test6991596.java crashes on fastdebug JDK7/b122
twisti
parents: 7397
diff changeset
   245
#endif // COMPILER2
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    // store result depending on type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    // (everything that is not T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   249
    __ movptr(rdi, result);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    Label is_long, is_float, is_double, exit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    __ movl(rsi, result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    __ cmpl(rsi, T_LONG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    __ jcc(Assembler::equal, is_long);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    __ cmpl(rsi, T_FLOAT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    __ jcc(Assembler::equal, is_float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    __ cmpl(rsi, T_DOUBLE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    __ jcc(Assembler::equal, is_double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    // handle T_INT case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    __ movl(Address(rdi, 0), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    __ BIND(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    // check that FPU stack is empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    __ verify_FPU(0, "generate_call_stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // pop parameters
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   267
    __ lea(rsp, rsp_after_call);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    // restore %mxcsr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (sse_save) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      __ ldmxcsr(mxcsr_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    // restore rdi, rsi and rbx,
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   275
    __ movptr(rbx, saved_rbx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   276
    __ movptr(rsi, saved_rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   277
    __ movptr(rdi, saved_rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   278
    __ addptr(rsp, 4*wordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    // return
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   281
    __ pop(rbp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    // handle return types different from T_INT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    __ BIND(is_long);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    __ movl(Address(rdi, 0 * wordSize), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    __ movl(Address(rdi, 1 * wordSize), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    __ jmp(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    __ BIND(is_float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    // interpreter uses xmm0 for return values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    if (UseSSE >= 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      __ movflt(Address(rdi, 0), xmm0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      __ fstp_s(Address(rdi, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    __ jmp(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    __ BIND(is_double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    // interpreter uses xmm0 for return values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    if (UseSSE >= 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      __ movdbl(Address(rdi, 0), xmm0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      __ fstp_d(Address(rdi, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    __ jmp(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // Return point for a Java call if there's an exception thrown in Java code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // The exception is caught and transformed into a pending exception stored in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  // JavaThread that can be tested from within the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Note: Usually the parameters are removed by the callee. In case of an exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  //       crossing an activation frame boundary, that is not the case if the callee
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  //       is compiled code => need to setup the rsp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  // rax,: exception oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  address generate_catch_exception() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    StubCodeMark mark(this, "StubRoutines", "catch_exception");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_call_stub()!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    const Address thread        (rbp,  9 * wordSize); // same as in generate_call_stub()!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    // get thread directly
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   330
    __ movptr(rcx, thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    // verify that threads correspond
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      __ get_thread(rbx);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   335
      __ cmpptr(rbx, rcx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      __ stop("StubRoutines::catch_exception: threads must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // set pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    __ verify_oop(rax);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   343
    __ movptr(Address(rcx, Thread::pending_exception_offset()), rax          );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    __ lea(Address(rcx, Thread::exception_file_offset   ()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
           ExternalAddress((address)__FILE__));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    __ movl(Address(rcx, Thread::exception_line_offset   ()), __LINE__ );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    // complete return to VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    assert(StubRoutines::_call_stub_return_address != NULL, "_call_stub_return_address must have been generated before");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // Continuation point for runtime calls returning with a pending exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  // The pending exception check happened in the runtime or native call stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  // The pending exception in Thread is converted into a Java-level exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  // Contract with Java-level exception handlers:
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   361
  // rax: exception
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // rdx: throwing pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  // NOTE: At entry of this stub, exception-pc must be on stack !!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  address generate_forward_exception() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    StubCodeMark mark(this, "StubRoutines", "forward exception");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    address start = __ pc();
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   369
    const Register thread = rcx;
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   370
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   371
    // other registers used in this stub
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   372
    const Register exception_oop = rax;
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   373
    const Register handler_addr  = rbx;
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   374
    const Register exception_pc  = rdx;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // Upon entry, the sp points to the return address returning into Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // (interpreted or compiled) code; i.e., the return address becomes the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    // throwing pc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    // Arguments pushed before the runtime call are still on the stack but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    // the exception handler will reset the stack pointer -> ignore them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    // A potential result in registers can be ignored as well.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    // make sure this code is only executed if there is a pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    { Label L;
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   387
      __ get_thread(thread);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   388
      __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      __ stop("StubRoutines::forward exception: no pending exception (1)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    // compute exception handler into rbx,
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   396
    __ get_thread(thread);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   397
    __ movptr(exception_pc, Address(rsp, 0));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    BLOCK_COMMENT("call exception_handler_for_return_address");
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   399
    __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   400
    __ mov(handler_addr, rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   402
    // setup rax & rdx, remove return address & clear pending exception
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   403
    __ get_thread(thread);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   404
    __ pop(exception_pc);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   405
    __ movptr(exception_oop, Address(thread, Thread::pending_exception_offset()));
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   406
    __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    // make sure exception is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    { Label L;
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   411
      __ testptr(exception_oop, exception_oop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      __ stop("StubRoutines::forward exception: no pending exception (2)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   418
    // Verify that there is really a valid exception in RAX.
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   419
    __ verify_oop(exception_oop);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   420
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    // continue at exception handler (return address removed)
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   422
    // rax: exception
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   423
    // rbx: exception handler
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    // rdx: throwing pc
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4740
diff changeset
   425
    __ jmp(handler_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  //----------------------------------------------------------------------------------------------------
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47810
diff changeset
   432
  // Support for int32_t Atomic::xchg(int32_t exchange_value, volatile int32_t* dest)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  // xchg exists as far back as 8086, lock needed for MP only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  // Stack layout immediately after call:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  // 0 [ret addr ] <--- rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  // 1 [  ex     ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  // 2 [  dest   ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  // Result:   *dest <- ex, return (old *dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  // Note: win32 does not currently use this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  address generate_atomic_xchg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    StubCodeMark mark(this, "StubRoutines", "atomic_xchg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   449
    __ push(rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    Address exchange(rsp, 2 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    Address dest_addr(rsp, 3 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    __ movl(rax, exchange);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   453
    __ movptr(rdx, dest_addr);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   454
    __ xchgl(rax, Address(rdx, 0));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   455
    __ pop(rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  //----------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  // Support for void verify_mxcsr()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  // This routine is used with -Xcheck:jni to verify that native
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  // JNI code does not return to Java code without restoring the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  // MXCSR register to our expected state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  address generate_verify_mxcsr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    StubCodeMark mark(this, "StubRoutines", "verify_mxcsr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    const Address mxcsr_save(rsp, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    if (CheckJNICalls && UseSSE > 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
      Label ok_ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
      ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std());
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   478
      __ push(rax);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   479
      __ subptr(rsp, wordSize);      // allocate a temp location
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      __ stmxcsr(mxcsr_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      __ movl(rax, mxcsr_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
      __ andl(rax, MXCSR_MASK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
      __ cmp32(rax, mxcsr_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      __ jcc(Assembler::equal, ok_ret);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
      __ warn("MXCSR changed by native JNI code.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      __ ldmxcsr(mxcsr_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
      __ bind(ok_ret);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   491
      __ addptr(rsp, wordSize);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   492
      __ pop(rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // Support for void verify_fpu_cntrl_wrd()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  // This routine is used with -Xcheck:jni to verify that native
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  // JNI code does not return to Java code without restoring the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  // FP control word to our expected state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  address generate_verify_fpu_cntrl_wrd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    StubCodeMark mark(this, "StubRoutines", "verify_spcw");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    const Address fpu_cntrl_wrd_save(rsp, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    if (CheckJNICalls) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      Label ok_ret;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   516
      __ push(rax);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   517
      __ subptr(rsp, wordSize);      // allocate a temp location
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      __ fnstcw(fpu_cntrl_wrd_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      __ movl(rax, fpu_cntrl_wrd_save);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      __ andl(rax, FPU_CNTRL_WRD_MASK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      ExternalAddress fpu_std(StubRoutines::addr_fpu_cntrl_wrd_std());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      __ cmp32(rax, fpu_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      __ jcc(Assembler::equal, ok_ret);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      __ warn("Floating point control word changed by native JNI code.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      __ fldcw(fpu_std);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      __ bind(ok_ret);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   530
      __ addptr(rsp, wordSize);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   531
      __ pop(rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  // Wrapper for slow-case handling of double-to-integer conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  // d2i or f2i fast case failed either because it is nan or because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  // of under/overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // Input:  FPU TOS: float value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // Output: rax, (rdx): integer (long) result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  address generate_d2i_wrapper(BasicType t, address fcn) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    StubCodeMark mark(this, "StubRoutines", "d2i_wrapper");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  // Capture info about frame layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  enum layout { FPUState_off         = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
                rbp_off              = FPUStateSizeInWords,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
                rdi_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
                rsi_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
                rcx_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
                rbx_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
                saved_argument_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                saved_argument_off2, // 2nd half of double
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
                framesize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  assert(FPUStateSizeInWords == 27, "update stack layout");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    // Save outgoing argument to stack across push_FPU_state()
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   565
    __ subptr(rsp, wordSize * 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    __ fstp_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    // Save CPU & FPU state
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   569
    __ push(rbx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   570
    __ push(rcx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   571
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   572
    __ push(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   573
    __ push(rbp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    __ push_FPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    // push_FPU_state() resets the FP top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    // Load original double into FP top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    __ fld_d(Address(rsp, saved_argument_off * wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    // Store double into stack as outgoing argument
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   580
    __ subptr(rsp, wordSize*2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    __ fst_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    // Prepare FPU for doing math in C-land
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    __ empty_FPU_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    // Call the C code to massage the double.  Result in EAX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    if (t == T_INT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      { BLOCK_COMMENT("SharedRuntime::d2i"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    else if (t == T_LONG)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
      { BLOCK_COMMENT("SharedRuntime::d2l"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    __ call_VM_leaf( fcn, 2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    // Restore CPU & FPU state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    __ pop_FPU_state();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   594
    __ pop(rbp);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   595
    __ pop(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   596
    __ pop(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   597
    __ pop(rcx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   598
    __ pop(rbx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   599
    __ addptr(rsp, wordSize * 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  //----------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  // Non-destructive plausibility checks for oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  address generate_verify_oop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    StubCodeMark mark(this, "StubRoutines", "verify_oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    // Incoming arguments on stack after saving rax,:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    // [tos    ]: saved rdx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    // [tos + 1]: saved EFLAGS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    // [tos + 2]: return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    // [tos + 3]: char* error message
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    // [tos + 4]: oop   object to verify
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    // [tos + 5]: saved rax, - saved by caller and bashed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    Label exit, error;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   624
    __ pushf();
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   625
    __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr()));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   626
    __ push(rdx);                                // save rdx
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    // make sure object is 'reasonable'
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   628
    __ movptr(rax, Address(rsp, 4 * wordSize));    // get object
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   629
    __ testptr(rax, rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    __ jcc(Assembler::zero, exit);               // if obj is NULL it is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    // Check if the oop is in the right area of memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    const int oop_mask = Universe::verify_oop_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    const int oop_bits = Universe::verify_oop_bits();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   635
    __ mov(rdx, rax);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   636
    __ andptr(rdx, oop_mask);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   637
    __ cmpptr(rdx, oop_bits);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    __ jcc(Assembler::notZero, error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   640
    // make sure klass is 'reasonable', which is not zero.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   641
    __ movptr(rax, Address(rax, oopDesc::klass_offset_in_bytes())); // get klass
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   642
    __ testptr(rax, rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    __ jcc(Assembler::zero, error);              // if klass is NULL it is broken
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    // return if everything seems ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    __ bind(exit);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   647
    __ movptr(rax, Address(rsp, 5 * wordSize));  // get saved rax, back
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   648
    __ pop(rdx);                                 // restore rdx
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   649
    __ popf();                                   // restore EFLAGS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    __ ret(3 * wordSize);                        // pop arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    // handle errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    __ bind(error);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   654
    __ movptr(rax, Address(rsp, 5 * wordSize));  // get saved rax, back
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   655
    __ pop(rdx);                                 // get saved rdx back
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   656
    __ popf();                                   // get saved EFLAGS off stack -- will be ignored
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   657
    __ pusha();                                  // push registers (eip = return address & msg are already pushed)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    BLOCK_COMMENT("call MacroAssembler::debug");
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   659
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug32)));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   660
    __ popa();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    __ ret(3 * wordSize);                        // pop arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   665
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   666
  // Copy 64 bytes chunks
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   667
  //
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   668
  // Inputs:
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   669
  //   from        - source array address
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   670
  //   to_from     - destination array address - from
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   671
  //   qword_count - 8-bytes element count, negative
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   672
  //
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   673
  void xmm_copy_forward(Register from, Register to_from, Register qword_count) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   674
    assert( UseSSE >= 2, "supported cpu only" );
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   675
    Label L_copy_64_bytes_loop, L_copy_64_bytes, L_copy_8_bytes, L_exit;
51976
390f529f4f22 8211251: Default mask register for avx512 instructions
kvn
parents: 51953
diff changeset
   676
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   677
    // Copy 64-byte chunks
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   678
    __ jmpb(L_copy_64_bytes);
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
   679
    __ align(OptoLoopAlignment);
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   680
  __ BIND(L_copy_64_bytes_loop);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   681
15115
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   682
    if (UseUnalignedLoadStores) {
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 30299
diff changeset
   683
      if (UseAVX > 2) {
32727
320855c2baef 8132160: support for AVX 512 call frames and stack management
mcberg
parents: 32596
diff changeset
   684
        __ evmovdqul(xmm0, Address(from, 0), Assembler::AVX_512bit);
320855c2baef 8132160: support for AVX 512 call frames and stack management
mcberg
parents: 32596
diff changeset
   685
        __ evmovdqul(Address(from, to_from, Address::times_1, 0), xmm0, Assembler::AVX_512bit);
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 30299
diff changeset
   686
      } else if (UseAVX == 2) {
15115
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   687
        __ vmovdqu(xmm0, Address(from,  0));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   688
        __ vmovdqu(Address(from, to_from, Address::times_1,  0), xmm0);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   689
        __ vmovdqu(xmm1, Address(from, 32));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   690
        __ vmovdqu(Address(from, to_from, Address::times_1, 32), xmm1);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   691
      } else {
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   692
        __ movdqu(xmm0, Address(from, 0));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   693
        __ movdqu(Address(from, to_from, Address::times_1, 0), xmm0);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   694
        __ movdqu(xmm1, Address(from, 16));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   695
        __ movdqu(Address(from, to_from, Address::times_1, 16), xmm1);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   696
        __ movdqu(xmm2, Address(from, 32));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   697
        __ movdqu(Address(from, to_from, Address::times_1, 32), xmm2);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   698
        __ movdqu(xmm3, Address(from, 48));
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   699
        __ movdqu(Address(from, to_from, Address::times_1, 48), xmm3);
f8ef87f6f07f 8005544: Use 256bit YMM registers in arraycopy stubs on x86
kvn
parents: 14834
diff changeset
   700
      }
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   701
    } else {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   702
      __ movq(xmm0, Address(from, 0));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   703
      __ movq(Address(from, to_from, Address::times_1, 0), xmm0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   704
      __ movq(xmm1, Address(from, 8));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   705
      __ movq(Address(from, to_from, Address::times_1, 8), xmm1);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   706
      __ movq(xmm2, Address(from, 16));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   707
      __ movq(Address(from, to_from, Address::times_1, 16), xmm2);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   708
      __ movq(xmm3, Address(from, 24));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   709
      __ movq(Address(from, to_from, Address::times_1, 24), xmm3);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   710
      __ movq(xmm4, Address(from, 32));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   711
      __ movq(Address(from, to_from, Address::times_1, 32), xmm4);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   712
      __ movq(xmm5, Address(from, 40));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   713
      __ movq(Address(from, to_from, Address::times_1, 40), xmm5);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   714
      __ movq(xmm6, Address(from, 48));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   715
      __ movq(Address(from, to_from, Address::times_1, 48), xmm6);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   716
      __ movq(xmm7, Address(from, 56));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   717
      __ movq(Address(from, to_from, Address::times_1, 56), xmm7);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   718
    }
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   719
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   720
    __ addl(from, 64);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   721
  __ BIND(L_copy_64_bytes);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   722
    __ subl(qword_count, 8);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   723
    __ jcc(Assembler::greaterEqual, L_copy_64_bytes_loop);
16624
9dbd4b210bf9 8011102: Clear AVX registers after return from JNI call
kvn
parents: 15115
diff changeset
   724
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 30299
diff changeset
   725
    if (UseUnalignedLoadStores && (UseAVX == 2)) {
16624
9dbd4b210bf9 8011102: Clear AVX registers after return from JNI call
kvn
parents: 15115
diff changeset
   726
      // clean upper bits of YMM registers
30299
1f6f7d1e0c1e 8078113: 8011102 changes may cause incorrect results
kvn
parents: 29695
diff changeset
   727
      __ vpxor(xmm0, xmm0);
1f6f7d1e0c1e 8078113: 8011102 changes may cause incorrect results
kvn
parents: 29695
diff changeset
   728
      __ vpxor(xmm1, xmm1);
16624
9dbd4b210bf9 8011102: Clear AVX registers after return from JNI call
kvn
parents: 15115
diff changeset
   729
    }
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   730
    __ addl(qword_count, 8);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   731
    __ jccb(Assembler::zero, L_exit);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   732
    //
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   733
    // length is too short, just copy qwords
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   734
    //
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   735
  __ BIND(L_copy_8_bytes);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   736
    __ movq(xmm0, Address(from, 0));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   737
    __ movq(Address(from, to_from, Address::times_1), xmm0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   738
    __ addl(from, 8);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   739
    __ decrement(qword_count);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   740
    __ jcc(Assembler::greater, L_copy_8_bytes);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   741
  __ BIND(L_exit);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   742
  }
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   743
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  // Copy 64 bytes chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  // Inputs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  //   from        - source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  //   to_from     - destination array address - from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  //   qword_count - 8-bytes element count, negative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  void mmx_copy_forward(Register from, Register to_from, Register qword_count) {
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   752
    assert( VM_Version::supports_mmx(), "supported cpu only" );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    Label L_copy_64_bytes_loop, L_copy_64_bytes, L_copy_8_bytes, L_exit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    // Copy 64-byte chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    __ jmpb(L_copy_64_bytes);
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
   756
    __ align(OptoLoopAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  __ BIND(L_copy_64_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    __ movq(mmx0, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    __ movq(mmx1, Address(from, 8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    __ movq(mmx2, Address(from, 16));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    __ movq(Address(from, to_from, Address::times_1, 0), mmx0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    __ movq(mmx3, Address(from, 24));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    __ movq(Address(from, to_from, Address::times_1, 8), mmx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    __ movq(mmx4, Address(from, 32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    __ movq(Address(from, to_from, Address::times_1, 16), mmx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    __ movq(mmx5, Address(from, 40));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    __ movq(Address(from, to_from, Address::times_1, 24), mmx3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    __ movq(mmx6, Address(from, 48));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    __ movq(Address(from, to_from, Address::times_1, 32), mmx4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    __ movq(mmx7, Address(from, 56));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    __ movq(Address(from, to_from, Address::times_1, 40), mmx5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    __ movq(Address(from, to_from, Address::times_1, 48), mmx6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    __ movq(Address(from, to_from, Address::times_1, 56), mmx7);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   774
    __ addptr(from, 64);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  __ BIND(L_copy_64_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    __ subl(qword_count, 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    __ jcc(Assembler::greaterEqual, L_copy_64_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    __ addl(qword_count, 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    __ jccb(Assembler::zero, L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    // length is too short, just copy qwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  __ BIND(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    __ movq(mmx0, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    __ movq(Address(from, to_from, Address::times_1), mmx0);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   786
    __ addptr(from, 8);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    __ decrement(qword_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    __ jcc(Assembler::greater, L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  __ BIND(L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    __ emms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  address generate_disjoint_copy(BasicType t, bool aligned,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
                                 Address::ScaleFactor sf,
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
   795
                                 address* entry, const char *name,
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
   796
                                 bool dest_uninitialized = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    Label L_0_count, L_exit, L_skip_align1, L_skip_align2, L_copy_byte;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    Label L_copy_2_bytes, L_copy_4_bytes, L_copy_64_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   804
    int shift = Address::times_ptr - sf;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    const Register from     = rsi;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    const Register to       = rdi;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    const Register count    = rcx;  // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    const Register to_from  = to;   // (to - from)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    const Register saved_to = rdx;  // saved destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   813
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   814
    __ push(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   815
    __ movptr(from , Address(rsp, 12+ 4));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   816
    __ movptr(to   , Address(rsp, 12+ 8));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    __ movl(count, Address(rsp, 12+ 12));
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   818
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   819
    if (entry != NULL) {
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   820
      *entry = __ pc(); // Entry point from conjoint arraycopy stub.
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   821
      BLOCK_COMMENT("Entry:");
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   822
    }
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
   823
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    if (t == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      __ testl(count, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      __ jcc(Assembler::zero, L_0_count);
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   827
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   828
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
   829
    DecoratorSet decorators = IN_HEAP | IS_ARRAY | ARRAYCOPY_DISJOINT;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   830
    if (dest_uninitialized) {
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
   831
      decorators |= IS_DEST_UNINITIALIZED;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    }
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   833
    if (aligned) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   834
      decorators |= ARRAYCOPY_ALIGNED;
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   835
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   836
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49484
diff changeset
   837
    BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   838
    bs->arraycopy_prologue(_masm, decorators, t, from, to, count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   840
    __ subptr(to, from); // to --> to_from
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   843
    if (!UseUnalignedLoadStores && !aligned && (t == T_BYTE || t == T_SHORT)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
      // align source address at 4 bytes address boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      if (t == T_BYTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
        // One byte misalignment happens only for byte arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
        __ testl(from, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
        __ jccb(Assembler::zero, L_skip_align1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
        __ movb(rax, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
        __ movb(Address(from, to_from, Address::times_1, 0), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
        __ increment(from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
        __ decrement(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      __ BIND(L_skip_align1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      // Two bytes misalignment happens only for byte and short (char) arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
      __ testl(from, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
      __ jccb(Assembler::zero, L_skip_align2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      __ movw(rax, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      __ movw(Address(from, to_from, Address::times_1, 0), rax);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   860
      __ addptr(from, 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
      __ subl(count, 1<<(shift-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    __ BIND(L_skip_align2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    if (!VM_Version::supports_mmx()) {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   865
      __ mov(rax, count);      // save 'count'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   866
      __ shrl(count, shift); // bytes count
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   867
      __ addptr(to_from, from);// restore 'to'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   868
      __ rep_mov();
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   869
      __ subptr(to_from, from);// restore 'to_from'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   870
      __ mov(count, rax);      // restore 'count'
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
      __ jmpb(L_copy_2_bytes); // all dwords were copied
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    } else {
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   873
      if (!UseUnalignedLoadStores) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   874
        // align to 8 bytes, we know we are 4 byte aligned to start
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   875
        __ testptr(from, 4);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   876
        __ jccb(Assembler::zero, L_copy_64_bytes);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   877
        __ movl(rax, Address(from, 0));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   878
        __ movl(Address(from, to_from, Address::times_1, 0), rax);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   879
        __ addptr(from, 4);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   880
        __ subl(count, 1<<shift);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   881
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
    __ BIND(L_copy_64_bytes);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   883
      __ mov(rax, count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      __ shrl(rax, shift+1);  // 8 bytes chunk count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
      // Copy 8-byte chunks through MMX registers, 8 per iteration of the loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
      //
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   888
      if (UseXMMForArrayCopy) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   889
        xmm_copy_forward(from, to_from, rax);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   890
      } else {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   891
        mmx_copy_forward(from, to_from, rax);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
   892
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
    // copy tailing dword
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  __ BIND(L_copy_4_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    __ testl(count, 1<<shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    __ jccb(Assembler::zero, L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    __ movl(rax, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    __ movl(Address(from, to_from, Address::times_1, 0), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    if (t == T_BYTE || t == T_SHORT) {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   901
      __ addptr(from, 4);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    __ BIND(L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      // copy tailing word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
      __ testl(count, 1<<(shift-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      __ jccb(Assembler::zero, L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      __ movw(rax, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      __ movw(Address(from, to_from, Address::times_1, 0), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      if (t == T_BYTE) {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   909
        __ addptr(from, 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      __ BIND(L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
        // copy tailing byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
        __ testl(count, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
        __ jccb(Assembler::zero, L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
        __ movb(rax, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
        __ movb(Address(from, to_from, Address::times_1, 0), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
      __ BIND(L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
      __ BIND(L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
    __ BIND(L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   924
    __ movl(count, Address(rsp, 12+12)); // reread 'count'
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   925
    bs->arraycopy_epilogue(_masm, decorators, t, from, to, count);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   926
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    if (t == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    __ BIND(L_0_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    inc_copy_counter_np(t);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   931
    __ pop(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   932
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    __ leave(); // required for proper stackwalking of RuntimeStub frame
46440
61025eecb743 8178811: Minimize the AVX <-> SSE transition penalty through generation of vzeroupper instruction on x86
vdeshpande
parents: 42618
diff changeset
   934
    __ vzeroupper();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   935
    __ xorptr(rax, rax); // return 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
6433
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   941
  address generate_fill(BasicType t, bool aligned, const char *name) {
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   942
    __ align(CodeEntryAlignment);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   943
    StubCodeMark mark(this, "StubRoutines", name);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   944
    address start = __ pc();
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   945
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   946
    BLOCK_COMMENT("Entry:");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   947
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   948
    const Register to       = rdi;  // source array address
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   949
    const Register value    = rdx;  // value
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   950
    const Register count    = rsi;  // elements count
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   951
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   952
    __ enter(); // required for proper stackwalking of RuntimeStub frame
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   953
    __ push(rsi);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   954
    __ push(rdi);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   955
    __ movptr(to   , Address(rsp, 12+ 4));
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   956
    __ movl(value, Address(rsp, 12+ 8));
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   957
    __ movl(count, Address(rsp, 12+ 12));
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   958
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   959
    __ generate_fill(t, aligned, to, value, count, rax, xmm0);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   960
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   961
    __ pop(rdi);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   962
    __ pop(rsi);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   963
    __ leave(); // required for proper stackwalking of RuntimeStub frame
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   964
    __ ret(0);
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   965
    return start;
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   966
  }
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   967
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  address generate_conjoint_copy(BasicType t, bool aligned,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
                                 Address::ScaleFactor sf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
                                 address nooverlap_target,
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
   971
                                 address* entry, const char *name,
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
   972
                                 bool dest_uninitialized = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    Label L_0_count, L_exit, L_skip_align1, L_skip_align2, L_copy_byte;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    Label L_copy_2_bytes, L_copy_4_bytes, L_copy_8_bytes, L_copy_8_bytes_loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   980
    int shift = Address::times_ptr - sf;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    const Register src   = rax;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    const Register dst   = rdx;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    const Register from  = rsi;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    const Register to    = rdi;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    const Register count = rcx;  // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    const Register end   = rax;  // array end address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   990
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   991
    __ push(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   992
    __ movptr(src  , Address(rsp, 12+ 4));   // from
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   993
    __ movptr(dst  , Address(rsp, 12+ 8));   // to
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
   994
    __ movl2ptr(count, Address(rsp, 12+12)); // count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    if (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
      *entry = __ pc(); // Entry point from generic arraycopy stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
      BLOCK_COMMENT("Entry:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1001
    // nooverlap_target expects arguments in rsi and rdi.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1002
    __ mov(from, src);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1003
    __ mov(to  , dst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1005
    // arrays overlap test: dispatch to disjoint stub if necessary.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    RuntimeAddress nooverlap(nooverlap_target);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1007
    __ cmpptr(dst, src);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1008
    __ lea(end, Address(src, count, sf, 0)); // src + count * elem_size
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    __ jump_cc(Assembler::belowEqual, nooverlap);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1010
    __ cmpptr(dst, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    __ jump_cc(Assembler::aboveEqual, nooverlap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1013
    if (t == T_OBJECT) {
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1014
      __ testl(count, count);
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1015
      __ jcc(Assembler::zero, L_0_count);
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1016
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1017
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1018
    DecoratorSet decorators = IN_HEAP | IS_ARRAY;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1019
    if (dest_uninitialized) {
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1020
      decorators |= IS_DEST_UNINITIALIZED;
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1021
    }
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1022
    if (aligned) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1023
      decorators |= ARRAYCOPY_ALIGNED;
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1024
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1025
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49484
diff changeset
  1026
    BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1027
    bs->arraycopy_prologue(_masm, decorators, t, from, to, count);
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1028
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    // copy from high to low
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    if (t == T_BYTE || t == T_SHORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
      // Align the end of destination array at 4 bytes address boundary
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1034
      __ lea(end, Address(dst, count, sf, 0));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
      if (t == T_BYTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
        // One byte misalignment happens only for byte arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
        __ testl(end, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
        __ jccb(Assembler::zero, L_skip_align1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
        __ decrement(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
        __ movb(rdx, Address(from, count, sf, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
        __ movb(Address(to, count, sf, 0), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
      __ BIND(L_skip_align1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
      // Two bytes misalignment happens only for byte and short (char) arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
      __ testl(end, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
      __ jccb(Assembler::zero, L_skip_align2);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1047
      __ subptr(count, 1<<(shift-1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
      __ movw(rdx, Address(from, count, sf, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
      __ movw(Address(to, count, sf, 0), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    __ BIND(L_skip_align2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
      __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
      __ jcc(Assembler::below, L_copy_4_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    if (!VM_Version::supports_mmx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
      __ std();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1057
      __ mov(rax, count); // Save 'count'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1058
      __ mov(rdx, to);    // Save 'to'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1059
      __ lea(rsi, Address(from, count, sf, -4));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1060
      __ lea(rdi, Address(to  , count, sf, -4));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1061
      __ shrptr(count, shift); // bytes count
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1062
      __ rep_mov();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
      __ cld();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1064
      __ mov(count, rax); // restore 'count'
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
      __ andl(count, (1<<shift)-1);      // mask the number of rest elements
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1066
      __ movptr(from, Address(rsp, 12+4)); // reread 'from'
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1067
      __ mov(to, rdx);   // restore 'to'
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
      __ jmpb(L_copy_2_bytes); // all dword were copied
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
   } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
      // Align to 8 bytes the end of array. It is aligned to 4 bytes already.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1071
      __ testptr(end, 4);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
      __ jccb(Assembler::zero, L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
      __ subl(count, 1<<shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
      __ movl(rdx, Address(from, count, sf, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
      __ movl(Address(to, count, sf, 0), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
      __ jmpb(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
  1078
      __ align(OptoLoopAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
      // Move 8 bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    __ BIND(L_copy_8_bytes_loop);
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1081
      if (UseXMMForArrayCopy) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1082
        __ movq(xmm0, Address(from, count, sf, 0));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1083
        __ movq(Address(to, count, sf, 0), xmm0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1084
      } else {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1085
        __ movq(mmx0, Address(from, count, sf, 0));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1086
        __ movq(Address(to, count, sf, 0), mmx0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1087
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    __ BIND(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
      __ subl(count, 2<<shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
      __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
      __ addl(count, 2<<shift);
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1092
      if (!UseXMMForArrayCopy) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1093
        __ emms();
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1094
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  __ BIND(L_copy_4_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    // copy prefix qword
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
    __ testl(count, 1<<shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
    __ jccb(Assembler::zero, L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
    __ movl(rdx, Address(from, count, sf, -4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
    __ movl(Address(to, count, sf, -4), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    if (t == T_BYTE || t == T_SHORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
        __ subl(count, (1<<shift));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
      __ BIND(L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
        // copy prefix dword
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
        __ testl(count, 1<<(shift-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
        __ jccb(Assembler::zero, L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
        __ movw(rdx, Address(from, count, sf, -2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
        __ movw(Address(to, count, sf, -2), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
        if (t == T_BYTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
          __ subl(count, 1<<(shift-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
        __ BIND(L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
          // copy prefix byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
          __ testl(count, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
          __ jccb(Assembler::zero, L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
          __ movb(rdx, Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
          __ movb(Address(to, 0), rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
        __ BIND(L_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
        __ BIND(L_copy_byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    __ BIND(L_copy_2_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
    }
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1126
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1127
    __ movl2ptr(count, Address(rsp, 12+12)); // reread count
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1128
    bs->arraycopy_epilogue(_masm, decorators, t, from, to, count);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1129
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    if (t == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    __ BIND(L_0_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    inc_copy_counter_np(t);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1134
    __ pop(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1135
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    __ leave(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1137
    __ xorptr(rax, rax); // return 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
  address generate_disjoint_long_copy(address* entry, const char *name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    Label L_copy_8_bytes, L_copy_8_bytes_loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    const Register from       = rax;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    const Register to         = rdx;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
    const Register count      = rcx;  // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    const Register to_from    = rdx;  // (to - from)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1155
    __ movptr(from , Address(rsp, 8+0));       // from
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1156
    __ movptr(to   , Address(rsp, 8+4));       // to
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1157
    __ movl2ptr(count, Address(rsp, 8+8));     // count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    *entry = __ pc(); // Entry point from conjoint arraycopy stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
    BLOCK_COMMENT("Entry:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1162
    __ subptr(to, from); // to --> to_from
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    if (VM_Version::supports_mmx()) {
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1164
      if (UseXMMForArrayCopy) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1165
        xmm_copy_forward(from, to_from, count);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1166
      } else {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1167
        mmx_copy_forward(from, to_from, count);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1168
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
      __ jmpb(L_copy_8_bytes);
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
  1171
      __ align(OptoLoopAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    __ BIND(L_copy_8_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
      __ fild_d(Address(from, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
      __ fistp_d(Address(from, to_from, Address::times_1));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1175
      __ addptr(from, 8);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
    __ BIND(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
      __ decrement(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
      __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    inc_copy_counter_np(T_LONG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
    __ leave(); // required for proper stackwalking of RuntimeStub frame
46440
61025eecb743 8178811: Minimize the AVX <-> SSE transition penalty through generation of vzeroupper instruction on x86
vdeshpande
parents: 42618
diff changeset
  1182
    __ vzeroupper();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1183
    __ xorptr(rax, rax); // return 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  address generate_conjoint_long_copy(address nooverlap_target,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
                                      address* entry, const char *name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
    Label L_copy_8_bytes, L_copy_8_bytes_loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    const Register from       = rax;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    const Register to         = rdx;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    const Register count      = rcx;  // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    const Register end_from   = rax;  // source array end address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1201
    __ movptr(from , Address(rsp, 8+0));       // from
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1202
    __ movptr(to   , Address(rsp, 8+4));       // to
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1203
    __ movl2ptr(count, Address(rsp, 8+8));     // count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    *entry = __ pc(); // Entry point from generic arraycopy stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    BLOCK_COMMENT("Entry:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    // arrays overlap test
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1209
    __ cmpptr(to, from);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
    RuntimeAddress nooverlap(nooverlap_target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    __ jump_cc(Assembler::belowEqual, nooverlap);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1212
    __ lea(end_from, Address(from, count, Address::times_8, 0));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1213
    __ cmpptr(to, end_from);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1214
    __ movptr(from, Address(rsp, 8));  // from
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    __ jump_cc(Assembler::aboveEqual, nooverlap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    __ jmpb(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
  1219
    __ align(OptoLoopAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
  __ BIND(L_copy_8_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    if (VM_Version::supports_mmx()) {
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1222
      if (UseXMMForArrayCopy) {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1223
        __ movq(xmm0, Address(from, count, Address::times_8));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1224
        __ movq(Address(to, count, Address::times_8), xmm0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1225
      } else {
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1226
        __ movq(mmx0, Address(from, count, Address::times_8));
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1227
        __ movq(Address(to, count, Address::times_8), mmx0);
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1228
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
      __ fild_d(Address(from, count, Address::times_8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
      __ fistp_d(Address(to, count, Address::times_8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
  __ BIND(L_copy_8_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    __ decrement(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
1437
d1846c1c04c4 6532536: Optimize arraycopy stubs for Intel cpus
kvn
parents: 1394
diff changeset
  1237
    if (VM_Version::supports_mmx() && !UseXMMForArrayCopy) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
      __ emms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
    inc_copy_counter_np(T_LONG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    __ leave(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1242
    __ xorptr(rax, rax); // return 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
  // Helper for generating a dynamic type check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  // The sub_klass must be one of {rbx, rdx, rsi}.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  // The temp is killed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  void generate_type_check(Register sub_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
                           Address& super_check_offset_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
                           Address& super_klass_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
                           Register temp,
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1255
                           Label* L_success, Label* L_failure) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
    BLOCK_COMMENT("type_check:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    Label L_fallthrough;
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1259
#define LOCAL_JCC(assembler_con, label_ptr)                             \
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1260
    if (label_ptr != NULL)  __ jcc(assembler_con, *(label_ptr));        \
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1261
    else                    __ jcc(assembler_con, L_fallthrough) /*omit semi*/
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1263
    // The following is a strange variation of the fast path which requires
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1264
    // one less register, because needed values are on the argument stack.
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1265
    // __ check_klass_subtype_fast_path(sub_klass, *super_klass*, temp,
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1266
    //                                  L_success, L_failure, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    assert_different_registers(sub_klass, temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
11430
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 10565
diff changeset
  1269
    int sc_offset = in_bytes(Klass::secondary_super_cache_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    // if the pointers are equal, we are done (e.g., String[] elements)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1272
    __ cmpptr(sub_klass, super_klass_addr);
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1273
    LOCAL_JCC(Assembler::equal, L_success);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    // check the supertype display:
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1276
    __ movl2ptr(temp, super_check_offset_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    Address super_check_addr(sub_klass, temp, Address::times_1, 0);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1278
    __ movptr(temp, super_check_addr); // load displayed supertype
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1279
    __ cmpptr(temp, super_klass_addr); // test the super type
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1280
    LOCAL_JCC(Assembler::equal, L_success);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    // if it was a primary super, we can just fail immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
    __ cmpl(super_check_offset_addr, sc_offset);
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1284
    LOCAL_JCC(Assembler::notEqual, L_failure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1286
    // The repne_scan instruction uses fixed registers, which will get spilled.
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1287
    // We happen to know this works best when super_klass is in rax.
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1288
    Register super_klass = temp;
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1289
    __ movptr(super_klass, super_klass_addr);
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1290
    __ check_klass_subtype_slow_path(sub_klass, super_klass, noreg, noreg,
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1291
                                     L_success, L_failure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1293
    __ bind(L_fallthrough);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1295
    if (L_success == NULL) { BLOCK_COMMENT("L_success:"); }
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1296
    if (L_failure == NULL) { BLOCK_COMMENT("L_failure:"); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
2256
82d4e10b7c6b 6813212: factor duplicated assembly code for general subclass check (for 6655638)
jrose
parents: 1909
diff changeset
  1298
#undef LOCAL_JCC
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  //  Generate checkcasting array copy stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  //  Input:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  //    4(rsp)   - source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  //    8(rsp)   - destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  //   12(rsp)   - element count, can be zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  //   16(rsp)   - size_t ckoff (super_check_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  //   20(rsp)   - oop ckval (super_klass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  //  Output:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  //    rax, ==  0  -  success
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  //    rax, == -1^K - failure, where K is partial transfer count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  //
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1315
  address generate_checkcast_copy(const char *name, address* entry, bool dest_uninitialized = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    Label L_load_element, L_store_element, L_do_card_marks, L_done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    // register use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    //  rax, rdx, rcx -- loop control (end_from, end_to, count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
    //  rdi, rsi      -- element access (oop, klass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
    //  rbx,           -- temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    const Register from       = rax;    // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    const Register to         = rdx;    // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    const Register length     = rcx;    // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    const Register elem       = rdi;    // each oop copied
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    const Register elem_klass = rsi;    // each elem._klass (sub_klass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
    const Register temp       = rbx;    // lone remaining temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
    __ enter(); // required for proper stackwalking of RuntimeStub frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1335
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1336
    __ push(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1337
    __ push(rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
    Address   from_arg(rsp, 16+ 4);     // from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
    Address     to_arg(rsp, 16+ 8);     // to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    Address length_arg(rsp, 16+12);     // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
    Address  ckoff_arg(rsp, 16+16);     // super_check_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
    Address  ckval_arg(rsp, 16+20);     // super_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
    // Load up:
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1346
    __ movptr(from,     from_arg);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1347
    __ movptr(to,         to_arg);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1348
    __ movl2ptr(length, length_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
8487
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1350
    if (entry != NULL) {
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1351
      *entry = __ pc(); // Entry point from generic arraycopy stub.
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1352
      BLOCK_COMMENT("Entry:");
bf96596f06d2 7020521: arraycopy stubs place prebarriers incorrectly
iveresov
parents: 8315
diff changeset
  1353
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    //---------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
    // Assembler stub will be used for this call to arraycopy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
    // if the two arrays are subtypes of Object[] but the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
    // destination array type is not equal to or a supertype
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
    // of the source type.  Each element must be separately
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
    // checked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
    // Loop-invariant addresses.  They are exclusive end pointers.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1363
    Address end_from_addr(from, length, Address::times_ptr, 0);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1364
    Address   end_to_addr(to,   length, Address::times_ptr, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    Register end_from = from;           // re-use
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
    Register end_to   = to;             // re-use
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    Register count    = length;         // re-use
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
    // Loop-variant addresses.  They assume post-incremented count < 0.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1371
    Address from_element_addr(end_from, count, Address::times_ptr, 0);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1372
    Address   to_element_addr(end_to,   count, Address::times_ptr, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
    Address elem_klass_addr(elem, oopDesc::klass_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1375
    DecoratorSet decorators = IN_HEAP | IS_ARRAY | ARRAYCOPY_CHECKCAST;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1376
    if (dest_uninitialized) {
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50179
diff changeset
  1377
      decorators |= IS_DEST_UNINITIALIZED;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1378
    }
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1379
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1380
    BasicType type = T_OBJECT;
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49484
diff changeset
  1381
    BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1382
    bs->arraycopy_prologue(_masm, decorators, type, from, to, count);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1383
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
    // Copy from low to high addresses, indexed from the end of each array.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1385
    __ lea(end_from, end_from_addr);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1386
    __ lea(end_to,   end_to_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
    assert(length == count, "");        // else fix next line:
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1388
    __ negptr(count);                   // negate and test the length
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    __ jccb(Assembler::notZero, L_load_element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    // Empty array:  Nothing to do.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1392
    __ xorptr(rax, rax);                  // return 0 on (trivial) success
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    __ jmp(L_done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
    // ======== begin loop ========
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
    // (Loop is rotated; its entry is L_load_element.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
    // Loop control:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
    //   for (count = -count; count != 0; count++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
    // Base pointers src, dst are biased by 8*count,to last element.
5249
5cac34e6fe54 6940701: Don't align loops in stubs for Niagara sparc
kvn
parents: 5050
diff changeset
  1400
    __ align(OptoLoopAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
    __ BIND(L_store_element);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1403
    __ movptr(to_element_addr, elem);     // store the oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    __ increment(count);                // increment the count toward zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
    __ jccb(Assembler::zero, L_do_card_marks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    // ======== loop entry is here ========
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
    __ BIND(L_load_element);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1409
    __ movptr(elem, from_element_addr);   // load the oop
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1410
    __ testptr(elem, elem);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    __ jccb(Assembler::zero, L_store_element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
    // (Could do a trick here:  Remember last successful non-null
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
    // element stored and make a quick oop equality check on it.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1416
    __ movptr(elem_klass, elem_klass_addr); // query the object klass
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
    generate_type_check(elem_klass, ckoff_arg, ckval_arg, temp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
                        &L_store_element, NULL);
17622
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1419
    // (On fall-through, we have failed the element type check.)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
    // ======== end loop ========
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    // It was a real error; we must depend on the caller to finish the job.
192
d66300cdf939 6614036: REGRESSION: Java server x86 VM intermittently crash with SIGSEGV (0xb)
rasbold
parents: 189
diff changeset
  1423
    // Register "count" = -1 * number of *remaining* oops, length_arg = *total* oops.
d66300cdf939 6614036: REGRESSION: Java server x86 VM intermittently crash with SIGSEGV (0xb)
rasbold
parents: 189
diff changeset
  1424
    // Emit GC store barriers for the oops we have copied (length_arg + count),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    // and report their number to the caller.
17622
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1426
    assert_different_registers(to, count, rax);
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1427
    Label L_post_barrier;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
    __ addl(count, length_arg);         // transfers = (length - remaining)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1429
    __ movl2ptr(rax, count);            // save the value
17622
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1430
    __ notptr(rax);                     // report (-1^K) to caller (does not affect flags)
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1431
    __ jccb(Assembler::notZero, L_post_barrier);
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1432
    __ jmp(L_done); // K == 0, nothing was copied, skip post barrier
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    // Come here on success only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    __ BIND(L_do_card_marks);
17622
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1436
    __ xorptr(rax, rax);                // return 0 on success
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1437
    __ movl2ptr(count, length_arg);
17622
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1438
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1439
    __ BIND(L_post_barrier);
4037daf22a17 8010927: Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
kvn
parents: 16624
diff changeset
  1440
    __ movptr(to, to_arg);              // reload
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
  1441
    bs->arraycopy_epilogue(_masm, decorators, type, from, to, count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    // Common exit point (success or failure).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    __ BIND(L_done);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1445
    __ pop(rbx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1446
    __ pop(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1447
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
    __ leave(); // required for proper stackwalking of RuntimeStub frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
  //  Generate 'unsafe' array copy stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
  //  Though just as safe as the other stubs, it takes an unscaled
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  //  size_t argument instead of an element count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
  //  Input:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
  //    4(rsp)   - source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  //    8(rsp)   - destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
  //   12(rsp)   - byte count, can be zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  //  Output:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  //    rax, ==  0  -  success
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
  //    rax, == -1  -  need to call System.arraycopy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  // Examines the alignment of the operands and dispatches
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
  // to a long, int, short, or byte copy loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
  address generate_unsafe_copy(const char *name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
                               address byte_copy_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
                               address short_copy_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
                               address int_copy_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
                               address long_copy_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
    Label L_long_aligned, L_int_aligned, L_short_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    const Register from       = rax;  // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
    const Register to         = rdx;  // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
    const Register count      = rcx;  // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1489
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1490
    __ push(rdi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
    Address  from_arg(rsp, 12+ 4);      // from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
    Address    to_arg(rsp, 12+ 8);      // to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
    Address count_arg(rsp, 12+12);      // byte count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
    // Load up:
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1496
    __ movptr(from ,  from_arg);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1497
    __ movptr(to   ,    to_arg);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1498
    __ movl2ptr(count, count_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
    // bump this on entry, not on exit:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
    inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    const Register bits = rsi;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1504
    __ mov(bits, from);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1505
    __ orptr(bits, to);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1506
    __ orptr(bits, count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
    __ testl(bits, BytesPerLong-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
    __ jccb(Assembler::zero, L_long_aligned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
    __ testl(bits, BytesPerInt-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
    __ jccb(Assembler::zero, L_int_aligned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
    __ testl(bits, BytesPerShort-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
    __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    __ BIND(L_short_aligned);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1518
    __ shrptr(count, LogBytesPerShort); // size => short_count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
    __ movl(count_arg, count);          // update 'count'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    __ jump(RuntimeAddress(short_copy_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    __ BIND(L_int_aligned);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1523
    __ shrptr(count, LogBytesPerInt); // size => int_count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    __ movl(count_arg, count);          // update 'count'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
    __ jump(RuntimeAddress(int_copy_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
    __ BIND(L_long_aligned);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1528
    __ shrptr(count, LogBytesPerLong); // size => qword_count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
    __ movl(count_arg, count);          // update 'count'
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1530
    __ pop(rdi); // Do pops here since jlong_arraycopy stub does not do it.
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1531
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
    __ jump(RuntimeAddress(long_copy_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
  // Perform range checks on the proposed arraycopy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
  // Smashes src_pos and dst_pos.  (Uses them up for temps.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
  void arraycopy_range_checks(Register src,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
                              Register src_pos,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
                              Register dst,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
                              Register dst_pos,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
                              Address& length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
                              Label& L_failed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    BLOCK_COMMENT("arraycopy_range_checks:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
    const Register src_end = src_pos;   // source array end position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
    const Register dst_end = dst_pos;   // destination array end position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
    __ addl(src_end, length); // src_pos + length
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
    __ addl(dst_end, length); // dst_pos + length
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
    //  if (src_pos + length > arrayOop(src)->length() ) FAIL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
    __ cmpl(src_end, Address(src, arrayOopDesc::length_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
    __ jcc(Assembler::above, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
    //  if (dst_pos + length > arrayOop(dst)->length() ) FAIL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
    __ cmpl(dst_end, Address(dst, arrayOopDesc::length_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
    __ jcc(Assembler::above, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
    BLOCK_COMMENT("arraycopy_range_checks done");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
  //  Generate generic array copy stubs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  //  Input:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
  //     4(rsp)    -  src oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
  //     8(rsp)    -  src_pos
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  //    12(rsp)    -  dst oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  //    16(rsp)    -  dst_pos
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  //    20(rsp)    -  element count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
  //  Output:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  //    rax, ==  0  -  success
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  //    rax, == -1^K - failure, where K is partial transfer count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  address generate_generic_copy(const char *name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
                                address entry_jbyte_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
                                address entry_jshort_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
                                address entry_jint_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
                                address entry_oop_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
                                address entry_jlong_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
                                address entry_checkcast_arraycopy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
    Label L_failed, L_failed_0, L_objArray;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
    { int modulus = CodeEntryAlignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
      int target  = modulus - 5; // 5 = sizeof jmp(L_failed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
      int advance = target - (__ offset() % modulus);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
      if (advance < 0)  advance += modulus;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
      if (advance > 0)  __ nop(advance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
    StubCodeMark mark(this, "StubRoutines", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
    // Short-hop target to L_failed.  Makes for denser prologue code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    __ BIND(L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
    __ jmp(L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
    assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
    __ align(CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    __ enter(); // required for proper stackwalking of RuntimeStub frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1604
    __ push(rsi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1605
    __ push(rdi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    // bump this on entry, not on exit:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
    inc_counter_np(SharedRuntime::_generic_array_copy_ctr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
    // Input values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
    Address SRC     (rsp, 12+ 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
    Address SRC_POS (rsp, 12+ 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    Address DST     (rsp, 12+12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    Address DST_POS (rsp, 12+16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    Address LENGTH  (rsp, 12+20);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    //-----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
    // Assembler stub will be used for this call to arraycopy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    // if the following conditions are met:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
    // (1) src and dst must not be null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
    // (2) src_pos must not be negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
    // (3) dst_pos must not be negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
    // (4) length  must not be negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
    // (5) src klass and dst klass should be the same and not NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
    // (6) src and dst should be arrays.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    // (7) src_pos + length must not exceed length of src.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
    // (8) dst_pos + length must not exceed length of dst.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
    const Register src     = rax;       // source array oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    const Register src_pos = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    const Register dst     = rdx;       // destination array oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    const Register dst_pos = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
    const Register length  = rcx;       // transfer count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
    //  if (src == NULL) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1638
    __ movptr(src, SRC);      // src oop
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1639
    __ testptr(src, src);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
    __ jccb(Assembler::zero, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
    //  if (src_pos < 0) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1643
    __ movl2ptr(src_pos, SRC_POS);  // src_pos
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
    __ testl(src_pos, src_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
    __ jccb(Assembler::negative, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    //  if (dst == NULL) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1648
    __ movptr(dst, DST);      // dst oop
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1649
    __ testptr(dst, dst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
    __ jccb(Assembler::zero, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
    //  if (dst_pos < 0) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1653
    __ movl2ptr(dst_pos, DST_POS);  // dst_pos
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
    __ testl(dst_pos, dst_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
    __ jccb(Assembler::negative, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
    //  if (length < 0) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1658
    __ movl2ptr(length, LENGTH);   // length
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
    __ testl(length, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
    __ jccb(Assembler::negative, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
    //  if (src->klass() == NULL) return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
    Address src_klass_addr(src, oopDesc::klass_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
    Address dst_klass_addr(dst, oopDesc::klass_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    const Register rcx_src_klass = rcx;    // array klass
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1666
    __ movptr(rcx_src_klass, Address(src, oopDesc::klass_offset_in_bytes()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    //  assert(src->klass() != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    BLOCK_COMMENT("assert klasses not null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
    { Label L1, L2;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1672
      __ testptr(rcx_src_klass, rcx_src_klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
      __ jccb(Assembler::notZero, L2);   // it is broken if klass is NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
      __ bind(L1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
      __ stop("broken null klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
      __ bind(L2);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1677
      __ cmpptr(dst_klass_addr, (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
      __ jccb(Assembler::equal, L1);      // this would be broken also
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
      BLOCK_COMMENT("assert done");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
    // Load layout helper (32-bits)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
    //  |array_tag|     | header_size | element_type |     |log2_element_size|
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    // 32        30    24            16              8     2                 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
    //   array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
11430
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 10565
diff changeset
  1691
    int lh_offset = in_bytes(Klass::layout_helper_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    Address src_klass_lh_addr(rcx_src_klass, lh_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
    // Handle objArrays completely differently...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
    jint objArray_lh = Klass::array_layout_helper(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
    __ cmpl(src_klass_lh_addr, objArray_lh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
    __ jcc(Assembler::equal, L_objArray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    //  if (src->klass() != dst->klass()) return -1;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1700
    __ cmpptr(rcx_src_klass, dst_klass_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
    __ jccb(Assembler::notEqual, L_failed_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
    const Register rcx_lh = rcx;  // layout helper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
    assert(rcx_lh == rcx_src_klass, "known alias");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
    __ movl(rcx_lh, src_klass_lh_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
    //  if (!src->is_Array()) return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
    __ cmpl(rcx_lh, Klass::_lh_neutral_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    __ jcc(Assembler::greaterEqual, L_failed_0); // signed cmp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
    // At this point, it is known to be a typeArray (array_tag 0x3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
    { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
      __ cmpl(rcx_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
      __ jcc(Assembler::greaterEqual, L); // signed cmp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
      __ stop("must be a primitive array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
    assert_different_registers(src, src_pos, dst, dst_pos, rcx_lh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
    arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
  1724
    // TypeArrayKlass
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
    // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
    // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
    const Register rsi_offset = rsi; // array offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
    const Register src_array  = src; // src array offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
    const Register dst_array  = dst; // dst array offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
    const Register rdi_elsize = rdi; // log2 element size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1734
    __ mov(rsi_offset, rcx_lh);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1735
    __ shrptr(rsi_offset, Klass::_lh_header_size_shift);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1736
    __ andptr(rsi_offset, Klass::_lh_header_size_mask);   // array_offset
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1737
    __ addptr(src_array, rsi_offset);  // src array offset
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1738
    __ addptr(dst_array, rsi_offset);  // dst array offset
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1739
    __ andptr(rcx_lh, Klass::_lh_log2_element_size_mask); // log2 elsize
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
    // next registers should be set before the jump to corresponding stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
    const Register from       = src; // source array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
    const Register to         = dst; // destination array address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
    const Register count      = rcx; // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
    // some of them should be duplicated on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
#define FROM   Address(rsp, 12+ 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
#define TO     Address(rsp, 12+ 8)   // Not used now
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
#define COUNT  Address(rsp, 12+12)   // Only for oop arraycopy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    BLOCK_COMMENT("scale indexes to element size");
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1751
    __ movl2ptr(rsi, SRC_POS);  // src_pos
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1752
    __ shlptr(rsi);             // src_pos << rcx (log2 elsize)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    assert(src_array == from, "");
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1754
    __ addptr(from, rsi);       // from = src_array + SRC_POS << log2 elsize
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1755
    __ movl2ptr(rdi, DST_POS);  // dst_pos
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1756
    __ shlptr(rdi);             // dst_pos << rcx (log2 elsize)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
    assert(dst_array == to, "");
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1758
    __ addptr(to,  rdi);        // to   = dst_array + DST_POS << log2 elsize
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1759
    __ movptr(FROM, from);      // src_addr
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1760
    __ mov(rdi_elsize, rcx_lh); // log2 elsize
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1761
    __ movl2ptr(count, LENGTH); // elements count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
    BLOCK_COMMENT("choose copy loop based on element size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
    __ cmpl(rdi_elsize, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
    __ jump_cc(Assembler::equal, RuntimeAddress(entry_jbyte_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
    __ cmpl(rdi_elsize, LogBytesPerShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    __ jump_cc(Assembler::equal, RuntimeAddress(entry_jshort_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
    __ cmpl(rdi_elsize, LogBytesPerInt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    __ jump_cc(Assembler::equal, RuntimeAddress(entry_jint_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
    __ cmpl(rdi_elsize, LogBytesPerLong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
    __ jccb(Assembler::notEqual, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
#endif
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1775
    __ pop(rdi); // Do pops here since jlong_arraycopy stub does not do it.
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1776
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
    __ jump(RuntimeAddress(entry_jlong_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  __ BIND(L_failed);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1780
    __ xorptr(rax, rax);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1781
    __ notptr(rax); // return -1
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1782
    __ pop(rdi);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1783
    __ pop(rsi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
    __ leave(); // required for proper stackwalking of RuntimeStub frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
    __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
  1787
    // ObjArrayKlass
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  __ BIND(L_objArray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    // live at this point:  rcx_src_klass, src[_pos], dst[_pos]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    Label L_plain_copy, L_checkcast_copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    //  test array classes for subtyping
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1793
    __ cmpptr(rcx_src_klass, dst_klass_addr); // usual case is exact equality
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    __ jccb(Assembler::notEqual, L_checkcast_copy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
    // Identically typed arrays can be copied without element-wise checks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
    assert_different_registers(src, src_pos, dst, dst_pos, rcx_src_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
    arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  __ BIND(L_plain_copy);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1801
    __ movl2ptr(count, LENGTH); // elements count
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1802
    __ movl2ptr(src_pos, SRC_POS);  // reload src_pos
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1803
    __ lea(from, Address(src, src_pos, Address::times_ptr,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1804
                 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1805
    __ movl2ptr(dst_pos, DST_POS);  // reload dst_pos
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1806
    __ lea(to,   Address(dst, dst_pos, Address::times_ptr,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1807
                 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1808
    __ movptr(FROM,  from);   // src_addr
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1809
    __ movptr(TO,    to);     // dst_addr
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
    __ movl(COUNT, count);  // count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
    __ jump(RuntimeAddress(entry_oop_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  __ BIND(L_checkcast_copy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    // live at this point:  rcx_src_klass, dst[_pos], src[_pos]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
      // Handy offsets:
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
  1817
      int  ek_offset = in_bytes(ObjArrayKlass::element_klass_offset());
11430
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 10565
diff changeset
  1818
      int sco_offset = in_bytes(Klass::super_check_offset_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
      Register rsi_dst_klass = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      Register rdi_temp      = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
      assert(rsi_dst_klass == src_pos, "expected alias w/ src_pos");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
      assert(rdi_temp      == dst_pos, "expected alias w/ dst_pos");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
      Address dst_klass_lh_addr(rsi_dst_klass, lh_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
      // Before looking at dst.length, make sure dst is also an objArray.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1827
      __ movptr(rsi_dst_klass, dst_klass_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
      __ cmpl(dst_klass_lh_addr, objArray_lh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
      __ jccb(Assembler::notEqual, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
      // It is safe to examine both src.length and dst.length.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1832
      __ movl2ptr(src_pos, SRC_POS);        // reload rsi
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
      arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
      // (Now src_pos and dst_pos are killed, but not src and dst.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
      // We'll need this temp (don't forget to pop it after the type check).
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1837
      __ push(rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      Register rbx_src_klass = rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1840
      __ mov(rbx_src_klass, rcx_src_klass); // spill away from rcx
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1841
      __ movptr(rsi_dst_klass, dst_klass_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
      Address super_check_offset_addr(rsi_dst_klass, sco_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
      Label L_fail_array_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      generate_type_check(rbx_src_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
                          super_check_offset_addr, dst_klass_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
                          rdi_temp, NULL, &L_fail_array_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
      // (On fall-through, we have passed the array type check.)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1848
      __ pop(rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
      __ jmp(L_plain_copy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
      __ BIND(L_fail_array_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
      // Reshuffle arguments so we can call checkcast_arraycopy:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
      // match initial saves for checkcast_arraycopy
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1855
      // push(rsi);    // already done; see above
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1856
      // push(rdi);    // already done; see above
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1857
      // push(rbx);    // already done; see above
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
      // Marshal outgoing arguments now, freeing registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
      Address   from_arg(rsp, 16+ 4);   // from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
      Address     to_arg(rsp, 16+ 8);   // to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
      Address length_arg(rsp, 16+12);   // elements count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
      Address  ckoff_arg(rsp, 16+16);   // super_check_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
      Address  ckval_arg(rsp, 16+20);   // super_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
      Address SRC_POS_arg(rsp, 16+ 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
      Address DST_POS_arg(rsp, 16+16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
      Address  LENGTH_arg(rsp, 16+20);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
      // push rbx, changed the incoming offsets (why not just use rbp,??)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
      // assert(SRC_POS_arg.disp() == SRC_POS.disp() + 4, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1872
      __ movptr(rbx, Address(rsi_dst_klass, ek_offset));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1873
      __ movl2ptr(length, LENGTH_arg);    // reload elements count
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1874
      __ movl2ptr(src_pos, SRC_POS_arg);  // reload src_pos
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1875
      __ movl2ptr(dst_pos, DST_POS_arg);  // reload dst_pos
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1877
      __ movptr(ckval_arg, rbx);          // destination element type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
      __ movl(rbx, Address(rbx, sco_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
      __ movl(ckoff_arg, rbx);          // corresponding class check offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
      __ movl(length_arg, length);      // outgoing length argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1883
      __ lea(from, Address(src, src_pos, Address::times_ptr,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
                            arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1885
      __ movptr(from_arg, from);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1887
      __ lea(to, Address(dst, dst_pos, Address::times_ptr,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
                          arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1889
      __ movptr(to_arg, to);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
      __ jump(RuntimeAddress(entry_checkcast_arraycopy));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
    return start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  void generate_arraycopy_stubs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    address entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    address entry_jbyte_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
    address entry_jshort_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    address entry_jint_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
    address entry_oop_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
    address entry_jlong_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
    address entry_checkcast_arraycopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    StubRoutines::_arrayof_jbyte_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
        generate_disjoint_copy(T_BYTE,  true, Address::times_1, &entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
                               "arrayof_jbyte_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
    StubRoutines::_arrayof_jbyte_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
        generate_conjoint_copy(T_BYTE,  true, Address::times_1,  entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
                               NULL, "arrayof_jbyte_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
    StubRoutines::_jbyte_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
        generate_disjoint_copy(T_BYTE, false, Address::times_1, &entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
                               "jbyte_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
    StubRoutines::_jbyte_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
        generate_conjoint_copy(T_BYTE, false, Address::times_1,  entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
                               &entry_jbyte_arraycopy, "jbyte_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
    StubRoutines::_arrayof_jshort_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
        generate_disjoint_copy(T_SHORT,  true, Address::times_2, &entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
                               "arrayof_jshort_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
    StubRoutines::_arrayof_jshort_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
        generate_conjoint_copy(T_SHORT,  true, Address::times_2,  entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
                               NULL, "arrayof_jshort_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    StubRoutines::_jshort_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
        generate_disjoint_copy(T_SHORT, false, Address::times_2, &entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
                               "jshort_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
    StubRoutines::_jshort_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
        generate_conjoint_copy(T_SHORT, false, Address::times_2,  entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
                               &entry_jshort_arraycopy, "jshort_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
    // Next arrays are always aligned on 4 bytes at least.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
    StubRoutines::_jint_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
        generate_disjoint_copy(T_INT, true, Address::times_4, &entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
                               "jint_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
    StubRoutines::_jint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
        generate_conjoint_copy(T_INT, true, Address::times_4,  entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
                               &entry_jint_arraycopy, "jint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
    StubRoutines::_oop_disjoint_arraycopy =
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1940
        generate_disjoint_copy(T_OBJECT, true, Address::times_ptr, &entry,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
                               "oop_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
    StubRoutines::_oop_arraycopy =
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  1943
        generate_conjoint_copy(T_OBJECT, true, Address::times_ptr,  entry,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
                               &entry_oop_arraycopy, "oop_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1946
    StubRoutines::_oop_disjoint_arraycopy_uninit =
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1947
        generate_disjoint_copy(T_OBJECT, true, Address::times_ptr, &entry,
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1948
                               "oop_disjoint_arraycopy_uninit",
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1949
                               /*dest_uninitialized*/true);
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1950
    StubRoutines::_oop_arraycopy_uninit =
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1951
        generate_conjoint_copy(T_OBJECT, true, Address::times_ptr,  entry,
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1952
                               NULL, "oop_arraycopy_uninit",
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1953
                               /*dest_uninitialized*/true);
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1954
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
    StubRoutines::_jlong_disjoint_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
        generate_disjoint_long_copy(&entry, "jlong_disjoint_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
    StubRoutines::_jlong_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
        generate_conjoint_long_copy(entry, &entry_jlong_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
                                    "jlong_arraycopy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
6433
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1961
    StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1962
    StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1963
    StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1964
    StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1965
    StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1966
    StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill");
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
  1967
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1968
    StubRoutines::_arrayof_jint_disjoint_arraycopy       = StubRoutines::_jint_disjoint_arraycopy;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1969
    StubRoutines::_arrayof_oop_disjoint_arraycopy        = StubRoutines::_oop_disjoint_arraycopy;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1970
    StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1971
    StubRoutines::_arrayof_jlong_disjoint_arraycopy      = StubRoutines::_jlong_disjoint_arraycopy;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1973
    StubRoutines::_arrayof_jint_arraycopy       = StubRoutines::_jint_arraycopy;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1974
    StubRoutines::_arrayof_oop_arraycopy        = StubRoutines::_oop_arraycopy;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1975
    StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit;
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1976
    StubRoutines::_arrayof_jlong_arraycopy      = StubRoutines::_jlong_arraycopy;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
    StubRoutines::_checkcast_arraycopy =
8498
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1979
        generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy);
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1980
    StubRoutines::_checkcast_arraycopy_uninit =
6398004126b9 6627983: G1: Bad oop deference during marking
iveresov
parents: 8495
diff changeset
  1981
        generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, /*dest_uninitialized*/true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
    StubRoutines::_unsafe_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
        generate_unsafe_copy("unsafe_arraycopy",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
                               entry_jbyte_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
                               entry_jshort_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
                               entry_jint_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
                               entry_jlong_arraycopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
    StubRoutines::_generic_arraycopy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
        generate_generic_copy("generic_arraycopy",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
                               entry_jbyte_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
                               entry_jshort_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
                               entry_jint_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
                               entry_oop_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
                               entry_jlong_arraycopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
                               entry_checkcast_arraycopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2000
  // AES intrinsic stubs
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2001
  enum {AESBlockSize = 16};
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2002
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2003
  address generate_key_shuffle_mask() {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2004
    __ align(16);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2005
    StubCodeMark mark(this, "StubRoutines", "key_shuffle_mask");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2006
    address start = __ pc();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2007
    __ emit_data(0x00010203, relocInfo::none, 0 );
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2008
    __ emit_data(0x04050607, relocInfo::none, 0 );
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2009
    __ emit_data(0x08090a0b, relocInfo::none, 0 );
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2010
    __ emit_data(0x0c0d0e0f, relocInfo::none, 0 );
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2011
    return start;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2012
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2013
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2014
  address generate_counter_shuffle_mask() {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2015
    __ align(16);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2016
    StubCodeMark mark(this, "StubRoutines", "counter_shuffle_mask");
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2017
    address start = __ pc();
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2018
    __ emit_data(0x0c0d0e0f, relocInfo::none, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2019
    __ emit_data(0x08090a0b, relocInfo::none, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2020
    __ emit_data(0x04050607, relocInfo::none, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2021
    __ emit_data(0x00010203, relocInfo::none, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2022
    return start;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2023
  }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2024
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2025
  // Utility routine for loading a 128-bit key word in little endian format
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2026
  // can optionally specify that the shuffle mask is already in an xmmregister
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2027
  void load_key(XMMRegister xmmdst, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2028
    __ movdqu(xmmdst, Address(key, offset));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2029
    if (xmm_shuf_mask != NULL) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2030
      __ pshufb(xmmdst, xmm_shuf_mask);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2031
    } else {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2032
      __ pshufb(xmmdst, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2033
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2034
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2035
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2036
  // aesenc using specified key+offset
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2037
  // can optionally specify that the shuffle mask is already in an xmmregister
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2038
  void aes_enc_key(XMMRegister xmmdst, XMMRegister xmmtmp, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2039
    load_key(xmmtmp, key, offset, xmm_shuf_mask);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2040
    __ aesenc(xmmdst, xmmtmp);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2041
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2042
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2043
  // aesdec using specified key+offset
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2044
  // can optionally specify that the shuffle mask is already in an xmmregister
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2045
  void aes_dec_key(XMMRegister xmmdst, XMMRegister xmmtmp, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2046
    load_key(xmmtmp, key, offset, xmm_shuf_mask);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2047
    __ aesdec(xmmdst, xmmtmp);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2048
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2049
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2050
  // Utility routine for increase 128bit counter (iv in CTR mode)
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2051
  //  XMM_128bit,  D3, D2, D1, D0
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2052
  void inc_counter(Register reg, XMMRegister xmmdst, int inc_delta, Label& next_block) {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2053
    __ pextrd(reg, xmmdst, 0x0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2054
    __ addl(reg, inc_delta);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2055
    __ pinsrd(xmmdst, reg, 0x0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2056
    __ jcc(Assembler::carryClear, next_block); // jump if no carry
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2057
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2058
    __ pextrd(reg, xmmdst, 0x01); // Carry-> D1
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2059
    __ addl(reg, 0x01);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2060
    __ pinsrd(xmmdst, reg, 0x01);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2061
    __ jcc(Assembler::carryClear, next_block); // jump if no carry
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2062
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2063
    __ pextrd(reg, xmmdst, 0x02); // Carry-> D2
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2064
    __ addl(reg, 0x01);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2065
    __ pinsrd(xmmdst, reg, 0x02);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2066
    __ jcc(Assembler::carryClear, next_block); // jump if no carry
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2067
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2068
    __ pextrd(reg, xmmdst, 0x03); // Carry -> D3
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2069
    __ addl(reg, 0x01);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2070
    __ pinsrd(xmmdst, reg, 0x03);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2071
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2072
    __ BIND(next_block);          // next instruction
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2073
  }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2074
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2075
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2076
  // Arguments:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2077
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2078
  // Inputs:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2079
  //   c_rarg0   - source byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2080
  //   c_rarg1   - destination byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2081
  //   c_rarg2   - K (key) in little endian int array
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2082
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2083
  address generate_aescrypt_encryptBlock() {
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2084
    assert(UseAES, "need AES instructions and misaligned SSE support");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2085
    __ align(CodeEntryAlignment);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2086
    StubCodeMark mark(this, "StubRoutines", "aescrypt_encryptBlock");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2087
    Label L_doLast;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2088
    address start = __ pc();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2089
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2090
    const Register from        = rdx;      // source array address
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2091
    const Register to          = rdx;      // destination array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2092
    const Register key         = rcx;      // key array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2093
    const Register keylen      = rax;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2094
    const Address  from_param(rbp, 8+0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2095
    const Address  to_param  (rbp, 8+4);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2096
    const Address  key_param (rbp, 8+8);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2097
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2098
    const XMMRegister xmm_result = xmm0;
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2099
    const XMMRegister xmm_key_shuf_mask = xmm1;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2100
    const XMMRegister xmm_temp1  = xmm2;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2101
    const XMMRegister xmm_temp2  = xmm3;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2102
    const XMMRegister xmm_temp3  = xmm4;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2103
    const XMMRegister xmm_temp4  = xmm5;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2104
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2105
    __ enter();   // required for proper stackwalking of RuntimeStub frame
32727
320855c2baef 8132160: support for AVX 512 call frames and stack management
mcberg
parents: 32596
diff changeset
  2106
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2107
    __ movptr(from, from_param);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2108
    __ movptr(key, key_param);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2109
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2110
    // keylen could be only {11, 13, 15} * 4 = {44, 52, 60}
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2111
    __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2112
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2113
    __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2114
    __ movdqu(xmm_result, Address(from, 0));  // get 16 bytes of input
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2115
    __ movptr(to, to_param);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2116
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2117
    // For encryption, the java expanded key ordering is just what we need
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2118
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2119
    load_key(xmm_temp1, key, 0x00, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2120
    __ pxor(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2121
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2122
    load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2123
    load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2124
    load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2125
    load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2126
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2127
    __ aesenc(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2128
    __ aesenc(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2129
    __ aesenc(xmm_result, xmm_temp3);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2130
    __ aesenc(xmm_result, xmm_temp4);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2131
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2132
    load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2133
    load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2134
    load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2135
    load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2136
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2137
    __ aesenc(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2138
    __ aesenc(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2139
    __ aesenc(xmm_result, xmm_temp3);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2140
    __ aesenc(xmm_result, xmm_temp4);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2141
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2142
    load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2143
    load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2144
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2145
    __ cmpl(keylen, 44);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2146
    __ jccb(Assembler::equal, L_doLast);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2147
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2148
    __ aesenc(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2149
    __ aesenc(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2150
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2151
    load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2152
    load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2153
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2154
    __ cmpl(keylen, 52);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2155
    __ jccb(Assembler::equal, L_doLast);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2156
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2157
    __ aesenc(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2158
    __ aesenc(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2159
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2160
    load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2161
    load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2162
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2163
    __ BIND(L_doLast);
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2164
    __ aesenc(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2165
    __ aesenclast(xmm_result, xmm_temp2);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2166
    __ movdqu(Address(to, 0), xmm_result);        // store the result
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2167
    __ xorptr(rax, rax); // return 0
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2168
    __ leave(); // required for proper stackwalking of RuntimeStub frame
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2169
    __ ret(0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2170
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2171
    return start;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2172
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2173
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2174
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2175
  // Arguments:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2176
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2177
  // Inputs:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2178
  //   c_rarg0   - source byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2179
  //   c_rarg1   - destination byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2180
  //   c_rarg2   - K (key) in little endian int array
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2181
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2182
  address generate_aescrypt_decryptBlock() {
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2183
    assert(UseAES, "need AES instructions and misaligned SSE support");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2184
    __ align(CodeEntryAlignment);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2185
    StubCodeMark mark(this, "StubRoutines", "aescrypt_decryptBlock");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2186
    Label L_doLast;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2187
    address start = __ pc();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2188
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2189
    const Register from        = rdx;      // source array address
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2190
    const Register to          = rdx;      // destination array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2191
    const Register key         = rcx;      // key array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2192
    const Register keylen      = rax;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2193
    const Address  from_param(rbp, 8+0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2194
    const Address  to_param  (rbp, 8+4);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2195
    const Address  key_param (rbp, 8+8);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2196
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2197
    const XMMRegister xmm_result = xmm0;
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2198
    const XMMRegister xmm_key_shuf_mask = xmm1;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2199
    const XMMRegister xmm_temp1  = xmm2;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2200
    const XMMRegister xmm_temp2  = xmm3;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2201
    const XMMRegister xmm_temp3  = xmm4;
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2202
    const XMMRegister xmm_temp4  = xmm5;
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2203
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2204
    __ enter(); // required for proper stackwalking of RuntimeStub frame
32727
320855c2baef 8132160: support for AVX 512 call frames and stack management
mcberg
parents: 32596
diff changeset
  2205
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2206
    __ movptr(from, from_param);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2207
    __ movptr(key, key_param);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2208
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2209
    // keylen could be only {11, 13, 15} * 4 = {44, 52, 60}
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2210
    __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2211
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2212
    __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2213
    __ movdqu(xmm_result, Address(from, 0));
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2214
    __ movptr(to, to_param);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2215
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2216
    // for decryption java expanded key ordering is rotated one position from what we want
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2217
    // so we start from 0x10 here and hit 0x00 last
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2218
    // we don't know if the key is aligned, hence not using load-execute form
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2219
    load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2220
    load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2221
    load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2222
    load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2223
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2224
    __ pxor  (xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2225
    __ aesdec(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2226
    __ aesdec(xmm_result, xmm_temp3);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2227
    __ aesdec(xmm_result, xmm_temp4);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2228
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2229
    load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2230
    load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2231
    load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2232
    load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2233
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2234
    __ aesdec(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2235
    __ aesdec(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2236
    __ aesdec(xmm_result, xmm_temp3);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2237
    __ aesdec(xmm_result, xmm_temp4);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2238
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2239
    load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2240
    load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2241
    load_key(xmm_temp3, key, 0x00, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2242
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2243
    __ cmpl(keylen, 44);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2244
    __ jccb(Assembler::equal, L_doLast);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2245
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2246
    __ aesdec(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2247
    __ aesdec(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2248
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2249
    load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2250
    load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2251
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2252
    __ cmpl(keylen, 52);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2253
    __ jccb(Assembler::equal, L_doLast);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2254
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2255
    __ aesdec(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2256
    __ aesdec(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2257
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2258
    load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2259
    load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2260
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2261
    __ BIND(L_doLast);
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2262
    __ aesdec(xmm_result, xmm_temp1);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2263
    __ aesdec(xmm_result, xmm_temp2);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2264
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2265
    // for decryption the aesdeclast operation is always on key+0x00
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2266
    __ aesdeclast(xmm_result, xmm_temp3);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2267
    __ movdqu(Address(to, 0), xmm_result);  // store the result
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2268
    __ xorptr(rax, rax); // return 0
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2269
    __ leave(); // required for proper stackwalking of RuntimeStub frame
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2270
    __ ret(0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2271
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2272
    return start;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2273
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2274
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2275
  void handleSOERegisters(bool saving) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2276
    const int saveFrameSizeInBytes = 4 * wordSize;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2277
    const Address saved_rbx     (rbp, -3 * wordSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2278
    const Address saved_rsi     (rbp, -2 * wordSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2279
    const Address saved_rdi     (rbp, -1 * wordSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2280
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2281
    if (saving) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2282
      __ subptr(rsp, saveFrameSizeInBytes);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2283
      __ movptr(saved_rsi, rsi);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2284
      __ movptr(saved_rdi, rdi);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2285
      __ movptr(saved_rbx, rbx);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2286
    } else {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2287
      // restoring
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2288
      __ movptr(rsi, saved_rsi);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2289
      __ movptr(rdi, saved_rdi);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2290
      __ movptr(rbx, saved_rbx);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2291
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2292
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2293
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2294
  // Arguments:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2295
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2296
  // Inputs:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2297
  //   c_rarg0   - source byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2298
  //   c_rarg1   - destination byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2299
  //   c_rarg2   - K (key) in little endian int array
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2300
  //   c_rarg3   - r vector byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2301
  //   c_rarg4   - input length
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2302
  //
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2303
  // Output:
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2304
  //   rax       - input length
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2305
  //
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2306
  address generate_cipherBlockChaining_encryptAESCrypt() {
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2307
    assert(UseAES, "need AES instructions and misaligned SSE support");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2308
    __ align(CodeEntryAlignment);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2309
    StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2310
    address start = __ pc();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2311
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2312
    Label L_exit, L_key_192_256, L_key_256, L_loopTop_128, L_loopTop_192, L_loopTop_256;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2313
    const Register from        = rsi;      // source array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2314
    const Register to          = rdx;      // destination array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2315
    const Register key         = rcx;      // key array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2316
    const Register rvec        = rdi;      // r byte array initialized from initvector array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2317
                                           // and left with the results of the last encryption block
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2318
    const Register len_reg     = rbx;      // src len (must be multiple of blocksize 16)
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2319
    const Register pos         = rax;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2320
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2321
    // xmm register assignments for the loops below
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2322
    const XMMRegister xmm_result = xmm0;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2323
    const XMMRegister xmm_temp   = xmm1;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2324
    // first 6 keys preloaded into xmm2-xmm7
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2325
    const int XMM_REG_NUM_KEY_FIRST = 2;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2326
    const int XMM_REG_NUM_KEY_LAST  = 7;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2327
    const XMMRegister xmm_key0   = as_XMMRegister(XMM_REG_NUM_KEY_FIRST);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2328
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2329
    __ enter(); // required for proper stackwalking of RuntimeStub frame
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2330
    handleSOERegisters(true /*saving*/);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2331
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2332
    // load registers from incoming parameters
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2333
    const Address  from_param(rbp, 8+0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2334
    const Address  to_param  (rbp, 8+4);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2335
    const Address  key_param (rbp, 8+8);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2336
    const Address  rvec_param (rbp, 8+12);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2337
    const Address  len_param  (rbp, 8+16);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2338
    __ movptr(from , from_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2339
    __ movptr(to   , to_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2340
    __ movptr(key  , key_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2341
    __ movptr(rvec , rvec_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2342
    __ movptr(len_reg , len_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2343
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2344
    const XMMRegister xmm_key_shuf_mask = xmm_temp;  // used temporarily to swap key bytes up front
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2345
    __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2346
    // load up xmm regs 2 thru 7 with keys 0-5
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2347
    for (int rnum = XMM_REG_NUM_KEY_FIRST, offset = 0x00; rnum  <= XMM_REG_NUM_KEY_LAST; rnum++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2348
      load_key(as_XMMRegister(rnum), key, offset, xmm_key_shuf_mask);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2349
      offset += 0x10;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2350
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2351
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2352
    __ movdqu(xmm_result, Address(rvec, 0x00));   // initialize xmm_result with r vec
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2353
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2354
    // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256))
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2355
    __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2356
    __ cmpl(rax, 44);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2357
    __ jcc(Assembler::notEqual, L_key_192_256);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2358
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2359
    // 128 bit code follows here
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2360
    __ movl(pos, 0);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2361
    __ align(OptoLoopAlignment);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2362
    __ BIND(L_loopTop_128);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2363
    __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0));   // get next 16 bytes of input
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2364
    __ pxor  (xmm_result, xmm_temp);                                // xor with the current r vector
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2365
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2366
    __ pxor  (xmm_result, xmm_key0);                                // do the aes rounds
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2367
    for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum  <= XMM_REG_NUM_KEY_LAST; rnum++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2368
      __ aesenc(xmm_result, as_XMMRegister(rnum));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2369
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2370
    for (int key_offset = 0x60; key_offset <= 0x90; key_offset += 0x10) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2371
      aes_enc_key(xmm_result, xmm_temp, key, key_offset);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2372
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2373
    load_key(xmm_temp, key, 0xa0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2374
    __ aesenclast(xmm_result, xmm_temp);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2375
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2376
    __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result);     // store into the next 16 bytes of output
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2377
    // no need to store r to memory until we exit
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2378
    __ addptr(pos, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2379
    __ subptr(len_reg, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2380
    __ jcc(Assembler::notEqual, L_loopTop_128);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2381
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2382
    __ BIND(L_exit);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2383
    __ movdqu(Address(rvec, 0), xmm_result);     // final value of r stored in rvec of CipherBlockChaining object
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2384
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2385
    handleSOERegisters(false /*restoring*/);
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2386
    __ movptr(rax, len_param); // return length
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2387
    __ leave();                                  // required for proper stackwalking of RuntimeStub frame
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2388
    __ ret(0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2389
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2390
    __ BIND(L_key_192_256);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2391
    // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256)
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2392
    __ cmpl(rax, 52);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2393
    __ jcc(Assembler::notEqual, L_key_256);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2394
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2395
    // 192-bit code follows here (could be changed to use more xmm registers)
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2396
    __ movl(pos, 0);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2397
    __ align(OptoLoopAlignment);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2398
    __ BIND(L_loopTop_192);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2399
    __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0));   // get next 16 bytes of input
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2400
    __ pxor  (xmm_result, xmm_temp);                                // xor with the current r vector
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2401
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2402
    __ pxor  (xmm_result, xmm_key0);                                // do the aes rounds
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2403
    for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum  <= XMM_REG_NUM_KEY_LAST; rnum++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2404
      __ aesenc(xmm_result, as_XMMRegister(rnum));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2405
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2406
    for (int key_offset = 0x60; key_offset <= 0xb0; key_offset += 0x10) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2407
      aes_enc_key(xmm_result, xmm_temp, key, key_offset);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2408
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2409
    load_key(xmm_temp, key, 0xc0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2410
    __ aesenclast(xmm_result, xmm_temp);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2411
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2412
    __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result);   // store into the next 16 bytes of output
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2413
    // no need to store r to memory until we exit
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2414
    __ addptr(pos, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2415
    __ subptr(len_reg, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2416
    __ jcc(Assembler::notEqual, L_loopTop_192);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2417
    __ jmp(L_exit);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2418
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2419
    __ BIND(L_key_256);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2420
    // 256-bit code follows here (could be changed to use more xmm registers)
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2421
    __ movl(pos, 0);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2422
    __ align(OptoLoopAlignment);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2423
    __ BIND(L_loopTop_256);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2424
    __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0));   // get next 16 bytes of input
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2425
    __ pxor  (xmm_result, xmm_temp);                                // xor with the current r vector
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2426
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2427
    __ pxor  (xmm_result, xmm_key0);                                // do the aes rounds
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2428
    for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum  <= XMM_REG_NUM_KEY_LAST; rnum++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2429
      __ aesenc(xmm_result, as_XMMRegister(rnum));
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2430
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2431
    for (int key_offset = 0x60; key_offset <= 0xd0; key_offset += 0x10) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2432
      aes_enc_key(xmm_result, xmm_temp, key, key_offset);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2433
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2434
    load_key(xmm_temp, key, 0xe0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2435
    __ aesenclast(xmm_result, xmm_temp);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2436
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2437
    __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result);   // store into the next 16 bytes of output
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2438
    // no need to store r to memory until we exit
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2439
    __ addptr(pos, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2440
    __ subptr(len_reg, AESBlockSize);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2441
    __ jcc(Assembler::notEqual, L_loopTop_256);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2442
    __ jmp(L_exit);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2443
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2444
    return start;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2445
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2446
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2447
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2448
  // CBC AES Decryption.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2449
  // In 32-bit stub, because of lack of registers we do not try to parallelize 4 blocks at a time.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2450
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2451
  // Arguments:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2452
  //
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2453
  // Inputs:
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2454
  //   c_rarg0   - source byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2455
  //   c_rarg1   - destination byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2456
  //   c_rarg2   - K (key) in little endian int array
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2457
  //   c_rarg3   - r vector byte array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2458
  //   c_rarg4   - input length
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2459
  //
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2460
  // Output:
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2461
  //   rax       - input length
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 19319
diff changeset
  2462
  //
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2463
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2464
  address generate_cipherBlockChaining_decryptAESCrypt_Parallel() {
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14633
diff changeset
  2465
    assert(UseAES, "need AES instructions and misaligned SSE support");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2466
    __ align(CodeEntryAlignment);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2467
    StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2468
    address start = __ pc();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2469
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2470
    const Register from        = rsi;      // source array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2471
    const Register to          = rdx;      // destination array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2472
    const Register key         = rcx;      // key array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2473
    const Register rvec        = rdi;      // r byte array initialized from initvector array address
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2474
                                           // and left with the results of the last encryption block
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2475
    const Register len_reg     = rbx;      // src len (must be multiple of blocksize 16)
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2476
    const Register pos         = rax;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2477
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2478
    const int PARALLEL_FACTOR = 4;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2479
    const int ROUNDS[3] = { 10, 12, 14 }; //aes rounds for key128, key192, key256
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2480
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2481
    Label L_exit;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2482
    Label L_singleBlock_loopTop[3]; //128, 192, 256
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2483
    Label L_multiBlock_loopTop[3]; //128, 192, 256
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2484
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2485
    const XMMRegister xmm_prev_block_cipher = xmm0; // holds cipher of previous block
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2486
    const XMMRegister xmm_key_shuf_mask = xmm1;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2487
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2488
    const XMMRegister xmm_key_tmp0 = xmm2;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2489
    const XMMRegister xmm_key_tmp1 = xmm3;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2490
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2491
    // registers holding the six results in the parallelized loop
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2492
    const XMMRegister xmm_result0 = xmm4;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2493
    const XMMRegister xmm_result1 = xmm5;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2494
    const XMMRegister xmm_result2 = xmm6;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2495
    const XMMRegister xmm_result3 = xmm7;
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2496
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2497
    __ enter(); // required for proper stackwalking of RuntimeStub frame
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2498
    handleSOERegisters(true /*saving*/);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2499
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2500
    // load registers from incoming parameters
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2501
    const Address  from_param(rbp, 8+0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2502
    const Address  to_param  (rbp, 8+4);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2503
    const Address  key_param (rbp, 8+8);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2504
    const Address  rvec_param (rbp, 8+12);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2505
    const Address  len_param  (rbp, 8+16);
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2506
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2507
    __ movptr(from , from_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2508
    __ movptr(to   , to_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2509
    __ movptr(key  , key_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2510
    __ movptr(rvec , rvec_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2511
    __ movptr(len_reg , len_param);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2512
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2513
    __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2514
    __ movdqu(xmm_prev_block_cipher, Address(rvec, 0x00)); // initialize with initial rvec
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2515
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2516
    __ xorptr(pos, pos);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2517
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2518
    // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256))
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2519
    // rvec is reused
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2520
    __ movl(rvec, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2521
    __ cmpl(rvec, 52);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2522
    __ jcc(Assembler::equal, L_multiBlock_loopTop[1]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2523
    __ cmpl(rvec, 60);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2524
    __ jcc(Assembler::equal, L_multiBlock_loopTop[2]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2525
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2526
#define DoFour(opc, src_reg)           \
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2527
  __ opc(xmm_result0, src_reg);         \
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2528
  __ opc(xmm_result1, src_reg);         \
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2529
  __ opc(xmm_result2, src_reg);         \
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2530
  __ opc(xmm_result3, src_reg);         \
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2531
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2532
    for (int k = 0; k < 3; ++k) {
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2533
      __ align(OptoLoopAlignment);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2534
      __ BIND(L_multiBlock_loopTop[k]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2535
      __ cmpptr(len_reg, PARALLEL_FACTOR * AESBlockSize); // see if at least 4 blocks left
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2536
      __ jcc(Assembler::less, L_singleBlock_loopTop[k]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2537
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2538
      __ movdqu(xmm_result0, Address(from, pos, Address::times_1, 0 * AESBlockSize)); // get next 4 blocks into xmmresult registers
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2539
      __ movdqu(xmm_result1, Address(from, pos, Address::times_1, 1 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2540
      __ movdqu(xmm_result2, Address(from, pos, Address::times_1, 2 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2541
      __ movdqu(xmm_result3, Address(from, pos, Address::times_1, 3 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2542
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2543
      // the java expanded key ordering is rotated one position from what we want
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2544
      // so we start from 0x10 here and hit 0x00 last
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2545
      load_key(xmm_key_tmp0, key, 0x10, xmm_key_shuf_mask);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2546
      DoFour(pxor, xmm_key_tmp0); //xor with first key
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2547
      // do the aes dec rounds
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2548
      for (int rnum = 1; rnum <= ROUNDS[k];) {
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2549
        //load two keys at a time
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2550
        //k1->0x20, ..., k9->0xa0, k10->0x00
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2551
        load_key(xmm_key_tmp1, key, (rnum + 1) * 0x10, xmm_key_shuf_mask);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2552
        load_key(xmm_key_tmp0, key, ((rnum + 2) % (ROUNDS[k] + 1)) * 0x10, xmm_key_shuf_mask); // hit 0x00 last!
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2553
        DoFour(aesdec, xmm_key_tmp1);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2554
        rnum++;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2555
        if (rnum != ROUNDS[k]) {
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2556
          DoFour(aesdec, xmm_key_tmp0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2557
        }
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2558
        else {
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2559
          DoFour(aesdeclast, xmm_key_tmp0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2560
        }
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2561
        rnum++;
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2562
      }
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2563
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2564
      // for each result, xor with the r vector of previous cipher block
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2565
      __ pxor(xmm_result0, xmm_prev_block_cipher);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2566
      __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 0 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2567
      __ pxor(xmm_result1, xmm_prev_block_cipher);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2568
      __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 1 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2569
      __ pxor(xmm_result2, xmm_prev_block_cipher);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2570
      __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 2 * AESBlockSize));
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2571
      __ pxor(xmm_result3, xmm_prev_block_cipher);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2572
      __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 3 * AESBlockSize)); // this will carry over to next set of blocks
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2573
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2574
            // store 4 results into the next 64 bytes of output
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2575
       __ movdqu(Address(to, pos, Address::times_1, 0 * AESBlockSize), xmm_result0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2576
       __ movdqu(Address(to, pos, Address::times_1, 1 * AESBlockSize), xmm_result1);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2577
       __ movdqu(Address(to, pos, Address::times_1, 2 * AESBlockSize), xmm_result2);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2578
       __ movdqu(Address(to, pos, Address::times_1, 3 * AESBlockSize), xmm_result3);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2579
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2580
       __ addptr(pos, 4 * AESBlockSize);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2581
       __ subptr(len_reg, 4 * AESBlockSize);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2582
       __ jmp(L_multiBlock_loopTop[k]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2583
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2584
       //singleBlock starts here
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2585
       __ align(OptoLoopAlignment);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2586
       __ BIND(L_singleBlock_loopTop[k]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2587
       __ cmpptr(len_reg, 0); // any blocks left?
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2588
       __ jcc(Assembler::equal, L_exit);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2589
       __ movdqu(xmm_result0, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2590
       __ movdqa(xmm_result1, xmm_result0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2591
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2592
       load_key(xmm_key_tmp0, key, 0x10, xmm_key_shuf_mask);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2593
       __ pxor(xmm_result0, xmm_key_tmp0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2594
       // do the aes dec rounds
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2595
       for (int rnum = 1; rnum < ROUNDS[k]; rnum++) {
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2596
         // the java expanded key ordering is rotated one position from what we want
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2597
         load_key(xmm_key_tmp0, key, (rnum + 1) * 0x10, xmm_key_shuf_mask);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2598
         __ aesdec(xmm_result0, xmm_key_tmp0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2599
       }
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2600
       load_key(xmm_key_tmp0, key, 0x00, xmm_key_shuf_mask);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2601
       __ aesdeclast(xmm_result0, xmm_key_tmp0);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2602
       __ pxor(xmm_result0, xmm_prev_block_cipher); // xor with the current r vector
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2603
       __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result0); // store into the next 16 bytes of output
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2604
       // no need to store r to memory until we exit
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2605
       __ movdqa(xmm_prev_block_cipher, xmm_result1); // set up next r vector with cipher input from this block
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2606
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2607
       __ addptr(pos, AESBlockSize);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2608
       __ subptr(len_reg, AESBlockSize);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2609
       __ jmp(L_singleBlock_loopTop[k]);
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2610
    }//for 128/192/256
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2611
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2612
    __ BIND(L_exit);
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2613
    __ movptr(rvec, rvec_param);                        // restore this since reused earlier
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2614
    __ movdqu(Address(rvec, 0), xmm_prev_block_cipher); // final value of r stored in rvec of CipherBlockChaining object
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2615
    handleSOERegisters(false /*restoring*/);
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2616
    __ movptr(rax, len_param);                          // return length
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  2617
    __ leave();                                         // required for proper stackwalking of RuntimeStub frame
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2618
    __ ret(0);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2619
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2620
    return start;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2621
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  2622
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2623
  // CTR AES crypt.
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2624
  // In 32-bit stub, parallelize 4 blocks at a time
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2625
  // Arguments:
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2626
  //
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2627
  // Inputs:
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2628
  //   c_rarg0   - source byte array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2629
  //   c_rarg1   - destination byte array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2630
  //   c_rarg2   - K (key) in little endian int array
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2631
  //   c_rarg3   - counter vector byte array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2632
  //   c_rarg4   - input length
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2633
  //
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2634
  // Output:
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2635
  //   rax       - input length
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2636
  //
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2637
  address generate_counterMode_AESCrypt_Parallel() {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2638
    assert(UseAES, "need AES instructions and misaligned SSE support");
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2639
    __ align(CodeEntryAlignment);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2640
    StubCodeMark mark(this, "StubRoutines", "counterMode_AESCrypt");
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2641
    address start = __ pc();
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2642
    const Register from        = rsi;      // source array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2643
    const Register to          = rdx;      // destination array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2644
    const Register key         = rcx;      // key array address
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2645
    const Register counter     = rdi;      // counter byte array initialized from initvector array address
35537
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2646
                                           // and updated with the incremented counter in the end
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2647
    const Register len_reg     = rbx;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2648
    const Register pos         = rax;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2649
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2650
    __ enter(); // required for proper stackwalking of RuntimeStub frame
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2651
    handleSOERegisters(true /*saving*/); // save rbx, rsi, rdi
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2652
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2653
    // load registers from incoming parameters
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2654
    const Address  from_param(rbp, 8+0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2655
    const Address  to_param  (rbp, 8+4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2656
    const Address  key_param (rbp, 8+8);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2657
    const Address  rvec_param (rbp, 8+12);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2658
    const Address  len_param  (rbp, 8+16);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2659
    const Address  saved_counter_param(rbp, 8 + 20);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2660
    const Address  used_addr_param(rbp, 8 + 24);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2661
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2662
    __ movptr(from , from_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2663
    __ movptr(to   , to_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2664
    __ movptr(len_reg , len_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2665
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2666
    // Use the partially used encrpyted counter from last invocation
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2667
    Label L_exit_preLoop, L_preLoop_start;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2668
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2669
    // Use the registers 'counter' and 'key' here in this preloop
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2670
    // to hold of last 2 params 'used' and 'saved_encCounter_start'
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2671
    Register used = counter;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2672
    Register saved_encCounter_start = key;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2673
    Register used_addr = saved_encCounter_start;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2674
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2675
    __ movptr(used_addr, used_addr_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2676
    __ movptr(used, Address(used_addr, 0));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2677
    __ movptr(saved_encCounter_start, saved_counter_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2678
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2679
    __ BIND(L_preLoop_start);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2680
    __ cmpptr(used, 16);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2681
    __ jcc(Assembler::aboveEqual, L_exit_preLoop);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2682
    __ cmpptr(len_reg, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2683
    __ jcc(Assembler::lessEqual, L_exit_preLoop);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2684
    __ movb(rax, Address(saved_encCounter_start, used));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2685
    __ xorb(rax, Address(from, 0));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2686
    __ movb(Address(to, 0), rax);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2687
    __ addptr(from, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2688
    __ addptr(to, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2689
    __ addptr(used, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2690
    __ subptr(len_reg, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2691
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2692
    __ jmp(L_preLoop_start);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2693
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2694
    __ BIND(L_exit_preLoop);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2695
    __ movptr(used_addr, used_addr_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2696
    __ movptr(used_addr, used_addr_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2697
    __ movl(Address(used_addr, 0), used);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2698
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2699
    // load the parameters 'key' and 'counter'
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2700
    __ movptr(key, key_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2701
    __ movptr(counter, rvec_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2702
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2703
    // xmm register assignments for the loops below
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2704
    const XMMRegister xmm_curr_counter      = xmm0;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2705
    const XMMRegister xmm_counter_shuf_mask = xmm1;  // need to be reloaded
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2706
    const XMMRegister xmm_key_shuf_mask     = xmm2;  // need to be reloaded
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2707
    const XMMRegister xmm_key               = xmm3;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2708
    const XMMRegister xmm_result0           = xmm4;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2709
    const XMMRegister xmm_result1           = xmm5;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2710
    const XMMRegister xmm_result2           = xmm6;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2711
    const XMMRegister xmm_result3           = xmm7;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2712
    const XMMRegister xmm_from0             = xmm1;   //reuse XMM register
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2713
    const XMMRegister xmm_from1             = xmm2;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2714
    const XMMRegister xmm_from2             = xmm3;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2715
    const XMMRegister xmm_from3             = xmm4;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2716
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2717
    //for key_128, key_192, key_256
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2718
    const int rounds[3] = {10, 12, 14};
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2719
    Label L_singleBlockLoopTop[3];
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2720
    Label L_multiBlock_loopTop[3];
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2721
    Label L_key192_top, L_key256_top;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2722
    Label L_incCounter[3][4]; // 3: different key length,  4: 4 blocks at a time
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2723
    Label L_incCounter_single[3]; //for single block, key128, key192, key256
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2724
    Label L_processTail_insr[3], L_processTail_4_insr[3], L_processTail_2_insr[3], L_processTail_1_insr[3], L_processTail_exit_insr[3];
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2725
    Label L_processTail_extr[3], L_processTail_4_extr[3], L_processTail_2_extr[3], L_processTail_1_extr[3], L_processTail_exit_extr[3];
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2726
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2727
    Label L_exit;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2728
    const int PARALLEL_FACTOR = 4;  //because of the limited register number
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2729
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2730
    // initialize counter with initial counter
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2731
    __ movdqu(xmm_curr_counter, Address(counter, 0x00));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2732
    __ movdqu(xmm_counter_shuf_mask, ExternalAddress(StubRoutines::x86::counter_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2733
    __ pshufb(xmm_curr_counter, xmm_counter_shuf_mask); //counter is shuffled for increase
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2734
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2735
    // key length could be only {11, 13, 15} * 4 = {44, 52, 60}
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2736
    __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2737
    __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2738
    __ cmpl(rax, 52);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2739
    __ jcc(Assembler::equal, L_key192_top);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2740
    __ cmpl(rax, 60);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2741
    __ jcc(Assembler::equal, L_key256_top);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2742
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2743
    //key128 begins here
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2744
    __ movptr(pos, 0); // init pos before L_multiBlock_loopTop
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2745
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2746
#define CTR_DoFour(opc, src_reg)               \
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2747
    __ opc(xmm_result0, src_reg);              \
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2748
    __ opc(xmm_result1, src_reg);              \
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2749
    __ opc(xmm_result2, src_reg);              \
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2750
    __ opc(xmm_result3, src_reg);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2751
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2752
    // k == 0 :  generate code for key_128
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2753
    // k == 1 :  generate code for key_192
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2754
    // k == 2 :  generate code for key_256
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2755
    for (int k = 0; k < 3; ++k) {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2756
      //multi blocks starts here
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2757
      __ align(OptoLoopAlignment);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2758
      __ BIND(L_multiBlock_loopTop[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2759
      __ cmpptr(len_reg, PARALLEL_FACTOR * AESBlockSize); // see if at least PARALLEL_FACTOR blocks left
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2760
      __ jcc(Assembler::less, L_singleBlockLoopTop[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2761
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2762
      __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2763
      __ movdqu(xmm_counter_shuf_mask, ExternalAddress(StubRoutines::x86::counter_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2764
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2765
      //load, then increase counters
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2766
      CTR_DoFour(movdqa, xmm_curr_counter);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2767
      __ push(rbx);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2768
      inc_counter(rbx, xmm_result1, 0x01, L_incCounter[k][0]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2769
      inc_counter(rbx, xmm_result2, 0x02, L_incCounter[k][1]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2770
      inc_counter(rbx, xmm_result3, 0x03, L_incCounter[k][2]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2771
      inc_counter(rbx, xmm_curr_counter, 0x04, L_incCounter[k][3]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2772
      __ pop (rbx);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2773
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2774
      load_key(xmm_key, key, 0x00, xmm_key_shuf_mask); // load Round 0 key. interleaving for better performance
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2775
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2776
      CTR_DoFour(pshufb, xmm_counter_shuf_mask); // after increased, shuffled counters back for PXOR
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2777
      CTR_DoFour(pxor, xmm_key);   //PXOR with Round 0 key
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2778
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2779
      for (int i = 1; i < rounds[k]; ++i) {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2780
        load_key(xmm_key, key, (0x10 * i), xmm_key_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2781
        CTR_DoFour(aesenc, xmm_key);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2782
      }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2783
      load_key(xmm_key, key, (0x10 * rounds[k]), xmm_key_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2784
      CTR_DoFour(aesenclast, xmm_key);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2785
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2786
      // get next PARALLEL_FACTOR blocks into xmm_from registers
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2787
      __ movdqu(xmm_from0, Address(from, pos, Address::times_1, 0 * AESBlockSize));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2788
      __ movdqu(xmm_from1, Address(from, pos, Address::times_1, 1 * AESBlockSize));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2789
      __ movdqu(xmm_from2, Address(from, pos, Address::times_1, 2 * AESBlockSize));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2790
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2791
      // PXOR with input text
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2792
      __ pxor(xmm_result0, xmm_from0); //result0 is xmm4
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2793
      __ pxor(xmm_result1, xmm_from1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2794
      __ pxor(xmm_result2, xmm_from2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2795
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2796
      // store PARALLEL_FACTOR results into the next 64 bytes of output
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2797
      __ movdqu(Address(to, pos, Address::times_1, 0 * AESBlockSize), xmm_result0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2798
      __ movdqu(Address(to, pos, Address::times_1, 1 * AESBlockSize), xmm_result1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2799
      __ movdqu(Address(to, pos, Address::times_1, 2 * AESBlockSize), xmm_result2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2800
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2801
      // do it here after xmm_result0 is saved, because xmm_from3 reuse the same register of xmm_result0.
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2802
      __ movdqu(xmm_from3, Address(from, pos, Address::times_1, 3 * AESBlockSize));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2803
      __ pxor(xmm_result3, xmm_from3);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2804
      __ movdqu(Address(to, pos, Address::times_1, 3 * AESBlockSize), xmm_result3);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2805
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2806
      __ addptr(pos, PARALLEL_FACTOR * AESBlockSize); // increase the length of crypt text
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2807
      __ subptr(len_reg, PARALLEL_FACTOR * AESBlockSize); // decrease the remaining length
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2808
      __ jmp(L_multiBlock_loopTop[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2809
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2810
      // singleBlock starts here
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2811
      __ align(OptoLoopAlignment);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2812
      __ BIND(L_singleBlockLoopTop[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2813
      __ cmpptr(len_reg, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2814
      __ jcc(Assembler::equal, L_exit);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2815
      __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2816
      __ movdqu(xmm_counter_shuf_mask, ExternalAddress(StubRoutines::x86::counter_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2817
      __ movdqa(xmm_result0, xmm_curr_counter);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2818
      load_key(xmm_key, key, 0x00, xmm_key_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2819
      __ push(rbx);//rbx is used for increasing counter
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2820
      inc_counter(rbx, xmm_curr_counter, 0x01, L_incCounter_single[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2821
      __ pop (rbx);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2822
      __ pshufb(xmm_result0, xmm_counter_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2823
      __ pxor(xmm_result0, xmm_key);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2824
      for (int i = 1; i < rounds[k]; i++) {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2825
        load_key(xmm_key, key, (0x10 * i), xmm_key_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2826
        __ aesenc(xmm_result0, xmm_key);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2827
      }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2828
      load_key(xmm_key, key, (0x10 * rounds[k]), xmm_key_shuf_mask);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2829
      __ aesenclast(xmm_result0, xmm_key);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2830
      __ cmpptr(len_reg, AESBlockSize);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2831
      __ jcc(Assembler::less, L_processTail_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2832
        __ movdqu(xmm_from0, Address(from, pos, Address::times_1, 0 * AESBlockSize));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2833
        __ pxor(xmm_result0, xmm_from0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2834
        __ movdqu(Address(to, pos, Address::times_1, 0 * AESBlockSize), xmm_result0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2835
        __ addptr(pos, AESBlockSize);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2836
        __ subptr(len_reg, AESBlockSize);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2837
        __ jmp(L_singleBlockLoopTop[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2838
35537
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2839
      __ BIND(L_processTail_insr[k]);                                               // Process the tail part of the input array
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2840
        __ addptr(pos, len_reg);                                                    // 1. Insert bytes from src array into xmm_from0 register
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2841
        __ testptr(len_reg, 8);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2842
        __ jcc(Assembler::zero, L_processTail_4_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2843
          __ subptr(pos,8);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2844
          __ pinsrd(xmm_from0, Address(from, pos), 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2845
          __ pinsrd(xmm_from0, Address(from, pos, Address::times_1, 4), 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2846
        __ BIND(L_processTail_4_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2847
        __ testptr(len_reg, 4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2848
        __ jcc(Assembler::zero, L_processTail_2_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2849
          __ subptr(pos,4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2850
          __ pslldq(xmm_from0, 4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2851
          __ pinsrd(xmm_from0, Address(from, pos), 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2852
        __ BIND(L_processTail_2_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2853
        __ testptr(len_reg, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2854
        __ jcc(Assembler::zero, L_processTail_1_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2855
          __ subptr(pos, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2856
          __ pslldq(xmm_from0, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2857
          __ pinsrw(xmm_from0, Address(from, pos), 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2858
        __ BIND(L_processTail_1_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2859
        __ testptr(len_reg, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2860
        __ jcc(Assembler::zero, L_processTail_exit_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2861
          __ subptr(pos, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2862
          __ pslldq(xmm_from0, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2863
          __ pinsrb(xmm_from0, Address(from, pos), 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2864
        __ BIND(L_processTail_exit_insr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2865
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2866
        __ movptr(saved_encCounter_start, saved_counter_param);
35537
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2867
        __ movdqu(Address(saved_encCounter_start, 0), xmm_result0);               // 2. Perform pxor of the encrypted counter and plaintext Bytes.
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2868
        __ pxor(xmm_result0, xmm_from0);                                          //    Also the encrypted counter is saved for next invocation.
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2869
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2870
        __ testptr(len_reg, 8);
35537
bed5e2dc57a1 8146581: Minor corrections to the patch submitted for earlier bug id - 8143925
kvn
parents: 35154
diff changeset
  2871
        __ jcc(Assembler::zero, L_processTail_4_extr[k]);                        // 3. Extract bytes from xmm_result0 into the dest. array
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2872
          __ pextrd(Address(to, pos), xmm_result0, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2873
          __ pextrd(Address(to, pos, Address::times_1, 4), xmm_result0, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2874
          __ psrldq(xmm_result0, 8);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2875
          __ addptr(pos, 8);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2876
        __ BIND(L_processTail_4_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2877
        __ testptr(len_reg, 4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2878
        __ jcc(Assembler::zero, L_processTail_2_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2879
          __ pextrd(Address(to, pos), xmm_result0, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2880
          __ psrldq(xmm_result0, 4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2881
          __ addptr(pos, 4);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2882
        __ BIND(L_processTail_2_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2883
        __ testptr(len_reg, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2884
        __ jcc(Assembler::zero, L_processTail_1_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2885
          __ pextrb(Address(to, pos), xmm_result0, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2886
          __ pextrb(Address(to, pos, Address::times_1, 1), xmm_result0, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2887
          __ psrldq(xmm_result0, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2888
          __ addptr(pos, 2);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2889
        __ BIND(L_processTail_1_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2890
        __ testptr(len_reg, 1);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2891
        __ jcc(Assembler::zero, L_processTail_exit_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2892
          __ pextrb(Address(to, pos), xmm_result0, 0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2893
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2894
        __ BIND(L_processTail_exit_extr[k]);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2895
        __ movptr(used_addr, used_addr_param);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2896
        __ movl(Address(used_addr, 0), len_reg);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2897
        __ jmp(L_exit);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2898
    }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2899
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2900
    __ BIND(L_exit);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2901
    __ movdqu(xmm_counter_shuf_mask, ExternalAddress(StubRoutines::x86::counter_shuffle_mask_addr()));
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2902
    __ pshufb(xmm_curr_counter, xmm_counter_shuf_mask); //counter is shuffled back.
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2903
    __ movdqu(Address(counter, 0), xmm_curr_counter); //save counter back
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2904
    handleSOERegisters(false /*restoring*/);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2905
    __ movptr(rax, len_param); // return length
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2906
    __ leave();                // required for proper stackwalking of RuntimeStub frame
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2907
    __ ret(0);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2908
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2909
    __ BIND (L_key192_top);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2910
    __ movptr(pos, 0); // init pos before L_multiBlock_loopTop
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2911
    __ jmp(L_multiBlock_loopTop[1]); //key192
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2912
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2913
    __ BIND (L_key256_top);
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2914
    __ movptr(pos, 0); // init pos before L_multiBlock_loopTop
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2915
    __ jmp(L_multiBlock_loopTop[2]); //key192
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2916
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2917
    return start;
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2918
  }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  2919
36555
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2920
  address generate_upper_word_mask() {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2921
    __ align(64);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2922
    StubCodeMark mark(this, "StubRoutines", "upper_word_mask");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2923
    address start = __ pc();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2924
    __ emit_data(0x00000000, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2925
    __ emit_data(0x00000000, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2926
    __ emit_data(0x00000000, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2927
    __ emit_data(0xFFFFFFFF, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2928
    return start;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2929
  }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2930
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2931
  address generate_shuffle_byte_flip_mask() {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2932
    __ align(64);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2933
    StubCodeMark mark(this, "StubRoutines", "shuffle_byte_flip_mask");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2934
    address start = __ pc();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2935
    __ emit_data(0x0c0d0e0f, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2936
    __ emit_data(0x08090a0b, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2937
    __ emit_data(0x04050607, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2938
    __ emit_data(0x00010203, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2939
    return start;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2940
  }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2941
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2942
  // ofs and limit are use for multi-block byte array.
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2943
  // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2944
  address generate_sha1_implCompress(bool multi_block, const char *name) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2945
    __ align(CodeEntryAlignment);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2946
    StubCodeMark mark(this, "StubRoutines", name);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2947
    address start = __ pc();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2948
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2949
    Register buf   = rax;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2950
    Register state = rdx;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2951
    Register ofs   = rcx;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2952
    Register limit = rdi;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2953
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2954
    const Address  buf_param(rbp, 8 + 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2955
    const Address  state_param(rbp, 8 + 4);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2956
    const Address  ofs_param(rbp, 8 + 8);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2957
    const Address  limit_param(rbp, 8 + 12);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2958
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2959
    const XMMRegister abcd = xmm0;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2960
    const XMMRegister e0 = xmm1;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2961
    const XMMRegister e1 = xmm2;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2962
    const XMMRegister msg0 = xmm3;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2963
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2964
    const XMMRegister msg1 = xmm4;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2965
    const XMMRegister msg2 = xmm5;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2966
    const XMMRegister msg3 = xmm6;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2967
    const XMMRegister shuf_mask = xmm7;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2968
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2969
    __ enter();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2970
    __ subptr(rsp, 8 * wordSize);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2971
    if (multi_block) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2972
      __ push(limit);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2973
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2974
    __ movptr(buf, buf_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2975
    __ movptr(state, state_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2976
    if (multi_block) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2977
      __ movptr(ofs, ofs_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2978
      __ movptr(limit, limit_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2979
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2980
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2981
    __ fast_sha1(abcd, e0, e1, msg0, msg1, msg2, msg3, shuf_mask,
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2982
      buf, state, ofs, limit, rsp, multi_block);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2983
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2984
    if (multi_block) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2985
      __ pop(limit);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2986
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2987
    __ addptr(rsp, 8 * wordSize);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2988
    __ leave();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2989
    __ ret(0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2990
    return start;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2991
  }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2992
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2993
  address generate_pshuffle_byte_flip_mask() {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2994
    __ align(64);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2995
    StubCodeMark mark(this, "StubRoutines", "pshuffle_byte_flip_mask");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2996
    address start = __ pc();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2997
    __ emit_data(0x00010203, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2998
    __ emit_data(0x04050607, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  2999
    __ emit_data(0x08090a0b, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3000
    __ emit_data(0x0c0d0e0f, relocInfo::none, 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3001
    return start;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3002
  }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3003
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3004
  // ofs and limit are use for multi-block byte array.
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3005
  // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3006
 address generate_sha256_implCompress(bool multi_block, const char *name) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3007
    __ align(CodeEntryAlignment);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3008
    StubCodeMark mark(this, "StubRoutines", name);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3009
    address start = __ pc();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3010
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3011
    Register buf = rbx;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3012
    Register state = rsi;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3013
    Register ofs = rdx;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3014
    Register limit = rcx;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3015
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3016
    const Address  buf_param(rbp, 8 + 0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3017
    const Address  state_param(rbp, 8 + 4);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3018
    const Address  ofs_param(rbp, 8 + 8);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3019
    const Address  limit_param(rbp, 8 + 12);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3020
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3021
    const XMMRegister msg = xmm0;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3022
    const XMMRegister state0 = xmm1;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3023
    const XMMRegister state1 = xmm2;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3024
    const XMMRegister msgtmp0 = xmm3;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3025
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3026
    const XMMRegister msgtmp1 = xmm4;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3027
    const XMMRegister msgtmp2 = xmm5;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3028
    const XMMRegister msgtmp3 = xmm6;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3029
    const XMMRegister msgtmp4 = xmm7;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3030
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3031
    __ enter();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3032
    __ subptr(rsp, 8 * wordSize);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3033
    handleSOERegisters(true /*saving*/);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3034
    __ movptr(buf, buf_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3035
    __ movptr(state, state_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3036
    if (multi_block) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3037
     __ movptr(ofs, ofs_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3038
     __ movptr(limit, limit_param);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3039
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3040
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3041
    __ fast_sha256(msg, state0, state1, msgtmp0, msgtmp1, msgtmp2, msgtmp3, msgtmp4,
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3042
      buf, state, ofs, limit, rsp, multi_block);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3043
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3044
    handleSOERegisters(false);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3045
    __ addptr(rsp, 8 * wordSize);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3046
    __ leave();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3047
    __ ret(0);
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3048
    return start;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3049
  }
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3050
31404
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3051
  // byte swap x86 long
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3052
  address generate_ghash_long_swap_mask() {
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3053
    __ align(CodeEntryAlignment);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3054
    StubCodeMark mark(this, "StubRoutines", "ghash_long_swap_mask");
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3055
    address start = __ pc();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3056
    __ emit_data(0x0b0a0908, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3057
    __ emit_data(0x0f0e0d0c, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3058
    __ emit_data(0x03020100, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3059
    __ emit_data(0x07060504, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3060
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3061
  return start;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3062
  }
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3063
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3064
  // byte swap x86 byte array
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3065
  address generate_ghash_byte_swap_mask() {
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3066
    __ align(CodeEntryAlignment);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3067
    StubCodeMark mark(this, "StubRoutines", "ghash_byte_swap_mask");
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3068
    address start = __ pc();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3069
    __ emit_data(0x0c0d0e0f, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3070
    __ emit_data(0x08090a0b, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3071
    __ emit_data(0x04050607, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3072
    __ emit_data(0x00010203, relocInfo::none, 0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3073
  return start;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3074
  }
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3075
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3076
  /* Single and multi-block ghash operations */
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3077
  address generate_ghash_processBlocks() {
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3078
    assert(UseGHASHIntrinsics, "need GHASH intrinsics and CLMUL support");
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3079
    __ align(CodeEntryAlignment);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3080
    Label L_ghash_loop, L_exit;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3081
    StubCodeMark mark(this, "StubRoutines", "ghash_processBlocks");
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3082
    address start = __ pc();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3083
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3084
    const Register state        = rdi;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3085
    const Register subkeyH      = rsi;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3086
    const Register data         = rdx;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3087
    const Register blocks       = rcx;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3088
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3089
    const Address  state_param(rbp, 8+0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3090
    const Address  subkeyH_param(rbp, 8+4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3091
    const Address  data_param(rbp, 8+8);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3092
    const Address  blocks_param(rbp, 8+12);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3093
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3094
    const XMMRegister xmm_temp0 = xmm0;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3095
    const XMMRegister xmm_temp1 = xmm1;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3096
    const XMMRegister xmm_temp2 = xmm2;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3097
    const XMMRegister xmm_temp3 = xmm3;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3098
    const XMMRegister xmm_temp4 = xmm4;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3099
    const XMMRegister xmm_temp5 = xmm5;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3100
    const XMMRegister xmm_temp6 = xmm6;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3101
    const XMMRegister xmm_temp7 = xmm7;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3102
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3103
    __ enter();
31771
c9f593020799 8130341: GHASH 32bit intrinsics has AEADBadTagException
ascarpino
parents: 31404
diff changeset
  3104
    handleSOERegisters(true);  // Save registers
31404
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3105
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3106
    __ movptr(state, state_param);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3107
    __ movptr(subkeyH, subkeyH_param);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3108
    __ movptr(data, data_param);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3109
    __ movptr(blocks, blocks_param);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3110
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3111
    __ movdqu(xmm_temp0, Address(state, 0));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3112
    __ pshufb(xmm_temp0, ExternalAddress(StubRoutines::x86::ghash_long_swap_mask_addr()));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3113
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3114
    __ movdqu(xmm_temp1, Address(subkeyH, 0));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3115
    __ pshufb(xmm_temp1, ExternalAddress(StubRoutines::x86::ghash_long_swap_mask_addr()));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3116
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3117
    __ BIND(L_ghash_loop);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3118
    __ movdqu(xmm_temp2, Address(data, 0));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3119
    __ pshufb(xmm_temp2, ExternalAddress(StubRoutines::x86::ghash_byte_swap_mask_addr()));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3120
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3121
    __ pxor(xmm_temp0, xmm_temp2);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3122
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3123
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3124
    // Multiply with the hash key
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3125
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3126
    __ movdqu(xmm_temp3, xmm_temp0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3127
    __ pclmulqdq(xmm_temp3, xmm_temp1, 0);      // xmm3 holds a0*b0
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3128
    __ movdqu(xmm_temp4, xmm_temp0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3129
    __ pclmulqdq(xmm_temp4, xmm_temp1, 16);     // xmm4 holds a0*b1
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3130
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3131
    __ movdqu(xmm_temp5, xmm_temp0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3132
    __ pclmulqdq(xmm_temp5, xmm_temp1, 1);      // xmm5 holds a1*b0
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3133
    __ movdqu(xmm_temp6, xmm_temp0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3134
    __ pclmulqdq(xmm_temp6, xmm_temp1, 17);     // xmm6 holds a1*b1
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3135
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3136
    __ pxor(xmm_temp4, xmm_temp5);      // xmm4 holds a0*b1 + a1*b0
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3137
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3138
    __ movdqu(xmm_temp5, xmm_temp4);    // move the contents of xmm4 to xmm5
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3139
    __ psrldq(xmm_temp4, 8);    // shift by xmm4 64 bits to the right
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3140
    __ pslldq(xmm_temp5, 8);    // shift by xmm5 64 bits to the left
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3141
    __ pxor(xmm_temp3, xmm_temp5);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3142
    __ pxor(xmm_temp6, xmm_temp4);      // Register pair <xmm6:xmm3> holds the result
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3143
                                        // of the carry-less multiplication of
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3144
                                        // xmm0 by xmm1.
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3145
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3146
    // We shift the result of the multiplication by one bit position
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3147
    // to the left to cope for the fact that the bits are reversed.
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3148
    __ movdqu(xmm_temp7, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3149
    __ movdqu(xmm_temp4, xmm_temp6);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3150
    __ pslld (xmm_temp3, 1);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3151
    __ pslld(xmm_temp6, 1);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3152
    __ psrld(xmm_temp7, 31);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3153
    __ psrld(xmm_temp4, 31);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3154
    __ movdqu(xmm_temp5, xmm_temp7);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3155
    __ pslldq(xmm_temp4, 4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3156
    __ pslldq(xmm_temp7, 4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3157
    __ psrldq(xmm_temp5, 12);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3158
    __ por(xmm_temp3, xmm_temp7);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3159
    __ por(xmm_temp6, xmm_temp4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3160
    __ por(xmm_temp6, xmm_temp5);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3161
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3162
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3163
    // First phase of the reduction
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3164
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3165
    // Move xmm3 into xmm4, xmm5, xmm7 in order to perform the shifts
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3166
    // independently.
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3167
    __ movdqu(xmm_temp7, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3168
    __ movdqu(xmm_temp4, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3169
    __ movdqu(xmm_temp5, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3170
    __ pslld(xmm_temp7, 31);    // packed right shift shifting << 31
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3171
    __ pslld(xmm_temp4, 30);    // packed right shift shifting << 30
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3172
    __ pslld(xmm_temp5, 25);    // packed right shift shifting << 25
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3173
    __ pxor(xmm_temp7, xmm_temp4);      // xor the shifted versions
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3174
    __ pxor(xmm_temp7, xmm_temp5);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3175
    __ movdqu(xmm_temp4, xmm_temp7);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3176
    __ pslldq(xmm_temp7, 12);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3177
    __ psrldq(xmm_temp4, 4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3178
    __ pxor(xmm_temp3, xmm_temp7);      // first phase of the reduction complete
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3179
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3180
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3181
    // Second phase of the reduction
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3182
    //
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3183
    // Make 3 copies of xmm3 in xmm2, xmm5, xmm7 for doing these
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3184
    // shift operations.
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3185
    __ movdqu(xmm_temp2, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3186
    __ movdqu(xmm_temp7, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3187
    __ movdqu(xmm_temp5, xmm_temp3);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3188
    __ psrld(xmm_temp2, 1);     // packed left shifting >> 1
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3189
    __ psrld(xmm_temp7, 2);     // packed left shifting >> 2
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3190
    __ psrld(xmm_temp5, 7);     // packed left shifting >> 7
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3191
    __ pxor(xmm_temp2, xmm_temp7);      // xor the shifted versions
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3192
    __ pxor(xmm_temp2, xmm_temp5);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3193
    __ pxor(xmm_temp2, xmm_temp4);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3194
    __ pxor(xmm_temp3, xmm_temp2);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3195
    __ pxor(xmm_temp6, xmm_temp3);      // the result is in xmm6
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3196
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3197
    __ decrement(blocks);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3198
    __ jcc(Assembler::zero, L_exit);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3199
    __ movdqu(xmm_temp0, xmm_temp6);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3200
    __ addptr(data, 16);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3201
    __ jmp(L_ghash_loop);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3202
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3203
    __ BIND(L_exit);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3204
       // Byte swap 16-byte result
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3205
    __ pshufb(xmm_temp6, ExternalAddress(StubRoutines::x86::ghash_long_swap_mask_addr()));
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3206
    __ movdqu(Address(state, 0), xmm_temp6);   // store the result
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3207
31771
c9f593020799 8130341: GHASH 32bit intrinsics has AEADBadTagException
ascarpino
parents: 31404
diff changeset
  3208
    handleSOERegisters(false);  // restore registers
31404
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3209
    __ leave();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3210
    __ ret(0);
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3211
    return start;
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3212
  }
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3213
18507
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3214
  /**
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3215
   *  Arguments:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3216
   *
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3217
   * Inputs:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3218
   *   rsp(4)   - int crc
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3219
   *   rsp(8)   - byte* buf
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3220
   *   rsp(12)  - int length
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3221
   *
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3222
   * Ouput:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3223
   *       rax   - int crc result
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3224
   */
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3225
  address generate_updateBytesCRC32() {
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3226
    assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions");
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3227
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3228
    __ align(CodeEntryAlignment);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3229
    StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32");
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3230
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3231
    address start = __ pc();
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3232
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3233
    const Register crc   = rdx;  // crc
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3234
    const Register buf   = rsi;  // source java byte array address
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3235
    const Register len   = rcx;  // length
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3236
    const Register table = rdi;  // crc_table address (reuse register)
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3237
    const Register tmp   = rbx;
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3238
    assert_different_registers(crc, buf, len, table, tmp, rax);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3239
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3240
    BLOCK_COMMENT("Entry:");
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3241
    __ enter(); // required for proper stackwalking of RuntimeStub frame
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3242
    __ push(rsi);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3243
    __ push(rdi);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3244
    __ push(rbx);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3245
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3246
    Address crc_arg(rbp, 8 + 0);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3247
    Address buf_arg(rbp, 8 + 4);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3248
    Address len_arg(rbp, 8 + 8);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3249
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3250
    // Load up:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3251
    __ movl(crc,   crc_arg);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3252
    __ movptr(buf, buf_arg);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3253
    __ movl(len,   len_arg);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3254
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3255
    __ kernel_crc32(crc, buf, len, table, tmp);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3256
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3257
    __ movl(rax, crc);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3258
    __ pop(rbx);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3259
    __ pop(rdi);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3260
    __ pop(rsi);
46440
61025eecb743 8178811: Minimize the AVX <-> SSE transition penalty through generation of vzeroupper instruction on x86
vdeshpande
parents: 42618
diff changeset
  3261
    __ vzeroupper();
18507
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3262
    __ leave(); // required for proper stackwalking of RuntimeStub frame
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3263
    __ ret(0);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3264
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3265
    return start;
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3266
  }
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3267
33066
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3268
  /**
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3269
  *  Arguments:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3270
  *
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3271
  * Inputs:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3272
  *   rsp(4)   - int crc
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3273
  *   rsp(8)   - byte* buf
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3274
  *   rsp(12)  - int length
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3275
  *   rsp(16)  - table_start - optional (present only when doing a library_calll,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3276
  *              not used by x86 algorithm)
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3277
  *
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3278
  * Ouput:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3279
  *       rax  - int crc result
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3280
  */
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3281
  address generate_updateBytesCRC32C(bool is_pclmulqdq_supported) {
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3282
    assert(UseCRC32CIntrinsics, "need SSE4_2");
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3283
    __ align(CodeEntryAlignment);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3284
    StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32C");
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3285
    address start = __ pc();
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3286
    const Register crc = rax;  // crc
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3287
    const Register buf = rcx;  // source java byte array address
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3288
    const Register len = rdx;  // length
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3289
    const Register d = rbx;
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3290
    const Register g = rsi;
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3291
    const Register h = rdi;
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3292
    const Register empty = 0; // will never be used, in order not
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3293
                              // to change a signature for crc32c_IPL_Alg2_Alt2
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3294
                              // between 64/32 I'm just keeping it here
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3295
    assert_different_registers(crc, buf, len, d, g, h);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3296
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3297
    BLOCK_COMMENT("Entry:");
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3298
    __ enter(); // required for proper stackwalking of RuntimeStub frame
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3299
    Address crc_arg(rsp, 4 + 4 + 0); // ESP+4 +
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3300
                                     // we need to add additional 4 because __ enter
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3301
                                     // have just pushed ebp on a stack
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3302
    Address buf_arg(rsp, 4 + 4 + 4);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3303
    Address len_arg(rsp, 4 + 4 + 8);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3304
      // Load up:
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3305
      __ movl(crc, crc_arg);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3306
      __ movl(buf, buf_arg);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3307
      __ movl(len, len_arg);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3308
      __ push(d);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3309
      __ push(g);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3310
      __ push(h);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3311
      __ crc32c_ipl_alg2_alt2(crc, buf, len,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3312
                              d, g, h,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3313
                              empty, empty, empty,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3314
                              xmm0, xmm1, xmm2,
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3315
                              is_pclmulqdq_supported);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3316
      __ pop(h);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3317
      __ pop(g);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3318
      __ pop(d);
46440
61025eecb743 8178811: Minimize the AVX <-> SSE transition penalty through generation of vzeroupper instruction on x86
vdeshpande
parents: 42618
diff changeset
  3319
    __ vzeroupper();
33066
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3320
    __ leave(); // required for proper stackwalking of RuntimeStub frame
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3321
    __ ret(0);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3322
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3323
    return start;
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3324
  }
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3325
33089
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3326
 address generate_libmExp() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3327
    StubCodeMark mark(this, "StubRoutines", "libmExp");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3328
33089
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3329
    address start = __ pc();
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3330
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3331
    const XMMRegister x0  = xmm0;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3332
    const XMMRegister x1  = xmm1;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3333
    const XMMRegister x2  = xmm2;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3334
    const XMMRegister x3  = xmm3;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3335
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3336
    const XMMRegister x4  = xmm4;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3337
    const XMMRegister x5  = xmm5;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3338
    const XMMRegister x6  = xmm6;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3339
    const XMMRegister x7  = xmm7;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3340
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3341
    const Register tmp   = rbx;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3342
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3343
    BLOCK_COMMENT("Entry:");
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3344
    __ enter(); // required for proper stackwalking of RuntimeStub frame
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3345
    __ fast_exp(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3346
    __ leave(); // required for proper stackwalking of RuntimeStub frame
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3347
    __ ret(0);
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3348
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3349
    return start;
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3350
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3351
  }
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3352
33465
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3353
 address generate_libmLog() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3354
   StubCodeMark mark(this, "StubRoutines", "libmLog");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3355
33465
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3356
   address start = __ pc();
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3357
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3358
   const XMMRegister x0 = xmm0;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3359
   const XMMRegister x1 = xmm1;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3360
   const XMMRegister x2 = xmm2;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3361
   const XMMRegister x3 = xmm3;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3362
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3363
   const XMMRegister x4 = xmm4;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3364
   const XMMRegister x5 = xmm5;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3365
   const XMMRegister x6 = xmm6;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3366
   const XMMRegister x7 = xmm7;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3367
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3368
   const Register tmp = rbx;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3369
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3370
   BLOCK_COMMENT("Entry:");
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3371
   __ enter(); // required for proper stackwalking of RuntimeStub frame
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3372
   __ fast_log(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3373
   __ leave(); // required for proper stackwalking of RuntimeStub frame
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3374
   __ ret(0);
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3375
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3376
   return start;
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3377
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3378
 }
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3379
38018
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3380
 address generate_libmLog10() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3381
   StubCodeMark mark(this, "StubRoutines", "libmLog10");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3382
38018
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3383
   address start = __ pc();
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3384
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3385
   const XMMRegister x0 = xmm0;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3386
   const XMMRegister x1 = xmm1;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3387
   const XMMRegister x2 = xmm2;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3388
   const XMMRegister x3 = xmm3;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3389
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3390
   const XMMRegister x4 = xmm4;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3391
   const XMMRegister x5 = xmm5;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3392
   const XMMRegister x6 = xmm6;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3393
   const XMMRegister x7 = xmm7;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3394
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3395
   const Register tmp = rbx;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3396
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3397
   BLOCK_COMMENT("Entry:");
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3398
   __ enter(); // required for proper stackwalking of RuntimeStub frame
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3399
   __ fast_log10(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3400
   __ leave(); // required for proper stackwalking of RuntimeStub frame
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3401
   __ ret(0);
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3402
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3403
   return start;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3404
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3405
 }
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3406
35146
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3407
 address generate_libmPow() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3408
   StubCodeMark mark(this, "StubRoutines", "libmPow");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3409
35146
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3410
   address start = __ pc();
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3411
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3412
   const XMMRegister x0 = xmm0;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3413
   const XMMRegister x1 = xmm1;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3414
   const XMMRegister x2 = xmm2;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3415
   const XMMRegister x3 = xmm3;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3416
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3417
   const XMMRegister x4 = xmm4;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3418
   const XMMRegister x5 = xmm5;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3419
   const XMMRegister x6 = xmm6;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3420
   const XMMRegister x7 = xmm7;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3421
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3422
   const Register tmp = rbx;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3423
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3424
   BLOCK_COMMENT("Entry:");
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3425
   __ enter(); // required for proper stackwalking of RuntimeStub frame
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3426
   __ fast_pow(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3427
   __ leave(); // required for proper stackwalking of RuntimeStub frame
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3428
   __ ret(0);
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3429
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3430
   return start;
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3431
9ebfec283f56 8145688: Update for x86 pow in the math lib
kvn
parents: 35135
diff changeset
  3432
 }
33465
6063f28a6efb 8139575: Update for x86 log in the math lib
iveresov
parents: 33089
diff changeset
  3433
35540
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3434
 address generate_libm_reduce_pi04l() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3435
   StubCodeMark mark(this, "StubRoutines", "libm_reduce_pi04l");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3436
35540
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3437
   address start = __ pc();
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3438
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3439
   BLOCK_COMMENT("Entry:");
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3440
   __ libm_reduce_pi04l(rax, rcx, rdx, rbx, rsi, rdi, rbp, rsp);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3441
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3442
   return start;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3443
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3444
 }
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3445
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3446
 address generate_libm_sin_cos_huge() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3447
   StubCodeMark mark(this, "StubRoutines", "libm_sin_cos_huge");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3448
35540
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3449
   address start = __ pc();
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3450
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3451
   const XMMRegister x0 = xmm0;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3452
   const XMMRegister x1 = xmm1;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3453
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3454
   BLOCK_COMMENT("Entry:");
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3455
   __ libm_sincos_huge(x0, x1, rax, rcx, rdx, rbx, rsi, rdi, rbp, rsp);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3456
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3457
   return start;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3458
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3459
 }
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3460
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3461
 address generate_libmSin() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3462
   StubCodeMark mark(this, "StubRoutines", "libmSin");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3463
35540
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3464
   address start = __ pc();
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3465
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3466
   const XMMRegister x0 = xmm0;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3467
   const XMMRegister x1 = xmm1;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3468
   const XMMRegister x2 = xmm2;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3469
   const XMMRegister x3 = xmm3;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3470
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3471
   const XMMRegister x4 = xmm4;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3472
   const XMMRegister x5 = xmm5;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3473
   const XMMRegister x6 = xmm6;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3474
   const XMMRegister x7 = xmm7;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3475
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3476
   BLOCK_COMMENT("Entry:");
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3477
   __ enter(); // required for proper stackwalking of RuntimeStub frame
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3478
   __ fast_sin(x0, x1, x2, x3, x4, x5, x6, x7, rax, rbx, rdx);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3479
   __ leave(); // required for proper stackwalking of RuntimeStub frame
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3480
   __ ret(0);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3481
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3482
   return start;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3483
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3484
 }
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3485
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3486
 address generate_libmCos() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3487
   StubCodeMark mark(this, "StubRoutines", "libmCos");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3488
35540
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3489
   address start = __ pc();
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3490
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3491
   const XMMRegister x0 = xmm0;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3492
   const XMMRegister x1 = xmm1;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3493
   const XMMRegister x2 = xmm2;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3494
   const XMMRegister x3 = xmm3;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3495
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3496
   const XMMRegister x4 = xmm4;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3497
   const XMMRegister x5 = xmm5;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3498
   const XMMRegister x6 = xmm6;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3499
   const XMMRegister x7 = xmm7;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3500
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3501
   const Register tmp = rbx;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3502
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3503
   BLOCK_COMMENT("Entry:");
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3504
   __ enter(); // required for proper stackwalking of RuntimeStub frame
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3505
   __ fast_cos(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3506
   __ leave(); // required for proper stackwalking of RuntimeStub frame
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3507
   __ ret(0);
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3508
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3509
   return start;
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3510
e001ad24dcdb 8143353: update for x86 sin and cos in the math lib
vdeshpande
parents: 35537
diff changeset
  3511
 }
33089
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3512
38018
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3513
 address generate_libm_tan_cot_huge() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3514
   StubCodeMark mark(this, "StubRoutines", "libm_tan_cot_huge");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3515
38018
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3516
   address start = __ pc();
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3517
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3518
   const XMMRegister x0 = xmm0;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3519
   const XMMRegister x1 = xmm1;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3520
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3521
   BLOCK_COMMENT("Entry:");
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3522
   __ libm_tancot_huge(x0, x1, rax, rcx, rdx, rbx, rsi, rdi, rbp, rsp);
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3523
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3524
   return start;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3525
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3526
 }
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3527
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3528
 address generate_libmTan() {
47810
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3529
   StubCodeMark mark(this, "StubRoutines", "libmTan");
083c15bfba35 8190887: Stub code marking missing from some x86 generated stub routines
psandoz
parents: 47216
diff changeset
  3530
38018
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3531
   address start = __ pc();
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3532
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3533
   const XMMRegister x0 = xmm0;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3534
   const XMMRegister x1 = xmm1;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3535
   const XMMRegister x2 = xmm2;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3536
   const XMMRegister x3 = xmm3;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3537
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3538
   const XMMRegister x4 = xmm4;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3539
   const XMMRegister x5 = xmm5;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3540
   const XMMRegister x6 = xmm6;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3541
   const XMMRegister x7 = xmm7;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3542
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3543
   const Register tmp = rbx;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3544
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3545
   BLOCK_COMMENT("Entry:");
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3546
   __ enter(); // required for proper stackwalking of RuntimeStub frame
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3547
   __ fast_tan(x0, x1, x2, x3, x4, x5, x6, x7, rax, rcx, rdx, tmp);
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3548
   __ leave(); // required for proper stackwalking of RuntimeStub frame
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3549
   __ ret(0);
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3550
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3551
   return start;
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3552
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3553
 }
1dc6c6f21231 8152907: Update for x86 tan and log10 in the math lib
vdeshpande
parents: 36825
diff changeset
  3554
18740
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3555
  // Safefetch stubs.
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3556
  void generate_safefetch(const char* name, int size, address* entry,
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3557
                          address* fault_pc, address* continuation_pc) {
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3558
    // safefetch signatures:
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3559
    //   int      SafeFetch32(int*      adr, int      errValue);
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3560
    //   intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue);
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3561
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3562
    StubCodeMark mark(this, "StubRoutines", name);
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3563
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3564
    // Entry point, pc or function descriptor.
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3565
    *entry = __ pc();
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3566
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3567
    __ movl(rax, Address(rsp, 0x8));
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3568
    __ movl(rcx, Address(rsp, 0x4));
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3569
    // Load *adr into eax, may fault.
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3570
    *fault_pc = __ pc();
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3571
    switch (size) {
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3572
      case 4:
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3573
        // int32_t
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3574
        __ movl(rax, Address(rcx, 0));
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3575
        break;
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3576
      case 8:
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3577
        // int64_t
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3578
        Unimplemented();
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3579
        break;
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3580
      default:
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3581
        ShouldNotReachHere();
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3582
    }
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3583
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3584
    // Return errValue or *adr.
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3585
    *continuation_pc = __ pc();
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3586
    __ ret(0);
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3587
  }
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3588
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3589
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3590
  // Information about frame layout at time of blocking runtime call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3591
  // Note that we only have to preserve callee-saved registers since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3592
  // the compilers are responsible for supplying a continuation point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3593
  // if they expect all registers to be preserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3594
  enum layout {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3595
    thread_off,    // last_java_sp
10004
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3596
    arg1_off,
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3597
    arg2_off,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3598
    rbp_off,       // callee saved register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3599
    ret_pc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3600
    framesize
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3601
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3603
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3604
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3605
#undef  __
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3606
#define __ masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3608
  //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3609
  // Continuation point for throwing of implicit exceptions that are not handled in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3610
  // the current activation. Fabricates an exception oop and initiates normal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3611
  // exception dispatching in this frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3612
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3613
  // Previously the compiler (c2) allowed for callee save registers on Java calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3614
  // This is no longer true after adapter frames were removed but could possibly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3615
  // be brought back in the future if the interpreter code was reworked and it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3616
  // was deemed worthwhile. The comment below was left to describe what must
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3617
  // happen here if callee saves were resurrected. As it stands now this stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3618
  // could actually be a vanilla BufferBlob and have now oopMap at all.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3619
  // Since it doesn't make much difference we've chosen to leave it the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3620
  // way it was in the callee save days and keep the comment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3621
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3622
  // If we need to preserve callee-saved values we need a callee-saved oop map and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3623
  // therefore have to make these stubs into RuntimeStubs rather than BufferBlobs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3624
  // If the compiler needs all registers to be preserved between the fault
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3625
  // point and the exception handler then it must assume responsibility for that in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3626
  // AbstractCompiler::continuation_for_implicit_null_exception or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3627
  // continuation_for_implicit_division_by_zero_exception. All other implicit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3628
  // exceptions (e.g., NullPointerException or AbstractMethodError on entry) are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3629
  // either at call sites or otherwise assume that stack unwinding will be initiated,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3630
  // so caller saved registers were assumed volatile in the compiler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3631
  address generate_throw_exception(const char* name, address runtime_entry,
10545
fec876499aae 7088020: SEGV in JNIHandleBlock::release_block
never
parents: 10004
diff changeset
  3632
                                   Register arg1 = noreg, Register arg2 = noreg) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3634
    int insts_size = 256;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3635
    int locs_size  = 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3637
    CodeBuffer code(name, insts_size, locs_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3638
    OopMapSet* oop_maps  = new OopMapSet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3639
    MacroAssembler* masm = new MacroAssembler(&code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3640
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3641
    address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3642
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3643
    // This is an inlined and slightly modified version of call_VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3644
    // which has the ability to fetch the return PC out of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3645
    // thread-local storage and also sets up last_Java_sp slightly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3646
    // differently than the real call_VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3647
    Register java_thread = rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3648
    __ get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3650
    __ enter(); // required for proper stackwalking of RuntimeStub frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3651
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3652
    // pc and rbp, already pushed
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  3653
    __ subptr(rsp, (framesize-2) * wordSize); // prolog
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3654
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3655
    // Frame is now completed as far as size and linkage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3657
    int frame_complete = __ pc() - start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3658
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3659
    // push java thread (becomes first argument of C function)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  3660
    __ movptr(Address(rsp, thread_off * wordSize), java_thread);
10004
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3661
    if (arg1 != noreg) {
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3662
      __ movptr(Address(rsp, arg1_off * wordSize), arg1);
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3663
    }
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3664
    if (arg2 != noreg) {
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3665
      assert(arg1 != noreg, "missing reg arg");
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3666
      __ movptr(Address(rsp, arg2_off * wordSize), arg2);
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3667
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3668
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3669
    // Set up last_Java_sp and last_Java_fp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3670
    __ set_last_Java_frame(java_thread, rsp, rbp, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3671
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3672
    // Call runtime
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3673
    BLOCK_COMMENT("call runtime_entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3674
    __ call(RuntimeAddress(runtime_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3675
    // Generate oop map
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3676
    OopMap* map =  new OopMap(framesize, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3677
    oop_maps->add_gc_map(__ pc() - start, map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3679
    // restore the thread (cannot use the pushed argument since arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3680
    // may be overwritten by C code generated by an optimizing compiler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3681
    // however can use the register value directly if it is callee saved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3682
    __ get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3683
40644
39e631ed7145 8161598: Kitchensink fails: assert(nm->insts_contains(original_pc)) failed: original PC must be in nmethod/CompiledMethod
dlong
parents: 38699
diff changeset
  3684
    __ reset_last_Java_frame(java_thread, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3685
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3686
    __ leave(); // required for proper stackwalking of RuntimeStub frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3687
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3688
    // check for pending exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3689
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3690
    Label L;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  3691
    __ cmpptr(Address(java_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3692
    __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3693
    __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3694
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3695
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3696
    __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3697
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3698
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3699
    RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &code, frame_complete, framesize, oop_maps, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3700
    return stub->entry_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3701
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3703
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3704
  void create_control_words() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3705
    // Round to nearest, 53-bit mode, exceptions masked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3706
    StubRoutines::_fpu_cntrl_wrd_std   = 0x027F;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3707
    // Round to zero, 53-bit mode, exception mased
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3708
    StubRoutines::_fpu_cntrl_wrd_trunc = 0x0D7F;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3709
    // Round to nearest, 24-bit mode, exceptions masked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3710
    StubRoutines::_fpu_cntrl_wrd_24    = 0x007F;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3711
    // Round to nearest, 64-bit mode, exceptions masked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3712
    StubRoutines::_mxcsr_std           = 0x1F80;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3713
    // Note: the following two constants are 80-bit values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3714
    //       layout is critical for correct loading by FPU.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3715
    // Bias for strict fp multiply/divide
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3716
    StubRoutines::_fpu_subnormal_bias1[0]= 0x00000000; // 2^(-15360) == 0x03ff 8000 0000 0000 0000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3717
    StubRoutines::_fpu_subnormal_bias1[1]= 0x80000000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3718
    StubRoutines::_fpu_subnormal_bias1[2]= 0x03ff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3719
    // Un-Bias for strict fp multiply/divide
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3720
    StubRoutines::_fpu_subnormal_bias2[0]= 0x00000000; // 2^(+15360) == 0x7bff 8000 0000 0000 0000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3721
    StubRoutines::_fpu_subnormal_bias2[1]= 0x80000000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3722
    StubRoutines::_fpu_subnormal_bias2[2]= 0x7bff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3724
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3725
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3726
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3727
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3728
  void generate_initial() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3729
    // Generates all stubs and initializes the entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3731
    //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3732
    // entry points that exist in all platforms
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3733
    // Note: This is code that could be shared among different platforms - however the benefit seems to be smaller than
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3734
    //       the disadvantage of having a much more complicated generator structure. See also comment in stubRoutines.hpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3735
    StubRoutines::_forward_exception_entry      = generate_forward_exception();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3736
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3737
    StubRoutines::_call_stub_entry              =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3738
      generate_call_stub(StubRoutines::_call_stub_return_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3739
    // is referenced by megamorphic call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3740
    StubRoutines::_catch_exception_entry        = generate_catch_exception();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3741
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3742
    // These are currently used by Solaris/Intel
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3743
    StubRoutines::_atomic_xchg_entry            = generate_atomic_xchg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3745
    // platform dependent
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3746
    create_control_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3747
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  3748
    StubRoutines::x86::_verify_mxcsr_entry                 = generate_verify_mxcsr();
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 957
diff changeset
  3749
    StubRoutines::x86::_verify_fpu_cntrl_wrd_entry         = generate_verify_fpu_cntrl_wrd();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3750
    StubRoutines::_d2i_wrapper                              = generate_d2i_wrapper(T_INT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3751
                                                                                   CAST_FROM_FN_PTR(address, SharedRuntime::d2i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3752
    StubRoutines::_d2l_wrapper                              = generate_d2i_wrapper(T_LONG,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3753
                                                                                   CAST_FROM_FN_PTR(address, SharedRuntime::d2l));
10004
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3754
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 8498
diff changeset
  3755
    // Build this early so it's available for the interpreter
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 33465
diff changeset
  3756
    StubRoutines::_throw_StackOverflowError_entry          = generate_throw_exception("StackOverflowError throw_exception",
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 33465
diff changeset
  3757
                                                                                      CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 33465
diff changeset
  3758
    StubRoutines::_throw_delayed_StackOverflowError_entry  = generate_throw_exception("delayed StackOverflowError throw_exception",
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 33465
diff changeset
  3759
                                                                                      CAST_FROM_FN_PTR(address, SharedRuntime::throw_delayed_StackOverflowError));
18507
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3760
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3761
    if (UseCRC32Intrinsics) {
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3762
      // set table address before stub generation which use it
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3763
      StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table;
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3764
      StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32();
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 18073
diff changeset
  3765
    }
33066
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3766
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3767
    if (UseCRC32CIntrinsics) {
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3768
      bool supports_clmul = VM_Version::supports_clmul();
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3769
      StubRoutines::x86::generate_CRC32C_table(supports_clmul);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3770
      StubRoutines::_crc32c_table_addr = (address)StubRoutines::x86::_crc32c_table;
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3771
      StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C(supports_clmul);
d98eab8215c4 8134553: CRC32C implementations for x86/x64 targets
kvn
parents: 32727
diff changeset
  3772
    }
42618
08162de8f053 8170430: x86 pow() stub from Intel libm is inconsistent with pow() from fdlib
vdeshpande
parents: 40644
diff changeset
  3773
    if (VM_Version::supports_sse2() && UseLibmIntrinsic && InlineIntrinsics) {
38699
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3774
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dsin) ||
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3775
          vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dcos) ||
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3776
          vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3777
        StubRoutines::x86::_L_2il0floatpacket_0_adr = (address)StubRoutines::x86::_L_2il0floatpacket_0;
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3778
        StubRoutines::x86::_Pi4Inv_adr = (address)StubRoutines::x86::_Pi4Inv;
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3779
        StubRoutines::x86::_Pi4x3_adr = (address)StubRoutines::x86::_Pi4x3;
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3780
        StubRoutines::x86::_Pi4x4_adr = (address)StubRoutines::x86::_Pi4x4;
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3781
        StubRoutines::x86::_ones_adr = (address)StubRoutines::x86::_ones;
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3782
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3783
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dexp)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3784
        StubRoutines::_dexp = generate_libmExp();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3785
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3786
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dlog)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3787
        StubRoutines::_dlog = generate_libmLog();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3788
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3789
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dlog10)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3790
        StubRoutines::_dlog10 = generate_libmLog10();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3791
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3792
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dpow)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3793
        StubRoutines::_dpow = generate_libmPow();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3794
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3795
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dsin) ||
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3796
        vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dcos) ||
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3797
        vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3798
        StubRoutines::_dlibm_reduce_pi04l = generate_libm_reduce_pi04l();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3799
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3800
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dsin) ||
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3801
        vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dcos)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3802
        StubRoutines::_dlibm_sin_cos_huge = generate_libm_sin_cos_huge();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3803
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3804
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dsin)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3805
        StubRoutines::_dsin = generate_libmSin();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3806
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3807
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dcos)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3808
        StubRoutines::_dcos = generate_libmCos();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3809
      }
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3810
      if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) {
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3811
        StubRoutines::_dlibm_tan_cot_huge = generate_libm_tan_cot_huge();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3812
        StubRoutines::_dtan = generate_libmTan();
f8bec5f6b09c 8154473: Update for CompilerDirectives to control stub generation and intrinsics
vdeshpande
parents: 38209
diff changeset
  3813
      }
33089
f4e956ed8b43 8132207: update for x86 exp in the math lib
iveresov
parents: 33066
diff changeset
  3814
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3817
  void generate_all() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3818
    // Generates all stubs and initializes the entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3819
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3820
    // These entry points require SharedInfo::stack0 to be set up in non-core builds
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3821
    // and need to be relocatable, so they each fabricate a RuntimeStub internally.
10545
fec876499aae 7088020: SEGV in JNIHandleBlock::release_block
never
parents: 10004
diff changeset
  3822
    StubRoutines::_throw_AbstractMethodError_entry         = generate_throw_exception("AbstractMethodError throw_exception",          CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError));
fec876499aae 7088020: SEGV in JNIHandleBlock::release_block
never
parents: 10004
diff changeset
  3823
    StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError));
fec876499aae 7088020: SEGV in JNIHandleBlock::release_block
never
parents: 10004
diff changeset
  3824
    StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3826
    //------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3827
    // entry points that are platform specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3828
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3829
    // support for verify_oop (must happen after universe_init)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3830
    StubRoutines::_verify_oop_subroutine_entry     = generate_verify_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3831
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3832
    // arraycopy stubs used by compilers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3833
    generate_arraycopy_stubs();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2259
diff changeset
  3834
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3835
    // don't bother generating these AES intrinsic stubs unless global flag is set
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3836
    if (UseAESIntrinsics) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3837
      StubRoutines::x86::_key_shuffle_mask_addr = generate_key_shuffle_mask();  // might be needed by the others
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3838
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3839
      StubRoutines::_aescrypt_encryptBlock = generate_aescrypt_encryptBlock();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3840
      StubRoutines::_aescrypt_decryptBlock = generate_aescrypt_decryptBlock();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3841
      StubRoutines::_cipherBlockChaining_encryptAESCrypt = generate_cipherBlockChaining_encryptAESCrypt();
36825
6ebe5519b753 8152354: Update for x86 AES CBC Decryption
vdeshpande
parents: 36555
diff changeset
  3842
      StubRoutines::_cipherBlockChaining_decryptAESCrypt = generate_cipherBlockChaining_decryptAESCrypt_Parallel();
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents: 13952
diff changeset
  3843
    }
18740
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3844
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3845
    if (UseAESCTRIntrinsics) {
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3846
      StubRoutines::x86::_counter_shuffle_mask_addr = generate_counter_shuffle_mask();
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3847
      StubRoutines::_counterMode_AESCrypt = generate_counterMode_AESCrypt_Parallel();
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3848
    }
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 35146
diff changeset
  3849
36555
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3850
    if (UseSHA1Intrinsics) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3851
      StubRoutines::x86::_upper_word_mask_addr = generate_upper_word_mask();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3852
      StubRoutines::x86::_shuffle_byte_flip_mask_addr = generate_shuffle_byte_flip_mask();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3853
      StubRoutines::_sha1_implCompress = generate_sha1_implCompress(false, "sha1_implCompress");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3854
      StubRoutines::_sha1_implCompressMB = generate_sha1_implCompress(true, "sha1_implCompressMB");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3855
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3856
    if (UseSHA256Intrinsics) {
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3857
      StubRoutines::x86::_k256_adr = (address)StubRoutines::x86::_k256;
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3858
      StubRoutines::x86::_pshuffle_byte_flip_mask_addr = generate_pshuffle_byte_flip_mask();
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3859
      StubRoutines::_sha256_implCompress = generate_sha256_implCompress(false, "sha256_implCompress");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3860
      StubRoutines::_sha256_implCompressMB = generate_sha256_implCompress(true, "sha256_implCompressMB");
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3861
    }
4f37fd7a5a09 8150767: Enables SHA Extensions on x86
vdeshpande
parents: 35540
diff changeset
  3862
31404
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3863
    // Generate GHASH intrinsics code
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3864
    if (UseGHASHIntrinsics) {
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3865
      StubRoutines::x86::_ghash_long_swap_mask_addr = generate_ghash_long_swap_mask();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3866
      StubRoutines::x86::_ghash_byte_swap_mask_addr = generate_ghash_byte_swap_mask();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3867
      StubRoutines::_ghash_processBlocks = generate_ghash_processBlocks();
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3868
    }
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 30624
diff changeset
  3869
18740
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3870
    // Safefetch stubs.
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3871
    generate_safefetch("SafeFetch32", sizeof(int), &StubRoutines::_safefetch32_entry,
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3872
                                                   &StubRoutines::_safefetch32_fault_pc,
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3873
                                                   &StubRoutines::_safefetch32_continuation_pc);
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3874
    StubRoutines::_safefetchN_entry           = StubRoutines::_safefetch32_entry;
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3875
    StubRoutines::_safefetchN_fault_pc        = StubRoutines::_safefetch32_fault_pc;
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 18507
diff changeset
  3876
    StubRoutines::_safefetchN_continuation_pc = StubRoutines::_safefetch32_continuation_pc;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3877
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3878
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3879
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3880
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3881
  StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3882
    if (all) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3883
      generate_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3884
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3885
      generate_initial();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3886
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3887
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3888
}; // end class declaration
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3891
void StubGenerator_generate(CodeBuffer* code, bool all) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3892
  StubGenerator g(code, all);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3893
}