src/cpu/sparc/vm/stubGenerator_sparc.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6697
0342d80559e0
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.inline.hpp"
aoqi@0 27 #include "interpreter/interpreter.hpp"
aoqi@0 28 #include "nativeInst_sparc.hpp"
aoqi@0 29 #include "oops/instanceOop.hpp"
aoqi@0 30 #include "oops/method.hpp"
aoqi@0 31 #include "oops/objArrayKlass.hpp"
aoqi@0 32 #include "oops/oop.inline.hpp"
aoqi@0 33 #include "prims/methodHandles.hpp"
aoqi@0 34 #include "runtime/frame.inline.hpp"
aoqi@0 35 #include "runtime/handles.inline.hpp"
aoqi@0 36 #include "runtime/sharedRuntime.hpp"
aoqi@0 37 #include "runtime/stubCodeGenerator.hpp"
aoqi@0 38 #include "runtime/stubRoutines.hpp"
aoqi@0 39 #include "runtime/thread.inline.hpp"
aoqi@0 40 #include "utilities/top.hpp"
aoqi@0 41 #ifdef COMPILER2
aoqi@0 42 #include "opto/runtime.hpp"
aoqi@0 43 #endif
aoqi@0 44
aoqi@0 45 // Declaration and definition of StubGenerator (no .hpp file).
aoqi@0 46 // For a more detailed description of the stub routine structure
aoqi@0 47 // see the comment in stubRoutines.hpp.
aoqi@0 48
aoqi@0 49 #define __ _masm->
aoqi@0 50
aoqi@0 51 #ifdef PRODUCT
aoqi@0 52 #define BLOCK_COMMENT(str) /* nothing */
aoqi@0 53 #else
aoqi@0 54 #define BLOCK_COMMENT(str) __ block_comment(str)
aoqi@0 55 #endif
aoqi@0 56
aoqi@0 57 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
aoqi@0 58
aoqi@0 59 // Note: The register L7 is used as L7_thread_cache, and may not be used
aoqi@0 60 // any other way within this module.
aoqi@0 61
aoqi@0 62
aoqi@0 63 static const Register& Lstub_temp = L2;
aoqi@0 64
aoqi@0 65 // -------------------------------------------------------------------------------------------------------------------------
aoqi@0 66 // Stub Code definitions
aoqi@0 67
aoqi@0 68 static address handle_unsafe_access() {
aoqi@0 69 JavaThread* thread = JavaThread::current();
aoqi@0 70 address pc = thread->saved_exception_pc();
aoqi@0 71 address npc = thread->saved_exception_npc();
aoqi@0 72 // pc is the instruction which we must emulate
aoqi@0 73 // doing a no-op is fine: return garbage from the load
aoqi@0 74
aoqi@0 75 // request an async exception
aoqi@0 76 thread->set_pending_unsafe_access_error();
aoqi@0 77
aoqi@0 78 // return address of next instruction to execute
aoqi@0 79 return npc;
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 class StubGenerator: public StubCodeGenerator {
aoqi@0 83 private:
aoqi@0 84
aoqi@0 85 #ifdef PRODUCT
aoqi@0 86 #define inc_counter_np(a,b,c)
aoqi@0 87 #else
aoqi@0 88 #define inc_counter_np(counter, t1, t2) \
aoqi@0 89 BLOCK_COMMENT("inc_counter " #counter); \
aoqi@0 90 __ inc_counter(&counter, t1, t2);
aoqi@0 91 #endif
aoqi@0 92
aoqi@0 93 //----------------------------------------------------------------------------------------------------
aoqi@0 94 // Call stubs are used to call Java from C
aoqi@0 95
aoqi@0 96 address generate_call_stub(address& return_pc) {
aoqi@0 97 StubCodeMark mark(this, "StubRoutines", "call_stub");
aoqi@0 98 address start = __ pc();
aoqi@0 99
aoqi@0 100 // Incoming arguments:
aoqi@0 101 //
aoqi@0 102 // o0 : call wrapper address
aoqi@0 103 // o1 : result (address)
aoqi@0 104 // o2 : result type
aoqi@0 105 // o3 : method
aoqi@0 106 // o4 : (interpreter) entry point
aoqi@0 107 // o5 : parameters (address)
aoqi@0 108 // [sp + 0x5c]: parameter size (in words)
aoqi@0 109 // [sp + 0x60]: thread
aoqi@0 110 //
aoqi@0 111 // +---------------+ <--- sp + 0
aoqi@0 112 // | |
aoqi@0 113 // . reg save area .
aoqi@0 114 // | |
aoqi@0 115 // +---------------+ <--- sp + 0x40
aoqi@0 116 // | |
aoqi@0 117 // . extra 7 slots .
aoqi@0 118 // | |
aoqi@0 119 // +---------------+ <--- sp + 0x5c
aoqi@0 120 // | param. size |
aoqi@0 121 // +---------------+ <--- sp + 0x60
aoqi@0 122 // | thread |
aoqi@0 123 // +---------------+
aoqi@0 124 // | |
aoqi@0 125
aoqi@0 126 // note: if the link argument position changes, adjust
aoqi@0 127 // the code in frame::entry_frame_call_wrapper()
aoqi@0 128
aoqi@0 129 const Argument link = Argument(0, false); // used only for GC
aoqi@0 130 const Argument result = Argument(1, false);
aoqi@0 131 const Argument result_type = Argument(2, false);
aoqi@0 132 const Argument method = Argument(3, false);
aoqi@0 133 const Argument entry_point = Argument(4, false);
aoqi@0 134 const Argument parameters = Argument(5, false);
aoqi@0 135 const Argument parameter_size = Argument(6, false);
aoqi@0 136 const Argument thread = Argument(7, false);
aoqi@0 137
aoqi@0 138 // setup thread register
aoqi@0 139 __ ld_ptr(thread.as_address(), G2_thread);
aoqi@0 140 __ reinit_heapbase();
aoqi@0 141
aoqi@0 142 #ifdef ASSERT
aoqi@0 143 // make sure we have no pending exceptions
aoqi@0 144 { const Register t = G3_scratch;
aoqi@0 145 Label L;
aoqi@0 146 __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), t);
aoqi@0 147 __ br_null_short(t, Assembler::pt, L);
aoqi@0 148 __ stop("StubRoutines::call_stub: entered with pending exception");
aoqi@0 149 __ bind(L);
aoqi@0 150 }
aoqi@0 151 #endif
aoqi@0 152
aoqi@0 153 // create activation frame & allocate space for parameters
aoqi@0 154 { const Register t = G3_scratch;
aoqi@0 155 __ ld_ptr(parameter_size.as_address(), t); // get parameter size (in words)
aoqi@0 156 __ add(t, frame::memory_parameter_word_sp_offset, t); // add space for save area (in words)
aoqi@0 157 __ round_to(t, WordsPerLong); // make sure it is multiple of 2 (in words)
aoqi@0 158 __ sll(t, Interpreter::logStackElementSize, t); // compute number of bytes
aoqi@0 159 __ neg(t); // negate so it can be used with save
aoqi@0 160 __ save(SP, t, SP); // setup new frame
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 // +---------------+ <--- sp + 0
aoqi@0 164 // | |
aoqi@0 165 // . reg save area .
aoqi@0 166 // | |
aoqi@0 167 // +---------------+ <--- sp + 0x40
aoqi@0 168 // | |
aoqi@0 169 // . extra 7 slots .
aoqi@0 170 // | |
aoqi@0 171 // +---------------+ <--- sp + 0x5c
aoqi@0 172 // | empty slot | (only if parameter size is even)
aoqi@0 173 // +---------------+
aoqi@0 174 // | |
aoqi@0 175 // . parameters .
aoqi@0 176 // | |
aoqi@0 177 // +---------------+ <--- fp + 0
aoqi@0 178 // | |
aoqi@0 179 // . reg save area .
aoqi@0 180 // | |
aoqi@0 181 // +---------------+ <--- fp + 0x40
aoqi@0 182 // | |
aoqi@0 183 // . extra 7 slots .
aoqi@0 184 // | |
aoqi@0 185 // +---------------+ <--- fp + 0x5c
aoqi@0 186 // | param. size |
aoqi@0 187 // +---------------+ <--- fp + 0x60
aoqi@0 188 // | thread |
aoqi@0 189 // +---------------+
aoqi@0 190 // | |
aoqi@0 191
aoqi@0 192 // pass parameters if any
aoqi@0 193 BLOCK_COMMENT("pass parameters if any");
aoqi@0 194 { const Register src = parameters.as_in().as_register();
aoqi@0 195 const Register dst = Lentry_args;
aoqi@0 196 const Register tmp = G3_scratch;
aoqi@0 197 const Register cnt = G4_scratch;
aoqi@0 198
aoqi@0 199 // test if any parameters & setup of Lentry_args
aoqi@0 200 Label exit;
aoqi@0 201 __ ld_ptr(parameter_size.as_in().as_address(), cnt); // parameter counter
aoqi@0 202 __ add( FP, STACK_BIAS, dst );
aoqi@0 203 __ cmp_zero_and_br(Assembler::zero, cnt, exit);
aoqi@0 204 __ delayed()->sub(dst, BytesPerWord, dst); // setup Lentry_args
aoqi@0 205
aoqi@0 206 // copy parameters if any
aoqi@0 207 Label loop;
aoqi@0 208 __ BIND(loop);
aoqi@0 209 // Store parameter value
aoqi@0 210 __ ld_ptr(src, 0, tmp);
aoqi@0 211 __ add(src, BytesPerWord, src);
aoqi@0 212 __ st_ptr(tmp, dst, 0);
aoqi@0 213 __ deccc(cnt);
aoqi@0 214 __ br(Assembler::greater, false, Assembler::pt, loop);
aoqi@0 215 __ delayed()->sub(dst, Interpreter::stackElementSize, dst);
aoqi@0 216
aoqi@0 217 // done
aoqi@0 218 __ BIND(exit);
aoqi@0 219 }
aoqi@0 220
aoqi@0 221 // setup parameters, method & call Java function
aoqi@0 222 #ifdef ASSERT
aoqi@0 223 // layout_activation_impl checks it's notion of saved SP against
aoqi@0 224 // this register, so if this changes update it as well.
aoqi@0 225 const Register saved_SP = Lscratch;
aoqi@0 226 __ mov(SP, saved_SP); // keep track of SP before call
aoqi@0 227 #endif
aoqi@0 228
aoqi@0 229 // setup parameters
aoqi@0 230 const Register t = G3_scratch;
aoqi@0 231 __ ld_ptr(parameter_size.as_in().as_address(), t); // get parameter size (in words)
aoqi@0 232 __ sll(t, Interpreter::logStackElementSize, t); // compute number of bytes
aoqi@0 233 __ sub(FP, t, Gargs); // setup parameter pointer
aoqi@0 234 #ifdef _LP64
aoqi@0 235 __ add( Gargs, STACK_BIAS, Gargs ); // Account for LP64 stack bias
aoqi@0 236 #endif
aoqi@0 237 __ mov(SP, O5_savedSP);
aoqi@0 238
aoqi@0 239
aoqi@0 240 // do the call
aoqi@0 241 //
aoqi@0 242 // the following register must be setup:
aoqi@0 243 //
aoqi@0 244 // G2_thread
aoqi@0 245 // G5_method
aoqi@0 246 // Gargs
aoqi@0 247 BLOCK_COMMENT("call Java function");
aoqi@0 248 __ jmpl(entry_point.as_in().as_register(), G0, O7);
aoqi@0 249 __ delayed()->mov(method.as_in().as_register(), G5_method); // setup method
aoqi@0 250
aoqi@0 251 BLOCK_COMMENT("call_stub_return_address:");
aoqi@0 252 return_pc = __ pc();
aoqi@0 253
aoqi@0 254 // The callee, if it wasn't interpreted, can return with SP changed so
aoqi@0 255 // we can no longer assert of change of SP.
aoqi@0 256
aoqi@0 257 // store result depending on type
aoqi@0 258 // (everything that is not T_OBJECT, T_LONG, T_FLOAT, or T_DOUBLE
aoqi@0 259 // is treated as T_INT)
aoqi@0 260 { const Register addr = result .as_in().as_register();
aoqi@0 261 const Register type = result_type.as_in().as_register();
aoqi@0 262 Label is_long, is_float, is_double, is_object, exit;
aoqi@0 263 __ cmp(type, T_OBJECT); __ br(Assembler::equal, false, Assembler::pn, is_object);
aoqi@0 264 __ delayed()->cmp(type, T_FLOAT); __ br(Assembler::equal, false, Assembler::pn, is_float);
aoqi@0 265 __ delayed()->cmp(type, T_DOUBLE); __ br(Assembler::equal, false, Assembler::pn, is_double);
aoqi@0 266 __ delayed()->cmp(type, T_LONG); __ br(Assembler::equal, false, Assembler::pn, is_long);
aoqi@0 267 __ delayed()->nop();
aoqi@0 268
aoqi@0 269 // store int result
aoqi@0 270 __ st(O0, addr, G0);
aoqi@0 271
aoqi@0 272 __ BIND(exit);
aoqi@0 273 __ ret();
aoqi@0 274 __ delayed()->restore();
aoqi@0 275
aoqi@0 276 __ BIND(is_object);
aoqi@0 277 __ ba(exit);
aoqi@0 278 __ delayed()->st_ptr(O0, addr, G0);
aoqi@0 279
aoqi@0 280 __ BIND(is_float);
aoqi@0 281 __ ba(exit);
aoqi@0 282 __ delayed()->stf(FloatRegisterImpl::S, F0, addr, G0);
aoqi@0 283
aoqi@0 284 __ BIND(is_double);
aoqi@0 285 __ ba(exit);
aoqi@0 286 __ delayed()->stf(FloatRegisterImpl::D, F0, addr, G0);
aoqi@0 287
aoqi@0 288 __ BIND(is_long);
aoqi@0 289 #ifdef _LP64
aoqi@0 290 __ ba(exit);
aoqi@0 291 __ delayed()->st_long(O0, addr, G0); // store entire long
aoqi@0 292 #else
aoqi@0 293 #if defined(COMPILER2)
aoqi@0 294 // All return values are where we want them, except for Longs. C2 returns
aoqi@0 295 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.
aoqi@0 296 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit
aoqi@0 297 // build we simply always use G1.
aoqi@0 298 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to
aoqi@0 299 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node
aoqi@0 300 // first which would move g1 -> O0/O1 and destroy the exception we were throwing.
aoqi@0 301
aoqi@0 302 __ ba(exit);
aoqi@0 303 __ delayed()->stx(G1, addr, G0); // store entire long
aoqi@0 304 #else
aoqi@0 305 __ st(O1, addr, BytesPerInt);
aoqi@0 306 __ ba(exit);
aoqi@0 307 __ delayed()->st(O0, addr, G0);
aoqi@0 308 #endif /* COMPILER2 */
aoqi@0 309 #endif /* _LP64 */
aoqi@0 310 }
aoqi@0 311 return start;
aoqi@0 312 }
aoqi@0 313
aoqi@0 314
aoqi@0 315 //----------------------------------------------------------------------------------------------------
aoqi@0 316 // Return point for a Java call if there's an exception thrown in Java code.
aoqi@0 317 // The exception is caught and transformed into a pending exception stored in
aoqi@0 318 // JavaThread that can be tested from within the VM.
aoqi@0 319 //
aoqi@0 320 // Oexception: exception oop
aoqi@0 321
aoqi@0 322 address generate_catch_exception() {
aoqi@0 323 StubCodeMark mark(this, "StubRoutines", "catch_exception");
aoqi@0 324
aoqi@0 325 address start = __ pc();
aoqi@0 326 // verify that thread corresponds
aoqi@0 327 __ verify_thread();
aoqi@0 328
aoqi@0 329 const Register& temp_reg = Gtemp;
aoqi@0 330 Address pending_exception_addr (G2_thread, Thread::pending_exception_offset());
aoqi@0 331 Address exception_file_offset_addr(G2_thread, Thread::exception_file_offset ());
aoqi@0 332 Address exception_line_offset_addr(G2_thread, Thread::exception_line_offset ());
aoqi@0 333
aoqi@0 334 // set pending exception
aoqi@0 335 __ verify_oop(Oexception);
aoqi@0 336 __ st_ptr(Oexception, pending_exception_addr);
aoqi@0 337 __ set((intptr_t)__FILE__, temp_reg);
aoqi@0 338 __ st_ptr(temp_reg, exception_file_offset_addr);
aoqi@0 339 __ set((intptr_t)__LINE__, temp_reg);
aoqi@0 340 __ st(temp_reg, exception_line_offset_addr);
aoqi@0 341
aoqi@0 342 // complete return to VM
aoqi@0 343 assert(StubRoutines::_call_stub_return_address != NULL, "must have been generated before");
aoqi@0 344
aoqi@0 345 AddressLiteral stub_ret(StubRoutines::_call_stub_return_address);
aoqi@0 346 __ jump_to(stub_ret, temp_reg);
aoqi@0 347 __ delayed()->nop();
aoqi@0 348
aoqi@0 349 return start;
aoqi@0 350 }
aoqi@0 351
aoqi@0 352
aoqi@0 353 //----------------------------------------------------------------------------------------------------
aoqi@0 354 // Continuation point for runtime calls returning with a pending exception
aoqi@0 355 // The pending exception check happened in the runtime or native call stub
aoqi@0 356 // The pending exception in Thread is converted into a Java-level exception
aoqi@0 357 //
aoqi@0 358 // Contract with Java-level exception handler: O0 = exception
aoqi@0 359 // O1 = throwing pc
aoqi@0 360
aoqi@0 361 address generate_forward_exception() {
aoqi@0 362 StubCodeMark mark(this, "StubRoutines", "forward_exception");
aoqi@0 363 address start = __ pc();
aoqi@0 364
aoqi@0 365 // Upon entry, O7 has the return address returning into Java
aoqi@0 366 // (interpreted or compiled) code; i.e. the return address
aoqi@0 367 // becomes the throwing pc.
aoqi@0 368
aoqi@0 369 const Register& handler_reg = Gtemp;
aoqi@0 370
aoqi@0 371 Address exception_addr(G2_thread, Thread::pending_exception_offset());
aoqi@0 372
aoqi@0 373 #ifdef ASSERT
aoqi@0 374 // make sure that this code is only executed if there is a pending exception
aoqi@0 375 { Label L;
aoqi@0 376 __ ld_ptr(exception_addr, Gtemp);
aoqi@0 377 __ br_notnull_short(Gtemp, Assembler::pt, L);
aoqi@0 378 __ stop("StubRoutines::forward exception: no pending exception (1)");
aoqi@0 379 __ bind(L);
aoqi@0 380 }
aoqi@0 381 #endif
aoqi@0 382
aoqi@0 383 // compute exception handler into handler_reg
aoqi@0 384 __ get_thread();
aoqi@0 385 __ ld_ptr(exception_addr, Oexception);
aoqi@0 386 __ verify_oop(Oexception);
aoqi@0 387 __ save_frame(0); // compensates for compiler weakness
aoqi@0 388 __ add(O7->after_save(), frame::pc_return_offset, Lscratch); // save the issuing PC
aoqi@0 389 BLOCK_COMMENT("call exception_handler_for_return_address");
aoqi@0 390 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), G2_thread, Lscratch);
aoqi@0 391 __ mov(O0, handler_reg);
aoqi@0 392 __ restore(); // compensates for compiler weakness
aoqi@0 393
aoqi@0 394 __ ld_ptr(exception_addr, Oexception);
aoqi@0 395 __ add(O7, frame::pc_return_offset, Oissuing_pc); // save the issuing PC
aoqi@0 396
aoqi@0 397 #ifdef ASSERT
aoqi@0 398 // make sure exception is set
aoqi@0 399 { Label L;
aoqi@0 400 __ br_notnull_short(Oexception, Assembler::pt, L);
aoqi@0 401 __ stop("StubRoutines::forward exception: no pending exception (2)");
aoqi@0 402 __ bind(L);
aoqi@0 403 }
aoqi@0 404 #endif
aoqi@0 405 // jump to exception handler
aoqi@0 406 __ jmp(handler_reg, 0);
aoqi@0 407 // clear pending exception
aoqi@0 408 __ delayed()->st_ptr(G0, exception_addr);
aoqi@0 409
aoqi@0 410 return start;
aoqi@0 411 }
aoqi@0 412
aoqi@0 413 // Safefetch stubs.
aoqi@0 414 void generate_safefetch(const char* name, int size, address* entry,
aoqi@0 415 address* fault_pc, address* continuation_pc) {
aoqi@0 416 // safefetch signatures:
aoqi@0 417 // int SafeFetch32(int* adr, int errValue);
aoqi@0 418 // intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue);
aoqi@0 419 //
aoqi@0 420 // arguments:
aoqi@0 421 // o0 = adr
aoqi@0 422 // o1 = errValue
aoqi@0 423 //
aoqi@0 424 // result:
aoqi@0 425 // o0 = *adr or errValue
aoqi@0 426
aoqi@0 427 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 428
aoqi@0 429 // Entry point, pc or function descriptor.
aoqi@0 430 __ align(CodeEntryAlignment);
aoqi@0 431 *entry = __ pc();
aoqi@0 432
aoqi@0 433 __ mov(O0, G1); // g1 = o0
aoqi@0 434 __ mov(O1, O0); // o0 = o1
aoqi@0 435 // Load *adr into c_rarg1, may fault.
aoqi@0 436 *fault_pc = __ pc();
aoqi@0 437 switch (size) {
aoqi@0 438 case 4:
aoqi@0 439 // int32_t
aoqi@0 440 __ ldsw(G1, 0, O0); // o0 = [g1]
aoqi@0 441 break;
aoqi@0 442 case 8:
aoqi@0 443 // int64_t
aoqi@0 444 __ ldx(G1, 0, O0); // o0 = [g1]
aoqi@0 445 break;
aoqi@0 446 default:
aoqi@0 447 ShouldNotReachHere();
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 // return errValue or *adr
aoqi@0 451 *continuation_pc = __ pc();
aoqi@0 452 // By convention with the trap handler we ensure there is a non-CTI
aoqi@0 453 // instruction in the trap shadow.
aoqi@0 454 __ nop();
aoqi@0 455 __ retl();
aoqi@0 456 __ delayed()->nop();
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 460 // Continuation point for throwing of implicit exceptions that are not handled in
aoqi@0 461 // the current activation. Fabricates an exception oop and initiates normal
aoqi@0 462 // exception dispatching in this frame. Only callee-saved registers are preserved
aoqi@0 463 // (through the normal register window / RegisterMap handling).
aoqi@0 464 // If the compiler needs all registers to be preserved between the fault
aoqi@0 465 // point and the exception handler then it must assume responsibility for that in
aoqi@0 466 // AbstractCompiler::continuation_for_implicit_null_exception or
aoqi@0 467 // continuation_for_implicit_division_by_zero_exception. All other implicit
aoqi@0 468 // exceptions (e.g., NullPointerException or AbstractMethodError on entry) are
aoqi@0 469 // either at call sites or otherwise assume that stack unwinding will be initiated,
aoqi@0 470 // so caller saved registers were assumed volatile in the compiler.
aoqi@0 471
aoqi@0 472 // Note that we generate only this stub into a RuntimeStub, because it needs to be
aoqi@0 473 // properly traversed and ignored during GC, so we change the meaning of the "__"
aoqi@0 474 // macro within this method.
aoqi@0 475 #undef __
aoqi@0 476 #define __ masm->
aoqi@0 477
aoqi@0 478 address generate_throw_exception(const char* name, address runtime_entry,
aoqi@0 479 Register arg1 = noreg, Register arg2 = noreg) {
aoqi@0 480 #ifdef ASSERT
aoqi@0 481 int insts_size = VerifyThread ? 1 * K : 600;
aoqi@0 482 #else
aoqi@0 483 int insts_size = VerifyThread ? 1 * K : 256;
aoqi@0 484 #endif /* ASSERT */
aoqi@0 485 int locs_size = 32;
aoqi@0 486
aoqi@0 487 CodeBuffer code(name, insts_size, locs_size);
aoqi@0 488 MacroAssembler* masm = new MacroAssembler(&code);
aoqi@0 489
aoqi@0 490 __ verify_thread();
aoqi@0 491
aoqi@0 492 // This is an inlined and slightly modified version of call_VM
aoqi@0 493 // which has the ability to fetch the return PC out of thread-local storage
aoqi@0 494 __ assert_not_delayed();
aoqi@0 495
aoqi@0 496 // Note that we always push a frame because on the SPARC
aoqi@0 497 // architecture, for all of our implicit exception kinds at call
aoqi@0 498 // sites, the implicit exception is taken before the callee frame
aoqi@0 499 // is pushed.
aoqi@0 500 __ save_frame(0);
aoqi@0 501
aoqi@0 502 int frame_complete = __ offset();
aoqi@0 503
aoqi@0 504 // Note that we always have a runtime stub frame on the top of stack by this point
aoqi@0 505 Register last_java_sp = SP;
aoqi@0 506 // 64-bit last_java_sp is biased!
aoqi@0 507 __ set_last_Java_frame(last_java_sp, G0);
aoqi@0 508 if (VerifyThread) __ mov(G2_thread, O0); // about to be smashed; pass early
aoqi@0 509 __ save_thread(noreg);
aoqi@0 510 if (arg1 != noreg) {
aoqi@0 511 assert(arg2 != O1, "clobbered");
aoqi@0 512 __ mov(arg1, O1);
aoqi@0 513 }
aoqi@0 514 if (arg2 != noreg) {
aoqi@0 515 __ mov(arg2, O2);
aoqi@0 516 }
aoqi@0 517 // do the call
aoqi@0 518 BLOCK_COMMENT("call runtime_entry");
aoqi@0 519 __ call(runtime_entry, relocInfo::runtime_call_type);
aoqi@0 520 if (!VerifyThread)
aoqi@0 521 __ delayed()->mov(G2_thread, O0); // pass thread as first argument
aoqi@0 522 else
aoqi@0 523 __ delayed()->nop(); // (thread already passed)
aoqi@0 524 __ restore_thread(noreg);
aoqi@0 525 __ reset_last_Java_frame();
aoqi@0 526
aoqi@0 527 // check for pending exceptions. use Gtemp as scratch register.
aoqi@0 528 #ifdef ASSERT
aoqi@0 529 Label L;
aoqi@0 530
aoqi@0 531 Address exception_addr(G2_thread, Thread::pending_exception_offset());
aoqi@0 532 Register scratch_reg = Gtemp;
aoqi@0 533 __ ld_ptr(exception_addr, scratch_reg);
aoqi@0 534 __ br_notnull_short(scratch_reg, Assembler::pt, L);
aoqi@0 535 __ should_not_reach_here();
aoqi@0 536 __ bind(L);
aoqi@0 537 #endif // ASSERT
aoqi@0 538 BLOCK_COMMENT("call forward_exception_entry");
aoqi@0 539 __ call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
aoqi@0 540 // we use O7 linkage so that forward_exception_entry has the issuing PC
aoqi@0 541 __ delayed()->restore();
aoqi@0 542
aoqi@0 543 RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &code, frame_complete, masm->total_frame_size_in_bytes(0), NULL, false);
aoqi@0 544 return stub->entry_point();
aoqi@0 545 }
aoqi@0 546
aoqi@0 547 #undef __
aoqi@0 548 #define __ _masm->
aoqi@0 549
aoqi@0 550
aoqi@0 551 // Generate a routine that sets all the registers so we
aoqi@0 552 // can tell if the stop routine prints them correctly.
aoqi@0 553 address generate_test_stop() {
aoqi@0 554 StubCodeMark mark(this, "StubRoutines", "test_stop");
aoqi@0 555 address start = __ pc();
aoqi@0 556
aoqi@0 557 int i;
aoqi@0 558
aoqi@0 559 __ save_frame(0);
aoqi@0 560
aoqi@0 561 static jfloat zero = 0.0, one = 1.0;
aoqi@0 562
aoqi@0 563 // put addr in L0, then load through L0 to F0
aoqi@0 564 __ set((intptr_t)&zero, L0); __ ldf( FloatRegisterImpl::S, L0, 0, F0);
aoqi@0 565 __ set((intptr_t)&one, L0); __ ldf( FloatRegisterImpl::S, L0, 0, F1); // 1.0 to F1
aoqi@0 566
aoqi@0 567 // use add to put 2..18 in F2..F18
aoqi@0 568 for ( i = 2; i <= 18; ++i ) {
aoqi@0 569 __ fadd( FloatRegisterImpl::S, F1, as_FloatRegister(i-1), as_FloatRegister(i));
aoqi@0 570 }
aoqi@0 571
aoqi@0 572 // Now put double 2 in F16, double 18 in F18
aoqi@0 573 __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, F2, F16 );
aoqi@0 574 __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, F18, F18 );
aoqi@0 575
aoqi@0 576 // use add to put 20..32 in F20..F32
aoqi@0 577 for (i = 20; i < 32; i += 2) {
aoqi@0 578 __ fadd( FloatRegisterImpl::D, F16, as_FloatRegister(i-2), as_FloatRegister(i));
aoqi@0 579 }
aoqi@0 580
aoqi@0 581 // put 0..7 in i's, 8..15 in l's, 16..23 in o's, 24..31 in g's
aoqi@0 582 for ( i = 0; i < 8; ++i ) {
aoqi@0 583 if (i < 6) {
aoqi@0 584 __ set( i, as_iRegister(i));
aoqi@0 585 __ set(16 + i, as_oRegister(i));
aoqi@0 586 __ set(24 + i, as_gRegister(i));
aoqi@0 587 }
aoqi@0 588 __ set( 8 + i, as_lRegister(i));
aoqi@0 589 }
aoqi@0 590
aoqi@0 591 __ stop("testing stop");
aoqi@0 592
aoqi@0 593
aoqi@0 594 __ ret();
aoqi@0 595 __ delayed()->restore();
aoqi@0 596
aoqi@0 597 return start;
aoqi@0 598 }
aoqi@0 599
aoqi@0 600
aoqi@0 601 address generate_stop_subroutine() {
aoqi@0 602 StubCodeMark mark(this, "StubRoutines", "stop_subroutine");
aoqi@0 603 address start = __ pc();
aoqi@0 604
aoqi@0 605 __ stop_subroutine();
aoqi@0 606
aoqi@0 607 return start;
aoqi@0 608 }
aoqi@0 609
aoqi@0 610 address generate_flush_callers_register_windows() {
aoqi@0 611 StubCodeMark mark(this, "StubRoutines", "flush_callers_register_windows");
aoqi@0 612 address start = __ pc();
aoqi@0 613
aoqi@0 614 __ flushw();
aoqi@0 615 __ retl(false);
aoqi@0 616 __ delayed()->add( FP, STACK_BIAS, O0 );
aoqi@0 617 // The returned value must be a stack pointer whose register save area
aoqi@0 618 // is flushed, and will stay flushed while the caller executes.
aoqi@0 619
aoqi@0 620 return start;
aoqi@0 621 }
aoqi@0 622
aoqi@0 623 // Support for jint Atomic::xchg(jint exchange_value, volatile jint* dest).
aoqi@0 624 //
aoqi@0 625 // Arguments:
aoqi@0 626 //
aoqi@0 627 // exchange_value: O0
aoqi@0 628 // dest: O1
aoqi@0 629 //
aoqi@0 630 // Results:
aoqi@0 631 //
aoqi@0 632 // O0: the value previously stored in dest
aoqi@0 633 //
aoqi@0 634 address generate_atomic_xchg() {
aoqi@0 635 StubCodeMark mark(this, "StubRoutines", "atomic_xchg");
aoqi@0 636 address start = __ pc();
aoqi@0 637
aoqi@0 638 if (UseCASForSwap) {
aoqi@0 639 // Use CAS instead of swap, just in case the MP hardware
aoqi@0 640 // prefers to work with just one kind of synch. instruction.
aoqi@0 641 Label retry;
aoqi@0 642 __ BIND(retry);
aoqi@0 643 __ mov(O0, O3); // scratch copy of exchange value
aoqi@0 644 __ ld(O1, 0, O2); // observe the previous value
aoqi@0 645 // try to replace O2 with O3
aoqi@0 646 __ cas(O1, O2, O3);
aoqi@0 647 __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pn, retry);
aoqi@0 648
aoqi@0 649 __ retl(false);
aoqi@0 650 __ delayed()->mov(O2, O0); // report previous value to caller
aoqi@0 651 } else {
aoqi@0 652 __ retl(false);
aoqi@0 653 __ delayed()->swap(O1, 0, O0);
aoqi@0 654 }
aoqi@0 655
aoqi@0 656 return start;
aoqi@0 657 }
aoqi@0 658
aoqi@0 659
aoqi@0 660 // Support for jint Atomic::cmpxchg(jint exchange_value, volatile jint* dest, jint compare_value)
aoqi@0 661 //
aoqi@0 662 // Arguments:
aoqi@0 663 //
aoqi@0 664 // exchange_value: O0
aoqi@0 665 // dest: O1
aoqi@0 666 // compare_value: O2
aoqi@0 667 //
aoqi@0 668 // Results:
aoqi@0 669 //
aoqi@0 670 // O0: the value previously stored in dest
aoqi@0 671 //
aoqi@0 672 address generate_atomic_cmpxchg() {
aoqi@0 673 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg");
aoqi@0 674 address start = __ pc();
aoqi@0 675
aoqi@0 676 // cmpxchg(dest, compare_value, exchange_value)
aoqi@0 677 __ cas(O1, O2, O0);
aoqi@0 678 __ retl(false);
aoqi@0 679 __ delayed()->nop();
aoqi@0 680
aoqi@0 681 return start;
aoqi@0 682 }
aoqi@0 683
aoqi@0 684 // Support for jlong Atomic::cmpxchg(jlong exchange_value, volatile jlong *dest, jlong compare_value)
aoqi@0 685 //
aoqi@0 686 // Arguments:
aoqi@0 687 //
aoqi@0 688 // exchange_value: O1:O0
aoqi@0 689 // dest: O2
aoqi@0 690 // compare_value: O4:O3
aoqi@0 691 //
aoqi@0 692 // Results:
aoqi@0 693 //
aoqi@0 694 // O1:O0: the value previously stored in dest
aoqi@0 695 //
aoqi@0 696 // Overwrites: G1,G2,G3
aoqi@0 697 //
aoqi@0 698 address generate_atomic_cmpxchg_long() {
aoqi@0 699 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long");
aoqi@0 700 address start = __ pc();
aoqi@0 701
aoqi@0 702 __ sllx(O0, 32, O0);
aoqi@0 703 __ srl(O1, 0, O1);
aoqi@0 704 __ or3(O0,O1,O0); // O0 holds 64-bit value from compare_value
aoqi@0 705 __ sllx(O3, 32, O3);
aoqi@0 706 __ srl(O4, 0, O4);
aoqi@0 707 __ or3(O3,O4,O3); // O3 holds 64-bit value from exchange_value
aoqi@0 708 __ casx(O2, O3, O0);
aoqi@0 709 __ srl(O0, 0, O1); // unpacked return value in O1:O0
aoqi@0 710 __ retl(false);
aoqi@0 711 __ delayed()->srlx(O0, 32, O0);
aoqi@0 712
aoqi@0 713 return start;
aoqi@0 714 }
aoqi@0 715
aoqi@0 716
aoqi@0 717 // Support for jint Atomic::add(jint add_value, volatile jint* dest).
aoqi@0 718 //
aoqi@0 719 // Arguments:
aoqi@0 720 //
aoqi@0 721 // add_value: O0 (e.g., +1 or -1)
aoqi@0 722 // dest: O1
aoqi@0 723 //
aoqi@0 724 // Results:
aoqi@0 725 //
aoqi@0 726 // O0: the new value stored in dest
aoqi@0 727 //
aoqi@0 728 // Overwrites: O3
aoqi@0 729 //
aoqi@0 730 address generate_atomic_add() {
aoqi@0 731 StubCodeMark mark(this, "StubRoutines", "atomic_add");
aoqi@0 732 address start = __ pc();
aoqi@0 733 __ BIND(_atomic_add_stub);
aoqi@0 734
aoqi@0 735 Label(retry);
aoqi@0 736 __ BIND(retry);
aoqi@0 737
aoqi@0 738 __ lduw(O1, 0, O2);
aoqi@0 739 __ add(O0, O2, O3);
aoqi@0 740 __ cas(O1, O2, O3);
aoqi@0 741 __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pn, retry);
aoqi@0 742 __ retl(false);
aoqi@0 743 __ delayed()->add(O0, O2, O0); // note that cas made O2==O3
aoqi@0 744
aoqi@0 745 return start;
aoqi@0 746 }
aoqi@0 747 Label _atomic_add_stub; // called from other stubs
aoqi@0 748
aoqi@0 749
aoqi@0 750 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 751 // The following routine generates a subroutine to throw an asynchronous
aoqi@0 752 // UnknownError when an unsafe access gets a fault that could not be
aoqi@0 753 // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.)
aoqi@0 754 //
aoqi@0 755 // Arguments :
aoqi@0 756 //
aoqi@0 757 // trapping PC: O7
aoqi@0 758 //
aoqi@0 759 // Results:
aoqi@0 760 // posts an asynchronous exception, skips the trapping instruction
aoqi@0 761 //
aoqi@0 762
aoqi@0 763 address generate_handler_for_unsafe_access() {
aoqi@0 764 StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access");
aoqi@0 765 address start = __ pc();
aoqi@0 766
aoqi@0 767 const int preserve_register_words = (64 * 2);
aoqi@0 768 Address preserve_addr(FP, (-preserve_register_words * wordSize) + STACK_BIAS);
aoqi@0 769
aoqi@0 770 Register Lthread = L7_thread_cache;
aoqi@0 771 int i;
aoqi@0 772
aoqi@0 773 __ save_frame(0);
aoqi@0 774 __ mov(G1, L1);
aoqi@0 775 __ mov(G2, L2);
aoqi@0 776 __ mov(G3, L3);
aoqi@0 777 __ mov(G4, L4);
aoqi@0 778 __ mov(G5, L5);
aoqi@0 779 for (i = 0; i < 64; i += 2) {
aoqi@0 780 __ stf(FloatRegisterImpl::D, as_FloatRegister(i), preserve_addr, i * wordSize);
aoqi@0 781 }
aoqi@0 782
aoqi@0 783 address entry_point = CAST_FROM_FN_PTR(address, handle_unsafe_access);
aoqi@0 784 BLOCK_COMMENT("call handle_unsafe_access");
aoqi@0 785 __ call(entry_point, relocInfo::runtime_call_type);
aoqi@0 786 __ delayed()->nop();
aoqi@0 787
aoqi@0 788 __ mov(L1, G1);
aoqi@0 789 __ mov(L2, G2);
aoqi@0 790 __ mov(L3, G3);
aoqi@0 791 __ mov(L4, G4);
aoqi@0 792 __ mov(L5, G5);
aoqi@0 793 for (i = 0; i < 64; i += 2) {
aoqi@0 794 __ ldf(FloatRegisterImpl::D, preserve_addr, as_FloatRegister(i), i * wordSize);
aoqi@0 795 }
aoqi@0 796
aoqi@0 797 __ verify_thread();
aoqi@0 798
aoqi@0 799 __ jmp(O0, 0);
aoqi@0 800 __ delayed()->restore();
aoqi@0 801
aoqi@0 802 return start;
aoqi@0 803 }
aoqi@0 804
aoqi@0 805
aoqi@0 806 // Support for uint StubRoutine::Sparc::partial_subtype_check( Klass sub, Klass super );
aoqi@0 807 // Arguments :
aoqi@0 808 //
aoqi@0 809 // ret : O0, returned
aoqi@0 810 // icc/xcc: set as O0 (depending on wordSize)
aoqi@0 811 // sub : O1, argument, not changed
aoqi@0 812 // super: O2, argument, not changed
aoqi@0 813 // raddr: O7, blown by call
aoqi@0 814 address generate_partial_subtype_check() {
aoqi@0 815 __ align(CodeEntryAlignment);
aoqi@0 816 StubCodeMark mark(this, "StubRoutines", "partial_subtype_check");
aoqi@0 817 address start = __ pc();
aoqi@0 818 Label miss;
aoqi@0 819
aoqi@0 820 #if defined(COMPILER2) && !defined(_LP64)
aoqi@0 821 // Do not use a 'save' because it blows the 64-bit O registers.
aoqi@0 822 __ add(SP,-4*wordSize,SP); // Make space for 4 temps (stack must be 2 words aligned)
aoqi@0 823 __ st_ptr(L0,SP,(frame::register_save_words+0)*wordSize);
aoqi@0 824 __ st_ptr(L1,SP,(frame::register_save_words+1)*wordSize);
aoqi@0 825 __ st_ptr(L2,SP,(frame::register_save_words+2)*wordSize);
aoqi@0 826 __ st_ptr(L3,SP,(frame::register_save_words+3)*wordSize);
aoqi@0 827 Register Rret = O0;
aoqi@0 828 Register Rsub = O1;
aoqi@0 829 Register Rsuper = O2;
aoqi@0 830 #else
aoqi@0 831 __ save_frame(0);
aoqi@0 832 Register Rret = I0;
aoqi@0 833 Register Rsub = I1;
aoqi@0 834 Register Rsuper = I2;
aoqi@0 835 #endif
aoqi@0 836
aoqi@0 837 Register L0_ary_len = L0;
aoqi@0 838 Register L1_ary_ptr = L1;
aoqi@0 839 Register L2_super = L2;
aoqi@0 840 Register L3_index = L3;
aoqi@0 841
aoqi@0 842 __ check_klass_subtype_slow_path(Rsub, Rsuper,
aoqi@0 843 L0, L1, L2, L3,
aoqi@0 844 NULL, &miss);
aoqi@0 845
aoqi@0 846 // Match falls through here.
aoqi@0 847 __ addcc(G0,0,Rret); // set Z flags, Z result
aoqi@0 848
aoqi@0 849 #if defined(COMPILER2) && !defined(_LP64)
aoqi@0 850 __ ld_ptr(SP,(frame::register_save_words+0)*wordSize,L0);
aoqi@0 851 __ ld_ptr(SP,(frame::register_save_words+1)*wordSize,L1);
aoqi@0 852 __ ld_ptr(SP,(frame::register_save_words+2)*wordSize,L2);
aoqi@0 853 __ ld_ptr(SP,(frame::register_save_words+3)*wordSize,L3);
aoqi@0 854 __ retl(); // Result in Rret is zero; flags set to Z
aoqi@0 855 __ delayed()->add(SP,4*wordSize,SP);
aoqi@0 856 #else
aoqi@0 857 __ ret(); // Result in Rret is zero; flags set to Z
aoqi@0 858 __ delayed()->restore();
aoqi@0 859 #endif
aoqi@0 860
aoqi@0 861 __ BIND(miss);
aoqi@0 862 __ addcc(G0,1,Rret); // set NZ flags, NZ result
aoqi@0 863
aoqi@0 864 #if defined(COMPILER2) && !defined(_LP64)
aoqi@0 865 __ ld_ptr(SP,(frame::register_save_words+0)*wordSize,L0);
aoqi@0 866 __ ld_ptr(SP,(frame::register_save_words+1)*wordSize,L1);
aoqi@0 867 __ ld_ptr(SP,(frame::register_save_words+2)*wordSize,L2);
aoqi@0 868 __ ld_ptr(SP,(frame::register_save_words+3)*wordSize,L3);
aoqi@0 869 __ retl(); // Result in Rret is != 0; flags set to NZ
aoqi@0 870 __ delayed()->add(SP,4*wordSize,SP);
aoqi@0 871 #else
aoqi@0 872 __ ret(); // Result in Rret is != 0; flags set to NZ
aoqi@0 873 __ delayed()->restore();
aoqi@0 874 #endif
aoqi@0 875
aoqi@0 876 return start;
aoqi@0 877 }
aoqi@0 878
aoqi@0 879
aoqi@0 880 // Called from MacroAssembler::verify_oop
aoqi@0 881 //
aoqi@0 882 address generate_verify_oop_subroutine() {
aoqi@0 883 StubCodeMark mark(this, "StubRoutines", "verify_oop_stub");
aoqi@0 884
aoqi@0 885 address start = __ pc();
aoqi@0 886
aoqi@0 887 __ verify_oop_subroutine();
aoqi@0 888
aoqi@0 889 return start;
aoqi@0 890 }
aoqi@0 891
aoqi@0 892
aoqi@0 893 //
aoqi@0 894 // Verify that a register contains clean 32-bits positive value
aoqi@0 895 // (high 32-bits are 0) so it could be used in 64-bits shifts (sllx, srax).
aoqi@0 896 //
aoqi@0 897 // Input:
aoqi@0 898 // Rint - 32-bits value
aoqi@0 899 // Rtmp - scratch
aoqi@0 900 //
aoqi@0 901 void assert_clean_int(Register Rint, Register Rtmp) {
aoqi@0 902 #if defined(ASSERT) && defined(_LP64)
aoqi@0 903 __ signx(Rint, Rtmp);
aoqi@0 904 __ cmp(Rint, Rtmp);
aoqi@0 905 __ breakpoint_trap(Assembler::notEqual, Assembler::xcc);
aoqi@0 906 #endif
aoqi@0 907 }
aoqi@0 908
aoqi@0 909 //
aoqi@0 910 // Generate overlap test for array copy stubs
aoqi@0 911 //
aoqi@0 912 // Input:
aoqi@0 913 // O0 - array1
aoqi@0 914 // O1 - array2
aoqi@0 915 // O2 - element count
aoqi@0 916 //
aoqi@0 917 // Kills temps: O3, O4
aoqi@0 918 //
aoqi@0 919 void array_overlap_test(address no_overlap_target, int log2_elem_size) {
aoqi@0 920 assert(no_overlap_target != NULL, "must be generated");
aoqi@0 921 array_overlap_test(no_overlap_target, NULL, log2_elem_size);
aoqi@0 922 }
aoqi@0 923 void array_overlap_test(Label& L_no_overlap, int log2_elem_size) {
aoqi@0 924 array_overlap_test(NULL, &L_no_overlap, log2_elem_size);
aoqi@0 925 }
aoqi@0 926 void array_overlap_test(address no_overlap_target, Label* NOLp, int log2_elem_size) {
aoqi@0 927 const Register from = O0;
aoqi@0 928 const Register to = O1;
aoqi@0 929 const Register count = O2;
aoqi@0 930 const Register to_from = O3; // to - from
aoqi@0 931 const Register byte_count = O4; // count << log2_elem_size
aoqi@0 932
aoqi@0 933 __ subcc(to, from, to_from);
aoqi@0 934 __ sll_ptr(count, log2_elem_size, byte_count);
aoqi@0 935 if (NOLp == NULL)
aoqi@0 936 __ brx(Assembler::lessEqualUnsigned, false, Assembler::pt, no_overlap_target);
aoqi@0 937 else
aoqi@0 938 __ brx(Assembler::lessEqualUnsigned, false, Assembler::pt, (*NOLp));
aoqi@0 939 __ delayed()->cmp(to_from, byte_count);
aoqi@0 940 if (NOLp == NULL)
aoqi@0 941 __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, no_overlap_target);
aoqi@0 942 else
aoqi@0 943 __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, (*NOLp));
aoqi@0 944 __ delayed()->nop();
aoqi@0 945 }
aoqi@0 946
aoqi@0 947 //
aoqi@0 948 // Generate pre-write barrier for array.
aoqi@0 949 //
aoqi@0 950 // Input:
aoqi@0 951 // addr - register containing starting address
aoqi@0 952 // count - register containing element count
aoqi@0 953 // tmp - scratch register
aoqi@0 954 //
aoqi@0 955 // The input registers are overwritten.
aoqi@0 956 //
aoqi@0 957 void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) {
aoqi@0 958 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 959 switch (bs->kind()) {
aoqi@0 960 case BarrierSet::G1SATBCT:
aoqi@0 961 case BarrierSet::G1SATBCTLogging:
aoqi@0 962 // With G1, don't generate the call if we statically know that the target in uninitialized
aoqi@0 963 if (!dest_uninitialized) {
aoqi@0 964 __ save_frame(0);
aoqi@0 965 // Save the necessary global regs... will be used after.
aoqi@0 966 if (addr->is_global()) {
aoqi@0 967 __ mov(addr, L0);
aoqi@0 968 }
aoqi@0 969 if (count->is_global()) {
aoqi@0 970 __ mov(count, L1);
aoqi@0 971 }
aoqi@0 972 __ mov(addr->after_save(), O0);
aoqi@0 973 // Get the count into O1
aoqi@0 974 __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre));
aoqi@0 975 __ delayed()->mov(count->after_save(), O1);
aoqi@0 976 if (addr->is_global()) {
aoqi@0 977 __ mov(L0, addr);
aoqi@0 978 }
aoqi@0 979 if (count->is_global()) {
aoqi@0 980 __ mov(L1, count);
aoqi@0 981 }
aoqi@0 982 __ restore();
aoqi@0 983 }
aoqi@0 984 break;
aoqi@0 985 case BarrierSet::CardTableModRef:
aoqi@0 986 case BarrierSet::CardTableExtension:
aoqi@0 987 case BarrierSet::ModRef:
aoqi@0 988 break;
aoqi@0 989 default:
aoqi@0 990 ShouldNotReachHere();
aoqi@0 991 }
aoqi@0 992 }
aoqi@0 993 //
aoqi@0 994 // Generate post-write barrier for array.
aoqi@0 995 //
aoqi@0 996 // Input:
aoqi@0 997 // addr - register containing starting address
aoqi@0 998 // count - register containing element count
aoqi@0 999 // tmp - scratch register
aoqi@0 1000 //
aoqi@0 1001 // The input registers are overwritten.
aoqi@0 1002 //
aoqi@0 1003 void gen_write_ref_array_post_barrier(Register addr, Register count,
aoqi@0 1004 Register tmp) {
aoqi@0 1005 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1006
aoqi@0 1007 switch (bs->kind()) {
aoqi@0 1008 case BarrierSet::G1SATBCT:
aoqi@0 1009 case BarrierSet::G1SATBCTLogging:
aoqi@0 1010 {
aoqi@0 1011 // Get some new fresh output registers.
aoqi@0 1012 __ save_frame(0);
aoqi@0 1013 __ mov(addr->after_save(), O0);
aoqi@0 1014 __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post));
aoqi@0 1015 __ delayed()->mov(count->after_save(), O1);
aoqi@0 1016 __ restore();
aoqi@0 1017 }
aoqi@0 1018 break;
aoqi@0 1019 case BarrierSet::CardTableModRef:
aoqi@0 1020 case BarrierSet::CardTableExtension:
aoqi@0 1021 {
aoqi@0 1022 CardTableModRefBS* ct = (CardTableModRefBS*)bs;
aoqi@0 1023 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@0 1024 assert_different_registers(addr, count, tmp);
aoqi@0 1025
aoqi@0 1026 Label L_loop;
aoqi@0 1027
aoqi@0 1028 __ sll_ptr(count, LogBytesPerHeapOop, count);
aoqi@0 1029 __ sub(count, BytesPerHeapOop, count);
aoqi@0 1030 __ add(count, addr, count);
aoqi@0 1031 // Use two shifts to clear out those low order two bits! (Cannot opt. into 1.)
aoqi@0 1032 __ srl_ptr(addr, CardTableModRefBS::card_shift, addr);
aoqi@0 1033 __ srl_ptr(count, CardTableModRefBS::card_shift, count);
aoqi@0 1034 __ sub(count, addr, count);
aoqi@0 1035 AddressLiteral rs(ct->byte_map_base);
aoqi@0 1036 __ set(rs, tmp);
aoqi@0 1037 __ BIND(L_loop);
aoqi@0 1038 __ stb(G0, tmp, addr);
aoqi@0 1039 __ subcc(count, 1, count);
aoqi@0 1040 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop);
aoqi@0 1041 __ delayed()->add(addr, 1, addr);
aoqi@0 1042 }
aoqi@0 1043 break;
aoqi@0 1044 case BarrierSet::ModRef:
aoqi@0 1045 break;
aoqi@0 1046 default:
aoqi@0 1047 ShouldNotReachHere();
aoqi@0 1048 }
aoqi@0 1049 }
aoqi@0 1050
aoqi@0 1051 //
aoqi@0 1052 // Generate main code for disjoint arraycopy
aoqi@0 1053 //
aoqi@0 1054 typedef void (StubGenerator::*CopyLoopFunc)(Register from, Register to, Register count, int count_dec,
aoqi@0 1055 Label& L_loop, bool use_prefetch, bool use_bis);
aoqi@0 1056
aoqi@0 1057 void disjoint_copy_core(Register from, Register to, Register count, int log2_elem_size,
aoqi@0 1058 int iter_size, StubGenerator::CopyLoopFunc copy_loop_func) {
aoqi@0 1059 Label L_copy;
aoqi@0 1060
aoqi@0 1061 assert(log2_elem_size <= 3, "the following code should be changed");
aoqi@0 1062 int count_dec = 16>>log2_elem_size;
aoqi@0 1063
aoqi@0 1064 int prefetch_dist = MAX2(ArraycopySrcPrefetchDistance, ArraycopyDstPrefetchDistance);
aoqi@0 1065 assert(prefetch_dist < 4096, "invalid value");
aoqi@0 1066 prefetch_dist = (prefetch_dist + (iter_size-1)) & (-iter_size); // round up to one iteration copy size
aoqi@0 1067 int prefetch_count = (prefetch_dist >> log2_elem_size); // elements count
aoqi@0 1068
aoqi@0 1069 if (UseBlockCopy) {
aoqi@0 1070 Label L_block_copy, L_block_copy_prefetch, L_skip_block_copy;
aoqi@0 1071
aoqi@0 1072 // 64 bytes tail + bytes copied in one loop iteration
aoqi@0 1073 int tail_size = 64 + iter_size;
aoqi@0 1074 int block_copy_count = (MAX2(tail_size, (int)BlockCopyLowLimit)) >> log2_elem_size;
aoqi@0 1075 // Use BIS copy only for big arrays since it requires membar.
aoqi@0 1076 __ set(block_copy_count, O4);
aoqi@0 1077 __ cmp_and_br_short(count, O4, Assembler::lessUnsigned, Assembler::pt, L_skip_block_copy);
aoqi@0 1078 // This code is for disjoint source and destination:
aoqi@0 1079 // to <= from || to >= from+count
aoqi@0 1080 // but BIS will stomp over 'from' if (to > from-tail_size && to <= from)
aoqi@0 1081 __ sub(from, to, O4);
aoqi@0 1082 __ srax(O4, 4, O4); // divide by 16 since following short branch have only 5 bits for imm.
aoqi@0 1083 __ cmp_and_br_short(O4, (tail_size>>4), Assembler::lessEqualUnsigned, Assembler::pn, L_skip_block_copy);
aoqi@0 1084
aoqi@0 1085 __ wrasi(G0, Assembler::ASI_ST_BLKINIT_PRIMARY);
aoqi@0 1086 // BIS should not be used to copy tail (64 bytes+iter_size)
aoqi@0 1087 // to avoid zeroing of following values.
aoqi@0 1088 __ sub(count, (tail_size>>log2_elem_size), count); // count is still positive >= 0
aoqi@0 1089
aoqi@0 1090 if (prefetch_count > 0) { // rounded up to one iteration count
aoqi@0 1091 // Do prefetching only if copy size is bigger
aoqi@0 1092 // than prefetch distance.
aoqi@0 1093 __ set(prefetch_count, O4);
aoqi@0 1094 __ cmp_and_brx_short(count, O4, Assembler::less, Assembler::pt, L_block_copy);
aoqi@0 1095 __ sub(count, prefetch_count, count);
aoqi@0 1096
aoqi@0 1097 (this->*copy_loop_func)(from, to, count, count_dec, L_block_copy_prefetch, true, true);
aoqi@0 1098 __ add(count, prefetch_count, count); // restore count
aoqi@0 1099
aoqi@0 1100 } // prefetch_count > 0
aoqi@0 1101
aoqi@0 1102 (this->*copy_loop_func)(from, to, count, count_dec, L_block_copy, false, true);
aoqi@0 1103 __ add(count, (tail_size>>log2_elem_size), count); // restore count
aoqi@0 1104
aoqi@0 1105 __ wrasi(G0, Assembler::ASI_PRIMARY_NOFAULT);
aoqi@0 1106 // BIS needs membar.
aoqi@0 1107 __ membar(Assembler::StoreLoad);
aoqi@0 1108 // Copy tail
aoqi@0 1109 __ ba_short(L_copy);
aoqi@0 1110
aoqi@0 1111 __ BIND(L_skip_block_copy);
aoqi@0 1112 } // UseBlockCopy
aoqi@0 1113
aoqi@0 1114 if (prefetch_count > 0) { // rounded up to one iteration count
aoqi@0 1115 // Do prefetching only if copy size is bigger
aoqi@0 1116 // than prefetch distance.
aoqi@0 1117 __ set(prefetch_count, O4);
aoqi@0 1118 __ cmp_and_brx_short(count, O4, Assembler::lessUnsigned, Assembler::pt, L_copy);
aoqi@0 1119 __ sub(count, prefetch_count, count);
aoqi@0 1120
aoqi@0 1121 Label L_copy_prefetch;
aoqi@0 1122 (this->*copy_loop_func)(from, to, count, count_dec, L_copy_prefetch, true, false);
aoqi@0 1123 __ add(count, prefetch_count, count); // restore count
aoqi@0 1124
aoqi@0 1125 } // prefetch_count > 0
aoqi@0 1126
aoqi@0 1127 (this->*copy_loop_func)(from, to, count, count_dec, L_copy, false, false);
aoqi@0 1128 }
aoqi@0 1129
aoqi@0 1130
aoqi@0 1131
aoqi@0 1132 //
aoqi@0 1133 // Helper methods for copy_16_bytes_forward_with_shift()
aoqi@0 1134 //
aoqi@0 1135 void copy_16_bytes_shift_loop(Register from, Register to, Register count, int count_dec,
aoqi@0 1136 Label& L_loop, bool use_prefetch, bool use_bis) {
aoqi@0 1137
aoqi@0 1138 const Register left_shift = G1; // left shift bit counter
aoqi@0 1139 const Register right_shift = G5; // right shift bit counter
aoqi@0 1140
aoqi@0 1141 __ align(OptoLoopAlignment);
aoqi@0 1142 __ BIND(L_loop);
aoqi@0 1143 if (use_prefetch) {
aoqi@0 1144 if (ArraycopySrcPrefetchDistance > 0) {
aoqi@0 1145 __ prefetch(from, ArraycopySrcPrefetchDistance, Assembler::severalReads);
aoqi@0 1146 }
aoqi@0 1147 if (ArraycopyDstPrefetchDistance > 0) {
aoqi@0 1148 __ prefetch(to, ArraycopyDstPrefetchDistance, Assembler::severalWritesAndPossiblyReads);
aoqi@0 1149 }
aoqi@0 1150 }
aoqi@0 1151 __ ldx(from, 0, O4);
aoqi@0 1152 __ ldx(from, 8, G4);
aoqi@0 1153 __ inc(to, 16);
aoqi@0 1154 __ inc(from, 16);
aoqi@0 1155 __ deccc(count, count_dec); // Can we do next iteration after this one?
aoqi@0 1156 __ srlx(O4, right_shift, G3);
aoqi@0 1157 __ bset(G3, O3);
aoqi@0 1158 __ sllx(O4, left_shift, O4);
aoqi@0 1159 __ srlx(G4, right_shift, G3);
aoqi@0 1160 __ bset(G3, O4);
aoqi@0 1161 if (use_bis) {
aoqi@0 1162 __ stxa(O3, to, -16);
aoqi@0 1163 __ stxa(O4, to, -8);
aoqi@0 1164 } else {
aoqi@0 1165 __ stx(O3, to, -16);
aoqi@0 1166 __ stx(O4, to, -8);
aoqi@0 1167 }
aoqi@0 1168 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop);
aoqi@0 1169 __ delayed()->sllx(G4, left_shift, O3);
aoqi@0 1170 }
aoqi@0 1171
aoqi@0 1172 // Copy big chunks forward with shift
aoqi@0 1173 //
aoqi@0 1174 // Inputs:
aoqi@0 1175 // from - source arrays
aoqi@0 1176 // to - destination array aligned to 8-bytes
aoqi@0 1177 // count - elements count to copy >= the count equivalent to 16 bytes
aoqi@0 1178 // count_dec - elements count's decrement equivalent to 16 bytes
aoqi@0 1179 // L_copy_bytes - copy exit label
aoqi@0 1180 //
aoqi@0 1181 void copy_16_bytes_forward_with_shift(Register from, Register to,
aoqi@0 1182 Register count, int log2_elem_size, Label& L_copy_bytes) {
aoqi@0 1183 Label L_aligned_copy, L_copy_last_bytes;
aoqi@0 1184 assert(log2_elem_size <= 3, "the following code should be changed");
aoqi@0 1185 int count_dec = 16>>log2_elem_size;
aoqi@0 1186
aoqi@0 1187 // if both arrays have the same alignment mod 8, do 8 bytes aligned copy
aoqi@0 1188 __ andcc(from, 7, G1); // misaligned bytes
aoqi@0 1189 __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy);
aoqi@0 1190 __ delayed()->nop();
aoqi@0 1191
aoqi@0 1192 const Register left_shift = G1; // left shift bit counter
aoqi@0 1193 const Register right_shift = G5; // right shift bit counter
aoqi@0 1194
aoqi@0 1195 __ sll(G1, LogBitsPerByte, left_shift);
aoqi@0 1196 __ mov(64, right_shift);
aoqi@0 1197 __ sub(right_shift, left_shift, right_shift);
aoqi@0 1198
aoqi@0 1199 //
aoqi@0 1200 // Load 2 aligned 8-bytes chunks and use one from previous iteration
aoqi@0 1201 // to form 2 aligned 8-bytes chunks to store.
aoqi@0 1202 //
aoqi@0 1203 __ dec(count, count_dec); // Pre-decrement 'count'
aoqi@0 1204 __ andn(from, 7, from); // Align address
aoqi@0 1205 __ ldx(from, 0, O3);
aoqi@0 1206 __ inc(from, 8);
aoqi@0 1207 __ sllx(O3, left_shift, O3);
aoqi@0 1208
aoqi@0 1209 disjoint_copy_core(from, to, count, log2_elem_size, 16, &StubGenerator::copy_16_bytes_shift_loop);
aoqi@0 1210
aoqi@0 1211 __ inccc(count, count_dec>>1 ); // + 8 bytes
aoqi@0 1212 __ brx(Assembler::negative, true, Assembler::pn, L_copy_last_bytes);
aoqi@0 1213 __ delayed()->inc(count, count_dec>>1); // restore 'count'
aoqi@0 1214
aoqi@0 1215 // copy 8 bytes, part of them already loaded in O3
aoqi@0 1216 __ ldx(from, 0, O4);
aoqi@0 1217 __ inc(to, 8);
aoqi@0 1218 __ inc(from, 8);
aoqi@0 1219 __ srlx(O4, right_shift, G3);
aoqi@0 1220 __ bset(O3, G3);
aoqi@0 1221 __ stx(G3, to, -8);
aoqi@0 1222
aoqi@0 1223 __ BIND(L_copy_last_bytes);
aoqi@0 1224 __ srl(right_shift, LogBitsPerByte, right_shift); // misaligned bytes
aoqi@0 1225 __ br(Assembler::always, false, Assembler::pt, L_copy_bytes);
aoqi@0 1226 __ delayed()->sub(from, right_shift, from); // restore address
aoqi@0 1227
aoqi@0 1228 __ BIND(L_aligned_copy);
aoqi@0 1229 }
aoqi@0 1230
aoqi@0 1231 // Copy big chunks backward with shift
aoqi@0 1232 //
aoqi@0 1233 // Inputs:
aoqi@0 1234 // end_from - source arrays end address
aoqi@0 1235 // end_to - destination array end address aligned to 8-bytes
aoqi@0 1236 // count - elements count to copy >= the count equivalent to 16 bytes
aoqi@0 1237 // count_dec - elements count's decrement equivalent to 16 bytes
aoqi@0 1238 // L_aligned_copy - aligned copy exit label
aoqi@0 1239 // L_copy_bytes - copy exit label
aoqi@0 1240 //
aoqi@0 1241 void copy_16_bytes_backward_with_shift(Register end_from, Register end_to,
aoqi@0 1242 Register count, int count_dec,
aoqi@0 1243 Label& L_aligned_copy, Label& L_copy_bytes) {
aoqi@0 1244 Label L_loop, L_copy_last_bytes;
aoqi@0 1245
aoqi@0 1246 // if both arrays have the same alignment mod 8, do 8 bytes aligned copy
aoqi@0 1247 __ andcc(end_from, 7, G1); // misaligned bytes
aoqi@0 1248 __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy);
aoqi@0 1249 __ delayed()->deccc(count, count_dec); // Pre-decrement 'count'
aoqi@0 1250
aoqi@0 1251 const Register left_shift = G1; // left shift bit counter
aoqi@0 1252 const Register right_shift = G5; // right shift bit counter
aoqi@0 1253
aoqi@0 1254 __ sll(G1, LogBitsPerByte, left_shift);
aoqi@0 1255 __ mov(64, right_shift);
aoqi@0 1256 __ sub(right_shift, left_shift, right_shift);
aoqi@0 1257
aoqi@0 1258 //
aoqi@0 1259 // Load 2 aligned 8-bytes chunks and use one from previous iteration
aoqi@0 1260 // to form 2 aligned 8-bytes chunks to store.
aoqi@0 1261 //
aoqi@0 1262 __ andn(end_from, 7, end_from); // Align address
aoqi@0 1263 __ ldx(end_from, 0, O3);
aoqi@0 1264 __ align(OptoLoopAlignment);
aoqi@0 1265 __ BIND(L_loop);
aoqi@0 1266 __ ldx(end_from, -8, O4);
aoqi@0 1267 __ deccc(count, count_dec); // Can we do next iteration after this one?
aoqi@0 1268 __ ldx(end_from, -16, G4);
aoqi@0 1269 __ dec(end_to, 16);
aoqi@0 1270 __ dec(end_from, 16);
aoqi@0 1271 __ srlx(O3, right_shift, O3);
aoqi@0 1272 __ sllx(O4, left_shift, G3);
aoqi@0 1273 __ bset(G3, O3);
aoqi@0 1274 __ stx(O3, end_to, 8);
aoqi@0 1275 __ srlx(O4, right_shift, O4);
aoqi@0 1276 __ sllx(G4, left_shift, G3);
aoqi@0 1277 __ bset(G3, O4);
aoqi@0 1278 __ stx(O4, end_to, 0);
aoqi@0 1279 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop);
aoqi@0 1280 __ delayed()->mov(G4, O3);
aoqi@0 1281
aoqi@0 1282 __ inccc(count, count_dec>>1 ); // + 8 bytes
aoqi@0 1283 __ brx(Assembler::negative, true, Assembler::pn, L_copy_last_bytes);
aoqi@0 1284 __ delayed()->inc(count, count_dec>>1); // restore 'count'
aoqi@0 1285
aoqi@0 1286 // copy 8 bytes, part of them already loaded in O3
aoqi@0 1287 __ ldx(end_from, -8, O4);
aoqi@0 1288 __ dec(end_to, 8);
aoqi@0 1289 __ dec(end_from, 8);
aoqi@0 1290 __ srlx(O3, right_shift, O3);
aoqi@0 1291 __ sllx(O4, left_shift, G3);
aoqi@0 1292 __ bset(O3, G3);
aoqi@0 1293 __ stx(G3, end_to, 0);
aoqi@0 1294
aoqi@0 1295 __ BIND(L_copy_last_bytes);
aoqi@0 1296 __ srl(left_shift, LogBitsPerByte, left_shift); // misaligned bytes
aoqi@0 1297 __ br(Assembler::always, false, Assembler::pt, L_copy_bytes);
aoqi@0 1298 __ delayed()->add(end_from, left_shift, end_from); // restore address
aoqi@0 1299 }
aoqi@0 1300
aoqi@0 1301 //
aoqi@0 1302 // Generate stub for disjoint byte copy. If "aligned" is true, the
aoqi@0 1303 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 1304 //
aoqi@0 1305 // Arguments for generated stub:
aoqi@0 1306 // from: O0
aoqi@0 1307 // to: O1
aoqi@0 1308 // count: O2 treated as signed
aoqi@0 1309 //
aoqi@0 1310 address generate_disjoint_byte_copy(bool aligned, address *entry, const char *name) {
aoqi@0 1311 __ align(CodeEntryAlignment);
aoqi@0 1312 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1313 address start = __ pc();
aoqi@0 1314
aoqi@0 1315 Label L_skip_alignment, L_align;
aoqi@0 1316 Label L_copy_byte, L_copy_byte_loop, L_exit;
aoqi@0 1317
aoqi@0 1318 const Register from = O0; // source array address
aoqi@0 1319 const Register to = O1; // destination array address
aoqi@0 1320 const Register count = O2; // elements count
aoqi@0 1321 const Register offset = O5; // offset from start of arrays
aoqi@0 1322 // O3, O4, G3, G4 are used as temp registers
aoqi@0 1323
aoqi@0 1324 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 1325
aoqi@0 1326 if (entry != NULL) {
aoqi@0 1327 *entry = __ pc();
aoqi@0 1328 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1329 BLOCK_COMMENT("Entry:");
aoqi@0 1330 }
aoqi@0 1331
aoqi@0 1332 // for short arrays, just do single element copy
aoqi@0 1333 __ cmp(count, 23); // 16 + 7
aoqi@0 1334 __ brx(Assembler::less, false, Assembler::pn, L_copy_byte);
aoqi@0 1335 __ delayed()->mov(G0, offset);
aoqi@0 1336
aoqi@0 1337 if (aligned) {
aoqi@0 1338 // 'aligned' == true when it is known statically during compilation
aoqi@0 1339 // of this arraycopy call site that both 'from' and 'to' addresses
aoqi@0 1340 // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()).
aoqi@0 1341 //
aoqi@0 1342 // Aligned arrays have 4 bytes alignment in 32-bits VM
aoqi@0 1343 // and 8 bytes - in 64-bits VM. So we do it only for 32-bits VM
aoqi@0 1344 //
aoqi@0 1345 #ifndef _LP64
aoqi@0 1346 // copy a 4-bytes word if necessary to align 'to' to 8 bytes
aoqi@0 1347 __ andcc(to, 7, G0);
aoqi@0 1348 __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment);
aoqi@0 1349 __ delayed()->ld(from, 0, O3);
aoqi@0 1350 __ inc(from, 4);
aoqi@0 1351 __ inc(to, 4);
aoqi@0 1352 __ dec(count, 4);
aoqi@0 1353 __ st(O3, to, -4);
aoqi@0 1354 __ BIND(L_skip_alignment);
aoqi@0 1355 #endif
aoqi@0 1356 } else {
aoqi@0 1357 // copy bytes to align 'to' on 8 byte boundary
aoqi@0 1358 __ andcc(to, 7, G1); // misaligned bytes
aoqi@0 1359 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 1360 __ delayed()->neg(G1);
aoqi@0 1361 __ inc(G1, 8); // bytes need to copy to next 8-bytes alignment
aoqi@0 1362 __ sub(count, G1, count);
aoqi@0 1363 __ BIND(L_align);
aoqi@0 1364 __ ldub(from, 0, O3);
aoqi@0 1365 __ deccc(G1);
aoqi@0 1366 __ inc(from);
aoqi@0 1367 __ stb(O3, to, 0);
aoqi@0 1368 __ br(Assembler::notZero, false, Assembler::pt, L_align);
aoqi@0 1369 __ delayed()->inc(to);
aoqi@0 1370 __ BIND(L_skip_alignment);
aoqi@0 1371 }
aoqi@0 1372 #ifdef _LP64
aoqi@0 1373 if (!aligned)
aoqi@0 1374 #endif
aoqi@0 1375 {
aoqi@0 1376 // Copy with shift 16 bytes per iteration if arrays do not have
aoqi@0 1377 // the same alignment mod 8, otherwise fall through to the next
aoqi@0 1378 // code for aligned copy.
aoqi@0 1379 // The compare above (count >= 23) guarantes 'count' >= 16 bytes.
aoqi@0 1380 // Also jump over aligned copy after the copy with shift completed.
aoqi@0 1381
aoqi@0 1382 copy_16_bytes_forward_with_shift(from, to, count, 0, L_copy_byte);
aoqi@0 1383 }
aoqi@0 1384
aoqi@0 1385 // Both array are 8 bytes aligned, copy 16 bytes at a time
aoqi@0 1386 __ and3(count, 7, G4); // Save count
aoqi@0 1387 __ srl(count, 3, count);
aoqi@0 1388 generate_disjoint_long_copy_core(aligned);
aoqi@0 1389 __ mov(G4, count); // Restore count
aoqi@0 1390
aoqi@0 1391 // copy tailing bytes
aoqi@0 1392 __ BIND(L_copy_byte);
aoqi@0 1393 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 1394 __ align(OptoLoopAlignment);
aoqi@0 1395 __ BIND(L_copy_byte_loop);
aoqi@0 1396 __ ldub(from, offset, O3);
aoqi@0 1397 __ deccc(count);
aoqi@0 1398 __ stb(O3, to, offset);
aoqi@0 1399 __ brx(Assembler::notZero, false, Assembler::pt, L_copy_byte_loop);
aoqi@0 1400 __ delayed()->inc(offset);
aoqi@0 1401
aoqi@0 1402 __ BIND(L_exit);
aoqi@0 1403 // O3, O4 are used as temp registers
aoqi@0 1404 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr, O3, O4);
aoqi@0 1405 __ retl();
aoqi@0 1406 __ delayed()->mov(G0, O0); // return 0
aoqi@0 1407 return start;
aoqi@0 1408 }
aoqi@0 1409
aoqi@0 1410 //
aoqi@0 1411 // Generate stub for conjoint byte copy. If "aligned" is true, the
aoqi@0 1412 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 1413 //
aoqi@0 1414 // Arguments for generated stub:
aoqi@0 1415 // from: O0
aoqi@0 1416 // to: O1
aoqi@0 1417 // count: O2 treated as signed
aoqi@0 1418 //
aoqi@0 1419 address generate_conjoint_byte_copy(bool aligned, address nooverlap_target,
aoqi@0 1420 address *entry, const char *name) {
aoqi@0 1421 // Do reverse copy.
aoqi@0 1422
aoqi@0 1423 __ align(CodeEntryAlignment);
aoqi@0 1424 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1425 address start = __ pc();
aoqi@0 1426
aoqi@0 1427 Label L_skip_alignment, L_align, L_aligned_copy;
aoqi@0 1428 Label L_copy_byte, L_copy_byte_loop, L_exit;
aoqi@0 1429
aoqi@0 1430 const Register from = O0; // source array address
aoqi@0 1431 const Register to = O1; // destination array address
aoqi@0 1432 const Register count = O2; // elements count
aoqi@0 1433 const Register end_from = from; // source array end address
aoqi@0 1434 const Register end_to = to; // destination array end address
aoqi@0 1435
aoqi@0 1436 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 1437
aoqi@0 1438 if (entry != NULL) {
aoqi@0 1439 *entry = __ pc();
aoqi@0 1440 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1441 BLOCK_COMMENT("Entry:");
aoqi@0 1442 }
aoqi@0 1443
aoqi@0 1444 array_overlap_test(nooverlap_target, 0);
aoqi@0 1445
aoqi@0 1446 __ add(to, count, end_to); // offset after last copied element
aoqi@0 1447
aoqi@0 1448 // for short arrays, just do single element copy
aoqi@0 1449 __ cmp(count, 23); // 16 + 7
aoqi@0 1450 __ brx(Assembler::less, false, Assembler::pn, L_copy_byte);
aoqi@0 1451 __ delayed()->add(from, count, end_from);
aoqi@0 1452
aoqi@0 1453 {
aoqi@0 1454 // Align end of arrays since they could be not aligned even
aoqi@0 1455 // when arrays itself are aligned.
aoqi@0 1456
aoqi@0 1457 // copy bytes to align 'end_to' on 8 byte boundary
aoqi@0 1458 __ andcc(end_to, 7, G1); // misaligned bytes
aoqi@0 1459 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 1460 __ delayed()->nop();
aoqi@0 1461 __ sub(count, G1, count);
aoqi@0 1462 __ BIND(L_align);
aoqi@0 1463 __ dec(end_from);
aoqi@0 1464 __ dec(end_to);
aoqi@0 1465 __ ldub(end_from, 0, O3);
aoqi@0 1466 __ deccc(G1);
aoqi@0 1467 __ brx(Assembler::notZero, false, Assembler::pt, L_align);
aoqi@0 1468 __ delayed()->stb(O3, end_to, 0);
aoqi@0 1469 __ BIND(L_skip_alignment);
aoqi@0 1470 }
aoqi@0 1471 #ifdef _LP64
aoqi@0 1472 if (aligned) {
aoqi@0 1473 // Both arrays are aligned to 8-bytes in 64-bits VM.
aoqi@0 1474 // The 'count' is decremented in copy_16_bytes_backward_with_shift()
aoqi@0 1475 // in unaligned case.
aoqi@0 1476 __ dec(count, 16);
aoqi@0 1477 } else
aoqi@0 1478 #endif
aoqi@0 1479 {
aoqi@0 1480 // Copy with shift 16 bytes per iteration if arrays do not have
aoqi@0 1481 // the same alignment mod 8, otherwise jump to the next
aoqi@0 1482 // code for aligned copy (and substracting 16 from 'count' before jump).
aoqi@0 1483 // The compare above (count >= 11) guarantes 'count' >= 16 bytes.
aoqi@0 1484 // Also jump over aligned copy after the copy with shift completed.
aoqi@0 1485
aoqi@0 1486 copy_16_bytes_backward_with_shift(end_from, end_to, count, 16,
aoqi@0 1487 L_aligned_copy, L_copy_byte);
aoqi@0 1488 }
aoqi@0 1489 // copy 4 elements (16 bytes) at a time
aoqi@0 1490 __ align(OptoLoopAlignment);
aoqi@0 1491 __ BIND(L_aligned_copy);
aoqi@0 1492 __ dec(end_from, 16);
aoqi@0 1493 __ ldx(end_from, 8, O3);
aoqi@0 1494 __ ldx(end_from, 0, O4);
aoqi@0 1495 __ dec(end_to, 16);
aoqi@0 1496 __ deccc(count, 16);
aoqi@0 1497 __ stx(O3, end_to, 8);
aoqi@0 1498 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy);
aoqi@0 1499 __ delayed()->stx(O4, end_to, 0);
aoqi@0 1500 __ inc(count, 16);
aoqi@0 1501
aoqi@0 1502 // copy 1 element (2 bytes) at a time
aoqi@0 1503 __ BIND(L_copy_byte);
aoqi@0 1504 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 1505 __ align(OptoLoopAlignment);
aoqi@0 1506 __ BIND(L_copy_byte_loop);
aoqi@0 1507 __ dec(end_from);
aoqi@0 1508 __ dec(end_to);
aoqi@0 1509 __ ldub(end_from, 0, O4);
aoqi@0 1510 __ deccc(count);
aoqi@0 1511 __ brx(Assembler::greater, false, Assembler::pt, L_copy_byte_loop);
aoqi@0 1512 __ delayed()->stb(O4, end_to, 0);
aoqi@0 1513
aoqi@0 1514 __ BIND(L_exit);
aoqi@0 1515 // O3, O4 are used as temp registers
aoqi@0 1516 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr, O3, O4);
aoqi@0 1517 __ retl();
aoqi@0 1518 __ delayed()->mov(G0, O0); // return 0
aoqi@0 1519 return start;
aoqi@0 1520 }
aoqi@0 1521
aoqi@0 1522 //
aoqi@0 1523 // Generate stub for disjoint short copy. If "aligned" is true, the
aoqi@0 1524 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 1525 //
aoqi@0 1526 // Arguments for generated stub:
aoqi@0 1527 // from: O0
aoqi@0 1528 // to: O1
aoqi@0 1529 // count: O2 treated as signed
aoqi@0 1530 //
aoqi@0 1531 address generate_disjoint_short_copy(bool aligned, address *entry, const char * name) {
aoqi@0 1532 __ align(CodeEntryAlignment);
aoqi@0 1533 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1534 address start = __ pc();
aoqi@0 1535
aoqi@0 1536 Label L_skip_alignment, L_skip_alignment2;
aoqi@0 1537 Label L_copy_2_bytes, L_copy_2_bytes_loop, L_exit;
aoqi@0 1538
aoqi@0 1539 const Register from = O0; // source array address
aoqi@0 1540 const Register to = O1; // destination array address
aoqi@0 1541 const Register count = O2; // elements count
aoqi@0 1542 const Register offset = O5; // offset from start of arrays
aoqi@0 1543 // O3, O4, G3, G4 are used as temp registers
aoqi@0 1544
aoqi@0 1545 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 1546
aoqi@0 1547 if (entry != NULL) {
aoqi@0 1548 *entry = __ pc();
aoqi@0 1549 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1550 BLOCK_COMMENT("Entry:");
aoqi@0 1551 }
aoqi@0 1552
aoqi@0 1553 // for short arrays, just do single element copy
aoqi@0 1554 __ cmp(count, 11); // 8 + 3 (22 bytes)
aoqi@0 1555 __ brx(Assembler::less, false, Assembler::pn, L_copy_2_bytes);
aoqi@0 1556 __ delayed()->mov(G0, offset);
aoqi@0 1557
aoqi@0 1558 if (aligned) {
aoqi@0 1559 // 'aligned' == true when it is known statically during compilation
aoqi@0 1560 // of this arraycopy call site that both 'from' and 'to' addresses
aoqi@0 1561 // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()).
aoqi@0 1562 //
aoqi@0 1563 // Aligned arrays have 4 bytes alignment in 32-bits VM
aoqi@0 1564 // and 8 bytes - in 64-bits VM.
aoqi@0 1565 //
aoqi@0 1566 #ifndef _LP64
aoqi@0 1567 // copy a 2-elements word if necessary to align 'to' to 8 bytes
aoqi@0 1568 __ andcc(to, 7, G0);
aoqi@0 1569 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 1570 __ delayed()->ld(from, 0, O3);
aoqi@0 1571 __ inc(from, 4);
aoqi@0 1572 __ inc(to, 4);
aoqi@0 1573 __ dec(count, 2);
aoqi@0 1574 __ st(O3, to, -4);
aoqi@0 1575 __ BIND(L_skip_alignment);
aoqi@0 1576 #endif
aoqi@0 1577 } else {
aoqi@0 1578 // copy 1 element if necessary to align 'to' on an 4 bytes
aoqi@0 1579 __ andcc(to, 3, G0);
aoqi@0 1580 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 1581 __ delayed()->lduh(from, 0, O3);
aoqi@0 1582 __ inc(from, 2);
aoqi@0 1583 __ inc(to, 2);
aoqi@0 1584 __ dec(count);
aoqi@0 1585 __ sth(O3, to, -2);
aoqi@0 1586 __ BIND(L_skip_alignment);
aoqi@0 1587
aoqi@0 1588 // copy 2 elements to align 'to' on an 8 byte boundary
aoqi@0 1589 __ andcc(to, 7, G0);
aoqi@0 1590 __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment2);
aoqi@0 1591 __ delayed()->lduh(from, 0, O3);
aoqi@0 1592 __ dec(count, 2);
aoqi@0 1593 __ lduh(from, 2, O4);
aoqi@0 1594 __ inc(from, 4);
aoqi@0 1595 __ inc(to, 4);
aoqi@0 1596 __ sth(O3, to, -4);
aoqi@0 1597 __ sth(O4, to, -2);
aoqi@0 1598 __ BIND(L_skip_alignment2);
aoqi@0 1599 }
aoqi@0 1600 #ifdef _LP64
aoqi@0 1601 if (!aligned)
aoqi@0 1602 #endif
aoqi@0 1603 {
aoqi@0 1604 // Copy with shift 16 bytes per iteration if arrays do not have
aoqi@0 1605 // the same alignment mod 8, otherwise fall through to the next
aoqi@0 1606 // code for aligned copy.
aoqi@0 1607 // The compare above (count >= 11) guarantes 'count' >= 16 bytes.
aoqi@0 1608 // Also jump over aligned copy after the copy with shift completed.
aoqi@0 1609
aoqi@0 1610 copy_16_bytes_forward_with_shift(from, to, count, 1, L_copy_2_bytes);
aoqi@0 1611 }
aoqi@0 1612
aoqi@0 1613 // Both array are 8 bytes aligned, copy 16 bytes at a time
aoqi@0 1614 __ and3(count, 3, G4); // Save
aoqi@0 1615 __ srl(count, 2, count);
aoqi@0 1616 generate_disjoint_long_copy_core(aligned);
aoqi@0 1617 __ mov(G4, count); // restore
aoqi@0 1618
aoqi@0 1619 // copy 1 element at a time
aoqi@0 1620 __ BIND(L_copy_2_bytes);
aoqi@0 1621 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 1622 __ align(OptoLoopAlignment);
aoqi@0 1623 __ BIND(L_copy_2_bytes_loop);
aoqi@0 1624 __ lduh(from, offset, O3);
aoqi@0 1625 __ deccc(count);
aoqi@0 1626 __ sth(O3, to, offset);
aoqi@0 1627 __ brx(Assembler::notZero, false, Assembler::pt, L_copy_2_bytes_loop);
aoqi@0 1628 __ delayed()->inc(offset, 2);
aoqi@0 1629
aoqi@0 1630 __ BIND(L_exit);
aoqi@0 1631 // O3, O4 are used as temp registers
aoqi@0 1632 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr, O3, O4);
aoqi@0 1633 __ retl();
aoqi@0 1634 __ delayed()->mov(G0, O0); // return 0
aoqi@0 1635 return start;
aoqi@0 1636 }
aoqi@0 1637
aoqi@0 1638 //
aoqi@0 1639 // Generate stub for disjoint short fill. If "aligned" is true, the
aoqi@0 1640 // "to" address is assumed to be heapword aligned.
aoqi@0 1641 //
aoqi@0 1642 // Arguments for generated stub:
aoqi@0 1643 // to: O0
aoqi@0 1644 // value: O1
aoqi@0 1645 // count: O2 treated as signed
aoqi@0 1646 //
aoqi@0 1647 address generate_fill(BasicType t, bool aligned, const char* name) {
aoqi@0 1648 __ align(CodeEntryAlignment);
aoqi@0 1649 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1650 address start = __ pc();
aoqi@0 1651
aoqi@0 1652 const Register to = O0; // source array address
aoqi@0 1653 const Register value = O1; // fill value
aoqi@0 1654 const Register count = O2; // elements count
aoqi@0 1655 // O3 is used as a temp register
aoqi@0 1656
aoqi@0 1657 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 1658
aoqi@0 1659 Label L_exit, L_skip_align1, L_skip_align2, L_fill_byte;
aoqi@0 1660 Label L_fill_2_bytes, L_fill_elements, L_fill_32_bytes;
aoqi@0 1661
aoqi@0 1662 int shift = -1;
aoqi@0 1663 switch (t) {
aoqi@0 1664 case T_BYTE:
aoqi@0 1665 shift = 2;
aoqi@0 1666 break;
aoqi@0 1667 case T_SHORT:
aoqi@0 1668 shift = 1;
aoqi@0 1669 break;
aoqi@0 1670 case T_INT:
aoqi@0 1671 shift = 0;
aoqi@0 1672 break;
aoqi@0 1673 default: ShouldNotReachHere();
aoqi@0 1674 }
aoqi@0 1675
aoqi@0 1676 BLOCK_COMMENT("Entry:");
aoqi@0 1677
aoqi@0 1678 if (t == T_BYTE) {
aoqi@0 1679 // Zero extend value
aoqi@0 1680 __ and3(value, 0xff, value);
aoqi@0 1681 __ sllx(value, 8, O3);
aoqi@0 1682 __ or3(value, O3, value);
aoqi@0 1683 }
aoqi@0 1684 if (t == T_SHORT) {
aoqi@0 1685 // Zero extend value
aoqi@0 1686 __ sllx(value, 48, value);
aoqi@0 1687 __ srlx(value, 48, value);
aoqi@0 1688 }
aoqi@0 1689 if (t == T_BYTE || t == T_SHORT) {
aoqi@0 1690 __ sllx(value, 16, O3);
aoqi@0 1691 __ or3(value, O3, value);
aoqi@0 1692 }
aoqi@0 1693
aoqi@0 1694 __ cmp(count, 2<<shift); // Short arrays (< 8 bytes) fill by element
aoqi@0 1695 __ brx(Assembler::lessUnsigned, false, Assembler::pn, L_fill_elements); // use unsigned cmp
aoqi@0 1696 __ delayed()->andcc(count, 1, G0);
aoqi@0 1697
aoqi@0 1698 if (!aligned && (t == T_BYTE || t == T_SHORT)) {
aoqi@0 1699 // align source address at 4 bytes address boundary
aoqi@0 1700 if (t == T_BYTE) {
aoqi@0 1701 // One byte misalignment happens only for byte arrays
aoqi@0 1702 __ andcc(to, 1, G0);
aoqi@0 1703 __ br(Assembler::zero, false, Assembler::pt, L_skip_align1);
aoqi@0 1704 __ delayed()->nop();
aoqi@0 1705 __ stb(value, to, 0);
aoqi@0 1706 __ inc(to, 1);
aoqi@0 1707 __ dec(count, 1);
aoqi@0 1708 __ BIND(L_skip_align1);
aoqi@0 1709 }
aoqi@0 1710 // Two bytes misalignment happens only for byte and short (char) arrays
aoqi@0 1711 __ andcc(to, 2, G0);
aoqi@0 1712 __ br(Assembler::zero, false, Assembler::pt, L_skip_align2);
aoqi@0 1713 __ delayed()->nop();
aoqi@0 1714 __ sth(value, to, 0);
aoqi@0 1715 __ inc(to, 2);
aoqi@0 1716 __ dec(count, 1 << (shift - 1));
aoqi@0 1717 __ BIND(L_skip_align2);
aoqi@0 1718 }
aoqi@0 1719 #ifdef _LP64
aoqi@0 1720 if (!aligned) {
aoqi@0 1721 #endif
aoqi@0 1722 // align to 8 bytes, we know we are 4 byte aligned to start
aoqi@0 1723 __ andcc(to, 7, G0);
aoqi@0 1724 __ br(Assembler::zero, false, Assembler::pt, L_fill_32_bytes);
aoqi@0 1725 __ delayed()->nop();
aoqi@0 1726 __ stw(value, to, 0);
aoqi@0 1727 __ inc(to, 4);
aoqi@0 1728 __ dec(count, 1 << shift);
aoqi@0 1729 __ BIND(L_fill_32_bytes);
aoqi@0 1730 #ifdef _LP64
aoqi@0 1731 }
aoqi@0 1732 #endif
aoqi@0 1733
aoqi@0 1734 if (t == T_INT) {
aoqi@0 1735 // Zero extend value
aoqi@0 1736 __ srl(value, 0, value);
aoqi@0 1737 }
aoqi@0 1738 if (t == T_BYTE || t == T_SHORT || t == T_INT) {
aoqi@0 1739 __ sllx(value, 32, O3);
aoqi@0 1740 __ or3(value, O3, value);
aoqi@0 1741 }
aoqi@0 1742
aoqi@0 1743 Label L_check_fill_8_bytes;
aoqi@0 1744 // Fill 32-byte chunks
aoqi@0 1745 __ subcc(count, 8 << shift, count);
aoqi@0 1746 __ brx(Assembler::less, false, Assembler::pt, L_check_fill_8_bytes);
aoqi@0 1747 __ delayed()->nop();
aoqi@0 1748
aoqi@0 1749 Label L_fill_32_bytes_loop, L_fill_4_bytes;
aoqi@0 1750 __ align(16);
aoqi@0 1751 __ BIND(L_fill_32_bytes_loop);
aoqi@0 1752
aoqi@0 1753 __ stx(value, to, 0);
aoqi@0 1754 __ stx(value, to, 8);
aoqi@0 1755 __ stx(value, to, 16);
aoqi@0 1756 __ stx(value, to, 24);
aoqi@0 1757
aoqi@0 1758 __ subcc(count, 8 << shift, count);
aoqi@0 1759 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_fill_32_bytes_loop);
aoqi@0 1760 __ delayed()->add(to, 32, to);
aoqi@0 1761
aoqi@0 1762 __ BIND(L_check_fill_8_bytes);
aoqi@0 1763 __ addcc(count, 8 << shift, count);
aoqi@0 1764 __ brx(Assembler::zero, false, Assembler::pn, L_exit);
aoqi@0 1765 __ delayed()->subcc(count, 1 << (shift + 1), count);
aoqi@0 1766 __ brx(Assembler::less, false, Assembler::pn, L_fill_4_bytes);
aoqi@0 1767 __ delayed()->andcc(count, 1<<shift, G0);
aoqi@0 1768
aoqi@0 1769 //
aoqi@0 1770 // length is too short, just fill 8 bytes at a time
aoqi@0 1771 //
aoqi@0 1772 Label L_fill_8_bytes_loop;
aoqi@0 1773 __ BIND(L_fill_8_bytes_loop);
aoqi@0 1774 __ stx(value, to, 0);
aoqi@0 1775 __ subcc(count, 1 << (shift + 1), count);
aoqi@0 1776 __ brx(Assembler::greaterEqual, false, Assembler::pn, L_fill_8_bytes_loop);
aoqi@0 1777 __ delayed()->add(to, 8, to);
aoqi@0 1778
aoqi@0 1779 // fill trailing 4 bytes
aoqi@0 1780 __ andcc(count, 1<<shift, G0); // in delay slot of branches
aoqi@0 1781 if (t == T_INT) {
aoqi@0 1782 __ BIND(L_fill_elements);
aoqi@0 1783 }
aoqi@0 1784 __ BIND(L_fill_4_bytes);
aoqi@0 1785 __ brx(Assembler::zero, false, Assembler::pt, L_fill_2_bytes);
aoqi@0 1786 if (t == T_BYTE || t == T_SHORT) {
aoqi@0 1787 __ delayed()->andcc(count, 1<<(shift-1), G0);
aoqi@0 1788 } else {
aoqi@0 1789 __ delayed()->nop();
aoqi@0 1790 }
aoqi@0 1791 __ stw(value, to, 0);
aoqi@0 1792 if (t == T_BYTE || t == T_SHORT) {
aoqi@0 1793 __ inc(to, 4);
aoqi@0 1794 // fill trailing 2 bytes
aoqi@0 1795 __ andcc(count, 1<<(shift-1), G0); // in delay slot of branches
aoqi@0 1796 __ BIND(L_fill_2_bytes);
aoqi@0 1797 __ brx(Assembler::zero, false, Assembler::pt, L_fill_byte);
aoqi@0 1798 __ delayed()->andcc(count, 1, count);
aoqi@0 1799 __ sth(value, to, 0);
aoqi@0 1800 if (t == T_BYTE) {
aoqi@0 1801 __ inc(to, 2);
aoqi@0 1802 // fill trailing byte
aoqi@0 1803 __ andcc(count, 1, count); // in delay slot of branches
aoqi@0 1804 __ BIND(L_fill_byte);
aoqi@0 1805 __ brx(Assembler::zero, false, Assembler::pt, L_exit);
aoqi@0 1806 __ delayed()->nop();
aoqi@0 1807 __ stb(value, to, 0);
aoqi@0 1808 } else {
aoqi@0 1809 __ BIND(L_fill_byte);
aoqi@0 1810 }
aoqi@0 1811 } else {
aoqi@0 1812 __ BIND(L_fill_2_bytes);
aoqi@0 1813 }
aoqi@0 1814 __ BIND(L_exit);
aoqi@0 1815 __ retl();
aoqi@0 1816 __ delayed()->nop();
aoqi@0 1817
aoqi@0 1818 // Handle copies less than 8 bytes. Int is handled elsewhere.
aoqi@0 1819 if (t == T_BYTE) {
aoqi@0 1820 __ BIND(L_fill_elements);
aoqi@0 1821 Label L_fill_2, L_fill_4;
aoqi@0 1822 // in delay slot __ andcc(count, 1, G0);
aoqi@0 1823 __ brx(Assembler::zero, false, Assembler::pt, L_fill_2);
aoqi@0 1824 __ delayed()->andcc(count, 2, G0);
aoqi@0 1825 __ stb(value, to, 0);
aoqi@0 1826 __ inc(to, 1);
aoqi@0 1827 __ BIND(L_fill_2);
aoqi@0 1828 __ brx(Assembler::zero, false, Assembler::pt, L_fill_4);
aoqi@0 1829 __ delayed()->andcc(count, 4, G0);
aoqi@0 1830 __ stb(value, to, 0);
aoqi@0 1831 __ stb(value, to, 1);
aoqi@0 1832 __ inc(to, 2);
aoqi@0 1833 __ BIND(L_fill_4);
aoqi@0 1834 __ brx(Assembler::zero, false, Assembler::pt, L_exit);
aoqi@0 1835 __ delayed()->nop();
aoqi@0 1836 __ stb(value, to, 0);
aoqi@0 1837 __ stb(value, to, 1);
aoqi@0 1838 __ stb(value, to, 2);
aoqi@0 1839 __ retl();
aoqi@0 1840 __ delayed()->stb(value, to, 3);
aoqi@0 1841 }
aoqi@0 1842
aoqi@0 1843 if (t == T_SHORT) {
aoqi@0 1844 Label L_fill_2;
aoqi@0 1845 __ BIND(L_fill_elements);
aoqi@0 1846 // in delay slot __ andcc(count, 1, G0);
aoqi@0 1847 __ brx(Assembler::zero, false, Assembler::pt, L_fill_2);
aoqi@0 1848 __ delayed()->andcc(count, 2, G0);
aoqi@0 1849 __ sth(value, to, 0);
aoqi@0 1850 __ inc(to, 2);
aoqi@0 1851 __ BIND(L_fill_2);
aoqi@0 1852 __ brx(Assembler::zero, false, Assembler::pt, L_exit);
aoqi@0 1853 __ delayed()->nop();
aoqi@0 1854 __ sth(value, to, 0);
aoqi@0 1855 __ retl();
aoqi@0 1856 __ delayed()->sth(value, to, 2);
aoqi@0 1857 }
aoqi@0 1858 return start;
aoqi@0 1859 }
aoqi@0 1860
aoqi@0 1861 //
aoqi@0 1862 // Generate stub for conjoint short copy. If "aligned" is true, the
aoqi@0 1863 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 1864 //
aoqi@0 1865 // Arguments for generated stub:
aoqi@0 1866 // from: O0
aoqi@0 1867 // to: O1
aoqi@0 1868 // count: O2 treated as signed
aoqi@0 1869 //
aoqi@0 1870 address generate_conjoint_short_copy(bool aligned, address nooverlap_target,
aoqi@0 1871 address *entry, const char *name) {
aoqi@0 1872 // Do reverse copy.
aoqi@0 1873
aoqi@0 1874 __ align(CodeEntryAlignment);
aoqi@0 1875 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1876 address start = __ pc();
aoqi@0 1877
aoqi@0 1878 Label L_skip_alignment, L_skip_alignment2, L_aligned_copy;
aoqi@0 1879 Label L_copy_2_bytes, L_copy_2_bytes_loop, L_exit;
aoqi@0 1880
aoqi@0 1881 const Register from = O0; // source array address
aoqi@0 1882 const Register to = O1; // destination array address
aoqi@0 1883 const Register count = O2; // elements count
aoqi@0 1884 const Register end_from = from; // source array end address
aoqi@0 1885 const Register end_to = to; // destination array end address
aoqi@0 1886
aoqi@0 1887 const Register byte_count = O3; // bytes count to copy
aoqi@0 1888
aoqi@0 1889 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 1890
aoqi@0 1891 if (entry != NULL) {
aoqi@0 1892 *entry = __ pc();
aoqi@0 1893 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1894 BLOCK_COMMENT("Entry:");
aoqi@0 1895 }
aoqi@0 1896
aoqi@0 1897 array_overlap_test(nooverlap_target, 1);
aoqi@0 1898
aoqi@0 1899 __ sllx(count, LogBytesPerShort, byte_count);
aoqi@0 1900 __ add(to, byte_count, end_to); // offset after last copied element
aoqi@0 1901
aoqi@0 1902 // for short arrays, just do single element copy
aoqi@0 1903 __ cmp(count, 11); // 8 + 3 (22 bytes)
aoqi@0 1904 __ brx(Assembler::less, false, Assembler::pn, L_copy_2_bytes);
aoqi@0 1905 __ delayed()->add(from, byte_count, end_from);
aoqi@0 1906
aoqi@0 1907 {
aoqi@0 1908 // Align end of arrays since they could be not aligned even
aoqi@0 1909 // when arrays itself are aligned.
aoqi@0 1910
aoqi@0 1911 // copy 1 element if necessary to align 'end_to' on an 4 bytes
aoqi@0 1912 __ andcc(end_to, 3, G0);
aoqi@0 1913 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 1914 __ delayed()->lduh(end_from, -2, O3);
aoqi@0 1915 __ dec(end_from, 2);
aoqi@0 1916 __ dec(end_to, 2);
aoqi@0 1917 __ dec(count);
aoqi@0 1918 __ sth(O3, end_to, 0);
aoqi@0 1919 __ BIND(L_skip_alignment);
aoqi@0 1920
aoqi@0 1921 // copy 2 elements to align 'end_to' on an 8 byte boundary
aoqi@0 1922 __ andcc(end_to, 7, G0);
aoqi@0 1923 __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment2);
aoqi@0 1924 __ delayed()->lduh(end_from, -2, O3);
aoqi@0 1925 __ dec(count, 2);
aoqi@0 1926 __ lduh(end_from, -4, O4);
aoqi@0 1927 __ dec(end_from, 4);
aoqi@0 1928 __ dec(end_to, 4);
aoqi@0 1929 __ sth(O3, end_to, 2);
aoqi@0 1930 __ sth(O4, end_to, 0);
aoqi@0 1931 __ BIND(L_skip_alignment2);
aoqi@0 1932 }
aoqi@0 1933 #ifdef _LP64
aoqi@0 1934 if (aligned) {
aoqi@0 1935 // Both arrays are aligned to 8-bytes in 64-bits VM.
aoqi@0 1936 // The 'count' is decremented in copy_16_bytes_backward_with_shift()
aoqi@0 1937 // in unaligned case.
aoqi@0 1938 __ dec(count, 8);
aoqi@0 1939 } else
aoqi@0 1940 #endif
aoqi@0 1941 {
aoqi@0 1942 // Copy with shift 16 bytes per iteration if arrays do not have
aoqi@0 1943 // the same alignment mod 8, otherwise jump to the next
aoqi@0 1944 // code for aligned copy (and substracting 8 from 'count' before jump).
aoqi@0 1945 // The compare above (count >= 11) guarantes 'count' >= 16 bytes.
aoqi@0 1946 // Also jump over aligned copy after the copy with shift completed.
aoqi@0 1947
aoqi@0 1948 copy_16_bytes_backward_with_shift(end_from, end_to, count, 8,
aoqi@0 1949 L_aligned_copy, L_copy_2_bytes);
aoqi@0 1950 }
aoqi@0 1951 // copy 4 elements (16 bytes) at a time
aoqi@0 1952 __ align(OptoLoopAlignment);
aoqi@0 1953 __ BIND(L_aligned_copy);
aoqi@0 1954 __ dec(end_from, 16);
aoqi@0 1955 __ ldx(end_from, 8, O3);
aoqi@0 1956 __ ldx(end_from, 0, O4);
aoqi@0 1957 __ dec(end_to, 16);
aoqi@0 1958 __ deccc(count, 8);
aoqi@0 1959 __ stx(O3, end_to, 8);
aoqi@0 1960 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy);
aoqi@0 1961 __ delayed()->stx(O4, end_to, 0);
aoqi@0 1962 __ inc(count, 8);
aoqi@0 1963
aoqi@0 1964 // copy 1 element (2 bytes) at a time
aoqi@0 1965 __ BIND(L_copy_2_bytes);
aoqi@0 1966 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 1967 __ BIND(L_copy_2_bytes_loop);
aoqi@0 1968 __ dec(end_from, 2);
aoqi@0 1969 __ dec(end_to, 2);
aoqi@0 1970 __ lduh(end_from, 0, O4);
aoqi@0 1971 __ deccc(count);
aoqi@0 1972 __ brx(Assembler::greater, false, Assembler::pt, L_copy_2_bytes_loop);
aoqi@0 1973 __ delayed()->sth(O4, end_to, 0);
aoqi@0 1974
aoqi@0 1975 __ BIND(L_exit);
aoqi@0 1976 // O3, O4 are used as temp registers
aoqi@0 1977 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr, O3, O4);
aoqi@0 1978 __ retl();
aoqi@0 1979 __ delayed()->mov(G0, O0); // return 0
aoqi@0 1980 return start;
aoqi@0 1981 }
aoqi@0 1982
aoqi@0 1983 //
aoqi@0 1984 // Helper methods for generate_disjoint_int_copy_core()
aoqi@0 1985 //
aoqi@0 1986 void copy_16_bytes_loop(Register from, Register to, Register count, int count_dec,
aoqi@0 1987 Label& L_loop, bool use_prefetch, bool use_bis) {
aoqi@0 1988
aoqi@0 1989 __ align(OptoLoopAlignment);
aoqi@0 1990 __ BIND(L_loop);
aoqi@0 1991 if (use_prefetch) {
aoqi@0 1992 if (ArraycopySrcPrefetchDistance > 0) {
aoqi@0 1993 __ prefetch(from, ArraycopySrcPrefetchDistance, Assembler::severalReads);
aoqi@0 1994 }
aoqi@0 1995 if (ArraycopyDstPrefetchDistance > 0) {
aoqi@0 1996 __ prefetch(to, ArraycopyDstPrefetchDistance, Assembler::severalWritesAndPossiblyReads);
aoqi@0 1997 }
aoqi@0 1998 }
aoqi@0 1999 __ ldx(from, 4, O4);
aoqi@0 2000 __ ldx(from, 12, G4);
aoqi@0 2001 __ inc(to, 16);
aoqi@0 2002 __ inc(from, 16);
aoqi@0 2003 __ deccc(count, 4); // Can we do next iteration after this one?
aoqi@0 2004
aoqi@0 2005 __ srlx(O4, 32, G3);
aoqi@0 2006 __ bset(G3, O3);
aoqi@0 2007 __ sllx(O4, 32, O4);
aoqi@0 2008 __ srlx(G4, 32, G3);
aoqi@0 2009 __ bset(G3, O4);
aoqi@0 2010 if (use_bis) {
aoqi@0 2011 __ stxa(O3, to, -16);
aoqi@0 2012 __ stxa(O4, to, -8);
aoqi@0 2013 } else {
aoqi@0 2014 __ stx(O3, to, -16);
aoqi@0 2015 __ stx(O4, to, -8);
aoqi@0 2016 }
aoqi@0 2017 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop);
aoqi@0 2018 __ delayed()->sllx(G4, 32, O3);
aoqi@0 2019
aoqi@0 2020 }
aoqi@0 2021
aoqi@0 2022 //
aoqi@0 2023 // Generate core code for disjoint int copy (and oop copy on 32-bit).
aoqi@0 2024 // If "aligned" is true, the "from" and "to" addresses are assumed
aoqi@0 2025 // to be heapword aligned.
aoqi@0 2026 //
aoqi@0 2027 // Arguments:
aoqi@0 2028 // from: O0
aoqi@0 2029 // to: O1
aoqi@0 2030 // count: O2 treated as signed
aoqi@0 2031 //
aoqi@0 2032 void generate_disjoint_int_copy_core(bool aligned) {
aoqi@0 2033
aoqi@0 2034 Label L_skip_alignment, L_aligned_copy;
aoqi@0 2035 Label L_copy_4_bytes, L_copy_4_bytes_loop, L_exit;
aoqi@0 2036
aoqi@0 2037 const Register from = O0; // source array address
aoqi@0 2038 const Register to = O1; // destination array address
aoqi@0 2039 const Register count = O2; // elements count
aoqi@0 2040 const Register offset = O5; // offset from start of arrays
aoqi@0 2041 // O3, O4, G3, G4 are used as temp registers
aoqi@0 2042
aoqi@0 2043 // 'aligned' == true when it is known statically during compilation
aoqi@0 2044 // of this arraycopy call site that both 'from' and 'to' addresses
aoqi@0 2045 // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()).
aoqi@0 2046 //
aoqi@0 2047 // Aligned arrays have 4 bytes alignment in 32-bits VM
aoqi@0 2048 // and 8 bytes - in 64-bits VM.
aoqi@0 2049 //
aoqi@0 2050 #ifdef _LP64
aoqi@0 2051 if (!aligned)
aoqi@0 2052 #endif
aoqi@0 2053 {
aoqi@0 2054 // The next check could be put under 'ifndef' since the code in
aoqi@0 2055 // generate_disjoint_long_copy_core() has own checks and set 'offset'.
aoqi@0 2056
aoqi@0 2057 // for short arrays, just do single element copy
aoqi@0 2058 __ cmp(count, 5); // 4 + 1 (20 bytes)
aoqi@0 2059 __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_4_bytes);
aoqi@0 2060 __ delayed()->mov(G0, offset);
aoqi@0 2061
aoqi@0 2062 // copy 1 element to align 'to' on an 8 byte boundary
aoqi@0 2063 __ andcc(to, 7, G0);
aoqi@0 2064 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 2065 __ delayed()->ld(from, 0, O3);
aoqi@0 2066 __ inc(from, 4);
aoqi@0 2067 __ inc(to, 4);
aoqi@0 2068 __ dec(count);
aoqi@0 2069 __ st(O3, to, -4);
aoqi@0 2070 __ BIND(L_skip_alignment);
aoqi@0 2071
aoqi@0 2072 // if arrays have same alignment mod 8, do 4 elements copy
aoqi@0 2073 __ andcc(from, 7, G0);
aoqi@0 2074 __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy);
aoqi@0 2075 __ delayed()->ld(from, 0, O3);
aoqi@0 2076
aoqi@0 2077 //
aoqi@0 2078 // Load 2 aligned 8-bytes chunks and use one from previous iteration
aoqi@0 2079 // to form 2 aligned 8-bytes chunks to store.
aoqi@0 2080 //
aoqi@0 2081 // copy_16_bytes_forward_with_shift() is not used here since this
aoqi@0 2082 // code is more optimal.
aoqi@0 2083
aoqi@0 2084 // copy with shift 4 elements (16 bytes) at a time
aoqi@0 2085 __ dec(count, 4); // The cmp at the beginning guaranty count >= 4
aoqi@0 2086 __ sllx(O3, 32, O3);
aoqi@0 2087
aoqi@0 2088 disjoint_copy_core(from, to, count, 2, 16, &StubGenerator::copy_16_bytes_loop);
aoqi@0 2089
aoqi@0 2090 __ br(Assembler::always, false, Assembler::pt, L_copy_4_bytes);
aoqi@0 2091 __ delayed()->inc(count, 4); // restore 'count'
aoqi@0 2092
aoqi@0 2093 __ BIND(L_aligned_copy);
aoqi@0 2094 } // !aligned
aoqi@0 2095
aoqi@0 2096 // copy 4 elements (16 bytes) at a time
aoqi@0 2097 __ and3(count, 1, G4); // Save
aoqi@0 2098 __ srl(count, 1, count);
aoqi@0 2099 generate_disjoint_long_copy_core(aligned);
aoqi@0 2100 __ mov(G4, count); // Restore
aoqi@0 2101
aoqi@0 2102 // copy 1 element at a time
aoqi@0 2103 __ BIND(L_copy_4_bytes);
aoqi@0 2104 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 2105 __ BIND(L_copy_4_bytes_loop);
aoqi@0 2106 __ ld(from, offset, O3);
aoqi@0 2107 __ deccc(count);
aoqi@0 2108 __ st(O3, to, offset);
aoqi@0 2109 __ brx(Assembler::notZero, false, Assembler::pt, L_copy_4_bytes_loop);
aoqi@0 2110 __ delayed()->inc(offset, 4);
aoqi@0 2111 __ BIND(L_exit);
aoqi@0 2112 }
aoqi@0 2113
aoqi@0 2114 //
aoqi@0 2115 // Generate stub for disjoint int copy. If "aligned" is true, the
aoqi@0 2116 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 2117 //
aoqi@0 2118 // Arguments for generated stub:
aoqi@0 2119 // from: O0
aoqi@0 2120 // to: O1
aoqi@0 2121 // count: O2 treated as signed
aoqi@0 2122 //
aoqi@0 2123 address generate_disjoint_int_copy(bool aligned, address *entry, const char *name) {
aoqi@0 2124 __ align(CodeEntryAlignment);
aoqi@0 2125 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2126 address start = __ pc();
aoqi@0 2127
aoqi@0 2128 const Register count = O2;
aoqi@0 2129 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 2130
aoqi@0 2131 if (entry != NULL) {
aoqi@0 2132 *entry = __ pc();
aoqi@0 2133 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2134 BLOCK_COMMENT("Entry:");
aoqi@0 2135 }
aoqi@0 2136
aoqi@0 2137 generate_disjoint_int_copy_core(aligned);
aoqi@0 2138
aoqi@0 2139 // O3, O4 are used as temp registers
aoqi@0 2140 inc_counter_np(SharedRuntime::_jint_array_copy_ctr, O3, O4);
aoqi@0 2141 __ retl();
aoqi@0 2142 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2143 return start;
aoqi@0 2144 }
aoqi@0 2145
aoqi@0 2146 //
aoqi@0 2147 // Generate core code for conjoint int copy (and oop copy on 32-bit).
aoqi@0 2148 // If "aligned" is true, the "from" and "to" addresses are assumed
aoqi@0 2149 // to be heapword aligned.
aoqi@0 2150 //
aoqi@0 2151 // Arguments:
aoqi@0 2152 // from: O0
aoqi@0 2153 // to: O1
aoqi@0 2154 // count: O2 treated as signed
aoqi@0 2155 //
aoqi@0 2156 void generate_conjoint_int_copy_core(bool aligned) {
aoqi@0 2157 // Do reverse copy.
aoqi@0 2158
aoqi@0 2159 Label L_skip_alignment, L_aligned_copy;
aoqi@0 2160 Label L_copy_16_bytes, L_copy_4_bytes, L_copy_4_bytes_loop, L_exit;
aoqi@0 2161
aoqi@0 2162 const Register from = O0; // source array address
aoqi@0 2163 const Register to = O1; // destination array address
aoqi@0 2164 const Register count = O2; // elements count
aoqi@0 2165 const Register end_from = from; // source array end address
aoqi@0 2166 const Register end_to = to; // destination array end address
aoqi@0 2167 // O3, O4, O5, G3 are used as temp registers
aoqi@0 2168
aoqi@0 2169 const Register byte_count = O3; // bytes count to copy
aoqi@0 2170
aoqi@0 2171 __ sllx(count, LogBytesPerInt, byte_count);
aoqi@0 2172 __ add(to, byte_count, end_to); // offset after last copied element
aoqi@0 2173
aoqi@0 2174 __ cmp(count, 5); // for short arrays, just do single element copy
aoqi@0 2175 __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_4_bytes);
aoqi@0 2176 __ delayed()->add(from, byte_count, end_from);
aoqi@0 2177
aoqi@0 2178 // copy 1 element to align 'to' on an 8 byte boundary
aoqi@0 2179 __ andcc(end_to, 7, G0);
aoqi@0 2180 __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment);
aoqi@0 2181 __ delayed()->nop();
aoqi@0 2182 __ dec(count);
aoqi@0 2183 __ dec(end_from, 4);
aoqi@0 2184 __ dec(end_to, 4);
aoqi@0 2185 __ ld(end_from, 0, O4);
aoqi@0 2186 __ st(O4, end_to, 0);
aoqi@0 2187 __ BIND(L_skip_alignment);
aoqi@0 2188
aoqi@0 2189 // Check if 'end_from' and 'end_to' has the same alignment.
aoqi@0 2190 __ andcc(end_from, 7, G0);
aoqi@0 2191 __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy);
aoqi@0 2192 __ delayed()->dec(count, 4); // The cmp at the start guaranty cnt >= 4
aoqi@0 2193
aoqi@0 2194 // copy with shift 4 elements (16 bytes) at a time
aoqi@0 2195 //
aoqi@0 2196 // Load 2 aligned 8-bytes chunks and use one from previous iteration
aoqi@0 2197 // to form 2 aligned 8-bytes chunks to store.
aoqi@0 2198 //
aoqi@0 2199 __ ldx(end_from, -4, O3);
aoqi@0 2200 __ align(OptoLoopAlignment);
aoqi@0 2201 __ BIND(L_copy_16_bytes);
aoqi@0 2202 __ ldx(end_from, -12, O4);
aoqi@0 2203 __ deccc(count, 4);
aoqi@0 2204 __ ldx(end_from, -20, O5);
aoqi@0 2205 __ dec(end_to, 16);
aoqi@0 2206 __ dec(end_from, 16);
aoqi@0 2207 __ srlx(O3, 32, O3);
aoqi@0 2208 __ sllx(O4, 32, G3);
aoqi@0 2209 __ bset(G3, O3);
aoqi@0 2210 __ stx(O3, end_to, 8);
aoqi@0 2211 __ srlx(O4, 32, O4);
aoqi@0 2212 __ sllx(O5, 32, G3);
aoqi@0 2213 __ bset(O4, G3);
aoqi@0 2214 __ stx(G3, end_to, 0);
aoqi@0 2215 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_copy_16_bytes);
aoqi@0 2216 __ delayed()->mov(O5, O3);
aoqi@0 2217
aoqi@0 2218 __ br(Assembler::always, false, Assembler::pt, L_copy_4_bytes);
aoqi@0 2219 __ delayed()->inc(count, 4);
aoqi@0 2220
aoqi@0 2221 // copy 4 elements (16 bytes) at a time
aoqi@0 2222 __ align(OptoLoopAlignment);
aoqi@0 2223 __ BIND(L_aligned_copy);
aoqi@0 2224 __ dec(end_from, 16);
aoqi@0 2225 __ ldx(end_from, 8, O3);
aoqi@0 2226 __ ldx(end_from, 0, O4);
aoqi@0 2227 __ dec(end_to, 16);
aoqi@0 2228 __ deccc(count, 4);
aoqi@0 2229 __ stx(O3, end_to, 8);
aoqi@0 2230 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy);
aoqi@0 2231 __ delayed()->stx(O4, end_to, 0);
aoqi@0 2232 __ inc(count, 4);
aoqi@0 2233
aoqi@0 2234 // copy 1 element (4 bytes) at a time
aoqi@0 2235 __ BIND(L_copy_4_bytes);
aoqi@0 2236 __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit);
aoqi@0 2237 __ BIND(L_copy_4_bytes_loop);
aoqi@0 2238 __ dec(end_from, 4);
aoqi@0 2239 __ dec(end_to, 4);
aoqi@0 2240 __ ld(end_from, 0, O4);
aoqi@0 2241 __ deccc(count);
aoqi@0 2242 __ brx(Assembler::greater, false, Assembler::pt, L_copy_4_bytes_loop);
aoqi@0 2243 __ delayed()->st(O4, end_to, 0);
aoqi@0 2244 __ BIND(L_exit);
aoqi@0 2245 }
aoqi@0 2246
aoqi@0 2247 //
aoqi@0 2248 // Generate stub for conjoint int copy. If "aligned" is true, the
aoqi@0 2249 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 2250 //
aoqi@0 2251 // Arguments for generated stub:
aoqi@0 2252 // from: O0
aoqi@0 2253 // to: O1
aoqi@0 2254 // count: O2 treated as signed
aoqi@0 2255 //
aoqi@0 2256 address generate_conjoint_int_copy(bool aligned, address nooverlap_target,
aoqi@0 2257 address *entry, const char *name) {
aoqi@0 2258 __ align(CodeEntryAlignment);
aoqi@0 2259 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2260 address start = __ pc();
aoqi@0 2261
aoqi@0 2262 assert_clean_int(O2, O3); // Make sure 'count' is clean int.
aoqi@0 2263
aoqi@0 2264 if (entry != NULL) {
aoqi@0 2265 *entry = __ pc();
aoqi@0 2266 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2267 BLOCK_COMMENT("Entry:");
aoqi@0 2268 }
aoqi@0 2269
aoqi@0 2270 array_overlap_test(nooverlap_target, 2);
aoqi@0 2271
aoqi@0 2272 generate_conjoint_int_copy_core(aligned);
aoqi@0 2273
aoqi@0 2274 // O3, O4 are used as temp registers
aoqi@0 2275 inc_counter_np(SharedRuntime::_jint_array_copy_ctr, O3, O4);
aoqi@0 2276 __ retl();
aoqi@0 2277 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2278 return start;
aoqi@0 2279 }
aoqi@0 2280
aoqi@0 2281 //
aoqi@0 2282 // Helper methods for generate_disjoint_long_copy_core()
aoqi@0 2283 //
aoqi@0 2284 void copy_64_bytes_loop(Register from, Register to, Register count, int count_dec,
aoqi@0 2285 Label& L_loop, bool use_prefetch, bool use_bis) {
aoqi@0 2286 __ align(OptoLoopAlignment);
aoqi@0 2287 __ BIND(L_loop);
aoqi@0 2288 for (int off = 0; off < 64; off += 16) {
aoqi@0 2289 if (use_prefetch && (off & 31) == 0) {
aoqi@0 2290 if (ArraycopySrcPrefetchDistance > 0) {
aoqi@0 2291 __ prefetch(from, ArraycopySrcPrefetchDistance+off, Assembler::severalReads);
aoqi@0 2292 }
aoqi@0 2293 if (ArraycopyDstPrefetchDistance > 0) {
aoqi@0 2294 __ prefetch(to, ArraycopyDstPrefetchDistance+off, Assembler::severalWritesAndPossiblyReads);
aoqi@0 2295 }
aoqi@0 2296 }
aoqi@0 2297 __ ldx(from, off+0, O4);
aoqi@0 2298 __ ldx(from, off+8, O5);
aoqi@0 2299 if (use_bis) {
aoqi@0 2300 __ stxa(O4, to, off+0);
aoqi@0 2301 __ stxa(O5, to, off+8);
aoqi@0 2302 } else {
aoqi@0 2303 __ stx(O4, to, off+0);
aoqi@0 2304 __ stx(O5, to, off+8);
aoqi@0 2305 }
aoqi@0 2306 }
aoqi@0 2307 __ deccc(count, 8);
aoqi@0 2308 __ inc(from, 64);
aoqi@0 2309 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop);
aoqi@0 2310 __ delayed()->inc(to, 64);
aoqi@0 2311 }
aoqi@0 2312
aoqi@0 2313 //
aoqi@0 2314 // Generate core code for disjoint long copy (and oop copy on 64-bit).
aoqi@0 2315 // "aligned" is ignored, because we must make the stronger
aoqi@0 2316 // assumption that both addresses are always 64-bit aligned.
aoqi@0 2317 //
aoqi@0 2318 // Arguments:
aoqi@0 2319 // from: O0
aoqi@0 2320 // to: O1
aoqi@0 2321 // count: O2 treated as signed
aoqi@0 2322 //
aoqi@0 2323 // count -= 2;
aoqi@0 2324 // if ( count >= 0 ) { // >= 2 elements
aoqi@0 2325 // if ( count > 6) { // >= 8 elements
aoqi@0 2326 // count -= 6; // original count - 8
aoqi@0 2327 // do {
aoqi@0 2328 // copy_8_elements;
aoqi@0 2329 // count -= 8;
aoqi@0 2330 // } while ( count >= 0 );
aoqi@0 2331 // count += 6;
aoqi@0 2332 // }
aoqi@0 2333 // if ( count >= 0 ) { // >= 2 elements
aoqi@0 2334 // do {
aoqi@0 2335 // copy_2_elements;
aoqi@0 2336 // } while ( (count=count-2) >= 0 );
aoqi@0 2337 // }
aoqi@0 2338 // }
aoqi@0 2339 // count += 2;
aoqi@0 2340 // if ( count != 0 ) { // 1 element left
aoqi@0 2341 // copy_1_element;
aoqi@0 2342 // }
aoqi@0 2343 //
aoqi@0 2344 void generate_disjoint_long_copy_core(bool aligned) {
aoqi@0 2345 Label L_copy_8_bytes, L_copy_16_bytes, L_exit;
aoqi@0 2346 const Register from = O0; // source array address
aoqi@0 2347 const Register to = O1; // destination array address
aoqi@0 2348 const Register count = O2; // elements count
aoqi@0 2349 const Register offset0 = O4; // element offset
aoqi@0 2350 const Register offset8 = O5; // next element offset
aoqi@0 2351
aoqi@0 2352 __ deccc(count, 2);
aoqi@0 2353 __ mov(G0, offset0); // offset from start of arrays (0)
aoqi@0 2354 __ brx(Assembler::negative, false, Assembler::pn, L_copy_8_bytes );
aoqi@0 2355 __ delayed()->add(offset0, 8, offset8);
aoqi@0 2356
aoqi@0 2357 // Copy by 64 bytes chunks
aoqi@0 2358
aoqi@0 2359 const Register from64 = O3; // source address
aoqi@0 2360 const Register to64 = G3; // destination address
aoqi@0 2361 __ subcc(count, 6, O3);
aoqi@0 2362 __ brx(Assembler::negative, false, Assembler::pt, L_copy_16_bytes );
aoqi@0 2363 __ delayed()->mov(to, to64);
aoqi@0 2364 // Now we can use O4(offset0), O5(offset8) as temps
aoqi@0 2365 __ mov(O3, count);
aoqi@0 2366 // count >= 0 (original count - 8)
aoqi@0 2367 __ mov(from, from64);
aoqi@0 2368
aoqi@0 2369 disjoint_copy_core(from64, to64, count, 3, 64, &StubGenerator::copy_64_bytes_loop);
aoqi@0 2370
aoqi@0 2371 // Restore O4(offset0), O5(offset8)
aoqi@0 2372 __ sub(from64, from, offset0);
aoqi@0 2373 __ inccc(count, 6); // restore count
aoqi@0 2374 __ brx(Assembler::negative, false, Assembler::pn, L_copy_8_bytes );
aoqi@0 2375 __ delayed()->add(offset0, 8, offset8);
aoqi@0 2376
aoqi@0 2377 // Copy by 16 bytes chunks
aoqi@0 2378 __ align(OptoLoopAlignment);
aoqi@0 2379 __ BIND(L_copy_16_bytes);
aoqi@0 2380 __ ldx(from, offset0, O3);
aoqi@0 2381 __ ldx(from, offset8, G3);
aoqi@0 2382 __ deccc(count, 2);
aoqi@0 2383 __ stx(O3, to, offset0);
aoqi@0 2384 __ inc(offset0, 16);
aoqi@0 2385 __ stx(G3, to, offset8);
aoqi@0 2386 __ brx(Assembler::greaterEqual, false, Assembler::pt, L_copy_16_bytes);
aoqi@0 2387 __ delayed()->inc(offset8, 16);
aoqi@0 2388
aoqi@0 2389 // Copy last 8 bytes
aoqi@0 2390 __ BIND(L_copy_8_bytes);
aoqi@0 2391 __ inccc(count, 2);
aoqi@0 2392 __ brx(Assembler::zero, true, Assembler::pn, L_exit );
aoqi@0 2393 __ delayed()->mov(offset0, offset8); // Set O5 used by other stubs
aoqi@0 2394 __ ldx(from, offset0, O3);
aoqi@0 2395 __ stx(O3, to, offset0);
aoqi@0 2396 __ BIND(L_exit);
aoqi@0 2397 }
aoqi@0 2398
aoqi@0 2399 //
aoqi@0 2400 // Generate stub for disjoint long copy.
aoqi@0 2401 // "aligned" is ignored, because we must make the stronger
aoqi@0 2402 // assumption that both addresses are always 64-bit aligned.
aoqi@0 2403 //
aoqi@0 2404 // Arguments for generated stub:
aoqi@0 2405 // from: O0
aoqi@0 2406 // to: O1
aoqi@0 2407 // count: O2 treated as signed
aoqi@0 2408 //
aoqi@0 2409 address generate_disjoint_long_copy(bool aligned, address *entry, const char *name) {
aoqi@0 2410 __ align(CodeEntryAlignment);
aoqi@0 2411 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2412 address start = __ pc();
aoqi@0 2413
aoqi@0 2414 assert_clean_int(O2, O3); // Make sure 'count' is clean int.
aoqi@0 2415
aoqi@0 2416 if (entry != NULL) {
aoqi@0 2417 *entry = __ pc();
aoqi@0 2418 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2419 BLOCK_COMMENT("Entry:");
aoqi@0 2420 }
aoqi@0 2421
aoqi@0 2422 generate_disjoint_long_copy_core(aligned);
aoqi@0 2423
aoqi@0 2424 // O3, O4 are used as temp registers
aoqi@0 2425 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr, O3, O4);
aoqi@0 2426 __ retl();
aoqi@0 2427 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2428 return start;
aoqi@0 2429 }
aoqi@0 2430
aoqi@0 2431 //
aoqi@0 2432 // Generate core code for conjoint long copy (and oop copy on 64-bit).
aoqi@0 2433 // "aligned" is ignored, because we must make the stronger
aoqi@0 2434 // assumption that both addresses are always 64-bit aligned.
aoqi@0 2435 //
aoqi@0 2436 // Arguments:
aoqi@0 2437 // from: O0
aoqi@0 2438 // to: O1
aoqi@0 2439 // count: O2 treated as signed
aoqi@0 2440 //
aoqi@0 2441 void generate_conjoint_long_copy_core(bool aligned) {
aoqi@0 2442 // Do reverse copy.
aoqi@0 2443 Label L_copy_8_bytes, L_copy_16_bytes, L_exit;
aoqi@0 2444 const Register from = O0; // source array address
aoqi@0 2445 const Register to = O1; // destination array address
aoqi@0 2446 const Register count = O2; // elements count
aoqi@0 2447 const Register offset8 = O4; // element offset
aoqi@0 2448 const Register offset0 = O5; // previous element offset
aoqi@0 2449
aoqi@0 2450 __ subcc(count, 1, count);
aoqi@0 2451 __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_8_bytes );
aoqi@0 2452 __ delayed()->sllx(count, LogBytesPerLong, offset8);
aoqi@0 2453 __ sub(offset8, 8, offset0);
aoqi@0 2454 __ align(OptoLoopAlignment);
aoqi@0 2455 __ BIND(L_copy_16_bytes);
aoqi@0 2456 __ ldx(from, offset8, O2);
aoqi@0 2457 __ ldx(from, offset0, O3);
aoqi@0 2458 __ stx(O2, to, offset8);
aoqi@0 2459 __ deccc(offset8, 16); // use offset8 as counter
aoqi@0 2460 __ stx(O3, to, offset0);
aoqi@0 2461 __ brx(Assembler::greater, false, Assembler::pt, L_copy_16_bytes);
aoqi@0 2462 __ delayed()->dec(offset0, 16);
aoqi@0 2463
aoqi@0 2464 __ BIND(L_copy_8_bytes);
aoqi@0 2465 __ brx(Assembler::negative, false, Assembler::pn, L_exit );
aoqi@0 2466 __ delayed()->nop();
aoqi@0 2467 __ ldx(from, 0, O3);
aoqi@0 2468 __ stx(O3, to, 0);
aoqi@0 2469 __ BIND(L_exit);
aoqi@0 2470 }
aoqi@0 2471
aoqi@0 2472 // Generate stub for conjoint long copy.
aoqi@0 2473 // "aligned" is ignored, because we must make the stronger
aoqi@0 2474 // assumption that both addresses are always 64-bit aligned.
aoqi@0 2475 //
aoqi@0 2476 // Arguments for generated stub:
aoqi@0 2477 // from: O0
aoqi@0 2478 // to: O1
aoqi@0 2479 // count: O2 treated as signed
aoqi@0 2480 //
aoqi@0 2481 address generate_conjoint_long_copy(bool aligned, address nooverlap_target,
aoqi@0 2482 address *entry, const char *name) {
aoqi@0 2483 __ align(CodeEntryAlignment);
aoqi@0 2484 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2485 address start = __ pc();
aoqi@0 2486
aoqi@0 2487 assert(aligned, "Should always be aligned");
aoqi@0 2488
aoqi@0 2489 assert_clean_int(O2, O3); // Make sure 'count' is clean int.
aoqi@0 2490
aoqi@0 2491 if (entry != NULL) {
aoqi@0 2492 *entry = __ pc();
aoqi@0 2493 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2494 BLOCK_COMMENT("Entry:");
aoqi@0 2495 }
aoqi@0 2496
aoqi@0 2497 array_overlap_test(nooverlap_target, 3);
aoqi@0 2498
aoqi@0 2499 generate_conjoint_long_copy_core(aligned);
aoqi@0 2500
aoqi@0 2501 // O3, O4 are used as temp registers
aoqi@0 2502 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr, O3, O4);
aoqi@0 2503 __ retl();
aoqi@0 2504 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2505 return start;
aoqi@0 2506 }
aoqi@0 2507
aoqi@0 2508 // Generate stub for disjoint oop copy. If "aligned" is true, the
aoqi@0 2509 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 2510 //
aoqi@0 2511 // Arguments for generated stub:
aoqi@0 2512 // from: O0
aoqi@0 2513 // to: O1
aoqi@0 2514 // count: O2 treated as signed
aoqi@0 2515 //
aoqi@0 2516 address generate_disjoint_oop_copy(bool aligned, address *entry, const char *name,
aoqi@0 2517 bool dest_uninitialized = false) {
aoqi@0 2518
aoqi@0 2519 const Register from = O0; // source array address
aoqi@0 2520 const Register to = O1; // destination array address
aoqi@0 2521 const Register count = O2; // elements count
aoqi@0 2522
aoqi@0 2523 __ align(CodeEntryAlignment);
aoqi@0 2524 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2525 address start = __ pc();
aoqi@0 2526
aoqi@0 2527 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 2528
aoqi@0 2529 if (entry != NULL) {
aoqi@0 2530 *entry = __ pc();
aoqi@0 2531 // caller can pass a 64-bit byte count here
aoqi@0 2532 BLOCK_COMMENT("Entry:");
aoqi@0 2533 }
aoqi@0 2534
aoqi@0 2535 // save arguments for barrier generation
aoqi@0 2536 __ mov(to, G1);
aoqi@0 2537 __ mov(count, G5);
aoqi@0 2538 gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized);
aoqi@0 2539 #ifdef _LP64
aoqi@0 2540 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 2541 if (UseCompressedOops) {
aoqi@0 2542 generate_disjoint_int_copy_core(aligned);
aoqi@0 2543 } else {
aoqi@0 2544 generate_disjoint_long_copy_core(aligned);
aoqi@0 2545 }
aoqi@0 2546 #else
aoqi@0 2547 generate_disjoint_int_copy_core(aligned);
aoqi@0 2548 #endif
aoqi@0 2549 // O0 is used as temp register
aoqi@0 2550 gen_write_ref_array_post_barrier(G1, G5, O0);
aoqi@0 2551
aoqi@0 2552 // O3, O4 are used as temp registers
aoqi@0 2553 inc_counter_np(SharedRuntime::_oop_array_copy_ctr, O3, O4);
aoqi@0 2554 __ retl();
aoqi@0 2555 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2556 return start;
aoqi@0 2557 }
aoqi@0 2558
aoqi@0 2559 // Generate stub for conjoint oop copy. If "aligned" is true, the
aoqi@0 2560 // "from" and "to" addresses are assumed to be heapword aligned.
aoqi@0 2561 //
aoqi@0 2562 // Arguments for generated stub:
aoqi@0 2563 // from: O0
aoqi@0 2564 // to: O1
aoqi@0 2565 // count: O2 treated as signed
aoqi@0 2566 //
aoqi@0 2567 address generate_conjoint_oop_copy(bool aligned, address nooverlap_target,
aoqi@0 2568 address *entry, const char *name,
aoqi@0 2569 bool dest_uninitialized = false) {
aoqi@0 2570
aoqi@0 2571 const Register from = O0; // source array address
aoqi@0 2572 const Register to = O1; // destination array address
aoqi@0 2573 const Register count = O2; // elements count
aoqi@0 2574
aoqi@0 2575 __ align(CodeEntryAlignment);
aoqi@0 2576 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2577 address start = __ pc();
aoqi@0 2578
aoqi@0 2579 assert_clean_int(count, O3); // Make sure 'count' is clean int.
aoqi@0 2580
aoqi@0 2581 if (entry != NULL) {
aoqi@0 2582 *entry = __ pc();
aoqi@0 2583 // caller can pass a 64-bit byte count here
aoqi@0 2584 BLOCK_COMMENT("Entry:");
aoqi@0 2585 }
aoqi@0 2586
aoqi@0 2587 array_overlap_test(nooverlap_target, LogBytesPerHeapOop);
aoqi@0 2588
aoqi@0 2589 // save arguments for barrier generation
aoqi@0 2590 __ mov(to, G1);
aoqi@0 2591 __ mov(count, G5);
aoqi@0 2592 gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized);
aoqi@0 2593
aoqi@0 2594 #ifdef _LP64
aoqi@0 2595 if (UseCompressedOops) {
aoqi@0 2596 generate_conjoint_int_copy_core(aligned);
aoqi@0 2597 } else {
aoqi@0 2598 generate_conjoint_long_copy_core(aligned);
aoqi@0 2599 }
aoqi@0 2600 #else
aoqi@0 2601 generate_conjoint_int_copy_core(aligned);
aoqi@0 2602 #endif
aoqi@0 2603
aoqi@0 2604 // O0 is used as temp register
aoqi@0 2605 gen_write_ref_array_post_barrier(G1, G5, O0);
aoqi@0 2606
aoqi@0 2607 // O3, O4 are used as temp registers
aoqi@0 2608 inc_counter_np(SharedRuntime::_oop_array_copy_ctr, O3, O4);
aoqi@0 2609 __ retl();
aoqi@0 2610 __ delayed()->mov(G0, O0); // return 0
aoqi@0 2611 return start;
aoqi@0 2612 }
aoqi@0 2613
aoqi@0 2614
aoqi@0 2615 // Helper for generating a dynamic type check.
aoqi@0 2616 // Smashes only the given temp registers.
aoqi@0 2617 void generate_type_check(Register sub_klass,
aoqi@0 2618 Register super_check_offset,
aoqi@0 2619 Register super_klass,
aoqi@0 2620 Register temp,
aoqi@0 2621 Label& L_success) {
aoqi@0 2622 assert_different_registers(sub_klass, super_check_offset, super_klass, temp);
aoqi@0 2623
aoqi@0 2624 BLOCK_COMMENT("type_check:");
aoqi@0 2625
aoqi@0 2626 Label L_miss, L_pop_to_miss;
aoqi@0 2627
aoqi@0 2628 assert_clean_int(super_check_offset, temp);
aoqi@0 2629
aoqi@0 2630 __ check_klass_subtype_fast_path(sub_klass, super_klass, temp, noreg,
aoqi@0 2631 &L_success, &L_miss, NULL,
aoqi@0 2632 super_check_offset);
aoqi@0 2633
aoqi@0 2634 BLOCK_COMMENT("type_check_slow_path:");
aoqi@0 2635 __ save_frame(0);
aoqi@0 2636 __ check_klass_subtype_slow_path(sub_klass->after_save(),
aoqi@0 2637 super_klass->after_save(),
aoqi@0 2638 L0, L1, L2, L4,
aoqi@0 2639 NULL, &L_pop_to_miss);
aoqi@0 2640 __ ba(L_success);
aoqi@0 2641 __ delayed()->restore();
aoqi@0 2642
aoqi@0 2643 __ bind(L_pop_to_miss);
aoqi@0 2644 __ restore();
aoqi@0 2645
aoqi@0 2646 // Fall through on failure!
aoqi@0 2647 __ BIND(L_miss);
aoqi@0 2648 }
aoqi@0 2649
aoqi@0 2650
aoqi@0 2651 // Generate stub for checked oop copy.
aoqi@0 2652 //
aoqi@0 2653 // Arguments for generated stub:
aoqi@0 2654 // from: O0
aoqi@0 2655 // to: O1
aoqi@0 2656 // count: O2 treated as signed
aoqi@0 2657 // ckoff: O3 (super_check_offset)
aoqi@0 2658 // ckval: O4 (super_klass)
aoqi@0 2659 // ret: O0 zero for success; (-1^K) where K is partial transfer count
aoqi@0 2660 //
aoqi@0 2661 address generate_checkcast_copy(const char *name, address *entry, bool dest_uninitialized = false) {
aoqi@0 2662
aoqi@0 2663 const Register O0_from = O0; // source array address
aoqi@0 2664 const Register O1_to = O1; // destination array address
aoqi@0 2665 const Register O2_count = O2; // elements count
aoqi@0 2666 const Register O3_ckoff = O3; // super_check_offset
aoqi@0 2667 const Register O4_ckval = O4; // super_klass
aoqi@0 2668
aoqi@0 2669 const Register O5_offset = O5; // loop var, with stride wordSize
aoqi@0 2670 const Register G1_remain = G1; // loop var, with stride -1
aoqi@0 2671 const Register G3_oop = G3; // actual oop copied
aoqi@0 2672 const Register G4_klass = G4; // oop._klass
aoqi@0 2673 const Register G5_super = G5; // oop._klass._primary_supers[ckval]
aoqi@0 2674
aoqi@0 2675 __ align(CodeEntryAlignment);
aoqi@0 2676 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2677 address start = __ pc();
aoqi@0 2678
aoqi@0 2679 #ifdef ASSERT
aoqi@0 2680 // We sometimes save a frame (see generate_type_check below).
aoqi@0 2681 // If this will cause trouble, let's fail now instead of later.
aoqi@0 2682 __ save_frame(0);
aoqi@0 2683 __ restore();
aoqi@0 2684 #endif
aoqi@0 2685
aoqi@0 2686 assert_clean_int(O2_count, G1); // Make sure 'count' is clean int.
aoqi@0 2687
aoqi@0 2688 #ifdef ASSERT
aoqi@0 2689 // caller guarantees that the arrays really are different
aoqi@0 2690 // otherwise, we would have to make conjoint checks
aoqi@0 2691 { Label L;
aoqi@0 2692 __ mov(O3, G1); // spill: overlap test smashes O3
aoqi@0 2693 __ mov(O4, G4); // spill: overlap test smashes O4
aoqi@0 2694 array_overlap_test(L, LogBytesPerHeapOop);
aoqi@0 2695 __ stop("checkcast_copy within a single array");
aoqi@0 2696 __ bind(L);
aoqi@0 2697 __ mov(G1, O3);
aoqi@0 2698 __ mov(G4, O4);
aoqi@0 2699 }
aoqi@0 2700 #endif //ASSERT
aoqi@0 2701
aoqi@0 2702 if (entry != NULL) {
aoqi@0 2703 *entry = __ pc();
aoqi@0 2704 // caller can pass a 64-bit byte count here (from generic stub)
aoqi@0 2705 BLOCK_COMMENT("Entry:");
aoqi@0 2706 }
aoqi@0 2707 gen_write_ref_array_pre_barrier(O1_to, O2_count, dest_uninitialized);
aoqi@0 2708
aoqi@0 2709 Label load_element, store_element, do_card_marks, fail, done;
aoqi@0 2710 __ addcc(O2_count, 0, G1_remain); // initialize loop index, and test it
aoqi@0 2711 __ brx(Assembler::notZero, false, Assembler::pt, load_element);
aoqi@0 2712 __ delayed()->mov(G0, O5_offset); // offset from start of arrays
aoqi@0 2713
aoqi@0 2714 // Empty array: Nothing to do.
aoqi@0 2715 inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr, O3, O4);
aoqi@0 2716 __ retl();
aoqi@0 2717 __ delayed()->set(0, O0); // return 0 on (trivial) success
aoqi@0 2718
aoqi@0 2719 // ======== begin loop ========
aoqi@0 2720 // (Loop is rotated; its entry is load_element.)
aoqi@0 2721 // Loop variables:
aoqi@0 2722 // (O5 = 0; ; O5 += wordSize) --- offset from src, dest arrays
aoqi@0 2723 // (O2 = len; O2 != 0; O2--) --- number of oops *remaining*
aoqi@0 2724 // G3, G4, G5 --- current oop, oop.klass, oop.klass.super
aoqi@0 2725 __ align(OptoLoopAlignment);
aoqi@0 2726
aoqi@0 2727 __ BIND(store_element);
aoqi@0 2728 __ deccc(G1_remain); // decrement the count
aoqi@0 2729 __ store_heap_oop(G3_oop, O1_to, O5_offset); // store the oop
aoqi@0 2730 __ inc(O5_offset, heapOopSize); // step to next offset
aoqi@0 2731 __ brx(Assembler::zero, true, Assembler::pt, do_card_marks);
aoqi@0 2732 __ delayed()->set(0, O0); // return -1 on success
aoqi@0 2733
aoqi@0 2734 // ======== loop entry is here ========
aoqi@0 2735 __ BIND(load_element);
aoqi@0 2736 __ load_heap_oop(O0_from, O5_offset, G3_oop); // load the oop
aoqi@0 2737 __ br_null_short(G3_oop, Assembler::pt, store_element);
aoqi@0 2738
aoqi@0 2739 __ load_klass(G3_oop, G4_klass); // query the object klass
aoqi@0 2740
aoqi@0 2741 generate_type_check(G4_klass, O3_ckoff, O4_ckval, G5_super,
aoqi@0 2742 // branch to this on success:
aoqi@0 2743 store_element);
aoqi@0 2744 // ======== end loop ========
aoqi@0 2745
aoqi@0 2746 // It was a real error; we must depend on the caller to finish the job.
aoqi@0 2747 // Register G1 has number of *remaining* oops, O2 number of *total* oops.
aoqi@0 2748 // Emit GC store barriers for the oops we have copied (O2 minus G1),
aoqi@0 2749 // and report their number to the caller.
aoqi@0 2750 __ BIND(fail);
aoqi@0 2751 __ subcc(O2_count, G1_remain, O2_count);
aoqi@0 2752 __ brx(Assembler::zero, false, Assembler::pt, done);
aoqi@0 2753 __ delayed()->not1(O2_count, O0); // report (-1^K) to caller
aoqi@0 2754
aoqi@0 2755 __ BIND(do_card_marks);
aoqi@0 2756 gen_write_ref_array_post_barrier(O1_to, O2_count, O3); // store check on O1[0..O2]
aoqi@0 2757
aoqi@0 2758 __ BIND(done);
aoqi@0 2759 inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr, O3, O4);
aoqi@0 2760 __ retl();
aoqi@0 2761 __ delayed()->nop(); // return value in 00
aoqi@0 2762
aoqi@0 2763 return start;
aoqi@0 2764 }
aoqi@0 2765
aoqi@0 2766
aoqi@0 2767 // Generate 'unsafe' array copy stub
aoqi@0 2768 // Though just as safe as the other stubs, it takes an unscaled
aoqi@0 2769 // size_t argument instead of an element count.
aoqi@0 2770 //
aoqi@0 2771 // Arguments for generated stub:
aoqi@0 2772 // from: O0
aoqi@0 2773 // to: O1
aoqi@0 2774 // count: O2 byte count, treated as ssize_t, can be zero
aoqi@0 2775 //
aoqi@0 2776 // Examines the alignment of the operands and dispatches
aoqi@0 2777 // to a long, int, short, or byte copy loop.
aoqi@0 2778 //
aoqi@0 2779 address generate_unsafe_copy(const char* name,
aoqi@0 2780 address byte_copy_entry,
aoqi@0 2781 address short_copy_entry,
aoqi@0 2782 address int_copy_entry,
aoqi@0 2783 address long_copy_entry) {
aoqi@0 2784
aoqi@0 2785 const Register O0_from = O0; // source array address
aoqi@0 2786 const Register O1_to = O1; // destination array address
aoqi@0 2787 const Register O2_count = O2; // elements count
aoqi@0 2788
aoqi@0 2789 const Register G1_bits = G1; // test copy of low bits
aoqi@0 2790
aoqi@0 2791 __ align(CodeEntryAlignment);
aoqi@0 2792 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2793 address start = __ pc();
aoqi@0 2794
aoqi@0 2795 // bump this on entry, not on exit:
aoqi@0 2796 inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr, G1, G3);
aoqi@0 2797
aoqi@0 2798 __ or3(O0_from, O1_to, G1_bits);
aoqi@0 2799 __ or3(O2_count, G1_bits, G1_bits);
aoqi@0 2800
aoqi@0 2801 __ btst(BytesPerLong-1, G1_bits);
aoqi@0 2802 __ br(Assembler::zero, true, Assembler::pt,
aoqi@0 2803 long_copy_entry, relocInfo::runtime_call_type);
aoqi@0 2804 // scale the count on the way out:
aoqi@0 2805 __ delayed()->srax(O2_count, LogBytesPerLong, O2_count);
aoqi@0 2806
aoqi@0 2807 __ btst(BytesPerInt-1, G1_bits);
aoqi@0 2808 __ br(Assembler::zero, true, Assembler::pt,
aoqi@0 2809 int_copy_entry, relocInfo::runtime_call_type);
aoqi@0 2810 // scale the count on the way out:
aoqi@0 2811 __ delayed()->srax(O2_count, LogBytesPerInt, O2_count);
aoqi@0 2812
aoqi@0 2813 __ btst(BytesPerShort-1, G1_bits);
aoqi@0 2814 __ br(Assembler::zero, true, Assembler::pt,
aoqi@0 2815 short_copy_entry, relocInfo::runtime_call_type);
aoqi@0 2816 // scale the count on the way out:
aoqi@0 2817 __ delayed()->srax(O2_count, LogBytesPerShort, O2_count);
aoqi@0 2818
aoqi@0 2819 __ br(Assembler::always, false, Assembler::pt,
aoqi@0 2820 byte_copy_entry, relocInfo::runtime_call_type);
aoqi@0 2821 __ delayed()->nop();
aoqi@0 2822
aoqi@0 2823 return start;
aoqi@0 2824 }
aoqi@0 2825
aoqi@0 2826
aoqi@0 2827 // Perform range checks on the proposed arraycopy.
aoqi@0 2828 // Kills the two temps, but nothing else.
aoqi@0 2829 // Also, clean the sign bits of src_pos and dst_pos.
aoqi@0 2830 void arraycopy_range_checks(Register src, // source array oop (O0)
aoqi@0 2831 Register src_pos, // source position (O1)
aoqi@0 2832 Register dst, // destination array oo (O2)
aoqi@0 2833 Register dst_pos, // destination position (O3)
aoqi@0 2834 Register length, // length of copy (O4)
aoqi@0 2835 Register temp1, Register temp2,
aoqi@0 2836 Label& L_failed) {
aoqi@0 2837 BLOCK_COMMENT("arraycopy_range_checks:");
aoqi@0 2838
aoqi@0 2839 // if (src_pos + length > arrayOop(src)->length() ) FAIL;
aoqi@0 2840
aoqi@0 2841 const Register array_length = temp1; // scratch
aoqi@0 2842 const Register end_pos = temp2; // scratch
aoqi@0 2843
aoqi@0 2844 // Note: This next instruction may be in the delay slot of a branch:
aoqi@0 2845 __ add(length, src_pos, end_pos); // src_pos + length
aoqi@0 2846 __ lduw(src, arrayOopDesc::length_offset_in_bytes(), array_length);
aoqi@0 2847 __ cmp(end_pos, array_length);
aoqi@0 2848 __ br(Assembler::greater, false, Assembler::pn, L_failed);
aoqi@0 2849
aoqi@0 2850 // if (dst_pos + length > arrayOop(dst)->length() ) FAIL;
aoqi@0 2851 __ delayed()->add(length, dst_pos, end_pos); // dst_pos + length
aoqi@0 2852 __ lduw(dst, arrayOopDesc::length_offset_in_bytes(), array_length);
aoqi@0 2853 __ cmp(end_pos, array_length);
aoqi@0 2854 __ br(Assembler::greater, false, Assembler::pn, L_failed);
aoqi@0 2855
aoqi@0 2856 // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'.
aoqi@0 2857 // Move with sign extension can be used since they are positive.
aoqi@0 2858 __ delayed()->signx(src_pos, src_pos);
aoqi@0 2859 __ signx(dst_pos, dst_pos);
aoqi@0 2860
aoqi@0 2861 BLOCK_COMMENT("arraycopy_range_checks done");
aoqi@0 2862 }
aoqi@0 2863
aoqi@0 2864
aoqi@0 2865 //
aoqi@0 2866 // Generate generic array copy stubs
aoqi@0 2867 //
aoqi@0 2868 // Input:
aoqi@0 2869 // O0 - src oop
aoqi@0 2870 // O1 - src_pos
aoqi@0 2871 // O2 - dst oop
aoqi@0 2872 // O3 - dst_pos
aoqi@0 2873 // O4 - element count
aoqi@0 2874 //
aoqi@0 2875 // Output:
aoqi@0 2876 // O0 == 0 - success
aoqi@0 2877 // O0 == -1 - need to call System.arraycopy
aoqi@0 2878 //
aoqi@0 2879 address generate_generic_copy(const char *name,
aoqi@0 2880 address entry_jbyte_arraycopy,
aoqi@0 2881 address entry_jshort_arraycopy,
aoqi@0 2882 address entry_jint_arraycopy,
aoqi@0 2883 address entry_oop_arraycopy,
aoqi@0 2884 address entry_jlong_arraycopy,
aoqi@0 2885 address entry_checkcast_arraycopy) {
aoqi@0 2886 Label L_failed, L_objArray;
aoqi@0 2887
aoqi@0 2888 // Input registers
aoqi@0 2889 const Register src = O0; // source array oop
aoqi@0 2890 const Register src_pos = O1; // source position
aoqi@0 2891 const Register dst = O2; // destination array oop
aoqi@0 2892 const Register dst_pos = O3; // destination position
aoqi@0 2893 const Register length = O4; // elements count
aoqi@0 2894
aoqi@0 2895 // registers used as temp
aoqi@0 2896 const Register G3_src_klass = G3; // source array klass
aoqi@0 2897 const Register G4_dst_klass = G4; // destination array klass
aoqi@0 2898 const Register G5_lh = G5; // layout handler
aoqi@0 2899 const Register O5_temp = O5;
aoqi@0 2900
aoqi@0 2901 __ align(CodeEntryAlignment);
aoqi@0 2902 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2903 address start = __ pc();
aoqi@0 2904
aoqi@0 2905 // bump this on entry, not on exit:
aoqi@0 2906 inc_counter_np(SharedRuntime::_generic_array_copy_ctr, G1, G3);
aoqi@0 2907
aoqi@0 2908 // In principle, the int arguments could be dirty.
aoqi@0 2909 //assert_clean_int(src_pos, G1);
aoqi@0 2910 //assert_clean_int(dst_pos, G1);
aoqi@0 2911 //assert_clean_int(length, G1);
aoqi@0 2912
aoqi@0 2913 //-----------------------------------------------------------------------
aoqi@0 2914 // Assembler stubs will be used for this call to arraycopy
aoqi@0 2915 // if the following conditions are met:
aoqi@0 2916 //
aoqi@0 2917 // (1) src and dst must not be null.
aoqi@0 2918 // (2) src_pos must not be negative.
aoqi@0 2919 // (3) dst_pos must not be negative.
aoqi@0 2920 // (4) length must not be negative.
aoqi@0 2921 // (5) src klass and dst klass should be the same and not NULL.
aoqi@0 2922 // (6) src and dst should be arrays.
aoqi@0 2923 // (7) src_pos + length must not exceed length of src.
aoqi@0 2924 // (8) dst_pos + length must not exceed length of dst.
aoqi@0 2925 BLOCK_COMMENT("arraycopy initial argument checks");
aoqi@0 2926
aoqi@0 2927 // if (src == NULL) return -1;
aoqi@0 2928 __ br_null(src, false, Assembler::pn, L_failed);
aoqi@0 2929
aoqi@0 2930 // if (src_pos < 0) return -1;
aoqi@0 2931 __ delayed()->tst(src_pos);
aoqi@0 2932 __ br(Assembler::negative, false, Assembler::pn, L_failed);
aoqi@0 2933 __ delayed()->nop();
aoqi@0 2934
aoqi@0 2935 // if (dst == NULL) return -1;
aoqi@0 2936 __ br_null(dst, false, Assembler::pn, L_failed);
aoqi@0 2937
aoqi@0 2938 // if (dst_pos < 0) return -1;
aoqi@0 2939 __ delayed()->tst(dst_pos);
aoqi@0 2940 __ br(Assembler::negative, false, Assembler::pn, L_failed);
aoqi@0 2941
aoqi@0 2942 // if (length < 0) return -1;
aoqi@0 2943 __ delayed()->tst(length);
aoqi@0 2944 __ br(Assembler::negative, false, Assembler::pn, L_failed);
aoqi@0 2945
aoqi@0 2946 BLOCK_COMMENT("arraycopy argument klass checks");
aoqi@0 2947 // get src->klass()
aoqi@0 2948 if (UseCompressedClassPointers) {
aoqi@0 2949 __ delayed()->nop(); // ??? not good
aoqi@0 2950 __ load_klass(src, G3_src_klass);
aoqi@0 2951 } else {
aoqi@0 2952 __ delayed()->ld_ptr(src, oopDesc::klass_offset_in_bytes(), G3_src_klass);
aoqi@0 2953 }
aoqi@0 2954
aoqi@0 2955 #ifdef ASSERT
aoqi@0 2956 // assert(src->klass() != NULL);
aoqi@0 2957 BLOCK_COMMENT("assert klasses not null");
aoqi@0 2958 { Label L_a, L_b;
aoqi@0 2959 __ br_notnull_short(G3_src_klass, Assembler::pt, L_b); // it is broken if klass is NULL
aoqi@0 2960 __ bind(L_a);
aoqi@0 2961 __ stop("broken null klass");
aoqi@0 2962 __ bind(L_b);
aoqi@0 2963 __ load_klass(dst, G4_dst_klass);
aoqi@0 2964 __ br_null(G4_dst_klass, false, Assembler::pn, L_a); // this would be broken also
aoqi@0 2965 __ delayed()->mov(G0, G4_dst_klass); // scribble the temp
aoqi@0 2966 BLOCK_COMMENT("assert done");
aoqi@0 2967 }
aoqi@0 2968 #endif
aoqi@0 2969
aoqi@0 2970 // Load layout helper
aoqi@0 2971 //
aoqi@0 2972 // |array_tag| | header_size | element_type | |log2_element_size|
aoqi@0 2973 // 32 30 24 16 8 2 0
aoqi@0 2974 //
aoqi@0 2975 // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0
aoqi@0 2976 //
aoqi@0 2977
aoqi@0 2978 int lh_offset = in_bytes(Klass::layout_helper_offset());
aoqi@0 2979
aoqi@0 2980 // Load 32-bits signed value. Use br() instruction with it to check icc.
aoqi@0 2981 __ lduw(G3_src_klass, lh_offset, G5_lh);
aoqi@0 2982
aoqi@0 2983 if (UseCompressedClassPointers) {
aoqi@0 2984 __ load_klass(dst, G4_dst_klass);
aoqi@0 2985 }
aoqi@0 2986 // Handle objArrays completely differently...
aoqi@0 2987 juint objArray_lh = Klass::array_layout_helper(T_OBJECT);
aoqi@0 2988 __ set(objArray_lh, O5_temp);
aoqi@0 2989 __ cmp(G5_lh, O5_temp);
aoqi@0 2990 __ br(Assembler::equal, false, Assembler::pt, L_objArray);
aoqi@0 2991 if (UseCompressedClassPointers) {
aoqi@0 2992 __ delayed()->nop();
aoqi@0 2993 } else {
aoqi@0 2994 __ delayed()->ld_ptr(dst, oopDesc::klass_offset_in_bytes(), G4_dst_klass);
aoqi@0 2995 }
aoqi@0 2996
aoqi@0 2997 // if (src->klass() != dst->klass()) return -1;
aoqi@0 2998 __ cmp_and_brx_short(G3_src_klass, G4_dst_klass, Assembler::notEqual, Assembler::pn, L_failed);
aoqi@0 2999
aoqi@0 3000 // if (!src->is_Array()) return -1;
aoqi@0 3001 __ cmp(G5_lh, Klass::_lh_neutral_value); // < 0
aoqi@0 3002 __ br(Assembler::greaterEqual, false, Assembler::pn, L_failed);
aoqi@0 3003
aoqi@0 3004 // At this point, it is known to be a typeArray (array_tag 0x3).
aoqi@0 3005 #ifdef ASSERT
aoqi@0 3006 __ delayed()->nop();
aoqi@0 3007 { Label L;
aoqi@0 3008 jint lh_prim_tag_in_place = (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift);
aoqi@0 3009 __ set(lh_prim_tag_in_place, O5_temp);
aoqi@0 3010 __ cmp(G5_lh, O5_temp);
aoqi@0 3011 __ br(Assembler::greaterEqual, false, Assembler::pt, L);
aoqi@0 3012 __ delayed()->nop();
aoqi@0 3013 __ stop("must be a primitive array");
aoqi@0 3014 __ bind(L);
aoqi@0 3015 }
aoqi@0 3016 #else
aoqi@0 3017 __ delayed(); // match next insn to prev branch
aoqi@0 3018 #endif
aoqi@0 3019
aoqi@0 3020 arraycopy_range_checks(src, src_pos, dst, dst_pos, length,
aoqi@0 3021 O5_temp, G4_dst_klass, L_failed);
aoqi@0 3022
aoqi@0 3023 // TypeArrayKlass
aoqi@0 3024 //
aoqi@0 3025 // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
aoqi@0 3026 // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
aoqi@0 3027 //
aoqi@0 3028
aoqi@0 3029 const Register G4_offset = G4_dst_klass; // array offset
aoqi@0 3030 const Register G3_elsize = G3_src_klass; // log2 element size
aoqi@0 3031
aoqi@0 3032 __ srl(G5_lh, Klass::_lh_header_size_shift, G4_offset);
aoqi@0 3033 __ and3(G4_offset, Klass::_lh_header_size_mask, G4_offset); // array_offset
aoqi@0 3034 __ add(src, G4_offset, src); // src array offset
aoqi@0 3035 __ add(dst, G4_offset, dst); // dst array offset
aoqi@0 3036 __ and3(G5_lh, Klass::_lh_log2_element_size_mask, G3_elsize); // log2 element size
aoqi@0 3037
aoqi@0 3038 // next registers should be set before the jump to corresponding stub
aoqi@0 3039 const Register from = O0; // source array address
aoqi@0 3040 const Register to = O1; // destination array address
aoqi@0 3041 const Register count = O2; // elements count
aoqi@0 3042
aoqi@0 3043 // 'from', 'to', 'count' registers should be set in this order
aoqi@0 3044 // since they are the same as 'src', 'src_pos', 'dst'.
aoqi@0 3045
aoqi@0 3046 BLOCK_COMMENT("scale indexes to element size");
aoqi@0 3047 __ sll_ptr(src_pos, G3_elsize, src_pos);
aoqi@0 3048 __ sll_ptr(dst_pos, G3_elsize, dst_pos);
aoqi@0 3049 __ add(src, src_pos, from); // src_addr
aoqi@0 3050 __ add(dst, dst_pos, to); // dst_addr
aoqi@0 3051
aoqi@0 3052 BLOCK_COMMENT("choose copy loop based on element size");
aoqi@0 3053 __ cmp(G3_elsize, 0);
aoqi@0 3054 __ br(Assembler::equal, true, Assembler::pt, entry_jbyte_arraycopy);
aoqi@0 3055 __ delayed()->signx(length, count); // length
aoqi@0 3056
aoqi@0 3057 __ cmp(G3_elsize, LogBytesPerShort);
aoqi@0 3058 __ br(Assembler::equal, true, Assembler::pt, entry_jshort_arraycopy);
aoqi@0 3059 __ delayed()->signx(length, count); // length
aoqi@0 3060
aoqi@0 3061 __ cmp(G3_elsize, LogBytesPerInt);
aoqi@0 3062 __ br(Assembler::equal, true, Assembler::pt, entry_jint_arraycopy);
aoqi@0 3063 __ delayed()->signx(length, count); // length
aoqi@0 3064 #ifdef ASSERT
aoqi@0 3065 { Label L;
aoqi@0 3066 __ cmp_and_br_short(G3_elsize, LogBytesPerLong, Assembler::equal, Assembler::pt, L);
aoqi@0 3067 __ stop("must be long copy, but elsize is wrong");
aoqi@0 3068 __ bind(L);
aoqi@0 3069 }
aoqi@0 3070 #endif
aoqi@0 3071 __ br(Assembler::always, false, Assembler::pt, entry_jlong_arraycopy);
aoqi@0 3072 __ delayed()->signx(length, count); // length
aoqi@0 3073
aoqi@0 3074 // ObjArrayKlass
aoqi@0 3075 __ BIND(L_objArray);
aoqi@0 3076 // live at this point: G3_src_klass, G4_dst_klass, src[_pos], dst[_pos], length
aoqi@0 3077
aoqi@0 3078 Label L_plain_copy, L_checkcast_copy;
aoqi@0 3079 // test array classes for subtyping
aoqi@0 3080 __ cmp(G3_src_klass, G4_dst_klass); // usual case is exact equality
aoqi@0 3081 __ brx(Assembler::notEqual, true, Assembler::pn, L_checkcast_copy);
aoqi@0 3082 __ delayed()->lduw(G4_dst_klass, lh_offset, O5_temp); // hoisted from below
aoqi@0 3083
aoqi@0 3084 // Identically typed arrays can be copied without element-wise checks.
aoqi@0 3085 arraycopy_range_checks(src, src_pos, dst, dst_pos, length,
aoqi@0 3086 O5_temp, G5_lh, L_failed);
aoqi@0 3087
aoqi@0 3088 __ add(src, arrayOopDesc::base_offset_in_bytes(T_OBJECT), src); //src offset
aoqi@0 3089 __ add(dst, arrayOopDesc::base_offset_in_bytes(T_OBJECT), dst); //dst offset
aoqi@0 3090 __ sll_ptr(src_pos, LogBytesPerHeapOop, src_pos);
aoqi@0 3091 __ sll_ptr(dst_pos, LogBytesPerHeapOop, dst_pos);
aoqi@0 3092 __ add(src, src_pos, from); // src_addr
aoqi@0 3093 __ add(dst, dst_pos, to); // dst_addr
aoqi@0 3094 __ BIND(L_plain_copy);
aoqi@0 3095 __ br(Assembler::always, false, Assembler::pt, entry_oop_arraycopy);
aoqi@0 3096 __ delayed()->signx(length, count); // length
aoqi@0 3097
aoqi@0 3098 __ BIND(L_checkcast_copy);
aoqi@0 3099 // live at this point: G3_src_klass, G4_dst_klass
aoqi@0 3100 {
aoqi@0 3101 // Before looking at dst.length, make sure dst is also an objArray.
aoqi@0 3102 // lduw(G4_dst_klass, lh_offset, O5_temp); // hoisted to delay slot
aoqi@0 3103 __ cmp(G5_lh, O5_temp);
aoqi@0 3104 __ br(Assembler::notEqual, false, Assembler::pn, L_failed);
aoqi@0 3105
aoqi@0 3106 // It is safe to examine both src.length and dst.length.
aoqi@0 3107 __ delayed(); // match next insn to prev branch
aoqi@0 3108 arraycopy_range_checks(src, src_pos, dst, dst_pos, length,
aoqi@0 3109 O5_temp, G5_lh, L_failed);
aoqi@0 3110
aoqi@0 3111 // Marshal the base address arguments now, freeing registers.
aoqi@0 3112 __ add(src, arrayOopDesc::base_offset_in_bytes(T_OBJECT), src); //src offset
aoqi@0 3113 __ add(dst, arrayOopDesc::base_offset_in_bytes(T_OBJECT), dst); //dst offset
aoqi@0 3114 __ sll_ptr(src_pos, LogBytesPerHeapOop, src_pos);
aoqi@0 3115 __ sll_ptr(dst_pos, LogBytesPerHeapOop, dst_pos);
aoqi@0 3116 __ add(src, src_pos, from); // src_addr
aoqi@0 3117 __ add(dst, dst_pos, to); // dst_addr
aoqi@0 3118 __ signx(length, count); // length (reloaded)
aoqi@0 3119
aoqi@0 3120 Register sco_temp = O3; // this register is free now
aoqi@0 3121 assert_different_registers(from, to, count, sco_temp,
aoqi@0 3122 G4_dst_klass, G3_src_klass);
aoqi@0 3123
aoqi@0 3124 // Generate the type check.
aoqi@0 3125 int sco_offset = in_bytes(Klass::super_check_offset_offset());
aoqi@0 3126 __ lduw(G4_dst_klass, sco_offset, sco_temp);
aoqi@0 3127 generate_type_check(G3_src_klass, sco_temp, G4_dst_klass,
aoqi@0 3128 O5_temp, L_plain_copy);
aoqi@0 3129
aoqi@0 3130 // Fetch destination element klass from the ObjArrayKlass header.
aoqi@0 3131 int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset());
aoqi@0 3132
aoqi@0 3133 // the checkcast_copy loop needs two extra arguments:
aoqi@0 3134 __ ld_ptr(G4_dst_klass, ek_offset, O4); // dest elem klass
aoqi@0 3135 // lduw(O4, sco_offset, O3); // sco of elem klass
aoqi@0 3136
aoqi@0 3137 __ br(Assembler::always, false, Assembler::pt, entry_checkcast_arraycopy);
aoqi@0 3138 __ delayed()->lduw(O4, sco_offset, O3);
aoqi@0 3139 }
aoqi@0 3140
aoqi@0 3141 __ BIND(L_failed);
aoqi@0 3142 __ retl();
aoqi@0 3143 __ delayed()->sub(G0, 1, O0); // return -1
aoqi@0 3144 return start;
aoqi@0 3145 }
aoqi@0 3146
aoqi@0 3147 //
aoqi@0 3148 // Generate stub for heap zeroing.
aoqi@0 3149 // "to" address is aligned to jlong (8 bytes).
aoqi@0 3150 //
aoqi@0 3151 // Arguments for generated stub:
aoqi@0 3152 // to: O0
aoqi@0 3153 // count: O1 treated as signed (count of HeapWord)
aoqi@0 3154 // count could be 0
aoqi@0 3155 //
aoqi@0 3156 address generate_zero_aligned_words(const char* name) {
aoqi@0 3157 __ align(CodeEntryAlignment);
aoqi@0 3158 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 3159 address start = __ pc();
aoqi@0 3160
aoqi@0 3161 const Register to = O0; // source array address
aoqi@0 3162 const Register count = O1; // HeapWords count
aoqi@0 3163 const Register temp = O2; // scratch
aoqi@0 3164
aoqi@0 3165 Label Ldone;
aoqi@0 3166 __ sllx(count, LogHeapWordSize, count); // to bytes count
aoqi@0 3167 // Use BIS for zeroing
aoqi@0 3168 __ bis_zeroing(to, count, temp, Ldone);
aoqi@0 3169 __ bind(Ldone);
aoqi@0 3170 __ retl();
aoqi@0 3171 __ delayed()->nop();
aoqi@0 3172 return start;
aoqi@0 3173 }
aoqi@0 3174
aoqi@0 3175 void generate_arraycopy_stubs() {
aoqi@0 3176 address entry;
aoqi@0 3177 address entry_jbyte_arraycopy;
aoqi@0 3178 address entry_jshort_arraycopy;
aoqi@0 3179 address entry_jint_arraycopy;
aoqi@0 3180 address entry_oop_arraycopy;
aoqi@0 3181 address entry_jlong_arraycopy;
aoqi@0 3182 address entry_checkcast_arraycopy;
aoqi@0 3183
aoqi@0 3184 //*** jbyte
aoqi@0 3185 // Always need aligned and unaligned versions
aoqi@0 3186 StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry,
aoqi@0 3187 "jbyte_disjoint_arraycopy");
aoqi@0 3188 StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry,
aoqi@0 3189 &entry_jbyte_arraycopy,
aoqi@0 3190 "jbyte_arraycopy");
aoqi@0 3191 StubRoutines::_arrayof_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(true, &entry,
aoqi@0 3192 "arrayof_jbyte_disjoint_arraycopy");
aoqi@0 3193 StubRoutines::_arrayof_jbyte_arraycopy = generate_conjoint_byte_copy(true, entry, NULL,
aoqi@0 3194 "arrayof_jbyte_arraycopy");
aoqi@0 3195
aoqi@0 3196 //*** jshort
aoqi@0 3197 // Always need aligned and unaligned versions
aoqi@0 3198 StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry,
aoqi@0 3199 "jshort_disjoint_arraycopy");
aoqi@0 3200 StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry,
aoqi@0 3201 &entry_jshort_arraycopy,
aoqi@0 3202 "jshort_arraycopy");
aoqi@0 3203 StubRoutines::_arrayof_jshort_disjoint_arraycopy = generate_disjoint_short_copy(true, &entry,
aoqi@0 3204 "arrayof_jshort_disjoint_arraycopy");
aoqi@0 3205 StubRoutines::_arrayof_jshort_arraycopy = generate_conjoint_short_copy(true, entry, NULL,
aoqi@0 3206 "arrayof_jshort_arraycopy");
aoqi@0 3207
aoqi@0 3208 //*** jint
aoqi@0 3209 // Aligned versions
aoqi@0 3210 StubRoutines::_arrayof_jint_disjoint_arraycopy = generate_disjoint_int_copy(true, &entry,
aoqi@0 3211 "arrayof_jint_disjoint_arraycopy");
aoqi@0 3212 StubRoutines::_arrayof_jint_arraycopy = generate_conjoint_int_copy(true, entry, &entry_jint_arraycopy,
aoqi@0 3213 "arrayof_jint_arraycopy");
aoqi@0 3214 #ifdef _LP64
aoqi@0 3215 // In 64 bit we need both aligned and unaligned versions of jint arraycopy.
aoqi@0 3216 // entry_jint_arraycopy always points to the unaligned version (notice that we overwrite it).
aoqi@0 3217 StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_copy(false, &entry,
aoqi@0 3218 "jint_disjoint_arraycopy");
aoqi@0 3219 StubRoutines::_jint_arraycopy = generate_conjoint_int_copy(false, entry,
aoqi@0 3220 &entry_jint_arraycopy,
aoqi@0 3221 "jint_arraycopy");
aoqi@0 3222 #else
aoqi@0 3223 // In 32 bit jints are always HeapWordSize aligned, so always use the aligned version
aoqi@0 3224 // (in fact in 32bit we always have a pre-loop part even in the aligned version,
aoqi@0 3225 // because it uses 64-bit loads/stores, so the aligned flag is actually ignored).
aoqi@0 3226 StubRoutines::_jint_disjoint_arraycopy = StubRoutines::_arrayof_jint_disjoint_arraycopy;
aoqi@0 3227 StubRoutines::_jint_arraycopy = StubRoutines::_arrayof_jint_arraycopy;
aoqi@0 3228 #endif
aoqi@0 3229
aoqi@0 3230
aoqi@0 3231 //*** jlong
aoqi@0 3232 // It is always aligned
aoqi@0 3233 StubRoutines::_arrayof_jlong_disjoint_arraycopy = generate_disjoint_long_copy(true, &entry,
aoqi@0 3234 "arrayof_jlong_disjoint_arraycopy");
aoqi@0 3235 StubRoutines::_arrayof_jlong_arraycopy = generate_conjoint_long_copy(true, entry, &entry_jlong_arraycopy,
aoqi@0 3236 "arrayof_jlong_arraycopy");
aoqi@0 3237 StubRoutines::_jlong_disjoint_arraycopy = StubRoutines::_arrayof_jlong_disjoint_arraycopy;
aoqi@0 3238 StubRoutines::_jlong_arraycopy = StubRoutines::_arrayof_jlong_arraycopy;
aoqi@0 3239
aoqi@0 3240
aoqi@0 3241 //*** oops
aoqi@0 3242 // Aligned versions
aoqi@0 3243 StubRoutines::_arrayof_oop_disjoint_arraycopy = generate_disjoint_oop_copy(true, &entry,
aoqi@0 3244 "arrayof_oop_disjoint_arraycopy");
aoqi@0 3245 StubRoutines::_arrayof_oop_arraycopy = generate_conjoint_oop_copy(true, entry, &entry_oop_arraycopy,
aoqi@0 3246 "arrayof_oop_arraycopy");
aoqi@0 3247 // Aligned versions without pre-barriers
aoqi@0 3248 StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(true, &entry,
aoqi@0 3249 "arrayof_oop_disjoint_arraycopy_uninit",
aoqi@0 3250 /*dest_uninitialized*/true);
aoqi@0 3251 StubRoutines::_arrayof_oop_arraycopy_uninit = generate_conjoint_oop_copy(true, entry, NULL,
aoqi@0 3252 "arrayof_oop_arraycopy_uninit",
aoqi@0 3253 /*dest_uninitialized*/true);
aoqi@0 3254 #ifdef _LP64
aoqi@0 3255 if (UseCompressedOops) {
aoqi@0 3256 // With compressed oops we need unaligned versions, notice that we overwrite entry_oop_arraycopy.
aoqi@0 3257 StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_oop_copy(false, &entry,
aoqi@0 3258 "oop_disjoint_arraycopy");
aoqi@0 3259 StubRoutines::_oop_arraycopy = generate_conjoint_oop_copy(false, entry, &entry_oop_arraycopy,
aoqi@0 3260 "oop_arraycopy");
aoqi@0 3261 // Unaligned versions without pre-barriers
aoqi@0 3262 StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(false, &entry,
aoqi@0 3263 "oop_disjoint_arraycopy_uninit",
aoqi@0 3264 /*dest_uninitialized*/true);
aoqi@0 3265 StubRoutines::_oop_arraycopy_uninit = generate_conjoint_oop_copy(false, entry, NULL,
aoqi@0 3266 "oop_arraycopy_uninit",
aoqi@0 3267 /*dest_uninitialized*/true);
aoqi@0 3268 } else
aoqi@0 3269 #endif
aoqi@0 3270 {
aoqi@0 3271 // oop arraycopy is always aligned on 32bit and 64bit without compressed oops
aoqi@0 3272 StubRoutines::_oop_disjoint_arraycopy = StubRoutines::_arrayof_oop_disjoint_arraycopy;
aoqi@0 3273 StubRoutines::_oop_arraycopy = StubRoutines::_arrayof_oop_arraycopy;
aoqi@0 3274 StubRoutines::_oop_disjoint_arraycopy_uninit = StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit;
aoqi@0 3275 StubRoutines::_oop_arraycopy_uninit = StubRoutines::_arrayof_oop_arraycopy_uninit;
aoqi@0 3276 }
aoqi@0 3277
aoqi@0 3278 StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy);
aoqi@0 3279 StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL,
aoqi@0 3280 /*dest_uninitialized*/true);
aoqi@0 3281
aoqi@0 3282 StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy",
aoqi@0 3283 entry_jbyte_arraycopy,
aoqi@0 3284 entry_jshort_arraycopy,
aoqi@0 3285 entry_jint_arraycopy,
aoqi@0 3286 entry_jlong_arraycopy);
aoqi@0 3287 StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy",
aoqi@0 3288 entry_jbyte_arraycopy,
aoqi@0 3289 entry_jshort_arraycopy,
aoqi@0 3290 entry_jint_arraycopy,
aoqi@0 3291 entry_oop_arraycopy,
aoqi@0 3292 entry_jlong_arraycopy,
aoqi@0 3293 entry_checkcast_arraycopy);
aoqi@0 3294
aoqi@0 3295 StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill");
aoqi@0 3296 StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill");
aoqi@0 3297 StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill");
aoqi@0 3298 StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill");
aoqi@0 3299 StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill");
aoqi@0 3300 StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill");
aoqi@0 3301
aoqi@0 3302 if (UseBlockZeroing) {
aoqi@0 3303 StubRoutines::_zero_aligned_words = generate_zero_aligned_words("zero_aligned_words");
aoqi@0 3304 }
aoqi@0 3305 }
aoqi@0 3306
aoqi@0 3307 address generate_aescrypt_encryptBlock() {
aoqi@0 3308 // required since we read expanded key 'int' array starting first element without alignment considerations
aoqi@0 3309 assert((arrayOopDesc::base_offset_in_bytes(T_INT) & 7) == 0,
aoqi@0 3310 "the following code assumes that first element of an int array is aligned to 8 bytes");
aoqi@0 3311 __ align(CodeEntryAlignment);
aoqi@0 3312 StubCodeMark mark(this, "StubRoutines", "aescrypt_encryptBlock");
aoqi@0 3313 Label L_load_misaligned_input, L_load_expanded_key, L_doLast128bit, L_storeOutput, L_store_misaligned_output;
aoqi@0 3314 address start = __ pc();
aoqi@0 3315 Register from = O0; // source byte array
aoqi@0 3316 Register to = O1; // destination byte array
aoqi@0 3317 Register key = O2; // expanded key array
aoqi@0 3318 const Register keylen = O4; //reg for storing expanded key array length
aoqi@0 3319
aoqi@0 3320 // read expanded key length
aoqi@0 3321 __ ldsw(Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)), keylen, 0);
aoqi@0 3322
aoqi@0 3323 // Method to address arbitrary alignment for load instructions:
aoqi@0 3324 // Check last 3 bits of 'from' address to see if it is aligned to 8-byte boundary
aoqi@0 3325 // If zero/aligned then continue with double FP load instructions
aoqi@0 3326 // If not zero/mis-aligned then alignaddr will set GSR.align with number of bytes to skip during faligndata
aoqi@0 3327 // alignaddr will also convert arbitrary aligned 'from' address to nearest 8-byte aligned address
aoqi@0 3328 // load 3 * 8-byte components (to read 16 bytes input) in 3 different FP regs starting at this aligned address
aoqi@0 3329 // faligndata will then extract (based on GSR.align value) the appropriate 8 bytes from the 2 source regs
aoqi@0 3330
aoqi@0 3331 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3332 __ andcc(from, 7, G0);
aoqi@0 3333 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input);
aoqi@0 3334 __ delayed()->alignaddr(from, G0, from);
aoqi@0 3335
aoqi@0 3336 // aligned case: load input into F54-F56
aoqi@0 3337 __ ldf(FloatRegisterImpl::D, from, 0, F54);
aoqi@0 3338 __ ldf(FloatRegisterImpl::D, from, 8, F56);
aoqi@0 3339 __ ba_short(L_load_expanded_key);
aoqi@0 3340
aoqi@0 3341 __ BIND(L_load_misaligned_input);
aoqi@0 3342 __ ldf(FloatRegisterImpl::D, from, 0, F54);
aoqi@0 3343 __ ldf(FloatRegisterImpl::D, from, 8, F56);
aoqi@0 3344 __ ldf(FloatRegisterImpl::D, from, 16, F58);
aoqi@0 3345 __ faligndata(F54, F56, F54);
aoqi@0 3346 __ faligndata(F56, F58, F56);
aoqi@0 3347
aoqi@0 3348 __ BIND(L_load_expanded_key);
aoqi@0 3349 // Since we load expanded key buffers starting first element, 8-byte alignment is guaranteed
aoqi@0 3350 for ( int i = 0; i <= 38; i += 2 ) {
aoqi@0 3351 __ ldf(FloatRegisterImpl::D, key, i*4, as_FloatRegister(i));
aoqi@0 3352 }
aoqi@0 3353
aoqi@0 3354 // perform cipher transformation
aoqi@0 3355 __ fxor(FloatRegisterImpl::D, F0, F54, F54);
aoqi@0 3356 __ fxor(FloatRegisterImpl::D, F2, F56, F56);
aoqi@0 3357 // rounds 1 through 8
aoqi@0 3358 for ( int i = 4; i <= 28; i += 8 ) {
aoqi@0 3359 __ aes_eround01(as_FloatRegister(i), F54, F56, F58);
aoqi@0 3360 __ aes_eround23(as_FloatRegister(i+2), F54, F56, F60);
aoqi@0 3361 __ aes_eround01(as_FloatRegister(i+4), F58, F60, F54);
aoqi@0 3362 __ aes_eround23(as_FloatRegister(i+6), F58, F60, F56);
aoqi@0 3363 }
aoqi@0 3364 __ aes_eround01(F36, F54, F56, F58); //round 9
aoqi@0 3365 __ aes_eround23(F38, F54, F56, F60);
aoqi@0 3366
aoqi@0 3367 // 128-bit original key size
aoqi@0 3368 __ cmp_and_brx_short(keylen, 44, Assembler::equal, Assembler::pt, L_doLast128bit);
aoqi@0 3369
aoqi@0 3370 for ( int i = 40; i <= 50; i += 2 ) {
aoqi@0 3371 __ ldf(FloatRegisterImpl::D, key, i*4, as_FloatRegister(i) );
aoqi@0 3372 }
aoqi@0 3373 __ aes_eround01(F40, F58, F60, F54); //round 10
aoqi@0 3374 __ aes_eround23(F42, F58, F60, F56);
aoqi@0 3375 __ aes_eround01(F44, F54, F56, F58); //round 11
aoqi@0 3376 __ aes_eround23(F46, F54, F56, F60);
aoqi@0 3377
aoqi@0 3378 // 192-bit original key size
aoqi@0 3379 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pt, L_storeOutput);
aoqi@0 3380
aoqi@0 3381 __ ldf(FloatRegisterImpl::D, key, 208, F52);
aoqi@0 3382 __ aes_eround01(F48, F58, F60, F54); //round 12
aoqi@0 3383 __ aes_eround23(F50, F58, F60, F56);
aoqi@0 3384 __ ldf(FloatRegisterImpl::D, key, 216, F46);
aoqi@0 3385 __ ldf(FloatRegisterImpl::D, key, 224, F48);
aoqi@0 3386 __ ldf(FloatRegisterImpl::D, key, 232, F50);
aoqi@0 3387 __ aes_eround01(F52, F54, F56, F58); //round 13
aoqi@0 3388 __ aes_eround23(F46, F54, F56, F60);
aoqi@0 3389 __ ba_short(L_storeOutput);
aoqi@0 3390
aoqi@0 3391 __ BIND(L_doLast128bit);
aoqi@0 3392 __ ldf(FloatRegisterImpl::D, key, 160, F48);
aoqi@0 3393 __ ldf(FloatRegisterImpl::D, key, 168, F50);
aoqi@0 3394
aoqi@0 3395 __ BIND(L_storeOutput);
aoqi@0 3396 // perform last round of encryption common for all key sizes
aoqi@0 3397 __ aes_eround01_l(F48, F58, F60, F54); //last round
aoqi@0 3398 __ aes_eround23_l(F50, F58, F60, F56);
aoqi@0 3399
aoqi@0 3400 // Method to address arbitrary alignment for store instructions:
aoqi@0 3401 // Check last 3 bits of 'dest' address to see if it is aligned to 8-byte boundary
aoqi@0 3402 // If zero/aligned then continue with double FP store instructions
aoqi@0 3403 // If not zero/mis-aligned then edge8n will generate edge mask in result reg (O3 in below case)
aoqi@0 3404 // Example: If dest address is 0x07 and nearest 8-byte aligned address is 0x00 then edge mask will be 00000001
aoqi@0 3405 // Compute (8-n) where n is # of bytes skipped by partial store(stpartialf) inst from edge mask, n=7 in this case
aoqi@0 3406 // We get the value of n from the andcc that checks 'dest' alignment. n is available in O5 in below case.
aoqi@0 3407 // Set GSR.align to (8-n) using alignaddr
aoqi@0 3408 // Circular byte shift store values by n places so that the original bytes are at correct position for stpartialf
aoqi@0 3409 // Set the arbitrarily aligned 'dest' address to nearest 8-byte aligned address
aoqi@0 3410 // Store (partial) the original first (8-n) bytes starting at the original 'dest' address
aoqi@0 3411 // Negate the edge mask so that the subsequent stpartialf can store the original (8-n-1)th through 8th bytes at appropriate address
aoqi@0 3412 // We need to execute this process for both the 8-byte result values
aoqi@0 3413
aoqi@0 3414 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3415 __ andcc(to, 7, O5);
aoqi@0 3416 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output);
aoqi@0 3417 __ delayed()->edge8n(to, G0, O3);
aoqi@0 3418
aoqi@0 3419 // aligned case: store output into the destination array
aoqi@0 3420 __ stf(FloatRegisterImpl::D, F54, to, 0);
aoqi@0 3421 __ retl();
aoqi@0 3422 __ delayed()->stf(FloatRegisterImpl::D, F56, to, 8);
aoqi@0 3423
aoqi@0 3424 __ BIND(L_store_misaligned_output);
aoqi@0 3425 __ add(to, 8, O4);
aoqi@0 3426 __ mov(8, O2);
aoqi@0 3427 __ sub(O2, O5, O2);
aoqi@0 3428 __ alignaddr(O2, G0, O2);
aoqi@0 3429 __ faligndata(F54, F54, F54);
aoqi@0 3430 __ faligndata(F56, F56, F56);
aoqi@0 3431 __ and3(to, -8, to);
aoqi@0 3432 __ and3(O4, -8, O4);
aoqi@0 3433 __ stpartialf(to, O3, F54, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3434 __ stpartialf(O4, O3, F56, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3435 __ add(to, 8, to);
aoqi@0 3436 __ add(O4, 8, O4);
aoqi@0 3437 __ orn(G0, O3, O3);
aoqi@0 3438 __ stpartialf(to, O3, F54, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3439 __ retl();
aoqi@0 3440 __ delayed()->stpartialf(O4, O3, F56, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3441
aoqi@0 3442 return start;
aoqi@0 3443 }
aoqi@0 3444
aoqi@0 3445 address generate_aescrypt_decryptBlock() {
aoqi@0 3446 assert((arrayOopDesc::base_offset_in_bytes(T_INT) & 7) == 0,
aoqi@0 3447 "the following code assumes that first element of an int array is aligned to 8 bytes");
aoqi@0 3448 // required since we read original key 'byte' array as well in the decryption stubs
aoqi@0 3449 assert((arrayOopDesc::base_offset_in_bytes(T_BYTE) & 7) == 0,
aoqi@0 3450 "the following code assumes that first element of a byte array is aligned to 8 bytes");
aoqi@0 3451 __ align(CodeEntryAlignment);
aoqi@0 3452 StubCodeMark mark(this, "StubRoutines", "aescrypt_decryptBlock");
aoqi@0 3453 address start = __ pc();
aoqi@0 3454 Label L_load_misaligned_input, L_load_original_key, L_expand192bit, L_expand256bit, L_reload_misaligned_input;
aoqi@0 3455 Label L_256bit_transform, L_common_transform, L_store_misaligned_output;
aoqi@0 3456 Register from = O0; // source byte array
aoqi@0 3457 Register to = O1; // destination byte array
aoqi@0 3458 Register key = O2; // expanded key array
aoqi@0 3459 Register original_key = O3; // original key array only required during decryption
aoqi@0 3460 const Register keylen = O4; // reg for storing expanded key array length
aoqi@0 3461
aoqi@0 3462 // read expanded key array length
aoqi@0 3463 __ ldsw(Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)), keylen, 0);
aoqi@0 3464
aoqi@0 3465 // save 'from' since we may need to recheck alignment in case of 256-bit decryption
aoqi@0 3466 __ mov(from, G1);
aoqi@0 3467
aoqi@0 3468 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3469 __ andcc(from, 7, G0);
aoqi@0 3470 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input);
aoqi@0 3471 __ delayed()->alignaddr(from, G0, from);
aoqi@0 3472
aoqi@0 3473 // aligned case: load input into F52-F54
aoqi@0 3474 __ ldf(FloatRegisterImpl::D, from, 0, F52);
aoqi@0 3475 __ ldf(FloatRegisterImpl::D, from, 8, F54);
aoqi@0 3476 __ ba_short(L_load_original_key);
aoqi@0 3477
aoqi@0 3478 __ BIND(L_load_misaligned_input);
aoqi@0 3479 __ ldf(FloatRegisterImpl::D, from, 0, F52);
aoqi@0 3480 __ ldf(FloatRegisterImpl::D, from, 8, F54);
aoqi@0 3481 __ ldf(FloatRegisterImpl::D, from, 16, F56);
aoqi@0 3482 __ faligndata(F52, F54, F52);
aoqi@0 3483 __ faligndata(F54, F56, F54);
aoqi@0 3484
aoqi@0 3485 __ BIND(L_load_original_key);
aoqi@0 3486 // load original key from SunJCE expanded decryption key
aoqi@0 3487 // Since we load original key buffer starting first element, 8-byte alignment is guaranteed
aoqi@0 3488 for ( int i = 0; i <= 3; i++ ) {
aoqi@0 3489 __ ldf(FloatRegisterImpl::S, original_key, i*4, as_FloatRegister(i));
aoqi@0 3490 }
aoqi@0 3491
aoqi@0 3492 // 256-bit original key size
aoqi@0 3493 __ cmp_and_brx_short(keylen, 60, Assembler::equal, Assembler::pn, L_expand256bit);
aoqi@0 3494
aoqi@0 3495 // 192-bit original key size
aoqi@0 3496 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pn, L_expand192bit);
aoqi@0 3497
aoqi@0 3498 // 128-bit original key size
aoqi@0 3499 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 3500 for ( int i = 0; i <= 36; i += 4 ) {
aoqi@0 3501 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+2), i/4, as_FloatRegister(i+4));
aoqi@0 3502 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+4), as_FloatRegister(i+6));
aoqi@0 3503 }
aoqi@0 3504
aoqi@0 3505 // perform 128-bit key specific inverse cipher transformation
aoqi@0 3506 __ fxor(FloatRegisterImpl::D, F42, F54, F54);
aoqi@0 3507 __ fxor(FloatRegisterImpl::D, F40, F52, F52);
aoqi@0 3508 __ ba_short(L_common_transform);
aoqi@0 3509
aoqi@0 3510 __ BIND(L_expand192bit);
aoqi@0 3511
aoqi@0 3512 // start loading rest of the 192-bit key
aoqi@0 3513 __ ldf(FloatRegisterImpl::S, original_key, 16, F4);
aoqi@0 3514 __ ldf(FloatRegisterImpl::S, original_key, 20, F5);
aoqi@0 3515
aoqi@0 3516 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 3517 for ( int i = 0; i <= 36; i += 6 ) {
aoqi@0 3518 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+4), i/6, as_FloatRegister(i+6));
aoqi@0 3519 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+6), as_FloatRegister(i+8));
aoqi@0 3520 __ aes_kexpand2(as_FloatRegister(i+4), as_FloatRegister(i+8), as_FloatRegister(i+10));
aoqi@0 3521 }
aoqi@0 3522 __ aes_kexpand1(F42, F46, 7, F48);
aoqi@0 3523 __ aes_kexpand2(F44, F48, F50);
aoqi@0 3524
aoqi@0 3525 // perform 192-bit key specific inverse cipher transformation
aoqi@0 3526 __ fxor(FloatRegisterImpl::D, F50, F54, F54);
aoqi@0 3527 __ fxor(FloatRegisterImpl::D, F48, F52, F52);
aoqi@0 3528 __ aes_dround23(F46, F52, F54, F58);
aoqi@0 3529 __ aes_dround01(F44, F52, F54, F56);
aoqi@0 3530 __ aes_dround23(F42, F56, F58, F54);
aoqi@0 3531 __ aes_dround01(F40, F56, F58, F52);
aoqi@0 3532 __ ba_short(L_common_transform);
aoqi@0 3533
aoqi@0 3534 __ BIND(L_expand256bit);
aoqi@0 3535
aoqi@0 3536 // load rest of the 256-bit key
aoqi@0 3537 for ( int i = 4; i <= 7; i++ ) {
aoqi@0 3538 __ ldf(FloatRegisterImpl::S, original_key, i*4, as_FloatRegister(i));
aoqi@0 3539 }
aoqi@0 3540
aoqi@0 3541 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 3542 for ( int i = 0; i <= 40; i += 8 ) {
aoqi@0 3543 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+6), i/8, as_FloatRegister(i+8));
aoqi@0 3544 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+8), as_FloatRegister(i+10));
aoqi@0 3545 __ aes_kexpand0(as_FloatRegister(i+4), as_FloatRegister(i+10), as_FloatRegister(i+12));
aoqi@0 3546 __ aes_kexpand2(as_FloatRegister(i+6), as_FloatRegister(i+12), as_FloatRegister(i+14));
aoqi@0 3547 }
aoqi@0 3548 __ aes_kexpand1(F48, F54, 6, F56);
aoqi@0 3549 __ aes_kexpand2(F50, F56, F58);
aoqi@0 3550
aoqi@0 3551 for ( int i = 0; i <= 6; i += 2 ) {
aoqi@0 3552 __ fsrc2(FloatRegisterImpl::D, as_FloatRegister(58-i), as_FloatRegister(i));
aoqi@0 3553 }
aoqi@0 3554
aoqi@0 3555 // reload original 'from' address
aoqi@0 3556 __ mov(G1, from);
aoqi@0 3557
aoqi@0 3558 // re-check 8-byte alignment
aoqi@0 3559 __ andcc(from, 7, G0);
aoqi@0 3560 __ br(Assembler::notZero, true, Assembler::pn, L_reload_misaligned_input);
aoqi@0 3561 __ delayed()->alignaddr(from, G0, from);
aoqi@0 3562
aoqi@0 3563 // aligned case: load input into F52-F54
aoqi@0 3564 __ ldf(FloatRegisterImpl::D, from, 0, F52);
aoqi@0 3565 __ ldf(FloatRegisterImpl::D, from, 8, F54);
aoqi@0 3566 __ ba_short(L_256bit_transform);
aoqi@0 3567
aoqi@0 3568 __ BIND(L_reload_misaligned_input);
aoqi@0 3569 __ ldf(FloatRegisterImpl::D, from, 0, F52);
aoqi@0 3570 __ ldf(FloatRegisterImpl::D, from, 8, F54);
aoqi@0 3571 __ ldf(FloatRegisterImpl::D, from, 16, F56);
aoqi@0 3572 __ faligndata(F52, F54, F52);
aoqi@0 3573 __ faligndata(F54, F56, F54);
aoqi@0 3574
aoqi@0 3575 // perform 256-bit key specific inverse cipher transformation
aoqi@0 3576 __ BIND(L_256bit_transform);
aoqi@0 3577 __ fxor(FloatRegisterImpl::D, F0, F54, F54);
aoqi@0 3578 __ fxor(FloatRegisterImpl::D, F2, F52, F52);
aoqi@0 3579 __ aes_dround23(F4, F52, F54, F58);
aoqi@0 3580 __ aes_dround01(F6, F52, F54, F56);
aoqi@0 3581 __ aes_dround23(F50, F56, F58, F54);
aoqi@0 3582 __ aes_dround01(F48, F56, F58, F52);
aoqi@0 3583 __ aes_dround23(F46, F52, F54, F58);
aoqi@0 3584 __ aes_dround01(F44, F52, F54, F56);
aoqi@0 3585 __ aes_dround23(F42, F56, F58, F54);
aoqi@0 3586 __ aes_dround01(F40, F56, F58, F52);
aoqi@0 3587
aoqi@0 3588 for ( int i = 0; i <= 7; i++ ) {
aoqi@0 3589 __ ldf(FloatRegisterImpl::S, original_key, i*4, as_FloatRegister(i));
aoqi@0 3590 }
aoqi@0 3591
aoqi@0 3592 // perform inverse cipher transformations common for all key sizes
aoqi@0 3593 __ BIND(L_common_transform);
aoqi@0 3594 for ( int i = 38; i >= 6; i -= 8 ) {
aoqi@0 3595 __ aes_dround23(as_FloatRegister(i), F52, F54, F58);
aoqi@0 3596 __ aes_dround01(as_FloatRegister(i-2), F52, F54, F56);
aoqi@0 3597 if ( i != 6) {
aoqi@0 3598 __ aes_dround23(as_FloatRegister(i-4), F56, F58, F54);
aoqi@0 3599 __ aes_dround01(as_FloatRegister(i-6), F56, F58, F52);
aoqi@0 3600 } else {
aoqi@0 3601 __ aes_dround23_l(as_FloatRegister(i-4), F56, F58, F54);
aoqi@0 3602 __ aes_dround01_l(as_FloatRegister(i-6), F56, F58, F52);
aoqi@0 3603 }
aoqi@0 3604 }
aoqi@0 3605
aoqi@0 3606 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3607 __ andcc(to, 7, O5);
aoqi@0 3608 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output);
aoqi@0 3609 __ delayed()->edge8n(to, G0, O3);
aoqi@0 3610
aoqi@0 3611 // aligned case: store output into the destination array
aoqi@0 3612 __ stf(FloatRegisterImpl::D, F52, to, 0);
aoqi@0 3613 __ retl();
aoqi@0 3614 __ delayed()->stf(FloatRegisterImpl::D, F54, to, 8);
aoqi@0 3615
aoqi@0 3616 __ BIND(L_store_misaligned_output);
aoqi@0 3617 __ add(to, 8, O4);
aoqi@0 3618 __ mov(8, O2);
aoqi@0 3619 __ sub(O2, O5, O2);
aoqi@0 3620 __ alignaddr(O2, G0, O2);
aoqi@0 3621 __ faligndata(F52, F52, F52);
aoqi@0 3622 __ faligndata(F54, F54, F54);
aoqi@0 3623 __ and3(to, -8, to);
aoqi@0 3624 __ and3(O4, -8, O4);
aoqi@0 3625 __ stpartialf(to, O3, F52, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3626 __ stpartialf(O4, O3, F54, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3627 __ add(to, 8, to);
aoqi@0 3628 __ add(O4, 8, O4);
aoqi@0 3629 __ orn(G0, O3, O3);
aoqi@0 3630 __ stpartialf(to, O3, F52, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3631 __ retl();
aoqi@0 3632 __ delayed()->stpartialf(O4, O3, F54, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3633
aoqi@0 3634 return start;
aoqi@0 3635 }
aoqi@0 3636
aoqi@0 3637 address generate_cipherBlockChaining_encryptAESCrypt() {
aoqi@0 3638 assert((arrayOopDesc::base_offset_in_bytes(T_INT) & 7) == 0,
aoqi@0 3639 "the following code assumes that first element of an int array is aligned to 8 bytes");
aoqi@0 3640 assert((arrayOopDesc::base_offset_in_bytes(T_BYTE) & 7) == 0,
aoqi@0 3641 "the following code assumes that first element of a byte array is aligned to 8 bytes");
aoqi@0 3642 __ align(CodeEntryAlignment);
aoqi@0 3643 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt");
aoqi@0 3644 Label L_cbcenc128, L_load_misaligned_input_128bit, L_128bit_transform, L_store_misaligned_output_128bit;
aoqi@0 3645 Label L_check_loop_end_128bit, L_cbcenc192, L_load_misaligned_input_192bit, L_192bit_transform;
aoqi@0 3646 Label L_store_misaligned_output_192bit, L_check_loop_end_192bit, L_cbcenc256, L_load_misaligned_input_256bit;
aoqi@0 3647 Label L_256bit_transform, L_store_misaligned_output_256bit, L_check_loop_end_256bit;
aoqi@0 3648 address start = __ pc();
aoqi@0 3649 Register from = I0; // source byte array
aoqi@0 3650 Register to = I1; // destination byte array
aoqi@0 3651 Register key = I2; // expanded key array
aoqi@0 3652 Register rvec = I3; // init vector
aoqi@0 3653 const Register len_reg = I4; // cipher length
aoqi@0 3654 const Register keylen = I5; // reg for storing expanded key array length
aoqi@0 3655
aoqi@0 3656 __ save_frame(0);
aoqi@0 3657 // save cipher len to return in the end
aoqi@0 3658 __ mov(len_reg, L0);
aoqi@0 3659
aoqi@0 3660 // read expanded key length
aoqi@0 3661 __ ldsw(Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)), keylen, 0);
aoqi@0 3662
aoqi@0 3663 // load initial vector, 8-byte alignment is guranteed
aoqi@0 3664 __ ldf(FloatRegisterImpl::D, rvec, 0, F60);
aoqi@0 3665 __ ldf(FloatRegisterImpl::D, rvec, 8, F62);
aoqi@0 3666 // load key, 8-byte alignment is guranteed
aoqi@0 3667 __ ldx(key,0,G1);
aoqi@0 3668 __ ldx(key,8,G5);
aoqi@0 3669
aoqi@0 3670 // start loading expanded key, 8-byte alignment is guranteed
aoqi@0 3671 for ( int i = 0, j = 16; i <= 38; i += 2, j += 8 ) {
aoqi@0 3672 __ ldf(FloatRegisterImpl::D, key, j, as_FloatRegister(i));
aoqi@0 3673 }
aoqi@0 3674
aoqi@0 3675 // 128-bit original key size
aoqi@0 3676 __ cmp_and_brx_short(keylen, 44, Assembler::equal, Assembler::pt, L_cbcenc128);
aoqi@0 3677
aoqi@0 3678 for ( int i = 40, j = 176; i <= 46; i += 2, j += 8 ) {
aoqi@0 3679 __ ldf(FloatRegisterImpl::D, key, j, as_FloatRegister(i));
aoqi@0 3680 }
aoqi@0 3681
aoqi@0 3682 // 192-bit original key size
aoqi@0 3683 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pt, L_cbcenc192);
aoqi@0 3684
aoqi@0 3685 for ( int i = 48, j = 208; i <= 54; i += 2, j += 8 ) {
aoqi@0 3686 __ ldf(FloatRegisterImpl::D, key, j, as_FloatRegister(i));
aoqi@0 3687 }
aoqi@0 3688
aoqi@0 3689 // 256-bit original key size
aoqi@0 3690 __ ba_short(L_cbcenc256);
aoqi@0 3691
aoqi@0 3692 __ align(OptoLoopAlignment);
aoqi@0 3693 __ BIND(L_cbcenc128);
aoqi@0 3694 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3695 __ andcc(from, 7, G0);
aoqi@0 3696 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input_128bit);
aoqi@0 3697 __ delayed()->mov(from, L1); // save original 'from' address before alignaddr
aoqi@0 3698
aoqi@0 3699 // aligned case: load input into G3 and G4
aoqi@0 3700 __ ldx(from,0,G3);
aoqi@0 3701 __ ldx(from,8,G4);
aoqi@0 3702 __ ba_short(L_128bit_transform);
aoqi@0 3703
aoqi@0 3704 __ BIND(L_load_misaligned_input_128bit);
aoqi@0 3705 // can clobber F48, F50 and F52 as they are not used in 128 and 192-bit key encryption
aoqi@0 3706 __ alignaddr(from, G0, from);
aoqi@0 3707 __ ldf(FloatRegisterImpl::D, from, 0, F48);
aoqi@0 3708 __ ldf(FloatRegisterImpl::D, from, 8, F50);
aoqi@0 3709 __ ldf(FloatRegisterImpl::D, from, 16, F52);
aoqi@0 3710 __ faligndata(F48, F50, F48);
aoqi@0 3711 __ faligndata(F50, F52, F50);
aoqi@0 3712 __ movdtox(F48, G3);
aoqi@0 3713 __ movdtox(F50, G4);
aoqi@0 3714 __ mov(L1, from);
aoqi@0 3715
aoqi@0 3716 __ BIND(L_128bit_transform);
aoqi@0 3717 __ xor3(G1,G3,G3);
aoqi@0 3718 __ xor3(G5,G4,G4);
aoqi@0 3719 __ movxtod(G3,F56);
aoqi@0 3720 __ movxtod(G4,F58);
aoqi@0 3721 __ fxor(FloatRegisterImpl::D, F60, F56, F60);
aoqi@0 3722 __ fxor(FloatRegisterImpl::D, F62, F58, F62);
aoqi@0 3723
aoqi@0 3724 // TEN_EROUNDS
aoqi@0 3725 for ( int i = 0; i <= 32; i += 8 ) {
aoqi@0 3726 __ aes_eround01(as_FloatRegister(i), F60, F62, F56);
aoqi@0 3727 __ aes_eround23(as_FloatRegister(i+2), F60, F62, F58);
aoqi@0 3728 if (i != 32 ) {
aoqi@0 3729 __ aes_eround01(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3730 __ aes_eround23(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3731 } else {
aoqi@0 3732 __ aes_eround01_l(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3733 __ aes_eround23_l(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3734 }
aoqi@0 3735 }
aoqi@0 3736
aoqi@0 3737 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3738 __ andcc(to, 7, L1);
aoqi@0 3739 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_128bit);
aoqi@0 3740 __ delayed()->edge8n(to, G0, L2);
aoqi@0 3741
aoqi@0 3742 // aligned case: store output into the destination array
aoqi@0 3743 __ stf(FloatRegisterImpl::D, F60, to, 0);
aoqi@0 3744 __ stf(FloatRegisterImpl::D, F62, to, 8);
aoqi@0 3745 __ ba_short(L_check_loop_end_128bit);
aoqi@0 3746
aoqi@0 3747 __ BIND(L_store_misaligned_output_128bit);
aoqi@0 3748 __ add(to, 8, L3);
aoqi@0 3749 __ mov(8, L4);
aoqi@0 3750 __ sub(L4, L1, L4);
aoqi@0 3751 __ alignaddr(L4, G0, L4);
aoqi@0 3752 // save cipher text before circular right shift
aoqi@0 3753 // as it needs to be stored as iv for next block (see code before next retl)
aoqi@0 3754 __ movdtox(F60, L6);
aoqi@0 3755 __ movdtox(F62, L7);
aoqi@0 3756 __ faligndata(F60, F60, F60);
aoqi@0 3757 __ faligndata(F62, F62, F62);
aoqi@0 3758 __ mov(to, L5);
aoqi@0 3759 __ and3(to, -8, to);
aoqi@0 3760 __ and3(L3, -8, L3);
aoqi@0 3761 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3762 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3763 __ add(to, 8, to);
aoqi@0 3764 __ add(L3, 8, L3);
aoqi@0 3765 __ orn(G0, L2, L2);
aoqi@0 3766 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3767 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3768 __ mov(L5, to);
aoqi@0 3769 __ movxtod(L6, F60);
aoqi@0 3770 __ movxtod(L7, F62);
aoqi@0 3771
aoqi@0 3772 __ BIND(L_check_loop_end_128bit);
aoqi@0 3773 __ add(from, 16, from);
aoqi@0 3774 __ add(to, 16, to);
aoqi@0 3775 __ subcc(len_reg, 16, len_reg);
aoqi@0 3776 __ br(Assembler::notEqual, false, Assembler::pt, L_cbcenc128);
aoqi@0 3777 __ delayed()->nop();
aoqi@0 3778 // re-init intial vector for next block, 8-byte alignment is guaranteed
aoqi@0 3779 __ stf(FloatRegisterImpl::D, F60, rvec, 0);
aoqi@0 3780 __ stf(FloatRegisterImpl::D, F62, rvec, 8);
aoqi@0 3781 __ mov(L0, I0);
aoqi@0 3782 __ ret();
aoqi@0 3783 __ delayed()->restore();
aoqi@0 3784
aoqi@0 3785 __ align(OptoLoopAlignment);
aoqi@0 3786 __ BIND(L_cbcenc192);
aoqi@0 3787 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3788 __ andcc(from, 7, G0);
aoqi@0 3789 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input_192bit);
aoqi@0 3790 __ delayed()->mov(from, L1); // save original 'from' address before alignaddr
aoqi@0 3791
aoqi@0 3792 // aligned case: load input into G3 and G4
aoqi@0 3793 __ ldx(from,0,G3);
aoqi@0 3794 __ ldx(from,8,G4);
aoqi@0 3795 __ ba_short(L_192bit_transform);
aoqi@0 3796
aoqi@0 3797 __ BIND(L_load_misaligned_input_192bit);
aoqi@0 3798 // can clobber F48, F50 and F52 as they are not used in 128 and 192-bit key encryption
aoqi@0 3799 __ alignaddr(from, G0, from);
aoqi@0 3800 __ ldf(FloatRegisterImpl::D, from, 0, F48);
aoqi@0 3801 __ ldf(FloatRegisterImpl::D, from, 8, F50);
aoqi@0 3802 __ ldf(FloatRegisterImpl::D, from, 16, F52);
aoqi@0 3803 __ faligndata(F48, F50, F48);
aoqi@0 3804 __ faligndata(F50, F52, F50);
aoqi@0 3805 __ movdtox(F48, G3);
aoqi@0 3806 __ movdtox(F50, G4);
aoqi@0 3807 __ mov(L1, from);
aoqi@0 3808
aoqi@0 3809 __ BIND(L_192bit_transform);
aoqi@0 3810 __ xor3(G1,G3,G3);
aoqi@0 3811 __ xor3(G5,G4,G4);
aoqi@0 3812 __ movxtod(G3,F56);
aoqi@0 3813 __ movxtod(G4,F58);
aoqi@0 3814 __ fxor(FloatRegisterImpl::D, F60, F56, F60);
aoqi@0 3815 __ fxor(FloatRegisterImpl::D, F62, F58, F62);
aoqi@0 3816
aoqi@0 3817 // TWELEVE_EROUNDS
aoqi@0 3818 for ( int i = 0; i <= 40; i += 8 ) {
aoqi@0 3819 __ aes_eround01(as_FloatRegister(i), F60, F62, F56);
aoqi@0 3820 __ aes_eround23(as_FloatRegister(i+2), F60, F62, F58);
aoqi@0 3821 if (i != 40 ) {
aoqi@0 3822 __ aes_eround01(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3823 __ aes_eround23(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3824 } else {
aoqi@0 3825 __ aes_eround01_l(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3826 __ aes_eround23_l(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3827 }
aoqi@0 3828 }
aoqi@0 3829
aoqi@0 3830 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3831 __ andcc(to, 7, L1);
aoqi@0 3832 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_192bit);
aoqi@0 3833 __ delayed()->edge8n(to, G0, L2);
aoqi@0 3834
aoqi@0 3835 // aligned case: store output into the destination array
aoqi@0 3836 __ stf(FloatRegisterImpl::D, F60, to, 0);
aoqi@0 3837 __ stf(FloatRegisterImpl::D, F62, to, 8);
aoqi@0 3838 __ ba_short(L_check_loop_end_192bit);
aoqi@0 3839
aoqi@0 3840 __ BIND(L_store_misaligned_output_192bit);
aoqi@0 3841 __ add(to, 8, L3);
aoqi@0 3842 __ mov(8, L4);
aoqi@0 3843 __ sub(L4, L1, L4);
aoqi@0 3844 __ alignaddr(L4, G0, L4);
aoqi@0 3845 __ movdtox(F60, L6);
aoqi@0 3846 __ movdtox(F62, L7);
aoqi@0 3847 __ faligndata(F60, F60, F60);
aoqi@0 3848 __ faligndata(F62, F62, F62);
aoqi@0 3849 __ mov(to, L5);
aoqi@0 3850 __ and3(to, -8, to);
aoqi@0 3851 __ and3(L3, -8, L3);
aoqi@0 3852 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3853 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3854 __ add(to, 8, to);
aoqi@0 3855 __ add(L3, 8, L3);
aoqi@0 3856 __ orn(G0, L2, L2);
aoqi@0 3857 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3858 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3859 __ mov(L5, to);
aoqi@0 3860 __ movxtod(L6, F60);
aoqi@0 3861 __ movxtod(L7, F62);
aoqi@0 3862
aoqi@0 3863 __ BIND(L_check_loop_end_192bit);
aoqi@0 3864 __ add(from, 16, from);
aoqi@0 3865 __ subcc(len_reg, 16, len_reg);
aoqi@0 3866 __ add(to, 16, to);
aoqi@0 3867 __ br(Assembler::notEqual, false, Assembler::pt, L_cbcenc192);
aoqi@0 3868 __ delayed()->nop();
aoqi@0 3869 // re-init intial vector for next block, 8-byte alignment is guaranteed
aoqi@0 3870 __ stf(FloatRegisterImpl::D, F60, rvec, 0);
aoqi@0 3871 __ stf(FloatRegisterImpl::D, F62, rvec, 8);
aoqi@0 3872 __ mov(L0, I0);
aoqi@0 3873 __ ret();
aoqi@0 3874 __ delayed()->restore();
aoqi@0 3875
aoqi@0 3876 __ align(OptoLoopAlignment);
aoqi@0 3877 __ BIND(L_cbcenc256);
aoqi@0 3878 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3879 __ andcc(from, 7, G0);
aoqi@0 3880 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input_256bit);
aoqi@0 3881 __ delayed()->mov(from, L1); // save original 'from' address before alignaddr
aoqi@0 3882
aoqi@0 3883 // aligned case: load input into G3 and G4
aoqi@0 3884 __ ldx(from,0,G3);
aoqi@0 3885 __ ldx(from,8,G4);
aoqi@0 3886 __ ba_short(L_256bit_transform);
aoqi@0 3887
aoqi@0 3888 __ BIND(L_load_misaligned_input_256bit);
aoqi@0 3889 // cannot clobber F48, F50 and F52. F56, F58 can be used though
aoqi@0 3890 __ alignaddr(from, G0, from);
aoqi@0 3891 __ movdtox(F60, L2); // save F60 before overwriting
aoqi@0 3892 __ ldf(FloatRegisterImpl::D, from, 0, F56);
aoqi@0 3893 __ ldf(FloatRegisterImpl::D, from, 8, F58);
aoqi@0 3894 __ ldf(FloatRegisterImpl::D, from, 16, F60);
aoqi@0 3895 __ faligndata(F56, F58, F56);
aoqi@0 3896 __ faligndata(F58, F60, F58);
aoqi@0 3897 __ movdtox(F56, G3);
aoqi@0 3898 __ movdtox(F58, G4);
aoqi@0 3899 __ mov(L1, from);
aoqi@0 3900 __ movxtod(L2, F60);
aoqi@0 3901
aoqi@0 3902 __ BIND(L_256bit_transform);
aoqi@0 3903 __ xor3(G1,G3,G3);
aoqi@0 3904 __ xor3(G5,G4,G4);
aoqi@0 3905 __ movxtod(G3,F56);
aoqi@0 3906 __ movxtod(G4,F58);
aoqi@0 3907 __ fxor(FloatRegisterImpl::D, F60, F56, F60);
aoqi@0 3908 __ fxor(FloatRegisterImpl::D, F62, F58, F62);
aoqi@0 3909
aoqi@0 3910 // FOURTEEN_EROUNDS
aoqi@0 3911 for ( int i = 0; i <= 48; i += 8 ) {
aoqi@0 3912 __ aes_eround01(as_FloatRegister(i), F60, F62, F56);
aoqi@0 3913 __ aes_eround23(as_FloatRegister(i+2), F60, F62, F58);
aoqi@0 3914 if (i != 48 ) {
aoqi@0 3915 __ aes_eround01(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3916 __ aes_eround23(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3917 } else {
aoqi@0 3918 __ aes_eround01_l(as_FloatRegister(i+4), F56, F58, F60);
aoqi@0 3919 __ aes_eround23_l(as_FloatRegister(i+6), F56, F58, F62);
aoqi@0 3920 }
aoqi@0 3921 }
aoqi@0 3922
aoqi@0 3923 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 3924 __ andcc(to, 7, L1);
aoqi@0 3925 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_256bit);
aoqi@0 3926 __ delayed()->edge8n(to, G0, L2);
aoqi@0 3927
aoqi@0 3928 // aligned case: store output into the destination array
aoqi@0 3929 __ stf(FloatRegisterImpl::D, F60, to, 0);
aoqi@0 3930 __ stf(FloatRegisterImpl::D, F62, to, 8);
aoqi@0 3931 __ ba_short(L_check_loop_end_256bit);
aoqi@0 3932
aoqi@0 3933 __ BIND(L_store_misaligned_output_256bit);
aoqi@0 3934 __ add(to, 8, L3);
aoqi@0 3935 __ mov(8, L4);
aoqi@0 3936 __ sub(L4, L1, L4);
aoqi@0 3937 __ alignaddr(L4, G0, L4);
aoqi@0 3938 __ movdtox(F60, L6);
aoqi@0 3939 __ movdtox(F62, L7);
aoqi@0 3940 __ faligndata(F60, F60, F60);
aoqi@0 3941 __ faligndata(F62, F62, F62);
aoqi@0 3942 __ mov(to, L5);
aoqi@0 3943 __ and3(to, -8, to);
aoqi@0 3944 __ and3(L3, -8, L3);
aoqi@0 3945 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3946 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3947 __ add(to, 8, to);
aoqi@0 3948 __ add(L3, 8, L3);
aoqi@0 3949 __ orn(G0, L2, L2);
aoqi@0 3950 __ stpartialf(to, L2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3951 __ stpartialf(L3, L2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 3952 __ mov(L5, to);
aoqi@0 3953 __ movxtod(L6, F60);
aoqi@0 3954 __ movxtod(L7, F62);
aoqi@0 3955
aoqi@0 3956 __ BIND(L_check_loop_end_256bit);
aoqi@0 3957 __ add(from, 16, from);
aoqi@0 3958 __ subcc(len_reg, 16, len_reg);
aoqi@0 3959 __ add(to, 16, to);
aoqi@0 3960 __ br(Assembler::notEqual, false, Assembler::pt, L_cbcenc256);
aoqi@0 3961 __ delayed()->nop();
aoqi@0 3962 // re-init intial vector for next block, 8-byte alignment is guaranteed
aoqi@0 3963 __ stf(FloatRegisterImpl::D, F60, rvec, 0);
aoqi@0 3964 __ stf(FloatRegisterImpl::D, F62, rvec, 8);
aoqi@0 3965 __ mov(L0, I0);
aoqi@0 3966 __ ret();
aoqi@0 3967 __ delayed()->restore();
aoqi@0 3968
aoqi@0 3969 return start;
aoqi@0 3970 }
aoqi@0 3971
aoqi@0 3972 address generate_cipherBlockChaining_decryptAESCrypt_Parallel() {
aoqi@0 3973 assert((arrayOopDesc::base_offset_in_bytes(T_INT) & 7) == 0,
aoqi@0 3974 "the following code assumes that first element of an int array is aligned to 8 bytes");
aoqi@0 3975 assert((arrayOopDesc::base_offset_in_bytes(T_BYTE) & 7) == 0,
aoqi@0 3976 "the following code assumes that first element of a byte array is aligned to 8 bytes");
aoqi@0 3977 __ align(CodeEntryAlignment);
aoqi@0 3978 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt");
aoqi@0 3979 Label L_cbcdec_end, L_expand192bit, L_expand256bit, L_dec_first_block_start;
aoqi@0 3980 Label L_dec_first_block128, L_dec_first_block192, L_dec_next2_blocks128, L_dec_next2_blocks192, L_dec_next2_blocks256;
aoqi@0 3981 Label L_load_misaligned_input_first_block, L_transform_first_block, L_load_misaligned_next2_blocks128, L_transform_next2_blocks128;
aoqi@0 3982 Label L_load_misaligned_next2_blocks192, L_transform_next2_blocks192, L_load_misaligned_next2_blocks256, L_transform_next2_blocks256;
aoqi@0 3983 Label L_store_misaligned_output_first_block, L_check_decrypt_end, L_store_misaligned_output_next2_blocks128;
aoqi@0 3984 Label L_check_decrypt_loop_end128, L_store_misaligned_output_next2_blocks192, L_check_decrypt_loop_end192;
aoqi@0 3985 Label L_store_misaligned_output_next2_blocks256, L_check_decrypt_loop_end256;
aoqi@0 3986 address start = __ pc();
aoqi@0 3987 Register from = I0; // source byte array
aoqi@0 3988 Register to = I1; // destination byte array
aoqi@0 3989 Register key = I2; // expanded key array
aoqi@0 3990 Register rvec = I3; // init vector
aoqi@0 3991 const Register len_reg = I4; // cipher length
aoqi@0 3992 const Register original_key = I5; // original key array only required during decryption
aoqi@0 3993 const Register keylen = L6; // reg for storing expanded key array length
aoqi@0 3994
aoqi@0 3995 __ save_frame(0); //args are read from I* registers since we save the frame in the beginning
aoqi@0 3996 // save cipher len to return in the end
aoqi@0 3997 __ mov(len_reg, L7);
aoqi@0 3998
aoqi@0 3999 // load original key from SunJCE expanded decryption key
aoqi@0 4000 // Since we load original key buffer starting first element, 8-byte alignment is guaranteed
aoqi@0 4001 for ( int i = 0; i <= 3; i++ ) {
aoqi@0 4002 __ ldf(FloatRegisterImpl::S, original_key, i*4, as_FloatRegister(i));
aoqi@0 4003 }
aoqi@0 4004
aoqi@0 4005 // load initial vector, 8-byte alignment is guaranteed
aoqi@0 4006 __ ldx(rvec,0,L0);
aoqi@0 4007 __ ldx(rvec,8,L1);
aoqi@0 4008
aoqi@0 4009 // read expanded key array length
aoqi@0 4010 __ ldsw(Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)), keylen, 0);
aoqi@0 4011
aoqi@0 4012 // 256-bit original key size
aoqi@0 4013 __ cmp_and_brx_short(keylen, 60, Assembler::equal, Assembler::pn, L_expand256bit);
aoqi@0 4014
aoqi@0 4015 // 192-bit original key size
aoqi@0 4016 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pn, L_expand192bit);
aoqi@0 4017
aoqi@0 4018 // 128-bit original key size
aoqi@0 4019 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 4020 for ( int i = 0; i <= 36; i += 4 ) {
aoqi@0 4021 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+2), i/4, as_FloatRegister(i+4));
aoqi@0 4022 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+4), as_FloatRegister(i+6));
aoqi@0 4023 }
aoqi@0 4024
aoqi@0 4025 // load expanded key[last-1] and key[last] elements
aoqi@0 4026 __ movdtox(F40,L2);
aoqi@0 4027 __ movdtox(F42,L3);
aoqi@0 4028
aoqi@0 4029 __ and3(len_reg, 16, L4);
aoqi@0 4030 __ br_null_short(L4, Assembler::pt, L_dec_next2_blocks128);
aoqi@0 4031 __ nop();
aoqi@0 4032
aoqi@0 4033 __ ba_short(L_dec_first_block_start);
aoqi@0 4034
aoqi@0 4035 __ BIND(L_expand192bit);
aoqi@0 4036 // load rest of the 192-bit key
aoqi@0 4037 __ ldf(FloatRegisterImpl::S, original_key, 16, F4);
aoqi@0 4038 __ ldf(FloatRegisterImpl::S, original_key, 20, F5);
aoqi@0 4039
aoqi@0 4040 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 4041 for ( int i = 0; i <= 36; i += 6 ) {
aoqi@0 4042 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+4), i/6, as_FloatRegister(i+6));
aoqi@0 4043 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+6), as_FloatRegister(i+8));
aoqi@0 4044 __ aes_kexpand2(as_FloatRegister(i+4), as_FloatRegister(i+8), as_FloatRegister(i+10));
aoqi@0 4045 }
aoqi@0 4046 __ aes_kexpand1(F42, F46, 7, F48);
aoqi@0 4047 __ aes_kexpand2(F44, F48, F50);
aoqi@0 4048
aoqi@0 4049 // load expanded key[last-1] and key[last] elements
aoqi@0 4050 __ movdtox(F48,L2);
aoqi@0 4051 __ movdtox(F50,L3);
aoqi@0 4052
aoqi@0 4053 __ and3(len_reg, 16, L4);
aoqi@0 4054 __ br_null_short(L4, Assembler::pt, L_dec_next2_blocks192);
aoqi@0 4055 __ nop();
aoqi@0 4056
aoqi@0 4057 __ ba_short(L_dec_first_block_start);
aoqi@0 4058
aoqi@0 4059 __ BIND(L_expand256bit);
aoqi@0 4060 // load rest of the 256-bit key
aoqi@0 4061 for ( int i = 4; i <= 7; i++ ) {
aoqi@0 4062 __ ldf(FloatRegisterImpl::S, original_key, i*4, as_FloatRegister(i));
aoqi@0 4063 }
aoqi@0 4064
aoqi@0 4065 // perform key expansion since SunJCE decryption-key expansion is not compatible with SPARC crypto instructions
aoqi@0 4066 for ( int i = 0; i <= 40; i += 8 ) {
aoqi@0 4067 __ aes_kexpand1(as_FloatRegister(i), as_FloatRegister(i+6), i/8, as_FloatRegister(i+8));
aoqi@0 4068 __ aes_kexpand2(as_FloatRegister(i+2), as_FloatRegister(i+8), as_FloatRegister(i+10));
aoqi@0 4069 __ aes_kexpand0(as_FloatRegister(i+4), as_FloatRegister(i+10), as_FloatRegister(i+12));
aoqi@0 4070 __ aes_kexpand2(as_FloatRegister(i+6), as_FloatRegister(i+12), as_FloatRegister(i+14));
aoqi@0 4071 }
aoqi@0 4072 __ aes_kexpand1(F48, F54, 6, F56);
aoqi@0 4073 __ aes_kexpand2(F50, F56, F58);
aoqi@0 4074
aoqi@0 4075 // load expanded key[last-1] and key[last] elements
aoqi@0 4076 __ movdtox(F56,L2);
aoqi@0 4077 __ movdtox(F58,L3);
aoqi@0 4078
aoqi@0 4079 __ and3(len_reg, 16, L4);
aoqi@0 4080 __ br_null_short(L4, Assembler::pt, L_dec_next2_blocks256);
aoqi@0 4081
aoqi@0 4082 __ BIND(L_dec_first_block_start);
aoqi@0 4083 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4084 __ andcc(from, 7, G0);
aoqi@0 4085 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_input_first_block);
aoqi@0 4086 __ delayed()->mov(from, G1); // save original 'from' address before alignaddr
aoqi@0 4087
aoqi@0 4088 // aligned case: load input into L4 and L5
aoqi@0 4089 __ ldx(from,0,L4);
aoqi@0 4090 __ ldx(from,8,L5);
aoqi@0 4091 __ ba_short(L_transform_first_block);
aoqi@0 4092
aoqi@0 4093 __ BIND(L_load_misaligned_input_first_block);
aoqi@0 4094 __ alignaddr(from, G0, from);
aoqi@0 4095 // F58, F60, F62 can be clobbered
aoqi@0 4096 __ ldf(FloatRegisterImpl::D, from, 0, F58);
aoqi@0 4097 __ ldf(FloatRegisterImpl::D, from, 8, F60);
aoqi@0 4098 __ ldf(FloatRegisterImpl::D, from, 16, F62);
aoqi@0 4099 __ faligndata(F58, F60, F58);
aoqi@0 4100 __ faligndata(F60, F62, F60);
aoqi@0 4101 __ movdtox(F58, L4);
aoqi@0 4102 __ movdtox(F60, L5);
aoqi@0 4103 __ mov(G1, from);
aoqi@0 4104
aoqi@0 4105 __ BIND(L_transform_first_block);
aoqi@0 4106 __ xor3(L2,L4,G1);
aoqi@0 4107 __ movxtod(G1,F60);
aoqi@0 4108 __ xor3(L3,L5,G1);
aoqi@0 4109 __ movxtod(G1,F62);
aoqi@0 4110
aoqi@0 4111 // 128-bit original key size
aoqi@0 4112 __ cmp_and_brx_short(keylen, 44, Assembler::equal, Assembler::pn, L_dec_first_block128);
aoqi@0 4113
aoqi@0 4114 // 192-bit original key size
aoqi@0 4115 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pn, L_dec_first_block192);
aoqi@0 4116
aoqi@0 4117 __ aes_dround23(F54, F60, F62, F58);
aoqi@0 4118 __ aes_dround01(F52, F60, F62, F56);
aoqi@0 4119 __ aes_dround23(F50, F56, F58, F62);
aoqi@0 4120 __ aes_dround01(F48, F56, F58, F60);
aoqi@0 4121
aoqi@0 4122 __ BIND(L_dec_first_block192);
aoqi@0 4123 __ aes_dround23(F46, F60, F62, F58);
aoqi@0 4124 __ aes_dround01(F44, F60, F62, F56);
aoqi@0 4125 __ aes_dround23(F42, F56, F58, F62);
aoqi@0 4126 __ aes_dround01(F40, F56, F58, F60);
aoqi@0 4127
aoqi@0 4128 __ BIND(L_dec_first_block128);
aoqi@0 4129 for ( int i = 38; i >= 6; i -= 8 ) {
aoqi@0 4130 __ aes_dround23(as_FloatRegister(i), F60, F62, F58);
aoqi@0 4131 __ aes_dround01(as_FloatRegister(i-2), F60, F62, F56);
aoqi@0 4132 if ( i != 6) {
aoqi@0 4133 __ aes_dround23(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4134 __ aes_dround01(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4135 } else {
aoqi@0 4136 __ aes_dround23_l(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4137 __ aes_dround01_l(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4138 }
aoqi@0 4139 }
aoqi@0 4140
aoqi@0 4141 __ movxtod(L0,F56);
aoqi@0 4142 __ movxtod(L1,F58);
aoqi@0 4143 __ mov(L4,L0);
aoqi@0 4144 __ mov(L5,L1);
aoqi@0 4145 __ fxor(FloatRegisterImpl::D, F56, F60, F60);
aoqi@0 4146 __ fxor(FloatRegisterImpl::D, F58, F62, F62);
aoqi@0 4147
aoqi@0 4148 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4149 __ andcc(to, 7, G1);
aoqi@0 4150 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_first_block);
aoqi@0 4151 __ delayed()->edge8n(to, G0, G2);
aoqi@0 4152
aoqi@0 4153 // aligned case: store output into the destination array
aoqi@0 4154 __ stf(FloatRegisterImpl::D, F60, to, 0);
aoqi@0 4155 __ stf(FloatRegisterImpl::D, F62, to, 8);
aoqi@0 4156 __ ba_short(L_check_decrypt_end);
aoqi@0 4157
aoqi@0 4158 __ BIND(L_store_misaligned_output_first_block);
aoqi@0 4159 __ add(to, 8, G3);
aoqi@0 4160 __ mov(8, G4);
aoqi@0 4161 __ sub(G4, G1, G4);
aoqi@0 4162 __ alignaddr(G4, G0, G4);
aoqi@0 4163 __ faligndata(F60, F60, F60);
aoqi@0 4164 __ faligndata(F62, F62, F62);
aoqi@0 4165 __ mov(to, G1);
aoqi@0 4166 __ and3(to, -8, to);
aoqi@0 4167 __ and3(G3, -8, G3);
aoqi@0 4168 __ stpartialf(to, G2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4169 __ stpartialf(G3, G2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4170 __ add(to, 8, to);
aoqi@0 4171 __ add(G3, 8, G3);
aoqi@0 4172 __ orn(G0, G2, G2);
aoqi@0 4173 __ stpartialf(to, G2, F60, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4174 __ stpartialf(G3, G2, F62, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4175 __ mov(G1, to);
aoqi@0 4176
aoqi@0 4177 __ BIND(L_check_decrypt_end);
aoqi@0 4178 __ add(from, 16, from);
aoqi@0 4179 __ add(to, 16, to);
aoqi@0 4180 __ subcc(len_reg, 16, len_reg);
aoqi@0 4181 __ br(Assembler::equal, false, Assembler::pt, L_cbcdec_end);
aoqi@0 4182 __ delayed()->nop();
aoqi@0 4183
aoqi@0 4184 // 256-bit original key size
aoqi@0 4185 __ cmp_and_brx_short(keylen, 60, Assembler::equal, Assembler::pn, L_dec_next2_blocks256);
aoqi@0 4186
aoqi@0 4187 // 192-bit original key size
aoqi@0 4188 __ cmp_and_brx_short(keylen, 52, Assembler::equal, Assembler::pn, L_dec_next2_blocks192);
aoqi@0 4189
aoqi@0 4190 __ align(OptoLoopAlignment);
aoqi@0 4191 __ BIND(L_dec_next2_blocks128);
aoqi@0 4192 __ nop();
aoqi@0 4193
aoqi@0 4194 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4195 __ andcc(from, 7, G0);
aoqi@0 4196 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_next2_blocks128);
aoqi@0 4197 __ delayed()->mov(from, G1); // save original 'from' address before alignaddr
aoqi@0 4198
aoqi@0 4199 // aligned case: load input into G4, G5, L4 and L5
aoqi@0 4200 __ ldx(from,0,G4);
aoqi@0 4201 __ ldx(from,8,G5);
aoqi@0 4202 __ ldx(from,16,L4);
aoqi@0 4203 __ ldx(from,24,L5);
aoqi@0 4204 __ ba_short(L_transform_next2_blocks128);
aoqi@0 4205
aoqi@0 4206 __ BIND(L_load_misaligned_next2_blocks128);
aoqi@0 4207 __ alignaddr(from, G0, from);
aoqi@0 4208 // F40, F42, F58, F60, F62 can be clobbered
aoqi@0 4209 __ ldf(FloatRegisterImpl::D, from, 0, F40);
aoqi@0 4210 __ ldf(FloatRegisterImpl::D, from, 8, F42);
aoqi@0 4211 __ ldf(FloatRegisterImpl::D, from, 16, F60);
aoqi@0 4212 __ ldf(FloatRegisterImpl::D, from, 24, F62);
aoqi@0 4213 __ ldf(FloatRegisterImpl::D, from, 32, F58);
aoqi@0 4214 __ faligndata(F40, F42, F40);
aoqi@0 4215 __ faligndata(F42, F60, F42);
aoqi@0 4216 __ faligndata(F60, F62, F60);
aoqi@0 4217 __ faligndata(F62, F58, F62);
aoqi@0 4218 __ movdtox(F40, G4);
aoqi@0 4219 __ movdtox(F42, G5);
aoqi@0 4220 __ movdtox(F60, L4);
aoqi@0 4221 __ movdtox(F62, L5);
aoqi@0 4222 __ mov(G1, from);
aoqi@0 4223
aoqi@0 4224 __ BIND(L_transform_next2_blocks128);
aoqi@0 4225 // F40:F42 used for first 16-bytes
aoqi@0 4226 __ xor3(L2,G4,G1);
aoqi@0 4227 __ movxtod(G1,F40);
aoqi@0 4228 __ xor3(L3,G5,G1);
aoqi@0 4229 __ movxtod(G1,F42);
aoqi@0 4230
aoqi@0 4231 // F60:F62 used for next 16-bytes
aoqi@0 4232 __ xor3(L2,L4,G1);
aoqi@0 4233 __ movxtod(G1,F60);
aoqi@0 4234 __ xor3(L3,L5,G1);
aoqi@0 4235 __ movxtod(G1,F62);
aoqi@0 4236
aoqi@0 4237 for ( int i = 38; i >= 6; i -= 8 ) {
aoqi@0 4238 __ aes_dround23(as_FloatRegister(i), F40, F42, F44);
aoqi@0 4239 __ aes_dround01(as_FloatRegister(i-2), F40, F42, F46);
aoqi@0 4240 __ aes_dround23(as_FloatRegister(i), F60, F62, F58);
aoqi@0 4241 __ aes_dround01(as_FloatRegister(i-2), F60, F62, F56);
aoqi@0 4242 if (i != 6 ) {
aoqi@0 4243 __ aes_dround23(as_FloatRegister(i-4), F46, F44, F42);
aoqi@0 4244 __ aes_dround01(as_FloatRegister(i-6), F46, F44, F40);
aoqi@0 4245 __ aes_dround23(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4246 __ aes_dround01(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4247 } else {
aoqi@0 4248 __ aes_dround23_l(as_FloatRegister(i-4), F46, F44, F42);
aoqi@0 4249 __ aes_dround01_l(as_FloatRegister(i-6), F46, F44, F40);
aoqi@0 4250 __ aes_dround23_l(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4251 __ aes_dround01_l(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4252 }
aoqi@0 4253 }
aoqi@0 4254
aoqi@0 4255 __ movxtod(L0,F46);
aoqi@0 4256 __ movxtod(L1,F44);
aoqi@0 4257 __ fxor(FloatRegisterImpl::D, F46, F40, F40);
aoqi@0 4258 __ fxor(FloatRegisterImpl::D, F44, F42, F42);
aoqi@0 4259
aoqi@0 4260 __ movxtod(G4,F56);
aoqi@0 4261 __ movxtod(G5,F58);
aoqi@0 4262 __ mov(L4,L0);
aoqi@0 4263 __ mov(L5,L1);
aoqi@0 4264 __ fxor(FloatRegisterImpl::D, F56, F60, F60);
aoqi@0 4265 __ fxor(FloatRegisterImpl::D, F58, F62, F62);
aoqi@0 4266
aoqi@0 4267 // For mis-aligned store of 32 bytes of result we can do:
aoqi@0 4268 // Circular right-shift all 4 FP registers so that 'head' and 'tail'
aoqi@0 4269 // parts that need to be stored starting at mis-aligned address are in a FP reg
aoqi@0 4270 // the other 3 FP regs can thus be stored using regular store
aoqi@0 4271 // we then use the edge + partial-store mechanism to store the 'head' and 'tail' parts
aoqi@0 4272
aoqi@0 4273 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4274 __ andcc(to, 7, G1);
aoqi@0 4275 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_next2_blocks128);
aoqi@0 4276 __ delayed()->edge8n(to, G0, G2);
aoqi@0 4277
aoqi@0 4278 // aligned case: store output into the destination array
aoqi@0 4279 __ stf(FloatRegisterImpl::D, F40, to, 0);
aoqi@0 4280 __ stf(FloatRegisterImpl::D, F42, to, 8);
aoqi@0 4281 __ stf(FloatRegisterImpl::D, F60, to, 16);
aoqi@0 4282 __ stf(FloatRegisterImpl::D, F62, to, 24);
aoqi@0 4283 __ ba_short(L_check_decrypt_loop_end128);
aoqi@0 4284
aoqi@0 4285 __ BIND(L_store_misaligned_output_next2_blocks128);
aoqi@0 4286 __ mov(8, G4);
aoqi@0 4287 __ sub(G4, G1, G4);
aoqi@0 4288 __ alignaddr(G4, G0, G4);
aoqi@0 4289 __ faligndata(F40, F42, F56); // F56 can be clobbered
aoqi@0 4290 __ faligndata(F42, F60, F42);
aoqi@0 4291 __ faligndata(F60, F62, F60);
aoqi@0 4292 __ faligndata(F62, F40, F40);
aoqi@0 4293 __ mov(to, G1);
aoqi@0 4294 __ and3(to, -8, to);
aoqi@0 4295 __ stpartialf(to, G2, F40, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4296 __ stf(FloatRegisterImpl::D, F56, to, 8);
aoqi@0 4297 __ stf(FloatRegisterImpl::D, F42, to, 16);
aoqi@0 4298 __ stf(FloatRegisterImpl::D, F60, to, 24);
aoqi@0 4299 __ add(to, 32, to);
aoqi@0 4300 __ orn(G0, G2, G2);
aoqi@0 4301 __ stpartialf(to, G2, F40, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4302 __ mov(G1, to);
aoqi@0 4303
aoqi@0 4304 __ BIND(L_check_decrypt_loop_end128);
aoqi@0 4305 __ add(from, 32, from);
aoqi@0 4306 __ add(to, 32, to);
aoqi@0 4307 __ subcc(len_reg, 32, len_reg);
aoqi@0 4308 __ br(Assembler::notEqual, false, Assembler::pt, L_dec_next2_blocks128);
aoqi@0 4309 __ delayed()->nop();
aoqi@0 4310 __ ba_short(L_cbcdec_end);
aoqi@0 4311
aoqi@0 4312 __ align(OptoLoopAlignment);
aoqi@0 4313 __ BIND(L_dec_next2_blocks192);
aoqi@0 4314 __ nop();
aoqi@0 4315
aoqi@0 4316 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4317 __ andcc(from, 7, G0);
aoqi@0 4318 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_next2_blocks192);
aoqi@0 4319 __ delayed()->mov(from, G1); // save original 'from' address before alignaddr
aoqi@0 4320
aoqi@0 4321 // aligned case: load input into G4, G5, L4 and L5
aoqi@0 4322 __ ldx(from,0,G4);
aoqi@0 4323 __ ldx(from,8,G5);
aoqi@0 4324 __ ldx(from,16,L4);
aoqi@0 4325 __ ldx(from,24,L5);
aoqi@0 4326 __ ba_short(L_transform_next2_blocks192);
aoqi@0 4327
aoqi@0 4328 __ BIND(L_load_misaligned_next2_blocks192);
aoqi@0 4329 __ alignaddr(from, G0, from);
aoqi@0 4330 // F48, F50, F52, F60, F62 can be clobbered
aoqi@0 4331 __ ldf(FloatRegisterImpl::D, from, 0, F48);
aoqi@0 4332 __ ldf(FloatRegisterImpl::D, from, 8, F50);
aoqi@0 4333 __ ldf(FloatRegisterImpl::D, from, 16, F60);
aoqi@0 4334 __ ldf(FloatRegisterImpl::D, from, 24, F62);
aoqi@0 4335 __ ldf(FloatRegisterImpl::D, from, 32, F52);
aoqi@0 4336 __ faligndata(F48, F50, F48);
aoqi@0 4337 __ faligndata(F50, F60, F50);
aoqi@0 4338 __ faligndata(F60, F62, F60);
aoqi@0 4339 __ faligndata(F62, F52, F62);
aoqi@0 4340 __ movdtox(F48, G4);
aoqi@0 4341 __ movdtox(F50, G5);
aoqi@0 4342 __ movdtox(F60, L4);
aoqi@0 4343 __ movdtox(F62, L5);
aoqi@0 4344 __ mov(G1, from);
aoqi@0 4345
aoqi@0 4346 __ BIND(L_transform_next2_blocks192);
aoqi@0 4347 // F48:F50 used for first 16-bytes
aoqi@0 4348 __ xor3(L2,G4,G1);
aoqi@0 4349 __ movxtod(G1,F48);
aoqi@0 4350 __ xor3(L3,G5,G1);
aoqi@0 4351 __ movxtod(G1,F50);
aoqi@0 4352
aoqi@0 4353 // F60:F62 used for next 16-bytes
aoqi@0 4354 __ xor3(L2,L4,G1);
aoqi@0 4355 __ movxtod(G1,F60);
aoqi@0 4356 __ xor3(L3,L5,G1);
aoqi@0 4357 __ movxtod(G1,F62);
aoqi@0 4358
aoqi@0 4359 for ( int i = 46; i >= 6; i -= 8 ) {
aoqi@0 4360 __ aes_dround23(as_FloatRegister(i), F48, F50, F52);
aoqi@0 4361 __ aes_dround01(as_FloatRegister(i-2), F48, F50, F54);
aoqi@0 4362 __ aes_dround23(as_FloatRegister(i), F60, F62, F58);
aoqi@0 4363 __ aes_dround01(as_FloatRegister(i-2), F60, F62, F56);
aoqi@0 4364 if (i != 6 ) {
aoqi@0 4365 __ aes_dround23(as_FloatRegister(i-4), F54, F52, F50);
aoqi@0 4366 __ aes_dround01(as_FloatRegister(i-6), F54, F52, F48);
aoqi@0 4367 __ aes_dround23(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4368 __ aes_dround01(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4369 } else {
aoqi@0 4370 __ aes_dround23_l(as_FloatRegister(i-4), F54, F52, F50);
aoqi@0 4371 __ aes_dround01_l(as_FloatRegister(i-6), F54, F52, F48);
aoqi@0 4372 __ aes_dround23_l(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4373 __ aes_dround01_l(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4374 }
aoqi@0 4375 }
aoqi@0 4376
aoqi@0 4377 __ movxtod(L0,F54);
aoqi@0 4378 __ movxtod(L1,F52);
aoqi@0 4379 __ fxor(FloatRegisterImpl::D, F54, F48, F48);
aoqi@0 4380 __ fxor(FloatRegisterImpl::D, F52, F50, F50);
aoqi@0 4381
aoqi@0 4382 __ movxtod(G4,F56);
aoqi@0 4383 __ movxtod(G5,F58);
aoqi@0 4384 __ mov(L4,L0);
aoqi@0 4385 __ mov(L5,L1);
aoqi@0 4386 __ fxor(FloatRegisterImpl::D, F56, F60, F60);
aoqi@0 4387 __ fxor(FloatRegisterImpl::D, F58, F62, F62);
aoqi@0 4388
aoqi@0 4389 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4390 __ andcc(to, 7, G1);
aoqi@0 4391 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_next2_blocks192);
aoqi@0 4392 __ delayed()->edge8n(to, G0, G2);
aoqi@0 4393
aoqi@0 4394 // aligned case: store output into the destination array
aoqi@0 4395 __ stf(FloatRegisterImpl::D, F48, to, 0);
aoqi@0 4396 __ stf(FloatRegisterImpl::D, F50, to, 8);
aoqi@0 4397 __ stf(FloatRegisterImpl::D, F60, to, 16);
aoqi@0 4398 __ stf(FloatRegisterImpl::D, F62, to, 24);
aoqi@0 4399 __ ba_short(L_check_decrypt_loop_end192);
aoqi@0 4400
aoqi@0 4401 __ BIND(L_store_misaligned_output_next2_blocks192);
aoqi@0 4402 __ mov(8, G4);
aoqi@0 4403 __ sub(G4, G1, G4);
aoqi@0 4404 __ alignaddr(G4, G0, G4);
aoqi@0 4405 __ faligndata(F48, F50, F56); // F56 can be clobbered
aoqi@0 4406 __ faligndata(F50, F60, F50);
aoqi@0 4407 __ faligndata(F60, F62, F60);
aoqi@0 4408 __ faligndata(F62, F48, F48);
aoqi@0 4409 __ mov(to, G1);
aoqi@0 4410 __ and3(to, -8, to);
aoqi@0 4411 __ stpartialf(to, G2, F48, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4412 __ stf(FloatRegisterImpl::D, F56, to, 8);
aoqi@0 4413 __ stf(FloatRegisterImpl::D, F50, to, 16);
aoqi@0 4414 __ stf(FloatRegisterImpl::D, F60, to, 24);
aoqi@0 4415 __ add(to, 32, to);
aoqi@0 4416 __ orn(G0, G2, G2);
aoqi@0 4417 __ stpartialf(to, G2, F48, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4418 __ mov(G1, to);
aoqi@0 4419
aoqi@0 4420 __ BIND(L_check_decrypt_loop_end192);
aoqi@0 4421 __ add(from, 32, from);
aoqi@0 4422 __ add(to, 32, to);
aoqi@0 4423 __ subcc(len_reg, 32, len_reg);
aoqi@0 4424 __ br(Assembler::notEqual, false, Assembler::pt, L_dec_next2_blocks192);
aoqi@0 4425 __ delayed()->nop();
aoqi@0 4426 __ ba_short(L_cbcdec_end);
aoqi@0 4427
aoqi@0 4428 __ align(OptoLoopAlignment);
aoqi@0 4429 __ BIND(L_dec_next2_blocks256);
aoqi@0 4430 __ nop();
aoqi@0 4431
aoqi@0 4432 // check for 8-byte alignment since source byte array may have an arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4433 __ andcc(from, 7, G0);
aoqi@0 4434 __ br(Assembler::notZero, true, Assembler::pn, L_load_misaligned_next2_blocks256);
aoqi@0 4435 __ delayed()->mov(from, G1); // save original 'from' address before alignaddr
aoqi@0 4436
aoqi@0 4437 // aligned case: load input into G4, G5, L4 and L5
aoqi@0 4438 __ ldx(from,0,G4);
aoqi@0 4439 __ ldx(from,8,G5);
aoqi@0 4440 __ ldx(from,16,L4);
aoqi@0 4441 __ ldx(from,24,L5);
aoqi@0 4442 __ ba_short(L_transform_next2_blocks256);
aoqi@0 4443
aoqi@0 4444 __ BIND(L_load_misaligned_next2_blocks256);
aoqi@0 4445 __ alignaddr(from, G0, from);
aoqi@0 4446 // F0, F2, F4, F60, F62 can be clobbered
aoqi@0 4447 __ ldf(FloatRegisterImpl::D, from, 0, F0);
aoqi@0 4448 __ ldf(FloatRegisterImpl::D, from, 8, F2);
aoqi@0 4449 __ ldf(FloatRegisterImpl::D, from, 16, F60);
aoqi@0 4450 __ ldf(FloatRegisterImpl::D, from, 24, F62);
aoqi@0 4451 __ ldf(FloatRegisterImpl::D, from, 32, F4);
aoqi@0 4452 __ faligndata(F0, F2, F0);
aoqi@0 4453 __ faligndata(F2, F60, F2);
aoqi@0 4454 __ faligndata(F60, F62, F60);
aoqi@0 4455 __ faligndata(F62, F4, F62);
aoqi@0 4456 __ movdtox(F0, G4);
aoqi@0 4457 __ movdtox(F2, G5);
aoqi@0 4458 __ movdtox(F60, L4);
aoqi@0 4459 __ movdtox(F62, L5);
aoqi@0 4460 __ mov(G1, from);
aoqi@0 4461
aoqi@0 4462 __ BIND(L_transform_next2_blocks256);
aoqi@0 4463 // F0:F2 used for first 16-bytes
aoqi@0 4464 __ xor3(L2,G4,G1);
aoqi@0 4465 __ movxtod(G1,F0);
aoqi@0 4466 __ xor3(L3,G5,G1);
aoqi@0 4467 __ movxtod(G1,F2);
aoqi@0 4468
aoqi@0 4469 // F60:F62 used for next 16-bytes
aoqi@0 4470 __ xor3(L2,L4,G1);
aoqi@0 4471 __ movxtod(G1,F60);
aoqi@0 4472 __ xor3(L3,L5,G1);
aoqi@0 4473 __ movxtod(G1,F62);
aoqi@0 4474
aoqi@0 4475 __ aes_dround23(F54, F0, F2, F4);
aoqi@0 4476 __ aes_dround01(F52, F0, F2, F6);
aoqi@0 4477 __ aes_dround23(F54, F60, F62, F58);
aoqi@0 4478 __ aes_dround01(F52, F60, F62, F56);
aoqi@0 4479 __ aes_dround23(F50, F6, F4, F2);
aoqi@0 4480 __ aes_dround01(F48, F6, F4, F0);
aoqi@0 4481 __ aes_dround23(F50, F56, F58, F62);
aoqi@0 4482 __ aes_dround01(F48, F56, F58, F60);
aoqi@0 4483 // save F48:F54 in temp registers
aoqi@0 4484 __ movdtox(F54,G2);
aoqi@0 4485 __ movdtox(F52,G3);
aoqi@0 4486 __ movdtox(F50,G6);
aoqi@0 4487 __ movdtox(F48,G1);
aoqi@0 4488 for ( int i = 46; i >= 14; i -= 8 ) {
aoqi@0 4489 __ aes_dround23(as_FloatRegister(i), F0, F2, F4);
aoqi@0 4490 __ aes_dround01(as_FloatRegister(i-2), F0, F2, F6);
aoqi@0 4491 __ aes_dround23(as_FloatRegister(i), F60, F62, F58);
aoqi@0 4492 __ aes_dround01(as_FloatRegister(i-2), F60, F62, F56);
aoqi@0 4493 __ aes_dround23(as_FloatRegister(i-4), F6, F4, F2);
aoqi@0 4494 __ aes_dround01(as_FloatRegister(i-6), F6, F4, F0);
aoqi@0 4495 __ aes_dround23(as_FloatRegister(i-4), F56, F58, F62);
aoqi@0 4496 __ aes_dround01(as_FloatRegister(i-6), F56, F58, F60);
aoqi@0 4497 }
aoqi@0 4498 // init F48:F54 with F0:F6 values (original key)
aoqi@0 4499 __ ldf(FloatRegisterImpl::D, original_key, 0, F48);
aoqi@0 4500 __ ldf(FloatRegisterImpl::D, original_key, 8, F50);
aoqi@0 4501 __ ldf(FloatRegisterImpl::D, original_key, 16, F52);
aoqi@0 4502 __ ldf(FloatRegisterImpl::D, original_key, 24, F54);
aoqi@0 4503 __ aes_dround23(F54, F0, F2, F4);
aoqi@0 4504 __ aes_dround01(F52, F0, F2, F6);
aoqi@0 4505 __ aes_dround23(F54, F60, F62, F58);
aoqi@0 4506 __ aes_dround01(F52, F60, F62, F56);
aoqi@0 4507 __ aes_dround23_l(F50, F6, F4, F2);
aoqi@0 4508 __ aes_dround01_l(F48, F6, F4, F0);
aoqi@0 4509 __ aes_dround23_l(F50, F56, F58, F62);
aoqi@0 4510 __ aes_dround01_l(F48, F56, F58, F60);
aoqi@0 4511 // re-init F48:F54 with their original values
aoqi@0 4512 __ movxtod(G2,F54);
aoqi@0 4513 __ movxtod(G3,F52);
aoqi@0 4514 __ movxtod(G6,F50);
aoqi@0 4515 __ movxtod(G1,F48);
aoqi@0 4516
aoqi@0 4517 __ movxtod(L0,F6);
aoqi@0 4518 __ movxtod(L1,F4);
aoqi@0 4519 __ fxor(FloatRegisterImpl::D, F6, F0, F0);
aoqi@0 4520 __ fxor(FloatRegisterImpl::D, F4, F2, F2);
aoqi@0 4521
aoqi@0 4522 __ movxtod(G4,F56);
aoqi@0 4523 __ movxtod(G5,F58);
aoqi@0 4524 __ mov(L4,L0);
aoqi@0 4525 __ mov(L5,L1);
aoqi@0 4526 __ fxor(FloatRegisterImpl::D, F56, F60, F60);
aoqi@0 4527 __ fxor(FloatRegisterImpl::D, F58, F62, F62);
aoqi@0 4528
aoqi@0 4529 // check for 8-byte alignment since dest byte array may have arbitrary alignment if offset mod 8 is non-zero
aoqi@0 4530 __ andcc(to, 7, G1);
aoqi@0 4531 __ br(Assembler::notZero, true, Assembler::pn, L_store_misaligned_output_next2_blocks256);
aoqi@0 4532 __ delayed()->edge8n(to, G0, G2);
aoqi@0 4533
aoqi@0 4534 // aligned case: store output into the destination array
aoqi@0 4535 __ stf(FloatRegisterImpl::D, F0, to, 0);
aoqi@0 4536 __ stf(FloatRegisterImpl::D, F2, to, 8);
aoqi@0 4537 __ stf(FloatRegisterImpl::D, F60, to, 16);
aoqi@0 4538 __ stf(FloatRegisterImpl::D, F62, to, 24);
aoqi@0 4539 __ ba_short(L_check_decrypt_loop_end256);
aoqi@0 4540
aoqi@0 4541 __ BIND(L_store_misaligned_output_next2_blocks256);
aoqi@0 4542 __ mov(8, G4);
aoqi@0 4543 __ sub(G4, G1, G4);
aoqi@0 4544 __ alignaddr(G4, G0, G4);
aoqi@0 4545 __ faligndata(F0, F2, F56); // F56 can be clobbered
aoqi@0 4546 __ faligndata(F2, F60, F2);
aoqi@0 4547 __ faligndata(F60, F62, F60);
aoqi@0 4548 __ faligndata(F62, F0, F0);
aoqi@0 4549 __ mov(to, G1);
aoqi@0 4550 __ and3(to, -8, to);
aoqi@0 4551 __ stpartialf(to, G2, F0, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4552 __ stf(FloatRegisterImpl::D, F56, to, 8);
aoqi@0 4553 __ stf(FloatRegisterImpl::D, F2, to, 16);
aoqi@0 4554 __ stf(FloatRegisterImpl::D, F60, to, 24);
aoqi@0 4555 __ add(to, 32, to);
aoqi@0 4556 __ orn(G0, G2, G2);
aoqi@0 4557 __ stpartialf(to, G2, F0, Assembler::ASI_PST8_PRIMARY);
aoqi@0 4558 __ mov(G1, to);
aoqi@0 4559
aoqi@0 4560 __ BIND(L_check_decrypt_loop_end256);
aoqi@0 4561 __ add(from, 32, from);
aoqi@0 4562 __ add(to, 32, to);
aoqi@0 4563 __ subcc(len_reg, 32, len_reg);
aoqi@0 4564 __ br(Assembler::notEqual, false, Assembler::pt, L_dec_next2_blocks256);
aoqi@0 4565 __ delayed()->nop();
aoqi@0 4566
aoqi@0 4567 __ BIND(L_cbcdec_end);
aoqi@0 4568 // re-init intial vector for next block, 8-byte alignment is guaranteed
aoqi@0 4569 __ stx(L0, rvec, 0);
aoqi@0 4570 __ stx(L1, rvec, 8);
aoqi@0 4571 __ mov(L7, I0);
aoqi@0 4572 __ ret();
aoqi@0 4573 __ delayed()->restore();
aoqi@0 4574
aoqi@0 4575 return start;
aoqi@0 4576 }
aoqi@0 4577
aoqi@0 4578 void generate_initial() {
aoqi@0 4579 // Generates all stubs and initializes the entry points
aoqi@0 4580
aoqi@0 4581 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 4582 // entry points that exist in all platforms
aoqi@0 4583 // Note: This is code that could be shared among different platforms - however the benefit seems to be smaller than
aoqi@0 4584 // the disadvantage of having a much more complicated generator structure. See also comment in stubRoutines.hpp.
aoqi@0 4585 StubRoutines::_forward_exception_entry = generate_forward_exception();
aoqi@0 4586
aoqi@0 4587 StubRoutines::_call_stub_entry = generate_call_stub(StubRoutines::_call_stub_return_address);
aoqi@0 4588 StubRoutines::_catch_exception_entry = generate_catch_exception();
aoqi@0 4589
aoqi@0 4590 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 4591 // entry points that are platform specific
aoqi@0 4592 StubRoutines::Sparc::_test_stop_entry = generate_test_stop();
aoqi@0 4593
aoqi@0 4594 StubRoutines::Sparc::_stop_subroutine_entry = generate_stop_subroutine();
aoqi@0 4595 StubRoutines::Sparc::_flush_callers_register_windows_entry = generate_flush_callers_register_windows();
aoqi@0 4596
aoqi@0 4597 #if !defined(COMPILER2) && !defined(_LP64)
aoqi@0 4598 StubRoutines::_atomic_xchg_entry = generate_atomic_xchg();
aoqi@0 4599 StubRoutines::_atomic_cmpxchg_entry = generate_atomic_cmpxchg();
aoqi@0 4600 StubRoutines::_atomic_add_entry = generate_atomic_add();
aoqi@0 4601 StubRoutines::_atomic_xchg_ptr_entry = StubRoutines::_atomic_xchg_entry;
aoqi@0 4602 StubRoutines::_atomic_cmpxchg_ptr_entry = StubRoutines::_atomic_cmpxchg_entry;
aoqi@0 4603 StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long();
aoqi@0 4604 StubRoutines::_atomic_add_ptr_entry = StubRoutines::_atomic_add_entry;
aoqi@0 4605 #endif // COMPILER2 !=> _LP64
aoqi@0 4606
aoqi@0 4607 // Build this early so it's available for the interpreter.
aoqi@0 4608 StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
aoqi@0 4609 }
aoqi@0 4610
aoqi@0 4611
aoqi@0 4612 void generate_all() {
aoqi@0 4613 // Generates all stubs and initializes the entry points
aoqi@0 4614
aoqi@0 4615 // Generate partial_subtype_check first here since its code depends on
aoqi@0 4616 // UseZeroBaseCompressedOops which is defined after heap initialization.
aoqi@0 4617 StubRoutines::Sparc::_partial_subtype_check = generate_partial_subtype_check();
aoqi@0 4618 // These entry points require SharedInfo::stack0 to be set up in non-core builds
aoqi@0 4619 StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError));
aoqi@0 4620 StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError));
aoqi@0 4621 StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call));
aoqi@0 4622
aoqi@0 4623 StubRoutines::_handler_for_unsafe_access_entry =
aoqi@0 4624 generate_handler_for_unsafe_access();
aoqi@0 4625
aoqi@0 4626 // support for verify_oop (must happen after universe_init)
aoqi@0 4627 StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop_subroutine();
aoqi@0 4628
aoqi@0 4629 // arraycopy stubs used by compilers
aoqi@0 4630 generate_arraycopy_stubs();
aoqi@0 4631
aoqi@0 4632 // Don't initialize the platform math functions since sparc
aoqi@0 4633 // doesn't have intrinsics for these operations.
aoqi@0 4634
aoqi@0 4635 // Safefetch stubs.
aoqi@0 4636 generate_safefetch("SafeFetch32", sizeof(int), &StubRoutines::_safefetch32_entry,
aoqi@0 4637 &StubRoutines::_safefetch32_fault_pc,
aoqi@0 4638 &StubRoutines::_safefetch32_continuation_pc);
aoqi@0 4639 generate_safefetch("SafeFetchN", sizeof(intptr_t), &StubRoutines::_safefetchN_entry,
aoqi@0 4640 &StubRoutines::_safefetchN_fault_pc,
aoqi@0 4641 &StubRoutines::_safefetchN_continuation_pc);
aoqi@0 4642
aoqi@0 4643 // generate AES intrinsics code
aoqi@0 4644 if (UseAESIntrinsics) {
aoqi@0 4645 StubRoutines::_aescrypt_encryptBlock = generate_aescrypt_encryptBlock();
aoqi@0 4646 StubRoutines::_aescrypt_decryptBlock = generate_aescrypt_decryptBlock();
aoqi@0 4647 StubRoutines::_cipherBlockChaining_encryptAESCrypt = generate_cipherBlockChaining_encryptAESCrypt();
aoqi@0 4648 StubRoutines::_cipherBlockChaining_decryptAESCrypt = generate_cipherBlockChaining_decryptAESCrypt_Parallel();
aoqi@0 4649 }
aoqi@0 4650 }
aoqi@0 4651
aoqi@0 4652
aoqi@0 4653 public:
aoqi@0 4654 StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
aoqi@0 4655 // replace the standard masm with a special one:
aoqi@0 4656 _masm = new MacroAssembler(code);
aoqi@0 4657
aoqi@0 4658 _stub_count = !all ? 0x100 : 0x200;
aoqi@0 4659 if (all) {
aoqi@0 4660 generate_all();
aoqi@0 4661 } else {
aoqi@0 4662 generate_initial();
aoqi@0 4663 }
aoqi@0 4664
aoqi@0 4665 // make sure this stub is available for all local calls
aoqi@0 4666 if (_atomic_add_stub.is_unbound()) {
aoqi@0 4667 // generate a second time, if necessary
aoqi@0 4668 (void) generate_atomic_add();
aoqi@0 4669 }
aoqi@0 4670 }
aoqi@0 4671
aoqi@0 4672
aoqi@0 4673 private:
aoqi@0 4674 int _stub_count;
aoqi@0 4675 void stub_prolog(StubCodeDesc* cdesc) {
aoqi@0 4676 # ifdef ASSERT
aoqi@0 4677 // put extra information in the stub code, to make it more readable
aoqi@0 4678 #ifdef _LP64
aoqi@0 4679 // Write the high part of the address
aoqi@0 4680 // [RGV] Check if there is a dependency on the size of this prolog
aoqi@0 4681 __ emit_data((intptr_t)cdesc >> 32, relocInfo::none);
aoqi@0 4682 #endif
aoqi@0 4683 __ emit_data((intptr_t)cdesc, relocInfo::none);
aoqi@0 4684 __ emit_data(++_stub_count, relocInfo::none);
aoqi@0 4685 # endif
aoqi@0 4686 align(true);
aoqi@0 4687 }
aoqi@0 4688
aoqi@0 4689 void align(bool at_header = false) {
aoqi@0 4690 // %%%%% move this constant somewhere else
aoqi@0 4691 // UltraSPARC cache line size is 8 instructions:
aoqi@0 4692 const unsigned int icache_line_size = 32;
aoqi@0 4693 const unsigned int icache_half_line_size = 16;
aoqi@0 4694
aoqi@0 4695 if (at_header) {
aoqi@0 4696 while ((intptr_t)(__ pc()) % icache_line_size != 0) {
aoqi@0 4697 __ emit_data(0, relocInfo::none);
aoqi@0 4698 }
aoqi@0 4699 } else {
aoqi@0 4700 while ((intptr_t)(__ pc()) % icache_half_line_size != 0) {
aoqi@0 4701 __ nop();
aoqi@0 4702 }
aoqi@0 4703 }
aoqi@0 4704 }
aoqi@0 4705
aoqi@0 4706 }; // end class declaration
aoqi@0 4707
aoqi@0 4708 void StubGenerator_generate(CodeBuffer* code, bool all) {
aoqi@0 4709 StubGenerator g(code, all);
aoqi@0 4710 }

mercurial