1 /* 2 * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/assembler.hpp" 27 #include "asm/macroAssembler.hpp" 28 #include "classfile/vmIntrinsics.hpp" 29 #include "compiler/oopMap.hpp" 30 #include "gc/shared/barrierSet.hpp" 31 #include "gc/shared/barrierSetAssembler.hpp" 32 #include "gc/shared/barrierSetNMethod.hpp" 33 #include "gc/shared/gc_globals.hpp" 34 #include "memory/universe.hpp" 35 #include "prims/jvmtiExport.hpp" 36 #include "runtime/arguments.hpp" 37 #include "runtime/javaThread.hpp" 38 #include "runtime/sharedRuntime.hpp" 39 #include "runtime/stubRoutines.hpp" 40 #include "utilities/macros.hpp" 41 #include "vmreg_x86.inline.hpp" 42 #include "stubGenerator_x86_64.hpp" 43 #ifdef COMPILER2 44 #include "opto/runtime.hpp" 45 #include "opto/c2_globals.hpp" 46 #endif 47 #if INCLUDE_JVMCI 48 #include "jvmci/jvmci_globals.hpp" 49 #endif 50 #if INCLUDE_ZGC 51 #include "gc/z/zThreadLocalData.hpp" 52 #endif 53 #if INCLUDE_JFR 54 #include "jfr/support/jfrIntrinsics.hpp" 55 #endif 56 57 // For a more detailed description of the stub routine structure 58 // see the comment in stubRoutines.hpp 59 60 #define __ _masm-> 61 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8) 62 63 #ifdef PRODUCT 64 #define BLOCK_COMMENT(str) /* nothing */ 65 #else 66 #define BLOCK_COMMENT(str) __ block_comment(str) 67 #endif // PRODUCT 68 69 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 70 71 // 72 // Linux Arguments: 73 // c_rarg0: call wrapper address address 74 // c_rarg1: result address 75 // c_rarg2: result type BasicType 76 // c_rarg3: method Method* 77 // c_rarg4: (interpreter) entry point address 78 // c_rarg5: parameters intptr_t* 79 // 16(rbp): parameter size (in words) int 80 // 24(rbp): thread Thread* 81 // 82 // [ return_from_Java ] <--- rsp 83 // [ argument word n ] 84 // ... 85 // -12 [ argument word 1 ] 86 // -11 [ saved r15 ] <--- rsp_after_call 87 // -10 [ saved r14 ] 88 // -9 [ saved r13 ] 89 // -8 [ saved r12 ] 90 // -7 [ saved rbx ] 91 // -6 [ call wrapper ] 92 // -5 [ result ] 93 // -4 [ result type ] 94 // -3 [ method ] 95 // -2 [ entry point ] 96 // -1 [ parameters ] 97 // 0 [ saved rbp ] <--- rbp 98 // 1 [ return address ] 99 // 2 [ parameter size ] 100 // 3 [ thread ] 101 // 102 // Windows Arguments: 103 // c_rarg0: call wrapper address address 104 // c_rarg1: result address 105 // c_rarg2: result type BasicType 106 // c_rarg3: method Method* 107 // 48(rbp): (interpreter) entry point address 108 // 56(rbp): parameters intptr_t* 109 // 64(rbp): parameter size (in words) int 110 // 72(rbp): thread Thread* 111 // 112 // [ return_from_Java ] <--- rsp 113 // [ argument word n ] 114 // ... 115 // -60 [ argument word 1 ] 116 // -59 [ saved xmm31 ] <--- rsp after_call 117 // [ saved xmm16-xmm30 ] (EVEX enabled, else the space is blank) 118 // -27 [ saved xmm15 ] 119 // [ saved xmm7-xmm14 ] 120 // -9 [ saved xmm6 ] (each xmm register takes 2 slots) 121 // -7 [ saved r15 ] 122 // -6 [ saved r14 ] 123 // -5 [ saved r13 ] 124 // -4 [ saved r12 ] 125 // -3 [ saved rdi ] 126 // -2 [ saved rsi ] 127 // -1 [ saved rbx ] 128 // 0 [ saved rbp ] <--- rbp 129 // 1 [ return address ] 130 // 2 [ call wrapper ] 131 // 3 [ result ] 132 // 4 [ result type ] 133 // 5 [ method ] 134 // 6 [ entry point ] 135 // 7 [ parameters ] 136 // 8 [ parameter size ] 137 // 9 [ thread ] 138 // 139 // Windows reserves the callers stack space for arguments 1-4. 140 // We spill c_rarg0-c_rarg3 to this space. 141 142 // Call stub stack layout word offsets from rbp 143 #ifdef _WIN64 144 enum call_stub_layout { 145 xmm_save_first = 6, // save from xmm6 146 xmm_save_last = 31, // to xmm31 147 xmm_save_base = -9, 148 rsp_after_call_off = xmm_save_base - 2 * (xmm_save_last - xmm_save_first), // -27 149 r15_off = -7, 150 r14_off = -6, 151 r13_off = -5, 152 r12_off = -4, 153 rdi_off = -3, 154 rsi_off = -2, 155 rbx_off = -1, 156 rbp_off = 0, 157 retaddr_off = 1, 158 call_wrapper_off = 2, 159 result_off = 3, 160 result_type_off = 4, 161 method_off = 5, 162 entry_point_off = 6, 163 parameters_off = 7, 164 parameter_size_off = 8, 165 thread_off = 9 166 }; 167 168 static Address xmm_save(int reg) { 169 assert(reg >= xmm_save_first && reg <= xmm_save_last, "XMM register number out of range"); 170 return Address(rbp, (xmm_save_base - (reg - xmm_save_first) * 2) * wordSize); 171 } 172 #else // !_WIN64 173 enum call_stub_layout { 174 rsp_after_call_off = -12, 175 mxcsr_off = rsp_after_call_off, 176 r15_off = -11, 177 r14_off = -10, 178 r13_off = -9, 179 r12_off = -8, 180 rbx_off = -7, 181 call_wrapper_off = -6, 182 result_off = -5, 183 result_type_off = -4, 184 method_off = -3, 185 entry_point_off = -2, 186 parameters_off = -1, 187 rbp_off = 0, 188 retaddr_off = 1, 189 parameter_size_off = 2, 190 thread_off = 3 191 }; 192 #endif // _WIN64 193 194 address StubGenerator::generate_call_stub(address& return_address) { 195 196 assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 && 197 (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off, 198 "adjust this code"); 199 StubCodeMark mark(this, "StubRoutines", "call_stub"); 200 address start = __ pc(); 201 202 // same as in generate_catch_exception()! 203 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); 204 205 const Address call_wrapper (rbp, call_wrapper_off * wordSize); 206 const Address result (rbp, result_off * wordSize); 207 const Address result_type (rbp, result_type_off * wordSize); 208 const Address method (rbp, method_off * wordSize); 209 const Address entry_point (rbp, entry_point_off * wordSize); 210 const Address parameters (rbp, parameters_off * wordSize); 211 const Address parameter_size(rbp, parameter_size_off * wordSize); 212 213 // same as in generate_catch_exception()! 214 const Address thread (rbp, thread_off * wordSize); 215 216 const Address r15_save(rbp, r15_off * wordSize); 217 const Address r14_save(rbp, r14_off * wordSize); 218 const Address r13_save(rbp, r13_off * wordSize); 219 const Address r12_save(rbp, r12_off * wordSize); 220 const Address rbx_save(rbp, rbx_off * wordSize); 221 222 // stub code 223 __ enter(); 224 __ subptr(rsp, -rsp_after_call_off * wordSize); 225 226 // save register parameters 227 #ifndef _WIN64 228 __ movptr(parameters, c_rarg5); // parameters 229 __ movptr(entry_point, c_rarg4); // entry_point 230 #endif 231 232 __ movptr(method, c_rarg3); // method 233 __ movl(result_type, c_rarg2); // result type 234 __ movptr(result, c_rarg1); // result 235 __ movptr(call_wrapper, c_rarg0); // call wrapper 236 237 // save regs belonging to calling function 238 __ movptr(rbx_save, rbx); 239 __ movptr(r12_save, r12); 240 __ movptr(r13_save, r13); 241 __ movptr(r14_save, r14); 242 __ movptr(r15_save, r15); 243 244 #ifdef _WIN64 245 int last_reg = 15; 246 if (UseAVX > 2) { 247 last_reg = 31; 248 } 249 if (VM_Version::supports_evex()) { 250 for (int i = xmm_save_first; i <= last_reg; i++) { 251 __ vextractf32x4(xmm_save(i), as_XMMRegister(i), 0); 252 } 253 } else { 254 for (int i = xmm_save_first; i <= last_reg; i++) { 255 __ movdqu(xmm_save(i), as_XMMRegister(i)); 256 } 257 } 258 259 const Address rdi_save(rbp, rdi_off * wordSize); 260 const Address rsi_save(rbp, rsi_off * wordSize); 261 262 __ movptr(rsi_save, rsi); 263 __ movptr(rdi_save, rdi); 264 #else 265 const Address mxcsr_save(rbp, mxcsr_off * wordSize); 266 { 267 Label skip_ldmx; 268 __ stmxcsr(mxcsr_save); 269 __ movl(rax, mxcsr_save); 270 __ andl(rax, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) 271 ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); 272 __ cmp32(rax, mxcsr_std, rscratch1); 273 __ jcc(Assembler::equal, skip_ldmx); 274 __ ldmxcsr(mxcsr_std, rscratch1); 275 __ bind(skip_ldmx); 276 } 277 #endif 278 279 // Load up thread register 280 __ movptr(r15_thread, thread); 281 __ reinit_heapbase(); 282 283 #ifdef ASSERT 284 // make sure we have no pending exceptions 285 { 286 Label L; 287 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD); 288 __ jcc(Assembler::equal, L); 289 __ stop("StubRoutines::call_stub: entered with pending exception"); 290 __ bind(L); 291 } 292 #endif 293 294 // pass parameters if any 295 BLOCK_COMMENT("pass parameters if any"); 296 Label parameters_done; 297 __ movl(c_rarg3, parameter_size); 298 __ testl(c_rarg3, c_rarg3); 299 __ jcc(Assembler::zero, parameters_done); 300 301 Label loop; 302 __ movptr(c_rarg2, parameters); // parameter pointer 303 __ movl(c_rarg1, c_rarg3); // parameter counter is in c_rarg1 304 __ BIND(loop); 305 __ movptr(rax, Address(c_rarg2, 0));// get parameter 306 __ addptr(c_rarg2, wordSize); // advance to next parameter 307 __ decrementl(c_rarg1); // decrement counter 308 __ push(rax); // pass parameter 309 __ jcc(Assembler::notZero, loop); 310 311 // call Java function 312 __ BIND(parameters_done); 313 __ movptr(rbx, method); // get Method* 314 __ movptr(c_rarg1, entry_point); // get entry_point 315 __ mov(r13, rsp); // set sender sp 316 BLOCK_COMMENT("call Java function"); 317 __ call(c_rarg1); 318 319 BLOCK_COMMENT("call_stub_return_address:"); 320 return_address = __ pc(); 321 322 // store result depending on type (everything that is not 323 // T_OBJECT, T_PRIMITIVE_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) 324 __ movptr(r13, result); 325 Label is_long, is_float, is_double, check_prim, exit; 326 __ movl(rbx, result_type); 327 __ cmpl(rbx, T_OBJECT); 328 __ jcc(Assembler::equal, check_prim); 329 __ cmpl(rbx, T_PRIMITIVE_OBJECT); 330 __ jcc(Assembler::equal, check_prim); 331 __ cmpl(rbx, T_LONG); 332 __ jcc(Assembler::equal, is_long); 333 __ cmpl(rbx, T_FLOAT); 334 __ jcc(Assembler::equal, is_float); 335 __ cmpl(rbx, T_DOUBLE); 336 __ jcc(Assembler::equal, is_double); 337 338 // handle T_INT case 339 __ movl(Address(r13, 0), rax); 340 341 __ BIND(exit); 342 343 // pop parameters 344 __ lea(rsp, rsp_after_call); 345 346 #ifdef ASSERT 347 // verify that threads correspond 348 { 349 Label L1, L2, L3; 350 __ cmpptr(r15_thread, thread); 351 __ jcc(Assembler::equal, L1); 352 __ stop("StubRoutines::call_stub: r15_thread is corrupted"); 353 __ bind(L1); 354 __ get_thread(rbx); 355 __ cmpptr(r15_thread, thread); 356 __ jcc(Assembler::equal, L2); 357 __ stop("StubRoutines::call_stub: r15_thread is modified by call"); 358 __ bind(L2); 359 __ cmpptr(r15_thread, rbx); 360 __ jcc(Assembler::equal, L3); 361 __ stop("StubRoutines::call_stub: threads must correspond"); 362 __ bind(L3); 363 } 364 #endif 365 366 __ pop_cont_fastpath(); 367 368 // restore regs belonging to calling function 369 #ifdef _WIN64 370 // emit the restores for xmm regs 371 if (VM_Version::supports_evex()) { 372 for (int i = xmm_save_first; i <= last_reg; i++) { 373 __ vinsertf32x4(as_XMMRegister(i), as_XMMRegister(i), xmm_save(i), 0); 374 } 375 } else { 376 for (int i = xmm_save_first; i <= last_reg; i++) { 377 __ movdqu(as_XMMRegister(i), xmm_save(i)); 378 } 379 } 380 #endif 381 __ movptr(r15, r15_save); 382 __ movptr(r14, r14_save); 383 __ movptr(r13, r13_save); 384 __ movptr(r12, r12_save); 385 __ movptr(rbx, rbx_save); 386 387 #ifdef _WIN64 388 __ movptr(rdi, rdi_save); 389 __ movptr(rsi, rsi_save); 390 #else 391 __ ldmxcsr(mxcsr_save); 392 #endif 393 394 // restore rsp 395 __ addptr(rsp, -rsp_after_call_off * wordSize); 396 397 // return 398 __ vzeroupper(); 399 __ pop(rbp); 400 __ ret(0); 401 402 // handle return types different from T_INT 403 __ BIND(check_prim); 404 if (InlineTypeReturnedAsFields) { 405 // Check for scalarized return value 406 __ testptr(rax, 1); 407 __ jcc(Assembler::zero, is_long); 408 // Load pack handler address 409 __ andptr(rax, -2); 410 __ movptr(rax, Address(rax, InstanceKlass::adr_inlineklass_fixed_block_offset())); 411 __ movptr(rbx, Address(rax, InlineKlass::pack_handler_jobject_offset())); 412 // Call pack handler to initialize the buffer 413 __ call(rbx); 414 __ jmp(exit); 415 } 416 __ BIND(is_long); 417 __ movq(Address(r13, 0), rax); 418 __ jmp(exit); 419 420 __ BIND(is_float); 421 __ movflt(Address(r13, 0), xmm0); 422 __ jmp(exit); 423 424 __ BIND(is_double); 425 __ movdbl(Address(r13, 0), xmm0); 426 __ jmp(exit); 427 428 return start; 429 } 430 431 // Return point for a Java call if there's an exception thrown in 432 // Java code. The exception is caught and transformed into a 433 // pending exception stored in JavaThread that can be tested from 434 // within the VM. 435 // 436 // Note: Usually the parameters are removed by the callee. In case 437 // of an exception crossing an activation frame boundary, that is 438 // not the case if the callee is compiled code => need to setup the 439 // rsp. 440 // 441 // rax: exception oop 442 443 address StubGenerator::generate_catch_exception() { 444 StubCodeMark mark(this, "StubRoutines", "catch_exception"); 445 address start = __ pc(); 446 447 // same as in generate_call_stub(): 448 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); 449 const Address thread (rbp, thread_off * wordSize); 450 451 #ifdef ASSERT 452 // verify that threads correspond 453 { 454 Label L1, L2, L3; 455 __ cmpptr(r15_thread, thread); 456 __ jcc(Assembler::equal, L1); 457 __ stop("StubRoutines::catch_exception: r15_thread is corrupted"); 458 __ bind(L1); 459 __ get_thread(rbx); 460 __ cmpptr(r15_thread, thread); 461 __ jcc(Assembler::equal, L2); 462 __ stop("StubRoutines::catch_exception: r15_thread is modified by call"); 463 __ bind(L2); 464 __ cmpptr(r15_thread, rbx); 465 __ jcc(Assembler::equal, L3); 466 __ stop("StubRoutines::catch_exception: threads must correspond"); 467 __ bind(L3); 468 } 469 #endif 470 471 // set pending exception 472 __ verify_oop(rax); 473 474 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax); 475 __ lea(rscratch1, ExternalAddress((address)__FILE__)); 476 __ movptr(Address(r15_thread, Thread::exception_file_offset()), rscratch1); 477 __ movl(Address(r15_thread, Thread::exception_line_offset()), (int) __LINE__); 478 479 // complete return to VM 480 assert(StubRoutines::_call_stub_return_address != NULL, 481 "_call_stub_return_address must have been generated before"); 482 __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address)); 483 484 return start; 485 } 486 487 // Continuation point for runtime calls returning with a pending 488 // exception. The pending exception check happened in the runtime 489 // or native call stub. The pending exception in Thread is 490 // converted into a Java-level exception. 491 // 492 // Contract with Java-level exception handlers: 493 // rax: exception 494 // rdx: throwing pc 495 // 496 // NOTE: At entry of this stub, exception-pc must be on stack !! 497 498 address StubGenerator::generate_forward_exception() { 499 StubCodeMark mark(this, "StubRoutines", "forward exception"); 500 address start = __ pc(); 501 502 // Upon entry, the sp points to the return address returning into 503 // Java (interpreted or compiled) code; i.e., the return address 504 // becomes the throwing pc. 505 // 506 // Arguments pushed before the runtime call are still on the stack 507 // but the exception handler will reset the stack pointer -> 508 // ignore them. A potential result in registers can be ignored as 509 // well. 510 511 #ifdef ASSERT 512 // make sure this code is only executed if there is a pending exception 513 { 514 Label L; 515 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD); 516 __ jcc(Assembler::notEqual, L); 517 __ stop("StubRoutines::forward exception: no pending exception (1)"); 518 __ bind(L); 519 } 520 #endif 521 522 // compute exception handler into rbx 523 __ movptr(c_rarg0, Address(rsp, 0)); 524 BLOCK_COMMENT("call exception_handler_for_return_address"); 525 __ call_VM_leaf(CAST_FROM_FN_PTR(address, 526 SharedRuntime::exception_handler_for_return_address), 527 r15_thread, c_rarg0); 528 __ mov(rbx, rax); 529 530 // setup rax & rdx, remove return address & clear pending exception 531 __ pop(rdx); 532 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset())); 533 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD); 534 535 #ifdef ASSERT 536 // make sure exception is set 537 { 538 Label L; 539 __ testptr(rax, rax); 540 __ jcc(Assembler::notEqual, L); 541 __ stop("StubRoutines::forward exception: no pending exception (2)"); 542 __ bind(L); 543 } 544 #endif 545 546 // continue at exception handler (return address removed) 547 // rax: exception 548 // rbx: exception handler 549 // rdx: throwing pc 550 __ verify_oop(rax); 551 __ jmp(rbx); 552 553 return start; 554 } 555 556 // Support for intptr_t OrderAccess::fence() 557 // 558 // Arguments : 559 // 560 // Result: 561 address StubGenerator::generate_orderaccess_fence() { 562 StubCodeMark mark(this, "StubRoutines", "orderaccess_fence"); 563 address start = __ pc(); 564 565 __ membar(Assembler::StoreLoad); 566 __ ret(0); 567 568 return start; 569 } 570 571 572 // Support for intptr_t get_previous_sp() 573 // 574 // This routine is used to find the previous stack pointer for the 575 // caller. 576 address StubGenerator::generate_get_previous_sp() { 577 StubCodeMark mark(this, "StubRoutines", "get_previous_sp"); 578 address start = __ pc(); 579 580 __ movptr(rax, rsp); 581 __ addptr(rax, 8); // return address is at the top of the stack. 582 __ ret(0); 583 584 return start; 585 } 586 587 //---------------------------------------------------------------------------------------------------- 588 // Support for void verify_mxcsr() 589 // 590 // This routine is used with -Xcheck:jni to verify that native 591 // JNI code does not return to Java code without restoring the 592 // MXCSR register to our expected state. 593 594 address StubGenerator::generate_verify_mxcsr() { 595 StubCodeMark mark(this, "StubRoutines", "verify_mxcsr"); 596 address start = __ pc(); 597 598 const Address mxcsr_save(rsp, 0); 599 600 if (CheckJNICalls) { 601 Label ok_ret; 602 ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); 603 __ push(rax); 604 __ subptr(rsp, wordSize); // allocate a temp location 605 __ stmxcsr(mxcsr_save); 606 __ movl(rax, mxcsr_save); 607 __ andl(rax, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) 608 __ cmp32(rax, mxcsr_std, rscratch1); 609 __ jcc(Assembler::equal, ok_ret); 610 611 __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall"); 612 613 __ ldmxcsr(mxcsr_std, rscratch1); 614 615 __ bind(ok_ret); 616 __ addptr(rsp, wordSize); 617 __ pop(rax); 618 } 619 620 __ ret(0); 621 622 return start; 623 } 624 625 address StubGenerator::generate_f2i_fixup() { 626 StubCodeMark mark(this, "StubRoutines", "f2i_fixup"); 627 Address inout(rsp, 5 * wordSize); // return address + 4 saves 628 629 address start = __ pc(); 630 631 Label L; 632 633 __ push(rax); 634 __ push(c_rarg3); 635 __ push(c_rarg2); 636 __ push(c_rarg1); 637 638 __ movl(rax, 0x7f800000); 639 __ xorl(c_rarg3, c_rarg3); 640 __ movl(c_rarg2, inout); 641 __ movl(c_rarg1, c_rarg2); 642 __ andl(c_rarg1, 0x7fffffff); 643 __ cmpl(rax, c_rarg1); // NaN? -> 0 644 __ jcc(Assembler::negative, L); 645 __ testl(c_rarg2, c_rarg2); // signed ? min_jint : max_jint 646 __ movl(c_rarg3, 0x80000000); 647 __ movl(rax, 0x7fffffff); 648 __ cmovl(Assembler::positive, c_rarg3, rax); 649 650 __ bind(L); 651 __ movptr(inout, c_rarg3); 652 653 __ pop(c_rarg1); 654 __ pop(c_rarg2); 655 __ pop(c_rarg3); 656 __ pop(rax); 657 658 __ ret(0); 659 660 return start; 661 } 662 663 address StubGenerator::generate_f2l_fixup() { 664 StubCodeMark mark(this, "StubRoutines", "f2l_fixup"); 665 Address inout(rsp, 5 * wordSize); // return address + 4 saves 666 address start = __ pc(); 667 668 Label L; 669 670 __ push(rax); 671 __ push(c_rarg3); 672 __ push(c_rarg2); 673 __ push(c_rarg1); 674 675 __ movl(rax, 0x7f800000); 676 __ xorl(c_rarg3, c_rarg3); 677 __ movl(c_rarg2, inout); 678 __ movl(c_rarg1, c_rarg2); 679 __ andl(c_rarg1, 0x7fffffff); 680 __ cmpl(rax, c_rarg1); // NaN? -> 0 681 __ jcc(Assembler::negative, L); 682 __ testl(c_rarg2, c_rarg2); // signed ? min_jlong : max_jlong 683 __ mov64(c_rarg3, 0x8000000000000000); 684 __ mov64(rax, 0x7fffffffffffffff); 685 __ cmov(Assembler::positive, c_rarg3, rax); 686 687 __ bind(L); 688 __ movptr(inout, c_rarg3); 689 690 __ pop(c_rarg1); 691 __ pop(c_rarg2); 692 __ pop(c_rarg3); 693 __ pop(rax); 694 695 __ ret(0); 696 697 return start; 698 } 699 700 address StubGenerator::generate_d2i_fixup() { 701 StubCodeMark mark(this, "StubRoutines", "d2i_fixup"); 702 Address inout(rsp, 6 * wordSize); // return address + 5 saves 703 704 address start = __ pc(); 705 706 Label L; 707 708 __ push(rax); 709 __ push(c_rarg3); 710 __ push(c_rarg2); 711 __ push(c_rarg1); 712 __ push(c_rarg0); 713 714 __ movl(rax, 0x7ff00000); 715 __ movq(c_rarg2, inout); 716 __ movl(c_rarg3, c_rarg2); 717 __ mov(c_rarg1, c_rarg2); 718 __ mov(c_rarg0, c_rarg2); 719 __ negl(c_rarg3); 720 __ shrptr(c_rarg1, 0x20); 721 __ orl(c_rarg3, c_rarg2); 722 __ andl(c_rarg1, 0x7fffffff); 723 __ xorl(c_rarg2, c_rarg2); 724 __ shrl(c_rarg3, 0x1f); 725 __ orl(c_rarg1, c_rarg3); 726 __ cmpl(rax, c_rarg1); 727 __ jcc(Assembler::negative, L); // NaN -> 0 728 __ testptr(c_rarg0, c_rarg0); // signed ? min_jint : max_jint 729 __ movl(c_rarg2, 0x80000000); 730 __ movl(rax, 0x7fffffff); 731 __ cmov(Assembler::positive, c_rarg2, rax); 732 733 __ bind(L); 734 __ movptr(inout, c_rarg2); 735 736 __ pop(c_rarg0); 737 __ pop(c_rarg1); 738 __ pop(c_rarg2); 739 __ pop(c_rarg3); 740 __ pop(rax); 741 742 __ ret(0); 743 744 return start; 745 } 746 747 address StubGenerator::generate_d2l_fixup() { 748 StubCodeMark mark(this, "StubRoutines", "d2l_fixup"); 749 Address inout(rsp, 6 * wordSize); // return address + 5 saves 750 751 address start = __ pc(); 752 753 Label L; 754 755 __ push(rax); 756 __ push(c_rarg3); 757 __ push(c_rarg2); 758 __ push(c_rarg1); 759 __ push(c_rarg0); 760 761 __ movl(rax, 0x7ff00000); 762 __ movq(c_rarg2, inout); 763 __ movl(c_rarg3, c_rarg2); 764 __ mov(c_rarg1, c_rarg2); 765 __ mov(c_rarg0, c_rarg2); 766 __ negl(c_rarg3); 767 __ shrptr(c_rarg1, 0x20); 768 __ orl(c_rarg3, c_rarg2); 769 __ andl(c_rarg1, 0x7fffffff); 770 __ xorl(c_rarg2, c_rarg2); 771 __ shrl(c_rarg3, 0x1f); 772 __ orl(c_rarg1, c_rarg3); 773 __ cmpl(rax, c_rarg1); 774 __ jcc(Assembler::negative, L); // NaN -> 0 775 __ testq(c_rarg0, c_rarg0); // signed ? min_jlong : max_jlong 776 __ mov64(c_rarg2, 0x8000000000000000); 777 __ mov64(rax, 0x7fffffffffffffff); 778 __ cmovq(Assembler::positive, c_rarg2, rax); 779 780 __ bind(L); 781 __ movq(inout, c_rarg2); 782 783 __ pop(c_rarg0); 784 __ pop(c_rarg1); 785 __ pop(c_rarg2); 786 __ pop(c_rarg3); 787 __ pop(rax); 788 789 __ ret(0); 790 791 return start; 792 } 793 794 address StubGenerator::generate_count_leading_zeros_lut(const char *stub_name) { 795 __ align64(); 796 StubCodeMark mark(this, "StubRoutines", stub_name); 797 address start = __ pc(); 798 799 __ emit_data64(0x0101010102020304, relocInfo::none); 800 __ emit_data64(0x0000000000000000, relocInfo::none); 801 __ emit_data64(0x0101010102020304, relocInfo::none); 802 __ emit_data64(0x0000000000000000, relocInfo::none); 803 __ emit_data64(0x0101010102020304, relocInfo::none); 804 __ emit_data64(0x0000000000000000, relocInfo::none); 805 __ emit_data64(0x0101010102020304, relocInfo::none); 806 __ emit_data64(0x0000000000000000, relocInfo::none); 807 808 return start; 809 } 810 811 address StubGenerator::generate_popcount_avx_lut(const char *stub_name) { 812 __ align64(); 813 StubCodeMark mark(this, "StubRoutines", stub_name); 814 address start = __ pc(); 815 816 __ emit_data64(0x0302020102010100, relocInfo::none); 817 __ emit_data64(0x0403030203020201, relocInfo::none); 818 __ emit_data64(0x0302020102010100, relocInfo::none); 819 __ emit_data64(0x0403030203020201, relocInfo::none); 820 __ emit_data64(0x0302020102010100, relocInfo::none); 821 __ emit_data64(0x0403030203020201, relocInfo::none); 822 __ emit_data64(0x0302020102010100, relocInfo::none); 823 __ emit_data64(0x0403030203020201, relocInfo::none); 824 825 return start; 826 } 827 828 address StubGenerator::generate_iota_indices(const char *stub_name) { 829 __ align(CodeEntryAlignment); 830 StubCodeMark mark(this, "StubRoutines", stub_name); 831 address start = __ pc(); 832 // B 833 __ emit_data64(0x0706050403020100, relocInfo::none); 834 __ emit_data64(0x0F0E0D0C0B0A0908, relocInfo::none); 835 __ emit_data64(0x1716151413121110, relocInfo::none); 836 __ emit_data64(0x1F1E1D1C1B1A1918, relocInfo::none); 837 __ emit_data64(0x2726252423222120, relocInfo::none); 838 __ emit_data64(0x2F2E2D2C2B2A2928, relocInfo::none); 839 __ emit_data64(0x3736353433323130, relocInfo::none); 840 __ emit_data64(0x3F3E3D3C3B3A3938, relocInfo::none); 841 // W 842 __ emit_data64(0x0003000200010000, relocInfo::none); 843 __ emit_data64(0x0007000600050004, relocInfo::none); 844 __ emit_data64(0x000B000A00090008, relocInfo::none); 845 __ emit_data64(0x000F000E000D000C, relocInfo::none); 846 __ emit_data64(0x0013001200110010, relocInfo::none); 847 __ emit_data64(0x0017001600150014, relocInfo::none); 848 __ emit_data64(0x001B001A00190018, relocInfo::none); 849 __ emit_data64(0x001F001E001D001C, relocInfo::none); 850 // D 851 __ emit_data64(0x0000000100000000, relocInfo::none); 852 __ emit_data64(0x0000000300000002, relocInfo::none); 853 __ emit_data64(0x0000000500000004, relocInfo::none); 854 __ emit_data64(0x0000000700000006, relocInfo::none); 855 __ emit_data64(0x0000000900000008, relocInfo::none); 856 __ emit_data64(0x0000000B0000000A, relocInfo::none); 857 __ emit_data64(0x0000000D0000000C, relocInfo::none); 858 __ emit_data64(0x0000000F0000000E, relocInfo::none); 859 // Q 860 __ emit_data64(0x0000000000000000, relocInfo::none); 861 __ emit_data64(0x0000000000000001, relocInfo::none); 862 __ emit_data64(0x0000000000000002, relocInfo::none); 863 __ emit_data64(0x0000000000000003, relocInfo::none); 864 __ emit_data64(0x0000000000000004, relocInfo::none); 865 __ emit_data64(0x0000000000000005, relocInfo::none); 866 __ emit_data64(0x0000000000000006, relocInfo::none); 867 __ emit_data64(0x0000000000000007, relocInfo::none); 868 // D - FP 869 __ emit_data64(0x3F80000000000000, relocInfo::none); // 0.0f, 1.0f 870 __ emit_data64(0x4040000040000000, relocInfo::none); // 2.0f, 3.0f 871 __ emit_data64(0x40A0000040800000, relocInfo::none); // 4.0f, 5.0f 872 __ emit_data64(0x40E0000040C00000, relocInfo::none); // 6.0f, 7.0f 873 __ emit_data64(0x4110000041000000, relocInfo::none); // 8.0f, 9.0f 874 __ emit_data64(0x4130000041200000, relocInfo::none); // 10.0f, 11.0f 875 __ emit_data64(0x4150000041400000, relocInfo::none); // 12.0f, 13.0f 876 __ emit_data64(0x4170000041600000, relocInfo::none); // 14.0f, 15.0f 877 // Q - FP 878 __ emit_data64(0x0000000000000000, relocInfo::none); // 0.0d 879 __ emit_data64(0x3FF0000000000000, relocInfo::none); // 1.0d 880 __ emit_data64(0x4000000000000000, relocInfo::none); // 2.0d 881 __ emit_data64(0x4008000000000000, relocInfo::none); // 3.0d 882 __ emit_data64(0x4010000000000000, relocInfo::none); // 4.0d 883 __ emit_data64(0x4014000000000000, relocInfo::none); // 5.0d 884 __ emit_data64(0x4018000000000000, relocInfo::none); // 6.0d 885 __ emit_data64(0x401c000000000000, relocInfo::none); // 7.0d 886 return start; 887 } 888 889 address StubGenerator::generate_vector_reverse_bit_lut(const char *stub_name) { 890 __ align(CodeEntryAlignment); 891 StubCodeMark mark(this, "StubRoutines", stub_name); 892 address start = __ pc(); 893 894 __ emit_data64(0x0E060A020C040800, relocInfo::none); 895 __ emit_data64(0x0F070B030D050901, relocInfo::none); 896 __ emit_data64(0x0E060A020C040800, relocInfo::none); 897 __ emit_data64(0x0F070B030D050901, relocInfo::none); 898 __ emit_data64(0x0E060A020C040800, relocInfo::none); 899 __ emit_data64(0x0F070B030D050901, relocInfo::none); 900 __ emit_data64(0x0E060A020C040800, relocInfo::none); 901 __ emit_data64(0x0F070B030D050901, relocInfo::none); 902 903 return start; 904 } 905 906 address StubGenerator::generate_vector_reverse_byte_perm_mask_long(const char *stub_name) { 907 __ align(CodeEntryAlignment); 908 StubCodeMark mark(this, "StubRoutines", stub_name); 909 address start = __ pc(); 910 911 __ emit_data64(0x0001020304050607, relocInfo::none); 912 __ emit_data64(0x08090A0B0C0D0E0F, relocInfo::none); 913 __ emit_data64(0x0001020304050607, relocInfo::none); 914 __ emit_data64(0x08090A0B0C0D0E0F, relocInfo::none); 915 __ emit_data64(0x0001020304050607, relocInfo::none); 916 __ emit_data64(0x08090A0B0C0D0E0F, relocInfo::none); 917 __ emit_data64(0x0001020304050607, relocInfo::none); 918 __ emit_data64(0x08090A0B0C0D0E0F, relocInfo::none); 919 920 return start; 921 } 922 923 address StubGenerator::generate_vector_reverse_byte_perm_mask_int(const char *stub_name) { 924 __ align(CodeEntryAlignment); 925 StubCodeMark mark(this, "StubRoutines", stub_name); 926 address start = __ pc(); 927 928 __ emit_data64(0x0405060700010203, relocInfo::none); 929 __ emit_data64(0x0C0D0E0F08090A0B, relocInfo::none); 930 __ emit_data64(0x0405060700010203, relocInfo::none); 931 __ emit_data64(0x0C0D0E0F08090A0B, relocInfo::none); 932 __ emit_data64(0x0405060700010203, relocInfo::none); 933 __ emit_data64(0x0C0D0E0F08090A0B, relocInfo::none); 934 __ emit_data64(0x0405060700010203, relocInfo::none); 935 __ emit_data64(0x0C0D0E0F08090A0B, relocInfo::none); 936 937 return start; 938 } 939 940 address StubGenerator::generate_vector_reverse_byte_perm_mask_short(const char *stub_name) { 941 __ align(CodeEntryAlignment); 942 StubCodeMark mark(this, "StubRoutines", stub_name); 943 address start = __ pc(); 944 945 __ emit_data64(0x0607040502030001, relocInfo::none); 946 __ emit_data64(0x0E0F0C0D0A0B0809, relocInfo::none); 947 __ emit_data64(0x0607040502030001, relocInfo::none); 948 __ emit_data64(0x0E0F0C0D0A0B0809, relocInfo::none); 949 __ emit_data64(0x0607040502030001, relocInfo::none); 950 __ emit_data64(0x0E0F0C0D0A0B0809, relocInfo::none); 951 __ emit_data64(0x0607040502030001, relocInfo::none); 952 __ emit_data64(0x0E0F0C0D0A0B0809, relocInfo::none); 953 954 return start; 955 } 956 957 address StubGenerator::generate_vector_byte_shuffle_mask(const char *stub_name) { 958 __ align(CodeEntryAlignment); 959 StubCodeMark mark(this, "StubRoutines", stub_name); 960 address start = __ pc(); 961 962 __ emit_data64(0x7070707070707070, relocInfo::none); 963 __ emit_data64(0x7070707070707070, relocInfo::none); 964 __ emit_data64(0xF0F0F0F0F0F0F0F0, relocInfo::none); 965 __ emit_data64(0xF0F0F0F0F0F0F0F0, relocInfo::none); 966 967 return start; 968 } 969 970 address StubGenerator::generate_fp_mask(const char *stub_name, int64_t mask) { 971 __ align(CodeEntryAlignment); 972 StubCodeMark mark(this, "StubRoutines", stub_name); 973 address start = __ pc(); 974 975 __ emit_data64( mask, relocInfo::none ); 976 __ emit_data64( mask, relocInfo::none ); 977 978 return start; 979 } 980 981 address StubGenerator::generate_vector_mask(const char *stub_name, int64_t mask) { 982 __ align(CodeEntryAlignment); 983 StubCodeMark mark(this, "StubRoutines", stub_name); 984 address start = __ pc(); 985 986 __ emit_data64(mask, relocInfo::none); 987 __ emit_data64(mask, relocInfo::none); 988 __ emit_data64(mask, relocInfo::none); 989 __ emit_data64(mask, relocInfo::none); 990 __ emit_data64(mask, relocInfo::none); 991 __ emit_data64(mask, relocInfo::none); 992 __ emit_data64(mask, relocInfo::none); 993 __ emit_data64(mask, relocInfo::none); 994 995 return start; 996 } 997 998 address StubGenerator::generate_vector_byte_perm_mask(const char *stub_name) { 999 __ align(CodeEntryAlignment); 1000 StubCodeMark mark(this, "StubRoutines", stub_name); 1001 address start = __ pc(); 1002 1003 __ emit_data64(0x0000000000000001, relocInfo::none); 1004 __ emit_data64(0x0000000000000003, relocInfo::none); 1005 __ emit_data64(0x0000000000000005, relocInfo::none); 1006 __ emit_data64(0x0000000000000007, relocInfo::none); 1007 __ emit_data64(0x0000000000000000, relocInfo::none); 1008 __ emit_data64(0x0000000000000002, relocInfo::none); 1009 __ emit_data64(0x0000000000000004, relocInfo::none); 1010 __ emit_data64(0x0000000000000006, relocInfo::none); 1011 1012 return start; 1013 } 1014 1015 address StubGenerator::generate_vector_fp_mask(const char *stub_name, int64_t mask) { 1016 __ align(CodeEntryAlignment); 1017 StubCodeMark mark(this, "StubRoutines", stub_name); 1018 address start = __ pc(); 1019 1020 __ emit_data64(mask, relocInfo::none); 1021 __ emit_data64(mask, relocInfo::none); 1022 __ emit_data64(mask, relocInfo::none); 1023 __ emit_data64(mask, relocInfo::none); 1024 __ emit_data64(mask, relocInfo::none); 1025 __ emit_data64(mask, relocInfo::none); 1026 __ emit_data64(mask, relocInfo::none); 1027 __ emit_data64(mask, relocInfo::none); 1028 1029 return start; 1030 } 1031 1032 address StubGenerator::generate_vector_custom_i32(const char *stub_name, Assembler::AvxVectorLen len, 1033 int32_t val0, int32_t val1, int32_t val2, int32_t val3, 1034 int32_t val4, int32_t val5, int32_t val6, int32_t val7, 1035 int32_t val8, int32_t val9, int32_t val10, int32_t val11, 1036 int32_t val12, int32_t val13, int32_t val14, int32_t val15) { 1037 __ align(CodeEntryAlignment); 1038 StubCodeMark mark(this, "StubRoutines", stub_name); 1039 address start = __ pc(); 1040 1041 assert(len != Assembler::AVX_NoVec, "vector len must be specified"); 1042 __ emit_data(val0, relocInfo::none, 0); 1043 __ emit_data(val1, relocInfo::none, 0); 1044 __ emit_data(val2, relocInfo::none, 0); 1045 __ emit_data(val3, relocInfo::none, 0); 1046 if (len >= Assembler::AVX_256bit) { 1047 __ emit_data(val4, relocInfo::none, 0); 1048 __ emit_data(val5, relocInfo::none, 0); 1049 __ emit_data(val6, relocInfo::none, 0); 1050 __ emit_data(val7, relocInfo::none, 0); 1051 if (len >= Assembler::AVX_512bit) { 1052 __ emit_data(val8, relocInfo::none, 0); 1053 __ emit_data(val9, relocInfo::none, 0); 1054 __ emit_data(val10, relocInfo::none, 0); 1055 __ emit_data(val11, relocInfo::none, 0); 1056 __ emit_data(val12, relocInfo::none, 0); 1057 __ emit_data(val13, relocInfo::none, 0); 1058 __ emit_data(val14, relocInfo::none, 0); 1059 __ emit_data(val15, relocInfo::none, 0); 1060 } 1061 } 1062 return start; 1063 } 1064 1065 // Non-destructive plausibility checks for oops 1066 // 1067 // Arguments: 1068 // all args on stack! 1069 // 1070 // Stack after saving c_rarg3: 1071 // [tos + 0]: saved c_rarg3 1072 // [tos + 1]: saved c_rarg2 1073 // [tos + 2]: saved r12 (several TemplateTable methods use it) 1074 // [tos + 3]: saved flags 1075 // [tos + 4]: return address 1076 // * [tos + 5]: error message (char*) 1077 // * [tos + 6]: object to verify (oop) 1078 // * [tos + 7]: saved rax - saved by caller and bashed 1079 // * [tos + 8]: saved r10 (rscratch1) - saved by caller 1080 // * = popped on exit 1081 address StubGenerator::generate_verify_oop() { 1082 StubCodeMark mark(this, "StubRoutines", "verify_oop"); 1083 address start = __ pc(); 1084 1085 Label exit, error; 1086 1087 __ pushf(); 1088 __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr()), rscratch1); 1089 1090 __ push(r12); 1091 1092 // save c_rarg2 and c_rarg3 1093 __ push(c_rarg2); 1094 __ push(c_rarg3); 1095 1096 enum { 1097 // After previous pushes. 1098 oop_to_verify = 6 * wordSize, 1099 saved_rax = 7 * wordSize, 1100 saved_r10 = 8 * wordSize, 1101 1102 // Before the call to MacroAssembler::debug(), see below. 1103 return_addr = 16 * wordSize, 1104 error_msg = 17 * wordSize 1105 }; 1106 1107 // get object 1108 __ movptr(rax, Address(rsp, oop_to_verify)); 1109 1110 // make sure object is 'reasonable' 1111 __ testptr(rax, rax); 1112 __ jcc(Assembler::zero, exit); // if obj is NULL it is OK 1113 1114 #if INCLUDE_ZGC 1115 if (UseZGC) { 1116 // Check if metadata bits indicate a bad oop 1117 __ testptr(rax, Address(r15_thread, ZThreadLocalData::address_bad_mask_offset())); 1118 __ jcc(Assembler::notZero, error); 1119 } 1120 #endif 1121 1122 // Check if the oop is in the right area of memory 1123 __ movptr(c_rarg2, rax); 1124 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_mask()); 1125 __ andptr(c_rarg2, c_rarg3); 1126 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_bits()); 1127 __ cmpptr(c_rarg2, c_rarg3); 1128 __ jcc(Assembler::notZero, error); 1129 1130 // make sure klass is 'reasonable', which is not zero. 1131 __ load_klass(rax, rax, rscratch1); // get klass 1132 __ testptr(rax, rax); 1133 __ jcc(Assembler::zero, error); // if klass is NULL it is broken 1134 1135 // return if everything seems ok 1136 __ bind(exit); 1137 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back 1138 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back 1139 __ pop(c_rarg3); // restore c_rarg3 1140 __ pop(c_rarg2); // restore c_rarg2 1141 __ pop(r12); // restore r12 1142 __ popf(); // restore flags 1143 __ ret(4 * wordSize); // pop caller saved stuff 1144 1145 // handle errors 1146 __ bind(error); 1147 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back 1148 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back 1149 __ pop(c_rarg3); // get saved c_rarg3 back 1150 __ pop(c_rarg2); // get saved c_rarg2 back 1151 __ pop(r12); // get saved r12 back 1152 __ popf(); // get saved flags off stack -- 1153 // will be ignored 1154 1155 __ pusha(); // push registers 1156 // (rip is already 1157 // already pushed) 1158 // debug(char* msg, int64_t pc, int64_t regs[]) 1159 // We've popped the registers we'd saved (c_rarg3, c_rarg2 and flags), and 1160 // pushed all the registers, so now the stack looks like: 1161 // [tos + 0] 16 saved registers 1162 // [tos + 16] return address 1163 // * [tos + 17] error message (char*) 1164 // * [tos + 18] object to verify (oop) 1165 // * [tos + 19] saved rax - saved by caller and bashed 1166 // * [tos + 20] saved r10 (rscratch1) - saved by caller 1167 // * = popped on exit 1168 1169 __ movptr(c_rarg0, Address(rsp, error_msg)); // pass address of error message 1170 __ movptr(c_rarg1, Address(rsp, return_addr)); // pass return address 1171 __ movq(c_rarg2, rsp); // pass address of regs on stack 1172 __ mov(r12, rsp); // remember rsp 1173 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows 1174 __ andptr(rsp, -16); // align stack as required by ABI 1175 BLOCK_COMMENT("call MacroAssembler::debug"); 1176 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64))); 1177 __ hlt(); 1178 1179 return start; 1180 } 1181 1182 1183 // Shuffle first three arg regs on Windows into Linux/Solaris locations. 1184 // 1185 // Outputs: 1186 // rdi - rcx 1187 // rsi - rdx 1188 // rdx - r8 1189 // rcx - r9 1190 // 1191 // Registers r9 and r10 are used to save rdi and rsi on Windows, which latter 1192 // are non-volatile. r9 and r10 should not be used by the caller. 1193 // 1194 void StubGenerator::setup_arg_regs(int nargs) { 1195 const Register saved_rdi = r9; 1196 const Register saved_rsi = r10; 1197 assert(nargs == 3 || nargs == 4, "else fix"); 1198 #ifdef _WIN64 1199 assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9, 1200 "unexpected argument registers"); 1201 if (nargs >= 4) 1202 __ mov(rax, r9); // r9 is also saved_rdi 1203 __ movptr(saved_rdi, rdi); 1204 __ movptr(saved_rsi, rsi); 1205 __ mov(rdi, rcx); // c_rarg0 1206 __ mov(rsi, rdx); // c_rarg1 1207 __ mov(rdx, r8); // c_rarg2 1208 if (nargs >= 4) 1209 __ mov(rcx, rax); // c_rarg3 (via rax) 1210 #else 1211 assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx, 1212 "unexpected argument registers"); 1213 #endif 1214 DEBUG_ONLY(_regs_in_thread = false;) 1215 } 1216 1217 1218 void StubGenerator::restore_arg_regs() { 1219 assert(!_regs_in_thread, "wrong call to restore_arg_regs"); 1220 const Register saved_rdi = r9; 1221 const Register saved_rsi = r10; 1222 #ifdef _WIN64 1223 __ movptr(rdi, saved_rdi); 1224 __ movptr(rsi, saved_rsi); 1225 #endif 1226 } 1227 1228 1229 // This is used in places where r10 is a scratch register, and can 1230 // be adapted if r9 is needed also. 1231 void StubGenerator::setup_arg_regs_using_thread() { 1232 const Register saved_r15 = r9; 1233 #ifdef _WIN64 1234 __ mov(saved_r15, r15); // r15 is callee saved and needs to be restored 1235 __ get_thread(r15_thread); 1236 assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9, 1237 "unexpected argument registers"); 1238 __ movptr(Address(r15_thread, in_bytes(JavaThread::windows_saved_rdi_offset())), rdi); 1239 __ movptr(Address(r15_thread, in_bytes(JavaThread::windows_saved_rsi_offset())), rsi); 1240 1241 __ mov(rdi, rcx); // c_rarg0 1242 __ mov(rsi, rdx); // c_rarg1 1243 __ mov(rdx, r8); // c_rarg2 1244 #else 1245 assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx, 1246 "unexpected argument registers"); 1247 #endif 1248 DEBUG_ONLY(_regs_in_thread = true;) 1249 } 1250 1251 1252 void StubGenerator::restore_arg_regs_using_thread() { 1253 assert(_regs_in_thread, "wrong call to restore_arg_regs"); 1254 const Register saved_r15 = r9; 1255 #ifdef _WIN64 1256 __ get_thread(r15_thread); 1257 __ movptr(rsi, Address(r15_thread, in_bytes(JavaThread::windows_saved_rsi_offset()))); 1258 __ movptr(rdi, Address(r15_thread, in_bytes(JavaThread::windows_saved_rdi_offset()))); 1259 __ mov(r15, saved_r15); // r15 is callee saved and needs to be restored 1260 #endif 1261 } 1262 1263 1264 void StubGenerator::setup_argument_regs(BasicType type) { 1265 if (type == T_BYTE || type == T_SHORT) { 1266 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1267 // r9 and r10 may be used to save non-volatile registers 1268 } else { 1269 setup_arg_regs_using_thread(); // from => rdi, to => rsi, count => rdx 1270 // r9 is used to save r15_thread 1271 } 1272 } 1273 1274 1275 void StubGenerator::restore_argument_regs(BasicType type) { 1276 if (type == T_BYTE || type == T_SHORT) { 1277 restore_arg_regs(); 1278 } else { 1279 restore_arg_regs_using_thread(); 1280 } 1281 } 1282 1283 address StubGenerator::generate_data_cache_writeback() { 1284 const Register src = c_rarg0; // source address 1285 1286 __ align(CodeEntryAlignment); 1287 1288 StubCodeMark mark(this, "StubRoutines", "_data_cache_writeback"); 1289 1290 address start = __ pc(); 1291 1292 __ enter(); 1293 __ cache_wb(Address(src, 0)); 1294 __ leave(); 1295 __ ret(0); 1296 1297 return start; 1298 } 1299 1300 address StubGenerator::generate_data_cache_writeback_sync() { 1301 const Register is_pre = c_rarg0; // pre or post sync 1302 1303 __ align(CodeEntryAlignment); 1304 1305 StubCodeMark mark(this, "StubRoutines", "_data_cache_writeback_sync"); 1306 1307 // pre wbsync is a no-op 1308 // post wbsync translates to an sfence 1309 1310 Label skip; 1311 address start = __ pc(); 1312 1313 __ enter(); 1314 __ cmpl(is_pre, 0); 1315 __ jcc(Assembler::notEqual, skip); 1316 __ cache_wbsync(false); 1317 __ bind(skip); 1318 __ leave(); 1319 __ ret(0); 1320 1321 return start; 1322 } 1323 1324 // ofs and limit are use for multi-block byte array. 1325 // int com.sun.security.provider.MD5.implCompress(byte[] b, int ofs) 1326 address StubGenerator::generate_md5_implCompress(bool multi_block, const char *name) { 1327 __ align(CodeEntryAlignment); 1328 StubCodeMark mark(this, "StubRoutines", name); 1329 address start = __ pc(); 1330 1331 const Register buf_param = r15; 1332 const Address state_param(rsp, 0 * wordSize); 1333 const Address ofs_param (rsp, 1 * wordSize ); 1334 const Address limit_param(rsp, 1 * wordSize + 4); 1335 1336 __ enter(); 1337 __ push(rbx); 1338 __ push(rdi); 1339 __ push(rsi); 1340 __ push(r15); 1341 __ subptr(rsp, 2 * wordSize); 1342 1343 __ movptr(buf_param, c_rarg0); 1344 __ movptr(state_param, c_rarg1); 1345 if (multi_block) { 1346 __ movl(ofs_param, c_rarg2); 1347 __ movl(limit_param, c_rarg3); 1348 } 1349 __ fast_md5(buf_param, state_param, ofs_param, limit_param, multi_block); 1350 1351 __ addptr(rsp, 2 * wordSize); 1352 __ pop(r15); 1353 __ pop(rsi); 1354 __ pop(rdi); 1355 __ pop(rbx); 1356 __ leave(); 1357 __ ret(0); 1358 1359 return start; 1360 } 1361 1362 address StubGenerator::generate_upper_word_mask() { 1363 __ align64(); 1364 StubCodeMark mark(this, "StubRoutines", "upper_word_mask"); 1365 address start = __ pc(); 1366 1367 __ emit_data64(0x0000000000000000, relocInfo::none); 1368 __ emit_data64(0xFFFFFFFF00000000, relocInfo::none); 1369 1370 return start; 1371 } 1372 1373 address StubGenerator::generate_shuffle_byte_flip_mask() { 1374 __ align64(); 1375 StubCodeMark mark(this, "StubRoutines", "shuffle_byte_flip_mask"); 1376 address start = __ pc(); 1377 1378 __ emit_data64(0x08090a0b0c0d0e0f, relocInfo::none); 1379 __ emit_data64(0x0001020304050607, relocInfo::none); 1380 1381 return start; 1382 } 1383 1384 // ofs and limit are use for multi-block byte array. 1385 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 1386 address StubGenerator::generate_sha1_implCompress(bool multi_block, const char *name) { 1387 __ align(CodeEntryAlignment); 1388 StubCodeMark mark(this, "StubRoutines", name); 1389 address start = __ pc(); 1390 1391 Register buf = c_rarg0; 1392 Register state = c_rarg1; 1393 Register ofs = c_rarg2; 1394 Register limit = c_rarg3; 1395 1396 const XMMRegister abcd = xmm0; 1397 const XMMRegister e0 = xmm1; 1398 const XMMRegister e1 = xmm2; 1399 const XMMRegister msg0 = xmm3; 1400 1401 const XMMRegister msg1 = xmm4; 1402 const XMMRegister msg2 = xmm5; 1403 const XMMRegister msg3 = xmm6; 1404 const XMMRegister shuf_mask = xmm7; 1405 1406 __ enter(); 1407 1408 __ subptr(rsp, 4 * wordSize); 1409 1410 __ fast_sha1(abcd, e0, e1, msg0, msg1, msg2, msg3, shuf_mask, 1411 buf, state, ofs, limit, rsp, multi_block); 1412 1413 __ addptr(rsp, 4 * wordSize); 1414 1415 __ leave(); 1416 __ ret(0); 1417 1418 return start; 1419 } 1420 1421 address StubGenerator::generate_pshuffle_byte_flip_mask() { 1422 __ align64(); 1423 StubCodeMark mark(this, "StubRoutines", "pshuffle_byte_flip_mask"); 1424 address start = __ pc(); 1425 1426 __ emit_data64(0x0405060700010203, relocInfo::none); 1427 __ emit_data64(0x0c0d0e0f08090a0b, relocInfo::none); 1428 1429 if (VM_Version::supports_avx2()) { 1430 __ emit_data64(0x0405060700010203, relocInfo::none); // second copy 1431 __ emit_data64(0x0c0d0e0f08090a0b, relocInfo::none); 1432 // _SHUF_00BA 1433 __ emit_data64(0x0b0a090803020100, relocInfo::none); 1434 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1435 __ emit_data64(0x0b0a090803020100, relocInfo::none); 1436 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1437 // _SHUF_DC00 1438 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1439 __ emit_data64(0x0b0a090803020100, relocInfo::none); 1440 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1441 __ emit_data64(0x0b0a090803020100, relocInfo::none); 1442 } 1443 1444 return start; 1445 } 1446 1447 //Mask for byte-swapping a couple of qwords in an XMM register using (v)pshufb. 1448 address StubGenerator::generate_pshuffle_byte_flip_mask_sha512() { 1449 __ align32(); 1450 StubCodeMark mark(this, "StubRoutines", "pshuffle_byte_flip_mask_sha512"); 1451 address start = __ pc(); 1452 1453 if (VM_Version::supports_avx2()) { 1454 __ emit_data64(0x0001020304050607, relocInfo::none); // PSHUFFLE_BYTE_FLIP_MASK 1455 __ emit_data64(0x08090a0b0c0d0e0f, relocInfo::none); 1456 __ emit_data64(0x1011121314151617, relocInfo::none); 1457 __ emit_data64(0x18191a1b1c1d1e1f, relocInfo::none); 1458 __ emit_data64(0x0000000000000000, relocInfo::none); //MASK_YMM_LO 1459 __ emit_data64(0x0000000000000000, relocInfo::none); 1460 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1461 __ emit_data64(0xFFFFFFFFFFFFFFFF, relocInfo::none); 1462 } 1463 1464 return start; 1465 } 1466 1467 // ofs and limit are use for multi-block byte array. 1468 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 1469 address StubGenerator::generate_sha256_implCompress(bool multi_block, const char *name) { 1470 assert(VM_Version::supports_sha() || VM_Version::supports_avx2(), ""); 1471 __ align(CodeEntryAlignment); 1472 StubCodeMark mark(this, "StubRoutines", name); 1473 address start = __ pc(); 1474 1475 Register buf = c_rarg0; 1476 Register state = c_rarg1; 1477 Register ofs = c_rarg2; 1478 Register limit = c_rarg3; 1479 1480 const XMMRegister msg = xmm0; 1481 const XMMRegister state0 = xmm1; 1482 const XMMRegister state1 = xmm2; 1483 const XMMRegister msgtmp0 = xmm3; 1484 1485 const XMMRegister msgtmp1 = xmm4; 1486 const XMMRegister msgtmp2 = xmm5; 1487 const XMMRegister msgtmp3 = xmm6; 1488 const XMMRegister msgtmp4 = xmm7; 1489 1490 const XMMRegister shuf_mask = xmm8; 1491 1492 __ enter(); 1493 1494 __ subptr(rsp, 4 * wordSize); 1495 1496 if (VM_Version::supports_sha()) { 1497 __ fast_sha256(msg, state0, state1, msgtmp0, msgtmp1, msgtmp2, msgtmp3, msgtmp4, 1498 buf, state, ofs, limit, rsp, multi_block, shuf_mask); 1499 } else if (VM_Version::supports_avx2()) { 1500 __ sha256_AVX2(msg, state0, state1, msgtmp0, msgtmp1, msgtmp2, msgtmp3, msgtmp4, 1501 buf, state, ofs, limit, rsp, multi_block, shuf_mask); 1502 } 1503 __ addptr(rsp, 4 * wordSize); 1504 __ vzeroupper(); 1505 __ leave(); 1506 __ ret(0); 1507 1508 return start; 1509 } 1510 1511 address StubGenerator::generate_sha512_implCompress(bool multi_block, const char *name) { 1512 assert(VM_Version::supports_avx2(), ""); 1513 assert(VM_Version::supports_bmi2(), ""); 1514 __ align(CodeEntryAlignment); 1515 StubCodeMark mark(this, "StubRoutines", name); 1516 address start = __ pc(); 1517 1518 Register buf = c_rarg0; 1519 Register state = c_rarg1; 1520 Register ofs = c_rarg2; 1521 Register limit = c_rarg3; 1522 1523 const XMMRegister msg = xmm0; 1524 const XMMRegister state0 = xmm1; 1525 const XMMRegister state1 = xmm2; 1526 const XMMRegister msgtmp0 = xmm3; 1527 const XMMRegister msgtmp1 = xmm4; 1528 const XMMRegister msgtmp2 = xmm5; 1529 const XMMRegister msgtmp3 = xmm6; 1530 const XMMRegister msgtmp4 = xmm7; 1531 1532 const XMMRegister shuf_mask = xmm8; 1533 1534 __ enter(); 1535 1536 __ sha512_AVX2(msg, state0, state1, msgtmp0, msgtmp1, msgtmp2, msgtmp3, msgtmp4, 1537 buf, state, ofs, limit, rsp, multi_block, shuf_mask); 1538 1539 __ vzeroupper(); 1540 __ leave(); 1541 __ ret(0); 1542 1543 return start; 1544 } 1545 1546 address StubGenerator::base64_shuffle_addr() { 1547 __ align64(); 1548 StubCodeMark mark(this, "StubRoutines", "shuffle_base64"); 1549 address start = __ pc(); 1550 1551 assert(((unsigned long long)start & 0x3f) == 0, 1552 "Alignment problem (0x%08llx)", (unsigned long long)start); 1553 __ emit_data64(0x0405030401020001, relocInfo::none); 1554 __ emit_data64(0x0a0b090a07080607, relocInfo::none); 1555 __ emit_data64(0x10110f100d0e0c0d, relocInfo::none); 1556 __ emit_data64(0x1617151613141213, relocInfo::none); 1557 __ emit_data64(0x1c1d1b1c191a1819, relocInfo::none); 1558 __ emit_data64(0x222321221f201e1f, relocInfo::none); 1559 __ emit_data64(0x2829272825262425, relocInfo::none); 1560 __ emit_data64(0x2e2f2d2e2b2c2a2b, relocInfo::none); 1561 1562 return start; 1563 } 1564 1565 address StubGenerator::base64_avx2_shuffle_addr() { 1566 __ align32(); 1567 StubCodeMark mark(this, "StubRoutines", "avx2_shuffle_base64"); 1568 address start = __ pc(); 1569 1570 __ emit_data64(0x0809070805060405, relocInfo::none); 1571 __ emit_data64(0x0e0f0d0e0b0c0a0b, relocInfo::none); 1572 __ emit_data64(0x0405030401020001, relocInfo::none); 1573 __ emit_data64(0x0a0b090a07080607, relocInfo::none); 1574 1575 return start; 1576 } 1577 1578 address StubGenerator::base64_avx2_input_mask_addr() { 1579 __ align32(); 1580 StubCodeMark mark(this, "StubRoutines", "avx2_input_mask_base64"); 1581 address start = __ pc(); 1582 1583 __ emit_data64(0x8000000000000000, relocInfo::none); 1584 __ emit_data64(0x8000000080000000, relocInfo::none); 1585 __ emit_data64(0x8000000080000000, relocInfo::none); 1586 __ emit_data64(0x8000000080000000, relocInfo::none); 1587 1588 return start; 1589 } 1590 1591 address StubGenerator::base64_avx2_lut_addr() { 1592 __ align32(); 1593 StubCodeMark mark(this, "StubRoutines", "avx2_lut_base64"); 1594 address start = __ pc(); 1595 1596 __ emit_data64(0xfcfcfcfcfcfc4741, relocInfo::none); 1597 __ emit_data64(0x0000f0edfcfcfcfc, relocInfo::none); 1598 __ emit_data64(0xfcfcfcfcfcfc4741, relocInfo::none); 1599 __ emit_data64(0x0000f0edfcfcfcfc, relocInfo::none); 1600 1601 // URL LUT 1602 __ emit_data64(0xfcfcfcfcfcfc4741, relocInfo::none); 1603 __ emit_data64(0x000020effcfcfcfc, relocInfo::none); 1604 __ emit_data64(0xfcfcfcfcfcfc4741, relocInfo::none); 1605 __ emit_data64(0x000020effcfcfcfc, relocInfo::none); 1606 1607 return start; 1608 } 1609 1610 address StubGenerator::base64_encoding_table_addr() { 1611 __ align64(); 1612 StubCodeMark mark(this, "StubRoutines", "encoding_table_base64"); 1613 address start = __ pc(); 1614 1615 assert(((unsigned long long)start & 0x3f) == 0, "Alignment problem (0x%08llx)", (unsigned long long)start); 1616 __ emit_data64(0x4847464544434241, relocInfo::none); 1617 __ emit_data64(0x504f4e4d4c4b4a49, relocInfo::none); 1618 __ emit_data64(0x5857565554535251, relocInfo::none); 1619 __ emit_data64(0x6665646362615a59, relocInfo::none); 1620 __ emit_data64(0x6e6d6c6b6a696867, relocInfo::none); 1621 __ emit_data64(0x767574737271706f, relocInfo::none); 1622 __ emit_data64(0x333231307a797877, relocInfo::none); 1623 __ emit_data64(0x2f2b393837363534, relocInfo::none); 1624 1625 // URL table 1626 __ emit_data64(0x4847464544434241, relocInfo::none); 1627 __ emit_data64(0x504f4e4d4c4b4a49, relocInfo::none); 1628 __ emit_data64(0x5857565554535251, relocInfo::none); 1629 __ emit_data64(0x6665646362615a59, relocInfo::none); 1630 __ emit_data64(0x6e6d6c6b6a696867, relocInfo::none); 1631 __ emit_data64(0x767574737271706f, relocInfo::none); 1632 __ emit_data64(0x333231307a797877, relocInfo::none); 1633 __ emit_data64(0x5f2d393837363534, relocInfo::none); 1634 1635 return start; 1636 } 1637 1638 // Code for generating Base64 encoding. 1639 // Intrinsic function prototype in Base64.java: 1640 // private void encodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, 1641 // boolean isURL) { 1642 address StubGenerator::generate_base64_encodeBlock() 1643 { 1644 __ align(CodeEntryAlignment); 1645 StubCodeMark mark(this, "StubRoutines", "implEncode"); 1646 address start = __ pc(); 1647 1648 __ enter(); 1649 1650 // Save callee-saved registers before using them 1651 __ push(r12); 1652 __ push(r13); 1653 __ push(r14); 1654 __ push(r15); 1655 1656 // arguments 1657 const Register source = c_rarg0; // Source Array 1658 const Register start_offset = c_rarg1; // start offset 1659 const Register end_offset = c_rarg2; // end offset 1660 const Register dest = c_rarg3; // destination array 1661 1662 #ifndef _WIN64 1663 const Register dp = c_rarg4; // Position for writing to dest array 1664 const Register isURL = c_rarg5; // Base64 or URL character set 1665 #else 1666 const Address dp_mem(rbp, 6 * wordSize); // length is on stack on Win64 1667 const Address isURL_mem(rbp, 7 * wordSize); 1668 const Register isURL = r10; // pick the volatile windows register 1669 const Register dp = r12; 1670 __ movl(dp, dp_mem); 1671 __ movl(isURL, isURL_mem); 1672 #endif 1673 1674 const Register length = r14; 1675 const Register encode_table = r13; 1676 Label L_process3, L_exit, L_processdata, L_vbmiLoop, L_not512, L_32byteLoop; 1677 1678 // calculate length from offsets 1679 __ movl(length, end_offset); 1680 __ subl(length, start_offset); 1681 __ cmpl(length, 0); 1682 __ jcc(Assembler::lessEqual, L_exit); 1683 1684 // Code for 512-bit VBMI encoding. Encodes 48 input bytes into 64 1685 // output bytes. We read 64 input bytes and ignore the last 16, so be 1686 // sure not to read past the end of the input buffer. 1687 if (VM_Version::supports_avx512_vbmi()) { 1688 __ cmpl(length, 64); // Do not overrun input buffer. 1689 __ jcc(Assembler::below, L_not512); 1690 1691 __ shll(isURL, 6); // index into decode table based on isURL 1692 __ lea(encode_table, ExternalAddress(StubRoutines::x86::base64_encoding_table_addr())); 1693 __ addptr(encode_table, isURL); 1694 __ shrl(isURL, 6); // restore isURL 1695 1696 __ mov64(rax, 0x3036242a1016040aull); // Shifts 1697 __ evmovdquq(xmm3, ExternalAddress(StubRoutines::x86::base64_shuffle_addr()), Assembler::AVX_512bit, r15); 1698 __ evmovdquq(xmm2, Address(encode_table, 0), Assembler::AVX_512bit); 1699 __ evpbroadcastq(xmm1, rax, Assembler::AVX_512bit); 1700 1701 __ align32(); 1702 __ BIND(L_vbmiLoop); 1703 1704 __ vpermb(xmm0, xmm3, Address(source, start_offset), Assembler::AVX_512bit); 1705 __ subl(length, 48); 1706 1707 // Put the input bytes into the proper lanes for writing, then 1708 // encode them. 1709 __ evpmultishiftqb(xmm0, xmm1, xmm0, Assembler::AVX_512bit); 1710 __ vpermb(xmm0, xmm0, xmm2, Assembler::AVX_512bit); 1711 1712 // Write to destination 1713 __ evmovdquq(Address(dest, dp), xmm0, Assembler::AVX_512bit); 1714 1715 __ addptr(dest, 64); 1716 __ addptr(source, 48); 1717 __ cmpl(length, 64); 1718 __ jcc(Assembler::aboveEqual, L_vbmiLoop); 1719 1720 __ vzeroupper(); 1721 } 1722 1723 __ BIND(L_not512); 1724 if (VM_Version::supports_avx2() 1725 && VM_Version::supports_avx512vlbw()) { 1726 /* 1727 ** This AVX2 encoder is based off the paper at: 1728 ** https://dl.acm.org/doi/10.1145/3132709 1729 ** 1730 ** We use AVX2 SIMD instructions to encode 24 bytes into 32 1731 ** output bytes. 1732 ** 1733 */ 1734 // Lengths under 32 bytes are done with scalar routine 1735 __ cmpl(length, 31); 1736 __ jcc(Assembler::belowEqual, L_process3); 1737 1738 // Set up supporting constant table data 1739 __ vmovdqu(xmm9, ExternalAddress(StubRoutines::x86::base64_avx2_shuffle_addr()), rax); 1740 // 6-bit mask for 2nd and 4th (and multiples) 6-bit values 1741 __ movl(rax, 0x0fc0fc00); 1742 __ vmovdqu(xmm1, ExternalAddress(StubRoutines::x86::base64_avx2_input_mask_addr()), rax); 1743 __ evpbroadcastd(xmm8, rax, Assembler::AVX_256bit); 1744 1745 // Multiplication constant for "shifting" right by 6 and 10 1746 // bits 1747 __ movl(rax, 0x04000040); 1748 1749 __ subl(length, 24); 1750 __ evpbroadcastd(xmm7, rax, Assembler::AVX_256bit); 1751 1752 // For the first load, we mask off reading of the first 4 1753 // bytes into the register. This is so we can get 4 3-byte 1754 // chunks into each lane of the register, avoiding having to 1755 // handle end conditions. We then shuffle these bytes into a 1756 // specific order so that manipulation is easier. 1757 // 1758 // The initial read loads the XMM register like this: 1759 // 1760 // Lower 128-bit lane: 1761 // +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 1762 // | XX | XX | XX | XX | A0 | A1 | A2 | B0 | B1 | B2 | C0 | C1 1763 // | C2 | D0 | D1 | D2 | 1764 // +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 1765 // 1766 // Upper 128-bit lane: 1767 // +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 1768 // | E0 | E1 | E2 | F0 | F1 | F2 | G0 | G1 | G2 | H0 | H1 | H2 1769 // | XX | XX | XX | XX | 1770 // +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 1771 // 1772 // Where A0 is the first input byte, B0 is the fourth, etc. 1773 // The alphabetical significance denotes the 3 bytes to be 1774 // consumed and encoded into 4 bytes. 1775 // 1776 // We then shuffle the register so each 32-bit word contains 1777 // the sequence: 1778 // A1 A0 A2 A1, B1, B0, B2, B1, etc. 1779 // Each of these byte sequences are then manipulated into 4 1780 // 6-bit values ready for encoding. 1781 // 1782 // If we focus on one set of 3-byte chunks, changing the 1783 // nomenclature such that A0 => a, A1 => b, and A2 => c, we 1784 // shuffle such that each 24-bit chunk contains: 1785 // 1786 // b7 b6 b5 b4 b3 b2 b1 b0 | a7 a6 a5 a4 a3 a2 a1 a0 | c7 c6 1787 // c5 c4 c3 c2 c1 c0 | b7 b6 b5 b4 b3 b2 b1 b0 1788 // Explain this step. 1789 // b3 b2 b1 b0 c5 c4 c3 c2 | c1 c0 d5 d4 d3 d2 d1 d0 | a5 a4 1790 // a3 a2 a1 a0 b5 b4 | b3 b2 b1 b0 c5 c4 c3 c2 1791 // 1792 // W first and off all but bits 4-9 and 16-21 (c5..c0 and 1793 // a5..a0) and shift them using a vector multiplication 1794 // operation (vpmulhuw) which effectively shifts c right by 6 1795 // bits and a right by 10 bits. We similarly mask bits 10-15 1796 // (d5..d0) and 22-27 (b5..b0) and shift them left by 8 and 4 1797 // bits respectively. This is done using vpmullw. We end up 1798 // with 4 6-bit values, thus splitting the 3 input bytes, 1799 // ready for encoding: 1800 // 0 0 d5..d0 0 0 c5..c0 0 0 b5..b0 0 0 a5..a0 1801 // 1802 // For translation, we recognize that there are 5 distinct 1803 // ranges of legal Base64 characters as below: 1804 // 1805 // +-------------+-------------+------------+ 1806 // | 6-bit value | ASCII range | offset | 1807 // +-------------+-------------+------------+ 1808 // | 0..25 | A..Z | 65 | 1809 // | 26..51 | a..z | 71 | 1810 // | 52..61 | 0..9 | -4 | 1811 // | 62 | + or - | -19 or -17 | 1812 // | 63 | / or _ | -16 or 32 | 1813 // +-------------+-------------+------------+ 1814 // 1815 // We note that vpshufb does a parallel lookup in a 1816 // destination register using the lower 4 bits of bytes from a 1817 // source register. If we use a saturated subtraction and 1818 // subtract 51 from each 6-bit value, bytes from [0,51] 1819 // saturate to 0, and [52,63] map to a range of [1,12]. We 1820 // distinguish the [0,25] and [26,51] ranges by assigning a 1821 // value of 13 for all 6-bit values less than 26. We end up 1822 // with: 1823 // 1824 // +-------------+-------------+------------+ 1825 // | 6-bit value | Reduced | offset | 1826 // +-------------+-------------+------------+ 1827 // | 0..25 | 13 | 65 | 1828 // | 26..51 | 0 | 71 | 1829 // | 52..61 | 0..9 | -4 | 1830 // | 62 | 11 | -19 or -17 | 1831 // | 63 | 12 | -16 or 32 | 1832 // +-------------+-------------+------------+ 1833 // 1834 // We then use a final vpshufb to add the appropriate offset, 1835 // translating the bytes. 1836 // 1837 // Load input bytes - only 28 bytes. Mask the first load to 1838 // not load into the full register. 1839 __ vpmaskmovd(xmm1, xmm1, Address(source, start_offset, Address::times_1, -4), Assembler::AVX_256bit); 1840 1841 // Move 3-byte chunks of input (12 bytes) into 16 bytes, 1842 // ordering by: 1843 // 1, 0, 2, 1; 4, 3, 5, 4; etc. This groups 6-bit chunks 1844 // for easy masking 1845 __ vpshufb(xmm1, xmm1, xmm9, Assembler::AVX_256bit); 1846 1847 __ addl(start_offset, 24); 1848 1849 // Load masking register for first and third (and multiples) 1850 // 6-bit values. 1851 __ movl(rax, 0x003f03f0); 1852 __ evpbroadcastd(xmm6, rax, Assembler::AVX_256bit); 1853 // Multiplication constant for "shifting" left by 4 and 8 bits 1854 __ movl(rax, 0x01000010); 1855 __ evpbroadcastd(xmm5, rax, Assembler::AVX_256bit); 1856 1857 // Isolate 6-bit chunks of interest 1858 __ vpand(xmm0, xmm8, xmm1, Assembler::AVX_256bit); 1859 1860 // Load constants for encoding 1861 __ movl(rax, 0x19191919); 1862 __ evpbroadcastd(xmm3, rax, Assembler::AVX_256bit); 1863 __ movl(rax, 0x33333333); 1864 __ evpbroadcastd(xmm4, rax, Assembler::AVX_256bit); 1865 1866 // Shift output bytes 0 and 2 into proper lanes 1867 __ vpmulhuw(xmm2, xmm0, xmm7, Assembler::AVX_256bit); 1868 1869 // Mask and shift output bytes 1 and 3 into proper lanes and 1870 // combine 1871 __ vpand(xmm0, xmm6, xmm1, Assembler::AVX_256bit); 1872 __ vpmullw(xmm0, xmm5, xmm0, Assembler::AVX_256bit); 1873 __ vpor(xmm0, xmm0, xmm2, Assembler::AVX_256bit); 1874 1875 // Find out which are 0..25. This indicates which input 1876 // values fall in the range of 'A'-'Z', which require an 1877 // additional offset (see comments above) 1878 __ vpcmpgtb(xmm2, xmm0, xmm3, Assembler::AVX_256bit); 1879 __ vpsubusb(xmm1, xmm0, xmm4, Assembler::AVX_256bit); 1880 __ vpsubb(xmm1, xmm1, xmm2, Assembler::AVX_256bit); 1881 1882 // Load the proper lookup table 1883 __ lea(r11, ExternalAddress(StubRoutines::x86::base64_avx2_lut_addr())); 1884 __ movl(r15, isURL); 1885 __ shll(r15, 5); 1886 __ vmovdqu(xmm2, Address(r11, r15)); 1887 1888 // Shuffle the offsets based on the range calculation done 1889 // above. This allows us to add the correct offset to the 1890 // 6-bit value corresponding to the range documented above. 1891 __ vpshufb(xmm1, xmm2, xmm1, Assembler::AVX_256bit); 1892 __ vpaddb(xmm0, xmm1, xmm0, Assembler::AVX_256bit); 1893 1894 // Store the encoded bytes 1895 __ vmovdqu(Address(dest, dp), xmm0); 1896 __ addl(dp, 32); 1897 1898 __ cmpl(length, 31); 1899 __ jcc(Assembler::belowEqual, L_process3); 1900 1901 __ align32(); 1902 __ BIND(L_32byteLoop); 1903 1904 // Get next 32 bytes 1905 __ vmovdqu(xmm1, Address(source, start_offset, Address::times_1, -4)); 1906 1907 __ subl(length, 24); 1908 __ addl(start_offset, 24); 1909 1910 // This logic is identical to the above, with only constant 1911 // register loads removed. Shuffle the input, mask off 6-bit 1912 // chunks, shift them into place, then add the offset to 1913 // encode. 1914 __ vpshufb(xmm1, xmm1, xmm9, Assembler::AVX_256bit); 1915 1916 __ vpand(xmm0, xmm8, xmm1, Assembler::AVX_256bit); 1917 __ vpmulhuw(xmm10, xmm0, xmm7, Assembler::AVX_256bit); 1918 __ vpand(xmm0, xmm6, xmm1, Assembler::AVX_256bit); 1919 __ vpmullw(xmm0, xmm5, xmm0, Assembler::AVX_256bit); 1920 __ vpor(xmm0, xmm0, xmm10, Assembler::AVX_256bit); 1921 __ vpcmpgtb(xmm10, xmm0, xmm3, Assembler::AVX_256bit); 1922 __ vpsubusb(xmm1, xmm0, xmm4, Assembler::AVX_256bit); 1923 __ vpsubb(xmm1, xmm1, xmm10, Assembler::AVX_256bit); 1924 __ vpshufb(xmm1, xmm2, xmm1, Assembler::AVX_256bit); 1925 __ vpaddb(xmm0, xmm1, xmm0, Assembler::AVX_256bit); 1926 1927 // Store the encoded bytes 1928 __ vmovdqu(Address(dest, dp), xmm0); 1929 __ addl(dp, 32); 1930 1931 __ cmpl(length, 31); 1932 __ jcc(Assembler::above, L_32byteLoop); 1933 1934 __ BIND(L_process3); 1935 __ vzeroupper(); 1936 } else { 1937 __ BIND(L_process3); 1938 } 1939 1940 __ cmpl(length, 3); 1941 __ jcc(Assembler::below, L_exit); 1942 1943 // Load the encoding table based on isURL 1944 __ lea(r11, ExternalAddress(StubRoutines::x86::base64_encoding_table_addr())); 1945 __ movl(r15, isURL); 1946 __ shll(r15, 6); 1947 __ addptr(r11, r15); 1948 1949 __ BIND(L_processdata); 1950 1951 // Load 3 bytes 1952 __ load_unsigned_byte(r15, Address(source, start_offset)); 1953 __ load_unsigned_byte(r10, Address(source, start_offset, Address::times_1, 1)); 1954 __ load_unsigned_byte(r13, Address(source, start_offset, Address::times_1, 2)); 1955 1956 // Build a 32-bit word with bytes 1, 2, 0, 1 1957 __ movl(rax, r10); 1958 __ shll(r10, 24); 1959 __ orl(rax, r10); 1960 1961 __ subl(length, 3); 1962 1963 __ shll(r15, 8); 1964 __ shll(r13, 16); 1965 __ orl(rax, r15); 1966 1967 __ addl(start_offset, 3); 1968 1969 __ orl(rax, r13); 1970 // At this point, rax contains | byte1 | byte2 | byte0 | byte1 1971 // r13 has byte2 << 16 - need low-order 6 bits to translate. 1972 // This translated byte is the fourth output byte. 1973 __ shrl(r13, 16); 1974 __ andl(r13, 0x3f); 1975 1976 // The high-order 6 bits of r15 (byte0) is translated. 1977 // The translated byte is the first output byte. 1978 __ shrl(r15, 10); 1979 1980 __ load_unsigned_byte(r13, Address(r11, r13)); 1981 __ load_unsigned_byte(r15, Address(r11, r15)); 1982 1983 __ movb(Address(dest, dp, Address::times_1, 3), r13); 1984 1985 // Extract high-order 4 bits of byte1 and low-order 2 bits of byte0. 1986 // This translated byte is the second output byte. 1987 __ shrl(rax, 4); 1988 __ movl(r10, rax); 1989 __ andl(rax, 0x3f); 1990 1991 __ movb(Address(dest, dp, Address::times_1, 0), r15); 1992 1993 __ load_unsigned_byte(rax, Address(r11, rax)); 1994 1995 // Extract low-order 2 bits of byte1 and high-order 4 bits of byte2. 1996 // This translated byte is the third output byte. 1997 __ shrl(r10, 18); 1998 __ andl(r10, 0x3f); 1999 2000 __ load_unsigned_byte(r10, Address(r11, r10)); 2001 2002 __ movb(Address(dest, dp, Address::times_1, 1), rax); 2003 __ movb(Address(dest, dp, Address::times_1, 2), r10); 2004 2005 __ addl(dp, 4); 2006 __ cmpl(length, 3); 2007 __ jcc(Assembler::aboveEqual, L_processdata); 2008 2009 __ BIND(L_exit); 2010 __ pop(r15); 2011 __ pop(r14); 2012 __ pop(r13); 2013 __ pop(r12); 2014 __ leave(); 2015 __ ret(0); 2016 2017 return start; 2018 } 2019 2020 // base64 AVX512vbmi tables 2021 address StubGenerator::base64_vbmi_lookup_lo_addr() { 2022 __ align64(); 2023 StubCodeMark mark(this, "StubRoutines", "lookup_lo_base64"); 2024 address start = __ pc(); 2025 2026 assert(((unsigned long long)start & 0x3f) == 0, 2027 "Alignment problem (0x%08llx)", (unsigned long long)start); 2028 __ emit_data64(0x8080808080808080, relocInfo::none); 2029 __ emit_data64(0x8080808080808080, relocInfo::none); 2030 __ emit_data64(0x8080808080808080, relocInfo::none); 2031 __ emit_data64(0x8080808080808080, relocInfo::none); 2032 __ emit_data64(0x8080808080808080, relocInfo::none); 2033 __ emit_data64(0x3f8080803e808080, relocInfo::none); 2034 __ emit_data64(0x3b3a393837363534, relocInfo::none); 2035 __ emit_data64(0x8080808080803d3c, relocInfo::none); 2036 2037 return start; 2038 } 2039 2040 address StubGenerator::base64_vbmi_lookup_hi_addr() { 2041 __ align64(); 2042 StubCodeMark mark(this, "StubRoutines", "lookup_hi_base64"); 2043 address start = __ pc(); 2044 2045 assert(((unsigned long long)start & 0x3f) == 0, 2046 "Alignment problem (0x%08llx)", (unsigned long long)start); 2047 __ emit_data64(0x0605040302010080, relocInfo::none); 2048 __ emit_data64(0x0e0d0c0b0a090807, relocInfo::none); 2049 __ emit_data64(0x161514131211100f, relocInfo::none); 2050 __ emit_data64(0x8080808080191817, relocInfo::none); 2051 __ emit_data64(0x201f1e1d1c1b1a80, relocInfo::none); 2052 __ emit_data64(0x2827262524232221, relocInfo::none); 2053 __ emit_data64(0x302f2e2d2c2b2a29, relocInfo::none); 2054 __ emit_data64(0x8080808080333231, relocInfo::none); 2055 2056 return start; 2057 } 2058 address StubGenerator::base64_vbmi_lookup_lo_url_addr() { 2059 __ align64(); 2060 StubCodeMark mark(this, "StubRoutines", "lookup_lo_base64url"); 2061 address start = __ pc(); 2062 2063 assert(((unsigned long long)start & 0x3f) == 0, 2064 "Alignment problem (0x%08llx)", (unsigned long long)start); 2065 __ emit_data64(0x8080808080808080, relocInfo::none); 2066 __ emit_data64(0x8080808080808080, relocInfo::none); 2067 __ emit_data64(0x8080808080808080, relocInfo::none); 2068 __ emit_data64(0x8080808080808080, relocInfo::none); 2069 __ emit_data64(0x8080808080808080, relocInfo::none); 2070 __ emit_data64(0x80803e8080808080, relocInfo::none); 2071 __ emit_data64(0x3b3a393837363534, relocInfo::none); 2072 __ emit_data64(0x8080808080803d3c, relocInfo::none); 2073 2074 return start; 2075 } 2076 2077 address StubGenerator::base64_vbmi_lookup_hi_url_addr() { 2078 __ align64(); 2079 StubCodeMark mark(this, "StubRoutines", "lookup_hi_base64url"); 2080 address start = __ pc(); 2081 2082 assert(((unsigned long long)start & 0x3f) == 0, 2083 "Alignment problem (0x%08llx)", (unsigned long long)start); 2084 __ emit_data64(0x0605040302010080, relocInfo::none); 2085 __ emit_data64(0x0e0d0c0b0a090807, relocInfo::none); 2086 __ emit_data64(0x161514131211100f, relocInfo::none); 2087 __ emit_data64(0x3f80808080191817, relocInfo::none); 2088 __ emit_data64(0x201f1e1d1c1b1a80, relocInfo::none); 2089 __ emit_data64(0x2827262524232221, relocInfo::none); 2090 __ emit_data64(0x302f2e2d2c2b2a29, relocInfo::none); 2091 __ emit_data64(0x8080808080333231, relocInfo::none); 2092 2093 return start; 2094 } 2095 2096 address StubGenerator::base64_vbmi_pack_vec_addr() { 2097 __ align64(); 2098 StubCodeMark mark(this, "StubRoutines", "pack_vec_base64"); 2099 address start = __ pc(); 2100 2101 assert(((unsigned long long)start & 0x3f) == 0, 2102 "Alignment problem (0x%08llx)", (unsigned long long)start); 2103 __ emit_data64(0x090a040506000102, relocInfo::none); 2104 __ emit_data64(0x161011120c0d0e08, relocInfo::none); 2105 __ emit_data64(0x1c1d1e18191a1415, relocInfo::none); 2106 __ emit_data64(0x292a242526202122, relocInfo::none); 2107 __ emit_data64(0x363031322c2d2e28, relocInfo::none); 2108 __ emit_data64(0x3c3d3e38393a3435, relocInfo::none); 2109 __ emit_data64(0x0000000000000000, relocInfo::none); 2110 __ emit_data64(0x0000000000000000, relocInfo::none); 2111 2112 return start; 2113 } 2114 2115 address StubGenerator::base64_vbmi_join_0_1_addr() { 2116 __ align64(); 2117 StubCodeMark mark(this, "StubRoutines", "join_0_1_base64"); 2118 address start = __ pc(); 2119 2120 assert(((unsigned long long)start & 0x3f) == 0, 2121 "Alignment problem (0x%08llx)", (unsigned long long)start); 2122 __ emit_data64(0x090a040506000102, relocInfo::none); 2123 __ emit_data64(0x161011120c0d0e08, relocInfo::none); 2124 __ emit_data64(0x1c1d1e18191a1415, relocInfo::none); 2125 __ emit_data64(0x292a242526202122, relocInfo::none); 2126 __ emit_data64(0x363031322c2d2e28, relocInfo::none); 2127 __ emit_data64(0x3c3d3e38393a3435, relocInfo::none); 2128 __ emit_data64(0x494a444546404142, relocInfo::none); 2129 __ emit_data64(0x565051524c4d4e48, relocInfo::none); 2130 2131 return start; 2132 } 2133 2134 address StubGenerator::base64_vbmi_join_1_2_addr() { 2135 __ align64(); 2136 StubCodeMark mark(this, "StubRoutines", "join_1_2_base64"); 2137 address start = __ pc(); 2138 2139 assert(((unsigned long long)start & 0x3f) == 0, 2140 "Alignment problem (0x%08llx)", (unsigned long long)start); 2141 __ emit_data64(0x1c1d1e18191a1415, relocInfo::none); 2142 __ emit_data64(0x292a242526202122, relocInfo::none); 2143 __ emit_data64(0x363031322c2d2e28, relocInfo::none); 2144 __ emit_data64(0x3c3d3e38393a3435, relocInfo::none); 2145 __ emit_data64(0x494a444546404142, relocInfo::none); 2146 __ emit_data64(0x565051524c4d4e48, relocInfo::none); 2147 __ emit_data64(0x5c5d5e58595a5455, relocInfo::none); 2148 __ emit_data64(0x696a646566606162, relocInfo::none); 2149 2150 return start; 2151 } 2152 2153 address StubGenerator::base64_vbmi_join_2_3_addr() { 2154 __ align64(); 2155 StubCodeMark mark(this, "StubRoutines", "join_2_3_base64"); 2156 address start = __ pc(); 2157 2158 assert(((unsigned long long)start & 0x3f) == 0, 2159 "Alignment problem (0x%08llx)", (unsigned long long)start); 2160 __ emit_data64(0x363031322c2d2e28, relocInfo::none); 2161 __ emit_data64(0x3c3d3e38393a3435, relocInfo::none); 2162 __ emit_data64(0x494a444546404142, relocInfo::none); 2163 __ emit_data64(0x565051524c4d4e48, relocInfo::none); 2164 __ emit_data64(0x5c5d5e58595a5455, relocInfo::none); 2165 __ emit_data64(0x696a646566606162, relocInfo::none); 2166 __ emit_data64(0x767071726c6d6e68, relocInfo::none); 2167 __ emit_data64(0x7c7d7e78797a7475, relocInfo::none); 2168 2169 return start; 2170 } 2171 2172 address StubGenerator::base64_decoding_table_addr() { 2173 StubCodeMark mark(this, "StubRoutines", "decoding_table_base64"); 2174 address start = __ pc(); 2175 2176 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2177 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2178 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2179 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2180 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2181 __ emit_data64(0x3fffffff3effffff, relocInfo::none); 2182 __ emit_data64(0x3b3a393837363534, relocInfo::none); 2183 __ emit_data64(0xffffffffffff3d3c, relocInfo::none); 2184 __ emit_data64(0x06050403020100ff, relocInfo::none); 2185 __ emit_data64(0x0e0d0c0b0a090807, relocInfo::none); 2186 __ emit_data64(0x161514131211100f, relocInfo::none); 2187 __ emit_data64(0xffffffffff191817, relocInfo::none); 2188 __ emit_data64(0x201f1e1d1c1b1aff, relocInfo::none); 2189 __ emit_data64(0x2827262524232221, relocInfo::none); 2190 __ emit_data64(0x302f2e2d2c2b2a29, relocInfo::none); 2191 __ emit_data64(0xffffffffff333231, relocInfo::none); 2192 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2193 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2194 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2195 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2196 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2197 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2198 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2199 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2200 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2201 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2202 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2203 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2204 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2205 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2206 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2207 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2208 2209 // URL table 2210 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2211 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2212 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2213 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2214 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2215 __ emit_data64(0xffff3effffffffff, relocInfo::none); 2216 __ emit_data64(0x3b3a393837363534, relocInfo::none); 2217 __ emit_data64(0xffffffffffff3d3c, relocInfo::none); 2218 __ emit_data64(0x06050403020100ff, relocInfo::none); 2219 __ emit_data64(0x0e0d0c0b0a090807, relocInfo::none); 2220 __ emit_data64(0x161514131211100f, relocInfo::none); 2221 __ emit_data64(0x3fffffffff191817, relocInfo::none); 2222 __ emit_data64(0x201f1e1d1c1b1aff, relocInfo::none); 2223 __ emit_data64(0x2827262524232221, relocInfo::none); 2224 __ emit_data64(0x302f2e2d2c2b2a29, relocInfo::none); 2225 __ emit_data64(0xffffffffff333231, relocInfo::none); 2226 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2227 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2228 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2229 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2230 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2231 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2232 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2233 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2234 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2235 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2236 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2237 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2238 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2239 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2240 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2241 __ emit_data64(0xffffffffffffffff, relocInfo::none); 2242 2243 return start; 2244 } 2245 2246 2247 // Code for generating Base64 decoding. 2248 // 2249 // Based on the article (and associated code) from https://arxiv.org/abs/1910.05109. 2250 // 2251 // Intrinsic function prototype in Base64.java: 2252 // private void decodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, boolean isURL, isMIME) { 2253 address StubGenerator::generate_base64_decodeBlock() { 2254 __ align(CodeEntryAlignment); 2255 StubCodeMark mark(this, "StubRoutines", "implDecode"); 2256 address start = __ pc(); 2257 2258 __ enter(); 2259 2260 // Save callee-saved registers before using them 2261 __ push(r12); 2262 __ push(r13); 2263 __ push(r14); 2264 __ push(r15); 2265 __ push(rbx); 2266 2267 // arguments 2268 const Register source = c_rarg0; // Source Array 2269 const Register start_offset = c_rarg1; // start offset 2270 const Register end_offset = c_rarg2; // end offset 2271 const Register dest = c_rarg3; // destination array 2272 const Register isMIME = rbx; 2273 2274 #ifndef _WIN64 2275 const Register dp = c_rarg4; // Position for writing to dest array 2276 const Register isURL = c_rarg5;// Base64 or URL character set 2277 __ movl(isMIME, Address(rbp, 2 * wordSize)); 2278 #else 2279 const Address dp_mem(rbp, 6 * wordSize); // length is on stack on Win64 2280 const Address isURL_mem(rbp, 7 * wordSize); 2281 const Register isURL = r10; // pick the volatile windows register 2282 const Register dp = r12; 2283 __ movl(dp, dp_mem); 2284 __ movl(isURL, isURL_mem); 2285 __ movl(isMIME, Address(rbp, 8 * wordSize)); 2286 #endif 2287 2288 const XMMRegister lookup_lo = xmm5; 2289 const XMMRegister lookup_hi = xmm6; 2290 const XMMRegister errorvec = xmm7; 2291 const XMMRegister pack16_op = xmm9; 2292 const XMMRegister pack32_op = xmm8; 2293 const XMMRegister input0 = xmm3; 2294 const XMMRegister input1 = xmm20; 2295 const XMMRegister input2 = xmm21; 2296 const XMMRegister input3 = xmm19; 2297 const XMMRegister join01 = xmm12; 2298 const XMMRegister join12 = xmm11; 2299 const XMMRegister join23 = xmm10; 2300 const XMMRegister translated0 = xmm2; 2301 const XMMRegister translated1 = xmm1; 2302 const XMMRegister translated2 = xmm0; 2303 const XMMRegister translated3 = xmm4; 2304 2305 const XMMRegister merged0 = xmm2; 2306 const XMMRegister merged1 = xmm1; 2307 const XMMRegister merged2 = xmm0; 2308 const XMMRegister merged3 = xmm4; 2309 const XMMRegister merge_ab_bc0 = xmm2; 2310 const XMMRegister merge_ab_bc1 = xmm1; 2311 const XMMRegister merge_ab_bc2 = xmm0; 2312 const XMMRegister merge_ab_bc3 = xmm4; 2313 2314 const XMMRegister pack24bits = xmm4; 2315 2316 const Register length = r14; 2317 const Register output_size = r13; 2318 const Register output_mask = r15; 2319 const KRegister input_mask = k1; 2320 2321 const XMMRegister input_initial_valid_b64 = xmm0; 2322 const XMMRegister tmp = xmm10; 2323 const XMMRegister mask = xmm0; 2324 const XMMRegister invalid_b64 = xmm1; 2325 2326 Label L_process256, L_process64, L_process64Loop, L_exit, L_processdata, L_loadURL; 2327 Label L_continue, L_finalBit, L_padding, L_donePadding, L_bruteForce; 2328 Label L_forceLoop, L_bottomLoop, L_checkMIME, L_exit_no_vzero; 2329 2330 // calculate length from offsets 2331 __ movl(length, end_offset); 2332 __ subl(length, start_offset); 2333 __ push(dest); // Save for return value calc 2334 2335 // If AVX512 VBMI not supported, just compile non-AVX code 2336 if(VM_Version::supports_avx512_vbmi() && 2337 VM_Version::supports_avx512bw()) { 2338 __ cmpl(length, 128); // 128-bytes is break-even for AVX-512 2339 __ jcc(Assembler::lessEqual, L_bruteForce); 2340 2341 __ cmpl(isMIME, 0); 2342 __ jcc(Assembler::notEqual, L_bruteForce); 2343 2344 // Load lookup tables based on isURL 2345 __ cmpl(isURL, 0); 2346 __ jcc(Assembler::notZero, L_loadURL); 2347 2348 __ evmovdquq(lookup_lo, ExternalAddress(StubRoutines::x86::base64_vbmi_lookup_lo_addr()), Assembler::AVX_512bit, r13); 2349 __ evmovdquq(lookup_hi, ExternalAddress(StubRoutines::x86::base64_vbmi_lookup_hi_addr()), Assembler::AVX_512bit, r13); 2350 2351 __ BIND(L_continue); 2352 2353 __ movl(r15, 0x01400140); 2354 __ evpbroadcastd(pack16_op, r15, Assembler::AVX_512bit); 2355 2356 __ movl(r15, 0x00011000); 2357 __ evpbroadcastd(pack32_op, r15, Assembler::AVX_512bit); 2358 2359 __ cmpl(length, 0xff); 2360 __ jcc(Assembler::lessEqual, L_process64); 2361 2362 // load masks required for decoding data 2363 __ BIND(L_processdata); 2364 __ evmovdquq(join01, ExternalAddress(StubRoutines::x86::base64_vbmi_join_0_1_addr()), Assembler::AVX_512bit,r13); 2365 __ evmovdquq(join12, ExternalAddress(StubRoutines::x86::base64_vbmi_join_1_2_addr()), Assembler::AVX_512bit, r13); 2366 __ evmovdquq(join23, ExternalAddress(StubRoutines::x86::base64_vbmi_join_2_3_addr()), Assembler::AVX_512bit, r13); 2367 2368 __ align32(); 2369 __ BIND(L_process256); 2370 // Grab input data 2371 __ evmovdquq(input0, Address(source, start_offset, Address::times_1, 0x00), Assembler::AVX_512bit); 2372 __ evmovdquq(input1, Address(source, start_offset, Address::times_1, 0x40), Assembler::AVX_512bit); 2373 __ evmovdquq(input2, Address(source, start_offset, Address::times_1, 0x80), Assembler::AVX_512bit); 2374 __ evmovdquq(input3, Address(source, start_offset, Address::times_1, 0xc0), Assembler::AVX_512bit); 2375 2376 // Copy the low part of the lookup table into the destination of the permutation 2377 __ evmovdquq(translated0, lookup_lo, Assembler::AVX_512bit); 2378 __ evmovdquq(translated1, lookup_lo, Assembler::AVX_512bit); 2379 __ evmovdquq(translated2, lookup_lo, Assembler::AVX_512bit); 2380 __ evmovdquq(translated3, lookup_lo, Assembler::AVX_512bit); 2381 2382 // Translate the base64 input into "decoded" bytes 2383 __ evpermt2b(translated0, input0, lookup_hi, Assembler::AVX_512bit); 2384 __ evpermt2b(translated1, input1, lookup_hi, Assembler::AVX_512bit); 2385 __ evpermt2b(translated2, input2, lookup_hi, Assembler::AVX_512bit); 2386 __ evpermt2b(translated3, input3, lookup_hi, Assembler::AVX_512bit); 2387 2388 // OR all of the translations together to check for errors (high-order bit of byte set) 2389 __ vpternlogd(input0, 0xfe, input1, input2, Assembler::AVX_512bit); 2390 2391 __ vpternlogd(input3, 0xfe, translated0, translated1, Assembler::AVX_512bit); 2392 __ vpternlogd(input0, 0xfe, translated2, translated3, Assembler::AVX_512bit); 2393 __ vpor(errorvec, input3, input0, Assembler::AVX_512bit); 2394 2395 // Check if there was an error - if so, try 64-byte chunks 2396 __ evpmovb2m(k3, errorvec, Assembler::AVX_512bit); 2397 __ kortestql(k3, k3); 2398 __ jcc(Assembler::notZero, L_process64); 2399 2400 // The merging and shuffling happens here 2401 // We multiply each byte pair [00dddddd | 00cccccc | 00bbbbbb | 00aaaaaa] 2402 // Multiply [00cccccc] by 2^6 added to [00dddddd] to get [0000cccc | ccdddddd] 2403 // The pack16_op is a vector of 0x01400140, so multiply D by 1 and C by 0x40 2404 __ vpmaddubsw(merge_ab_bc0, translated0, pack16_op, Assembler::AVX_512bit); 2405 __ vpmaddubsw(merge_ab_bc1, translated1, pack16_op, Assembler::AVX_512bit); 2406 __ vpmaddubsw(merge_ab_bc2, translated2, pack16_op, Assembler::AVX_512bit); 2407 __ vpmaddubsw(merge_ab_bc3, translated3, pack16_op, Assembler::AVX_512bit); 2408 2409 // Now do the same with packed 16-bit values. 2410 // We start with [0000cccc | ccdddddd | 0000aaaa | aabbbbbb] 2411 // pack32_op is 0x00011000 (2^12, 1), so this multiplies [0000aaaa | aabbbbbb] by 2^12 2412 // and adds [0000cccc | ccdddddd] to yield [00000000 | aaaaaabb | bbbbcccc | ccdddddd] 2413 __ vpmaddwd(merged0, merge_ab_bc0, pack32_op, Assembler::AVX_512bit); 2414 __ vpmaddwd(merged1, merge_ab_bc1, pack32_op, Assembler::AVX_512bit); 2415 __ vpmaddwd(merged2, merge_ab_bc2, pack32_op, Assembler::AVX_512bit); 2416 __ vpmaddwd(merged3, merge_ab_bc3, pack32_op, Assembler::AVX_512bit); 2417 2418 // The join vectors specify which byte from which vector goes into the outputs 2419 // One of every 4 bytes in the extended vector is zero, so we pack them into their 2420 // final positions in the register for storing (256 bytes in, 192 bytes out) 2421 __ evpermt2b(merged0, join01, merged1, Assembler::AVX_512bit); 2422 __ evpermt2b(merged1, join12, merged2, Assembler::AVX_512bit); 2423 __ evpermt2b(merged2, join23, merged3, Assembler::AVX_512bit); 2424 2425 // Store result 2426 __ evmovdquq(Address(dest, dp, Address::times_1, 0x00), merged0, Assembler::AVX_512bit); 2427 __ evmovdquq(Address(dest, dp, Address::times_1, 0x40), merged1, Assembler::AVX_512bit); 2428 __ evmovdquq(Address(dest, dp, Address::times_1, 0x80), merged2, Assembler::AVX_512bit); 2429 2430 __ addptr(source, 0x100); 2431 __ addptr(dest, 0xc0); 2432 __ subl(length, 0x100); 2433 __ cmpl(length, 64 * 4); 2434 __ jcc(Assembler::greaterEqual, L_process256); 2435 2436 // At this point, we've decoded 64 * 4 * n bytes. 2437 // The remaining length will be <= 64 * 4 - 1. 2438 // UNLESS there was an error decoding the first 256-byte chunk. In this 2439 // case, the length will be arbitrarily long. 2440 // 2441 // Note that this will be the path for MIME-encoded strings. 2442 2443 __ BIND(L_process64); 2444 2445 __ evmovdquq(pack24bits, ExternalAddress(StubRoutines::x86::base64_vbmi_pack_vec_addr()), Assembler::AVX_512bit, r13); 2446 2447 __ cmpl(length, 63); 2448 __ jcc(Assembler::lessEqual, L_finalBit); 2449 2450 __ mov64(rax, 0x0000ffffffffffff); 2451 __ kmovql(k2, rax); 2452 2453 __ align32(); 2454 __ BIND(L_process64Loop); 2455 2456 // Handle first 64-byte block 2457 2458 __ evmovdquq(input0, Address(source, start_offset), Assembler::AVX_512bit); 2459 __ evmovdquq(translated0, lookup_lo, Assembler::AVX_512bit); 2460 __ evpermt2b(translated0, input0, lookup_hi, Assembler::AVX_512bit); 2461 2462 __ vpor(errorvec, translated0, input0, Assembler::AVX_512bit); 2463 2464 // Check for error and bomb out before updating dest 2465 __ evpmovb2m(k3, errorvec, Assembler::AVX_512bit); 2466 __ kortestql(k3, k3); 2467 __ jcc(Assembler::notZero, L_exit); 2468 2469 // Pack output register, selecting correct byte ordering 2470 __ vpmaddubsw(merge_ab_bc0, translated0, pack16_op, Assembler::AVX_512bit); 2471 __ vpmaddwd(merged0, merge_ab_bc0, pack32_op, Assembler::AVX_512bit); 2472 __ vpermb(merged0, pack24bits, merged0, Assembler::AVX_512bit); 2473 2474 __ evmovdqub(Address(dest, dp), k2, merged0, true, Assembler::AVX_512bit); 2475 2476 __ subl(length, 64); 2477 __ addptr(source, 64); 2478 __ addptr(dest, 48); 2479 2480 __ cmpl(length, 64); 2481 __ jcc(Assembler::greaterEqual, L_process64Loop); 2482 2483 __ cmpl(length, 0); 2484 __ jcc(Assembler::lessEqual, L_exit); 2485 2486 __ BIND(L_finalBit); 2487 // Now have 1 to 63 bytes left to decode 2488 2489 // I was going to let Java take care of the final fragment 2490 // however it will repeatedly call this routine for every 4 bytes 2491 // of input data, so handle the rest here. 2492 __ movq(rax, -1); 2493 __ bzhiq(rax, rax, length); // Input mask in rax 2494 2495 __ movl(output_size, length); 2496 __ shrl(output_size, 2); // Find (len / 4) * 3 (output length) 2497 __ lea(output_size, Address(output_size, output_size, Address::times_2, 0)); 2498 // output_size in r13 2499 2500 // Strip pad characters, if any, and adjust length and mask 2501 __ cmpb(Address(source, length, Address::times_1, -1), '='); 2502 __ jcc(Assembler::equal, L_padding); 2503 2504 __ BIND(L_donePadding); 2505 2506 // Output size is (64 - output_size), output mask is (all 1s >> output_size). 2507 __ kmovql(input_mask, rax); 2508 __ movq(output_mask, -1); 2509 __ bzhiq(output_mask, output_mask, output_size); 2510 2511 // Load initial input with all valid base64 characters. Will be used 2512 // in merging source bytes to avoid masking when determining if an error occurred. 2513 __ movl(rax, 0x61616161); 2514 __ evpbroadcastd(input_initial_valid_b64, rax, Assembler::AVX_512bit); 2515 2516 // A register containing all invalid base64 decoded values 2517 __ movl(rax, 0x80808080); 2518 __ evpbroadcastd(invalid_b64, rax, Assembler::AVX_512bit); 2519 2520 // input_mask is in k1 2521 // output_size is in r13 2522 // output_mask is in r15 2523 // zmm0 - free 2524 // zmm1 - 0x00011000 2525 // zmm2 - 0x01400140 2526 // zmm3 - errorvec 2527 // zmm4 - pack vector 2528 // zmm5 - lookup_lo 2529 // zmm6 - lookup_hi 2530 // zmm7 - errorvec 2531 // zmm8 - 0x61616161 2532 // zmm9 - 0x80808080 2533 2534 // Load only the bytes from source, merging into our "fully-valid" register 2535 __ evmovdqub(input_initial_valid_b64, input_mask, Address(source, start_offset, Address::times_1, 0x0), true, Assembler::AVX_512bit); 2536 2537 // Decode all bytes within our merged input 2538 __ evmovdquq(tmp, lookup_lo, Assembler::AVX_512bit); 2539 __ evpermt2b(tmp, input_initial_valid_b64, lookup_hi, Assembler::AVX_512bit); 2540 __ evporq(mask, tmp, input_initial_valid_b64, Assembler::AVX_512bit); 2541 2542 // Check for error. Compare (decoded | initial) to all invalid. 2543 // If any bytes have their high-order bit set, then we have an error. 2544 __ evptestmb(k2, mask, invalid_b64, Assembler::AVX_512bit); 2545 __ kortestql(k2, k2); 2546 2547 // If we have an error, use the brute force loop to decode what we can (4-byte chunks). 2548 __ jcc(Assembler::notZero, L_bruteForce); 2549 2550 // Shuffle output bytes 2551 __ vpmaddubsw(tmp, tmp, pack16_op, Assembler::AVX_512bit); 2552 __ vpmaddwd(tmp, tmp, pack32_op, Assembler::AVX_512bit); 2553 2554 __ vpermb(tmp, pack24bits, tmp, Assembler::AVX_512bit); 2555 __ kmovql(k1, output_mask); 2556 __ evmovdqub(Address(dest, dp), k1, tmp, true, Assembler::AVX_512bit); 2557 2558 __ addptr(dest, output_size); 2559 2560 __ BIND(L_exit); 2561 __ vzeroupper(); 2562 __ pop(rax); // Get original dest value 2563 __ subptr(dest, rax); // Number of bytes converted 2564 __ movptr(rax, dest); 2565 __ pop(rbx); 2566 __ pop(r15); 2567 __ pop(r14); 2568 __ pop(r13); 2569 __ pop(r12); 2570 __ leave(); 2571 __ ret(0); 2572 2573 __ BIND(L_loadURL); 2574 __ evmovdquq(lookup_lo, ExternalAddress(StubRoutines::x86::base64_vbmi_lookup_lo_url_addr()), Assembler::AVX_512bit, r13); 2575 __ evmovdquq(lookup_hi, ExternalAddress(StubRoutines::x86::base64_vbmi_lookup_hi_url_addr()), Assembler::AVX_512bit, r13); 2576 __ jmp(L_continue); 2577 2578 __ BIND(L_padding); 2579 __ decrementq(output_size, 1); 2580 __ shrq(rax, 1); 2581 2582 __ cmpb(Address(source, length, Address::times_1, -2), '='); 2583 __ jcc(Assembler::notEqual, L_donePadding); 2584 2585 __ decrementq(output_size, 1); 2586 __ shrq(rax, 1); 2587 __ jmp(L_donePadding); 2588 2589 __ align32(); 2590 __ BIND(L_bruteForce); 2591 } // End of if(avx512_vbmi) 2592 2593 // Use non-AVX code to decode 4-byte chunks into 3 bytes of output 2594 2595 // Register state (Linux): 2596 // r12-15 - saved on stack 2597 // rdi - src 2598 // rsi - sp 2599 // rdx - sl 2600 // rcx - dst 2601 // r8 - dp 2602 // r9 - isURL 2603 2604 // Register state (Windows): 2605 // r12-15 - saved on stack 2606 // rcx - src 2607 // rdx - sp 2608 // r8 - sl 2609 // r9 - dst 2610 // r12 - dp 2611 // r10 - isURL 2612 2613 // Registers (common): 2614 // length (r14) - bytes in src 2615 2616 const Register decode_table = r11; 2617 const Register out_byte_count = rbx; 2618 const Register byte1 = r13; 2619 const Register byte2 = r15; 2620 const Register byte3 = WIN64_ONLY(r8) NOT_WIN64(rdx); 2621 const Register byte4 = WIN64_ONLY(r10) NOT_WIN64(r9); 2622 2623 __ shrl(length, 2); // Multiple of 4 bytes only - length is # 4-byte chunks 2624 __ cmpl(length, 0); 2625 __ jcc(Assembler::lessEqual, L_exit_no_vzero); 2626 2627 __ shll(isURL, 8); // index into decode table based on isURL 2628 __ lea(decode_table, ExternalAddress(StubRoutines::x86::base64_decoding_table_addr())); 2629 __ addptr(decode_table, isURL); 2630 2631 __ jmp(L_bottomLoop); 2632 2633 __ align32(); 2634 __ BIND(L_forceLoop); 2635 __ shll(byte1, 18); 2636 __ shll(byte2, 12); 2637 __ shll(byte3, 6); 2638 __ orl(byte1, byte2); 2639 __ orl(byte1, byte3); 2640 __ orl(byte1, byte4); 2641 2642 __ addptr(source, 4); 2643 2644 __ movb(Address(dest, dp, Address::times_1, 2), byte1); 2645 __ shrl(byte1, 8); 2646 __ movb(Address(dest, dp, Address::times_1, 1), byte1); 2647 __ shrl(byte1, 8); 2648 __ movb(Address(dest, dp, Address::times_1, 0), byte1); 2649 2650 __ addptr(dest, 3); 2651 __ decrementl(length, 1); 2652 __ jcc(Assembler::zero, L_exit_no_vzero); 2653 2654 __ BIND(L_bottomLoop); 2655 __ load_unsigned_byte(byte1, Address(source, start_offset, Address::times_1, 0x00)); 2656 __ load_unsigned_byte(byte2, Address(source, start_offset, Address::times_1, 0x01)); 2657 __ load_signed_byte(byte1, Address(decode_table, byte1)); 2658 __ load_signed_byte(byte2, Address(decode_table, byte2)); 2659 __ load_unsigned_byte(byte3, Address(source, start_offset, Address::times_1, 0x02)); 2660 __ load_unsigned_byte(byte4, Address(source, start_offset, Address::times_1, 0x03)); 2661 __ load_signed_byte(byte3, Address(decode_table, byte3)); 2662 __ load_signed_byte(byte4, Address(decode_table, byte4)); 2663 2664 __ mov(rax, byte1); 2665 __ orl(rax, byte2); 2666 __ orl(rax, byte3); 2667 __ orl(rax, byte4); 2668 __ jcc(Assembler::positive, L_forceLoop); 2669 2670 __ BIND(L_exit_no_vzero); 2671 __ pop(rax); // Get original dest value 2672 __ subptr(dest, rax); // Number of bytes converted 2673 __ movptr(rax, dest); 2674 __ pop(rbx); 2675 __ pop(r15); 2676 __ pop(r14); 2677 __ pop(r13); 2678 __ pop(r12); 2679 __ leave(); 2680 __ ret(0); 2681 2682 return start; 2683 } 2684 2685 2686 /** 2687 * Arguments: 2688 * 2689 * Inputs: 2690 * c_rarg0 - int crc 2691 * c_rarg1 - byte* buf 2692 * c_rarg2 - int length 2693 * 2694 * Output: 2695 * rax - int crc result 2696 */ 2697 address StubGenerator::generate_updateBytesCRC32() { 2698 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions"); 2699 2700 __ align(CodeEntryAlignment); 2701 StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32"); 2702 2703 address start = __ pc(); 2704 2705 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) 2706 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...) 2707 // rscratch1: r10 2708 const Register crc = c_rarg0; // crc 2709 const Register buf = c_rarg1; // source java byte array address 2710 const Register len = c_rarg2; // length 2711 const Register table = c_rarg3; // crc_table address (reuse register) 2712 const Register tmp1 = r11; 2713 const Register tmp2 = r10; 2714 assert_different_registers(crc, buf, len, table, tmp1, tmp2, rax); 2715 2716 BLOCK_COMMENT("Entry:"); 2717 __ enter(); // required for proper stackwalking of RuntimeStub frame 2718 2719 if (VM_Version::supports_sse4_1() && VM_Version::supports_avx512_vpclmulqdq() && 2720 VM_Version::supports_avx512bw() && 2721 VM_Version::supports_avx512vl()) { 2722 // The constants used in the CRC32 algorithm requires the 1's compliment of the initial crc value. 2723 // However, the constant table for CRC32-C assumes the original crc value. Account for this 2724 // difference before calling and after returning. 2725 __ lea(table, ExternalAddress(StubRoutines::x86::crc_table_avx512_addr())); 2726 __ notl(crc); 2727 __ kernel_crc32_avx512(crc, buf, len, table, tmp1, tmp2); 2728 __ notl(crc); 2729 } else { 2730 __ kernel_crc32(crc, buf, len, table, tmp1); 2731 } 2732 2733 __ movl(rax, crc); 2734 __ vzeroupper(); 2735 __ leave(); // required for proper stackwalking of RuntimeStub frame 2736 __ ret(0); 2737 2738 return start; 2739 } 2740 2741 /** 2742 * Arguments: 2743 * 2744 * Inputs: 2745 * c_rarg0 - int crc 2746 * c_rarg1 - byte* buf 2747 * c_rarg2 - long length 2748 * c_rarg3 - table_start - optional (present only when doing a library_call, 2749 * not used by x86 algorithm) 2750 * 2751 * Output: 2752 * rax - int crc result 2753 */ 2754 address StubGenerator::generate_updateBytesCRC32C(bool is_pclmulqdq_supported) { 2755 assert(UseCRC32CIntrinsics, "need SSE4_2"); 2756 __ align(CodeEntryAlignment); 2757 StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32C"); 2758 address start = __ pc(); 2759 2760 //reg.arg int#0 int#1 int#2 int#3 int#4 int#5 float regs 2761 //Windows RCX RDX R8 R9 none none XMM0..XMM3 2762 //Lin / Sol RDI RSI RDX RCX R8 R9 XMM0..XMM7 2763 const Register crc = c_rarg0; // crc 2764 const Register buf = c_rarg1; // source java byte array address 2765 const Register len = c_rarg2; // length 2766 const Register a = rax; 2767 const Register j = r9; 2768 const Register k = r10; 2769 const Register l = r11; 2770 #ifdef _WIN64 2771 const Register y = rdi; 2772 const Register z = rsi; 2773 #else 2774 const Register y = rcx; 2775 const Register z = r8; 2776 #endif 2777 assert_different_registers(crc, buf, len, a, j, k, l, y, z); 2778 2779 BLOCK_COMMENT("Entry:"); 2780 __ enter(); // required for proper stackwalking of RuntimeStub frame 2781 if (VM_Version::supports_sse4_1() && VM_Version::supports_avx512_vpclmulqdq() && 2782 VM_Version::supports_avx512bw() && 2783 VM_Version::supports_avx512vl()) { 2784 __ lea(j, ExternalAddress(StubRoutines::x86::crc32c_table_avx512_addr())); 2785 __ kernel_crc32_avx512(crc, buf, len, j, l, k); 2786 } else { 2787 #ifdef _WIN64 2788 __ push(y); 2789 __ push(z); 2790 #endif 2791 __ crc32c_ipl_alg2_alt2(crc, buf, len, 2792 a, j, k, 2793 l, y, z, 2794 c_farg0, c_farg1, c_farg2, 2795 is_pclmulqdq_supported); 2796 #ifdef _WIN64 2797 __ pop(z); 2798 __ pop(y); 2799 #endif 2800 } 2801 __ movl(rax, crc); 2802 __ vzeroupper(); 2803 __ leave(); // required for proper stackwalking of RuntimeStub frame 2804 __ ret(0); 2805 2806 return start; 2807 } 2808 2809 2810 /** 2811 * Arguments: 2812 * 2813 * Input: 2814 * c_rarg0 - x address 2815 * c_rarg1 - x length 2816 * c_rarg2 - y address 2817 * c_rarg3 - y length 2818 * not Win64 2819 * c_rarg4 - z address 2820 * c_rarg5 - z length 2821 * Win64 2822 * rsp+40 - z address 2823 * rsp+48 - z length 2824 */ 2825 address StubGenerator::generate_multiplyToLen() { 2826 __ align(CodeEntryAlignment); 2827 StubCodeMark mark(this, "StubRoutines", "multiplyToLen"); 2828 address start = __ pc(); 2829 2830 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) 2831 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...) 2832 const Register x = rdi; 2833 const Register xlen = rax; 2834 const Register y = rsi; 2835 const Register ylen = rcx; 2836 const Register z = r8; 2837 const Register zlen = r11; 2838 2839 // Next registers will be saved on stack in multiply_to_len(). 2840 const Register tmp1 = r12; 2841 const Register tmp2 = r13; 2842 const Register tmp3 = r14; 2843 const Register tmp4 = r15; 2844 const Register tmp5 = rbx; 2845 2846 BLOCK_COMMENT("Entry:"); 2847 __ enter(); // required for proper stackwalking of RuntimeStub frame 2848 2849 #ifndef _WIN64 2850 __ movptr(zlen, r9); // Save r9 in r11 - zlen 2851 #endif 2852 setup_arg_regs(4); // x => rdi, xlen => rsi, y => rdx 2853 // ylen => rcx, z => r8, zlen => r11 2854 // r9 and r10 may be used to save non-volatile registers 2855 #ifdef _WIN64 2856 // last 2 arguments (#4, #5) are on stack on Win64 2857 __ movptr(z, Address(rsp, 6 * wordSize)); 2858 __ movptr(zlen, Address(rsp, 7 * wordSize)); 2859 #endif 2860 2861 __ movptr(xlen, rsi); 2862 __ movptr(y, rdx); 2863 __ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5); 2864 2865 restore_arg_regs(); 2866 2867 __ leave(); // required for proper stackwalking of RuntimeStub frame 2868 __ ret(0); 2869 2870 return start; 2871 } 2872 2873 /** 2874 * Arguments: 2875 * 2876 * Input: 2877 * c_rarg0 - obja address 2878 * c_rarg1 - objb address 2879 * c_rarg3 - length length 2880 * c_rarg4 - scale log2_array_indxscale 2881 * 2882 * Output: 2883 * rax - int >= mismatched index, < 0 bitwise complement of tail 2884 */ 2885 address StubGenerator::generate_vectorizedMismatch() { 2886 __ align(CodeEntryAlignment); 2887 StubCodeMark mark(this, "StubRoutines", "vectorizedMismatch"); 2888 address start = __ pc(); 2889 2890 BLOCK_COMMENT("Entry:"); 2891 __ enter(); 2892 2893 #ifdef _WIN64 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) 2894 const Register scale = c_rarg0; //rcx, will exchange with r9 2895 const Register objb = c_rarg1; //rdx 2896 const Register length = c_rarg2; //r8 2897 const Register obja = c_rarg3; //r9 2898 __ xchgq(obja, scale); //now obja and scale contains the correct contents 2899 2900 const Register tmp1 = r10; 2901 const Register tmp2 = r11; 2902 #endif 2903 #ifndef _WIN64 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...) 2904 const Register obja = c_rarg0; //U:rdi 2905 const Register objb = c_rarg1; //U:rsi 2906 const Register length = c_rarg2; //U:rdx 2907 const Register scale = c_rarg3; //U:rcx 2908 const Register tmp1 = r8; 2909 const Register tmp2 = r9; 2910 #endif 2911 const Register result = rax; //return value 2912 const XMMRegister vec0 = xmm0; 2913 const XMMRegister vec1 = xmm1; 2914 const XMMRegister vec2 = xmm2; 2915 2916 __ vectorized_mismatch(obja, objb, length, scale, result, tmp1, tmp2, vec0, vec1, vec2); 2917 2918 __ vzeroupper(); 2919 __ leave(); 2920 __ ret(0); 2921 2922 return start; 2923 } 2924 2925 /** 2926 * Arguments: 2927 * 2928 // Input: 2929 // c_rarg0 - x address 2930 // c_rarg1 - x length 2931 // c_rarg2 - z address 2932 // c_rarg3 - z length 2933 * 2934 */ 2935 address StubGenerator::generate_squareToLen() { 2936 2937 __ align(CodeEntryAlignment); 2938 StubCodeMark mark(this, "StubRoutines", "squareToLen"); 2939 address start = __ pc(); 2940 2941 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) 2942 // Unix: rdi, rsi, rdx, rcx (c_rarg0, c_rarg1, ...) 2943 const Register x = rdi; 2944 const Register len = rsi; 2945 const Register z = r8; 2946 const Register zlen = rcx; 2947 2948 const Register tmp1 = r12; 2949 const Register tmp2 = r13; 2950 const Register tmp3 = r14; 2951 const Register tmp4 = r15; 2952 const Register tmp5 = rbx; 2953 2954 BLOCK_COMMENT("Entry:"); 2955 __ enter(); // required for proper stackwalking of RuntimeStub frame 2956 2957 setup_arg_regs(4); // x => rdi, len => rsi, z => rdx 2958 // zlen => rcx 2959 // r9 and r10 may be used to save non-volatile registers 2960 __ movptr(r8, rdx); 2961 __ square_to_len(x, len, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, rdx, rax); 2962 2963 restore_arg_regs(); 2964 2965 __ leave(); // required for proper stackwalking of RuntimeStub frame 2966 __ ret(0); 2967 2968 return start; 2969 } 2970 2971 address StubGenerator::generate_method_entry_barrier() { 2972 __ align(CodeEntryAlignment); 2973 StubCodeMark mark(this, "StubRoutines", "nmethod_entry_barrier"); 2974 address start = __ pc(); 2975 2976 Label deoptimize_label; 2977 2978 __ push(-1); // cookie, this is used for writing the new rsp when deoptimizing 2979 2980 BLOCK_COMMENT("Entry:"); 2981 __ enter(); // save rbp 2982 2983 // save c_rarg0, because we want to use that value. 2984 // We could do without it but then we depend on the number of slots used by pusha 2985 __ push(c_rarg0); 2986 2987 __ lea(c_rarg0, Address(rsp, wordSize * 3)); // 1 for cookie, 1 for rbp, 1 for c_rarg0 - this should be the return address 2988 2989 __ pusha(); 2990 2991 // The method may have floats as arguments, and we must spill them before calling 2992 // the VM runtime. 2993 assert(Argument::n_float_register_parameters_j == 8, "Assumption"); 2994 const int xmm_size = wordSize * 2; 2995 const int xmm_spill_size = xmm_size * Argument::n_float_register_parameters_j; 2996 __ subptr(rsp, xmm_spill_size); 2997 __ movdqu(Address(rsp, xmm_size * 7), xmm7); 2998 __ movdqu(Address(rsp, xmm_size * 6), xmm6); 2999 __ movdqu(Address(rsp, xmm_size * 5), xmm5); 3000 __ movdqu(Address(rsp, xmm_size * 4), xmm4); 3001 __ movdqu(Address(rsp, xmm_size * 3), xmm3); 3002 __ movdqu(Address(rsp, xmm_size * 2), xmm2); 3003 __ movdqu(Address(rsp, xmm_size * 1), xmm1); 3004 __ movdqu(Address(rsp, xmm_size * 0), xmm0); 3005 3006 __ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(address*)>(BarrierSetNMethod::nmethod_stub_entry_barrier)), 1); 3007 3008 __ movdqu(xmm0, Address(rsp, xmm_size * 0)); 3009 __ movdqu(xmm1, Address(rsp, xmm_size * 1)); 3010 __ movdqu(xmm2, Address(rsp, xmm_size * 2)); 3011 __ movdqu(xmm3, Address(rsp, xmm_size * 3)); 3012 __ movdqu(xmm4, Address(rsp, xmm_size * 4)); 3013 __ movdqu(xmm5, Address(rsp, xmm_size * 5)); 3014 __ movdqu(xmm6, Address(rsp, xmm_size * 6)); 3015 __ movdqu(xmm7, Address(rsp, xmm_size * 7)); 3016 __ addptr(rsp, xmm_spill_size); 3017 3018 __ cmpl(rax, 1); // 1 means deoptimize 3019 __ jcc(Assembler::equal, deoptimize_label); 3020 3021 __ popa(); 3022 __ pop(c_rarg0); 3023 3024 __ leave(); 3025 3026 __ addptr(rsp, 1 * wordSize); // cookie 3027 __ ret(0); 3028 3029 3030 __ BIND(deoptimize_label); 3031 3032 __ popa(); 3033 __ pop(c_rarg0); 3034 3035 __ leave(); 3036 3037 // this can be taken out, but is good for verification purposes. getting a SIGSEGV 3038 // here while still having a correct stack is valuable 3039 __ testptr(rsp, Address(rsp, 0)); 3040 3041 __ movptr(rsp, Address(rsp, 0)); // new rsp was written in the barrier 3042 __ jmp(Address(rsp, -1 * wordSize)); // jmp target should be callers verified_entry_point 3043 3044 return start; 3045 } 3046 3047 /** 3048 * Arguments: 3049 * 3050 * Input: 3051 * c_rarg0 - out address 3052 * c_rarg1 - in address 3053 * c_rarg2 - offset 3054 * c_rarg3 - len 3055 * not Win64 3056 * c_rarg4 - k 3057 * Win64 3058 * rsp+40 - k 3059 */ 3060 address StubGenerator::generate_mulAdd() { 3061 __ align(CodeEntryAlignment); 3062 StubCodeMark mark(this, "StubRoutines", "mulAdd"); 3063 address start = __ pc(); 3064 3065 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) 3066 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...) 3067 const Register out = rdi; 3068 const Register in = rsi; 3069 const Register offset = r11; 3070 const Register len = rcx; 3071 const Register k = r8; 3072 3073 // Next registers will be saved on stack in mul_add(). 3074 const Register tmp1 = r12; 3075 const Register tmp2 = r13; 3076 const Register tmp3 = r14; 3077 const Register tmp4 = r15; 3078 const Register tmp5 = rbx; 3079 3080 BLOCK_COMMENT("Entry:"); 3081 __ enter(); // required for proper stackwalking of RuntimeStub frame 3082 3083 setup_arg_regs(4); // out => rdi, in => rsi, offset => rdx 3084 // len => rcx, k => r8 3085 // r9 and r10 may be used to save non-volatile registers 3086 #ifdef _WIN64 3087 // last argument is on stack on Win64 3088 __ movl(k, Address(rsp, 6 * wordSize)); 3089 #endif 3090 __ movptr(r11, rdx); // move offset in rdx to offset(r11) 3091 __ mul_add(out, in, offset, len, k, tmp1, tmp2, tmp3, tmp4, tmp5, rdx, rax); 3092 3093 restore_arg_regs(); 3094 3095 __ leave(); // required for proper stackwalking of RuntimeStub frame 3096 __ ret(0); 3097 3098 return start; 3099 } 3100 3101 address StubGenerator::generate_bigIntegerRightShift() { 3102 __ align(CodeEntryAlignment); 3103 StubCodeMark mark(this, "StubRoutines", "bigIntegerRightShiftWorker"); 3104 address start = __ pc(); 3105 3106 Label Shift512Loop, ShiftTwo, ShiftTwoLoop, ShiftOne, Exit; 3107 // For Unix, the arguments are as follows: rdi, rsi, rdx, rcx, r8. 3108 const Register newArr = rdi; 3109 const Register oldArr = rsi; 3110 const Register newIdx = rdx; 3111 const Register shiftCount = rcx; // It was intentional to have shiftCount in rcx since it is used implicitly for shift. 3112 const Register totalNumIter = r8; 3113 3114 // For windows, we use r9 and r10 as temps to save rdi and rsi. Thus we cannot allocate them for our temps. 3115 // For everything else, we prefer using r9 and r10 since we do not have to save them before use. 3116 const Register tmp1 = r11; // Caller save. 3117 const Register tmp2 = rax; // Caller save. 3118 const Register tmp3 = WIN64_ONLY(r12) NOT_WIN64(r9); // Windows: Callee save. Linux: Caller save. 3119 const Register tmp4 = WIN64_ONLY(r13) NOT_WIN64(r10); // Windows: Callee save. Linux: Caller save. 3120 const Register tmp5 = r14; // Callee save. 3121 const Register tmp6 = r15; 3122 3123 const XMMRegister x0 = xmm0; 3124 const XMMRegister x1 = xmm1; 3125 const XMMRegister x2 = xmm2; 3126 3127 BLOCK_COMMENT("Entry:"); 3128 __ enter(); // required for proper stackwalking of RuntimeStub frame 3129 3130 #ifdef _WIN64 3131 setup_arg_regs(4); 3132 // For windows, since last argument is on stack, we need to move it to the appropriate register. 3133 __ movl(totalNumIter, Address(rsp, 6 * wordSize)); 3134 // Save callee save registers. 3135 __ push(tmp3); 3136 __ push(tmp4); 3137 #endif 3138 __ push(tmp5); 3139 3140 // Rename temps used throughout the code. 3141 const Register idx = tmp1; 3142 const Register nIdx = tmp2; 3143 3144 __ xorl(idx, idx); 3145 3146 // Start right shift from end of the array. 3147 // For example, if #iteration = 4 and newIdx = 1 3148 // then dest[4] = src[4] >> shiftCount | src[3] <<< (shiftCount - 32) 3149 // if #iteration = 4 and newIdx = 0 3150 // then dest[3] = src[4] >> shiftCount | src[3] <<< (shiftCount - 32) 3151 __ movl(idx, totalNumIter); 3152 __ movl(nIdx, idx); 3153 __ addl(nIdx, newIdx); 3154 3155 // If vectorization is enabled, check if the number of iterations is at least 64 3156 // If not, then go to ShifTwo processing 2 iterations 3157 if (VM_Version::supports_avx512_vbmi2()) { 3158 __ cmpptr(totalNumIter, (AVX3Threshold/64)); 3159 __ jcc(Assembler::less, ShiftTwo); 3160 3161 if (AVX3Threshold < 16 * 64) { 3162 __ cmpl(totalNumIter, 16); 3163 __ jcc(Assembler::less, ShiftTwo); 3164 } 3165 __ evpbroadcastd(x0, shiftCount, Assembler::AVX_512bit); 3166 __ subl(idx, 16); 3167 __ subl(nIdx, 16); 3168 __ BIND(Shift512Loop); 3169 __ evmovdqul(x2, Address(oldArr, idx, Address::times_4, 4), Assembler::AVX_512bit); 3170 __ evmovdqul(x1, Address(oldArr, idx, Address::times_4), Assembler::AVX_512bit); 3171 __ vpshrdvd(x2, x1, x0, Assembler::AVX_512bit); 3172 __ evmovdqul(Address(newArr, nIdx, Address::times_4), x2, Assembler::AVX_512bit); 3173 __ subl(nIdx, 16); 3174 __ subl(idx, 16); 3175 __ jcc(Assembler::greaterEqual, Shift512Loop); 3176 __ addl(idx, 16); 3177 __ addl(nIdx, 16); 3178 } 3179 __ BIND(ShiftTwo); 3180 __ cmpl(idx, 2); 3181 __ jcc(Assembler::less, ShiftOne); 3182 __ subl(idx, 2); 3183 __ subl(nIdx, 2); 3184 __ BIND(ShiftTwoLoop); 3185 __ movl(tmp5, Address(oldArr, idx, Address::times_4, 8)); 3186 __ movl(tmp4, Address(oldArr, idx, Address::times_4, 4)); 3187 __ movl(tmp3, Address(oldArr, idx, Address::times_4)); 3188 __ shrdl(tmp5, tmp4); 3189 __ shrdl(tmp4, tmp3); 3190 __ movl(Address(newArr, nIdx, Address::times_4, 4), tmp5); 3191 __ movl(Address(newArr, nIdx, Address::times_4), tmp4); 3192 __ subl(nIdx, 2); 3193 __ subl(idx, 2); 3194 __ jcc(Assembler::greaterEqual, ShiftTwoLoop); 3195 __ addl(idx, 2); 3196 __ addl(nIdx, 2); 3197 3198 // Do the last iteration 3199 __ BIND(ShiftOne); 3200 __ cmpl(idx, 1); 3201 __ jcc(Assembler::less, Exit); 3202 __ subl(idx, 1); 3203 __ subl(nIdx, 1); 3204 __ movl(tmp4, Address(oldArr, idx, Address::times_4, 4)); 3205 __ movl(tmp3, Address(oldArr, idx, Address::times_4)); 3206 __ shrdl(tmp4, tmp3); 3207 __ movl(Address(newArr, nIdx, Address::times_4), tmp4); 3208 __ BIND(Exit); 3209 __ vzeroupper(); 3210 // Restore callee save registers. 3211 __ pop(tmp5); 3212 #ifdef _WIN64 3213 __ pop(tmp4); 3214 __ pop(tmp3); 3215 restore_arg_regs(); 3216 #endif 3217 __ leave(); // required for proper stackwalking of RuntimeStub frame 3218 __ ret(0); 3219 3220 return start; 3221 } 3222 3223 /** 3224 * Arguments: 3225 * 3226 * Input: 3227 * c_rarg0 - newArr address 3228 * c_rarg1 - oldArr address 3229 * c_rarg2 - newIdx 3230 * c_rarg3 - shiftCount 3231 * not Win64 3232 * c_rarg4 - numIter 3233 * Win64 3234 * rsp40 - numIter 3235 */ 3236 address StubGenerator::generate_bigIntegerLeftShift() { 3237 __ align(CodeEntryAlignment); 3238 StubCodeMark mark(this, "StubRoutines", "bigIntegerLeftShiftWorker"); 3239 address start = __ pc(); 3240 3241 Label Shift512Loop, ShiftTwo, ShiftTwoLoop, ShiftOne, Exit; 3242 // For Unix, the arguments are as follows: rdi, rsi, rdx, rcx, r8. 3243 const Register newArr = rdi; 3244 const Register oldArr = rsi; 3245 const Register newIdx = rdx; 3246 const Register shiftCount = rcx; // It was intentional to have shiftCount in rcx since it is used implicitly for shift. 3247 const Register totalNumIter = r8; 3248 // For windows, we use r9 and r10 as temps to save rdi and rsi. Thus we cannot allocate them for our temps. 3249 // For everything else, we prefer using r9 and r10 since we do not have to save them before use. 3250 const Register tmp1 = r11; // Caller save. 3251 const Register tmp2 = rax; // Caller save. 3252 const Register tmp3 = WIN64_ONLY(r12) NOT_WIN64(r9); // Windows: Callee save. Linux: Caller save. 3253 const Register tmp4 = WIN64_ONLY(r13) NOT_WIN64(r10); // Windows: Callee save. Linux: Caller save. 3254 const Register tmp5 = r14; // Callee save. 3255 3256 const XMMRegister x0 = xmm0; 3257 const XMMRegister x1 = xmm1; 3258 const XMMRegister x2 = xmm2; 3259 BLOCK_COMMENT("Entry:"); 3260 __ enter(); // required for proper stackwalking of RuntimeStub frame 3261 3262 #ifdef _WIN64 3263 setup_arg_regs(4); 3264 // For windows, since last argument is on stack, we need to move it to the appropriate register. 3265 __ movl(totalNumIter, Address(rsp, 6 * wordSize)); 3266 // Save callee save registers. 3267 __ push(tmp3); 3268 __ push(tmp4); 3269 #endif 3270 __ push(tmp5); 3271 3272 // Rename temps used throughout the code 3273 const Register idx = tmp1; 3274 const Register numIterTmp = tmp2; 3275 3276 // Start idx from zero. 3277 __ xorl(idx, idx); 3278 // Compute interior pointer for new array. We do this so that we can use same index for both old and new arrays. 3279 __ lea(newArr, Address(newArr, newIdx, Address::times_4)); 3280 __ movl(numIterTmp, totalNumIter); 3281 3282 // If vectorization is enabled, check if the number of iterations is at least 64 3283 // If not, then go to ShiftTwo shifting two numbers at a time 3284 if (VM_Version::supports_avx512_vbmi2()) { 3285 __ cmpl(totalNumIter, (AVX3Threshold/64)); 3286 __ jcc(Assembler::less, ShiftTwo); 3287 3288 if (AVX3Threshold < 16 * 64) { 3289 __ cmpl(totalNumIter, 16); 3290 __ jcc(Assembler::less, ShiftTwo); 3291 } 3292 __ evpbroadcastd(x0, shiftCount, Assembler::AVX_512bit); 3293 __ subl(numIterTmp, 16); 3294 __ BIND(Shift512Loop); 3295 __ evmovdqul(x1, Address(oldArr, idx, Address::times_4), Assembler::AVX_512bit); 3296 __ evmovdqul(x2, Address(oldArr, idx, Address::times_4, 0x4), Assembler::AVX_512bit); 3297 __ vpshldvd(x1, x2, x0, Assembler::AVX_512bit); 3298 __ evmovdqul(Address(newArr, idx, Address::times_4), x1, Assembler::AVX_512bit); 3299 __ addl(idx, 16); 3300 __ subl(numIterTmp, 16); 3301 __ jcc(Assembler::greaterEqual, Shift512Loop); 3302 __ addl(numIterTmp, 16); 3303 } 3304 __ BIND(ShiftTwo); 3305 __ cmpl(totalNumIter, 1); 3306 __ jcc(Assembler::less, Exit); 3307 __ movl(tmp3, Address(oldArr, idx, Address::times_4)); 3308 __ subl(numIterTmp, 2); 3309 __ jcc(Assembler::less, ShiftOne); 3310 3311 __ BIND(ShiftTwoLoop); 3312 __ movl(tmp4, Address(oldArr, idx, Address::times_4, 0x4)); 3313 __ movl(tmp5, Address(oldArr, idx, Address::times_4, 0x8)); 3314 __ shldl(tmp3, tmp4); 3315 __ shldl(tmp4, tmp5); 3316 __ movl(Address(newArr, idx, Address::times_4), tmp3); 3317 __ movl(Address(newArr, idx, Address::times_4, 0x4), tmp4); 3318 __ movl(tmp3, tmp5); 3319 __ addl(idx, 2); 3320 __ subl(numIterTmp, 2); 3321 __ jcc(Assembler::greaterEqual, ShiftTwoLoop); 3322 3323 // Do the last iteration 3324 __ BIND(ShiftOne); 3325 __ addl(numIterTmp, 2); 3326 __ cmpl(numIterTmp, 1); 3327 __ jcc(Assembler::less, Exit); 3328 __ movl(tmp4, Address(oldArr, idx, Address::times_4, 0x4)); 3329 __ shldl(tmp3, tmp4); 3330 __ movl(Address(newArr, idx, Address::times_4), tmp3); 3331 3332 __ BIND(Exit); 3333 __ vzeroupper(); 3334 // Restore callee save registers. 3335 __ pop(tmp5); 3336 #ifdef _WIN64 3337 __ pop(tmp4); 3338 __ pop(tmp3); 3339 restore_arg_regs(); 3340 #endif 3341 __ leave(); // required for proper stackwalking of RuntimeStub frame 3342 __ ret(0); 3343 3344 return start; 3345 } 3346 3347 void StubGenerator::generate_libm_stubs() { 3348 if (UseLibmIntrinsic && InlineIntrinsics) { 3349 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dsin)) { 3350 StubRoutines::_dsin = generate_libmSin(); // from stubGenerator_x86_64_sin.cpp 3351 } 3352 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dcos)) { 3353 StubRoutines::_dcos = generate_libmCos(); // from stubGenerator_x86_64_cos.cpp 3354 } 3355 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) { 3356 StubRoutines::_dtan = generate_libmTan(); // from stubGenerator_x86_64_tan.cpp 3357 } 3358 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dexp)) { 3359 StubRoutines::_dexp = generate_libmExp(); // from stubGenerator_x86_64_exp.cpp 3360 } 3361 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dpow)) { 3362 StubRoutines::_dpow = generate_libmPow(); // from stubGenerator_x86_64_pow.cpp 3363 } 3364 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dlog)) { 3365 StubRoutines::_dlog = generate_libmLog(); // from stubGenerator_x86_64_log.cpp 3366 } 3367 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dlog10)) { 3368 StubRoutines::_dlog10 = generate_libmLog10(); // from stubGenerator_x86_64_log.cpp 3369 } 3370 } 3371 } 3372 3373 3374 address StubGenerator::generate_cont_thaw(const char* label, Continuation::thaw_kind kind) { 3375 if (!Continuations::enabled()) return nullptr; 3376 3377 bool return_barrier = Continuation::is_thaw_return_barrier(kind); 3378 bool return_barrier_exception = Continuation::is_thaw_return_barrier_exception(kind); 3379 3380 StubCodeMark mark(this, "StubRoutines", label); 3381 address start = __ pc(); 3382 3383 // TODO: Handle Valhalla return types. May require generating different return barriers. 3384 3385 if (!return_barrier) { 3386 // Pop return address. If we don't do this, we get a drift, 3387 // where the bottom-most frozen frame continuously grows. 3388 __ pop(c_rarg3); 3389 } else { 3390 __ movptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset())); 3391 } 3392 3393 #ifdef ASSERT 3394 { 3395 Label L_good_sp; 3396 __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset())); 3397 __ jcc(Assembler::equal, L_good_sp); 3398 __ stop("Incorrect rsp at thaw entry"); 3399 __ BIND(L_good_sp); 3400 } 3401 #endif // ASSERT 3402 3403 if (return_barrier) { 3404 // Preserve possible return value from a method returning to the return barrier. 3405 __ push(rax); 3406 __ push_d(xmm0); 3407 } 3408 3409 __ movptr(c_rarg0, r15_thread); 3410 __ movptr(c_rarg1, (return_barrier ? 1 : 0)); 3411 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Continuation::prepare_thaw), 2); 3412 __ movptr(rbx, rax); 3413 3414 if (return_barrier) { 3415 // Restore return value from a method returning to the return barrier. 3416 // No safepoint in the call to thaw, so even an oop return value should be OK. 3417 __ pop_d(xmm0); 3418 __ pop(rax); 3419 } 3420 3421 #ifdef ASSERT 3422 { 3423 Label L_good_sp; 3424 __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset())); 3425 __ jcc(Assembler::equal, L_good_sp); 3426 __ stop("Incorrect rsp after prepare thaw"); 3427 __ BIND(L_good_sp); 3428 } 3429 #endif // ASSERT 3430 3431 // rbx contains the size of the frames to thaw, 0 if overflow or no more frames 3432 Label L_thaw_success; 3433 __ testptr(rbx, rbx); 3434 __ jccb(Assembler::notZero, L_thaw_success); 3435 __ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry())); 3436 __ bind(L_thaw_success); 3437 3438 // Make room for the thawed frames and align the stack. 3439 __ subptr(rsp, rbx); 3440 __ andptr(rsp, -StackAlignmentInBytes); 3441 3442 if (return_barrier) { 3443 // Preserve possible return value from a method returning to the return barrier. (Again.) 3444 __ push(rax); 3445 __ push_d(xmm0); 3446 } 3447 3448 // If we want, we can templatize thaw by kind, and have three different entries. 3449 __ movptr(c_rarg0, r15_thread); 3450 __ movptr(c_rarg1, kind); 3451 __ call_VM_leaf(Continuation::thaw_entry(), 2); 3452 __ movptr(rbx, rax); 3453 3454 if (return_barrier) { 3455 // Restore return value from a method returning to the return barrier. (Again.) 3456 // No safepoint in the call to thaw, so even an oop return value should be OK. 3457 __ pop_d(xmm0); 3458 __ pop(rax); 3459 } else { 3460 // Return 0 (success) from doYield. 3461 __ xorptr(rax, rax); 3462 } 3463 3464 // After thawing, rbx is the SP of the yielding frame. 3465 // Move there, and then to saved RBP slot. 3466 __ movptr(rsp, rbx); 3467 __ subptr(rsp, 2*wordSize); 3468 3469 if (return_barrier_exception) { 3470 __ movptr(c_rarg0, r15_thread); 3471 __ movptr(c_rarg1, Address(rsp, wordSize)); // return address 3472 3473 // rax still holds the original exception oop, save it before the call 3474 __ push(rax); 3475 3476 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), 2); 3477 __ movptr(rbx, rax); 3478 3479 // Continue at exception handler: 3480 // rax: exception oop 3481 // rbx: exception handler 3482 // rdx: exception pc 3483 __ pop(rax); 3484 __ verify_oop(rax); 3485 __ pop(rbp); // pop out RBP here too 3486 __ pop(rdx); 3487 __ jmp(rbx); 3488 } else { 3489 // We are "returning" into the topmost thawed frame; see Thaw::push_return_frame 3490 __ pop(rbp); 3491 __ ret(0); 3492 } 3493 3494 return start; 3495 } 3496 3497 address StubGenerator::generate_cont_thaw() { 3498 return generate_cont_thaw("Cont thaw", Continuation::thaw_top); 3499 } 3500 3501 // TODO: will probably need multiple return barriers depending on return type 3502 3503 address StubGenerator::generate_cont_returnBarrier() { 3504 return generate_cont_thaw("Cont thaw return barrier", Continuation::thaw_return_barrier); 3505 } 3506 3507 address StubGenerator::generate_cont_returnBarrier_exception() { 3508 return generate_cont_thaw("Cont thaw return barrier exception", Continuation::thaw_return_barrier_exception); 3509 } 3510 3511 #if INCLUDE_JFR 3512 3513 // For c2: c_rarg0 is junk, call to runtime to write a checkpoint. 3514 // It returns a jobject handle to the event writer. 3515 // The handle is dereferenced and the return value is the event writer oop. 3516 RuntimeStub* StubGenerator::generate_jfr_write_checkpoint() { 3517 enum layout { 3518 rbp_off, 3519 rbpH_off, 3520 return_off, 3521 return_off2, 3522 framesize // inclusive of return address 3523 }; 3524 3525 CodeBuffer code("jfr_write_checkpoint", 512, 64); 3526 MacroAssembler* _masm = new MacroAssembler(&code); 3527 address start = __ pc(); 3528 3529 __ enter(); 3530 address the_pc = __ pc(); 3531 3532 int frame_complete = the_pc - start; 3533 3534 __ set_last_Java_frame(rsp, rbp, the_pc, rscratch1); 3535 __ movptr(c_rarg0, r15_thread); 3536 __ call_VM_leaf(CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::write_checkpoint), 1); 3537 __ reset_last_Java_frame(true); 3538 3539 // rax is jobject handle result, unpack and process it through a barrier. 3540 Label L_null_jobject; 3541 __ testptr(rax, rax); 3542 __ jcc(Assembler::zero, L_null_jobject); 3543 3544 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler(); 3545 bs->load_at(_masm, ACCESS_READ | IN_NATIVE, T_OBJECT, rax, Address(rax, 0), c_rarg0, r15_thread); 3546 3547 __ bind(L_null_jobject); 3548 3549 __ leave(); 3550 __ ret(0); 3551 3552 OopMapSet* oop_maps = new OopMapSet(); 3553 OopMap* map = new OopMap(framesize, 1); 3554 oop_maps->add_gc_map(frame_complete, map); 3555 3556 RuntimeStub* stub = 3557 RuntimeStub::new_runtime_stub(code.name(), 3558 &code, 3559 frame_complete, 3560 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 3561 oop_maps, 3562 false); 3563 return stub; 3564 } 3565 3566 #endif // INCLUDE_JFR 3567 3568 // Continuation point for throwing of implicit exceptions that are 3569 // not handled in the current activation. Fabricates an exception 3570 // oop and initiates normal exception dispatching in this 3571 // frame. Since we need to preserve callee-saved values (currently 3572 // only for C2, but done for C1 as well) we need a callee-saved oop 3573 // map and therefore have to make these stubs into RuntimeStubs 3574 // rather than BufferBlobs. If the compiler needs all registers to 3575 // be preserved between the fault point and the exception handler 3576 // then it must assume responsibility for that in 3577 // AbstractCompiler::continuation_for_implicit_null_exception or 3578 // continuation_for_implicit_division_by_zero_exception. All other 3579 // implicit exceptions (e.g., NullPointerException or 3580 // AbstractMethodError on entry) are either at call sites or 3581 // otherwise assume that stack unwinding will be initiated, so 3582 // caller saved registers were assumed volatile in the compiler. 3583 address StubGenerator::generate_throw_exception(const char* name, 3584 address runtime_entry, 3585 Register arg1, 3586 Register arg2) { 3587 // Information about frame layout at time of blocking runtime call. 3588 // Note that we only have to preserve callee-saved registers since 3589 // the compilers are responsible for supplying a continuation point 3590 // if they expect all registers to be preserved. 3591 enum layout { 3592 rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt, 3593 rbp_off2, 3594 return_off, 3595 return_off2, 3596 framesize // inclusive of return address 3597 }; 3598 3599 int insts_size = 512; 3600 int locs_size = 64; 3601 3602 CodeBuffer code(name, insts_size, locs_size); 3603 OopMapSet* oop_maps = new OopMapSet(); 3604 MacroAssembler* _masm = new MacroAssembler(&code); 3605 3606 address start = __ pc(); 3607 3608 // This is an inlined and slightly modified version of call_VM 3609 // which has the ability to fetch the return PC out of 3610 // thread-local storage and also sets up last_Java_sp slightly 3611 // differently than the real call_VM 3612 3613 __ enter(); // required for proper stackwalking of RuntimeStub frame 3614 3615 assert(is_even(framesize/2), "sp not 16-byte aligned"); 3616 3617 // return address and rbp are already in place 3618 __ subptr(rsp, (framesize-4) << LogBytesPerInt); // prolog 3619 3620 int frame_complete = __ pc() - start; 3621 3622 // Set up last_Java_sp and last_Java_fp 3623 address the_pc = __ pc(); 3624 __ set_last_Java_frame(rsp, rbp, the_pc, rscratch1); 3625 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack 3626 3627 // Call runtime 3628 if (arg1 != noreg) { 3629 assert(arg2 != c_rarg1, "clobbered"); 3630 __ movptr(c_rarg1, arg1); 3631 } 3632 if (arg2 != noreg) { 3633 __ movptr(c_rarg2, arg2); 3634 } 3635 __ movptr(c_rarg0, r15_thread); 3636 BLOCK_COMMENT("call runtime_entry"); 3637 __ call(RuntimeAddress(runtime_entry)); 3638 3639 // Generate oop map 3640 OopMap* map = new OopMap(framesize, 0); 3641 3642 oop_maps->add_gc_map(the_pc - start, map); 3643 3644 __ reset_last_Java_frame(true); 3645 3646 __ leave(); // required for proper stackwalking of RuntimeStub frame 3647 3648 // check for pending exceptions 3649 #ifdef ASSERT 3650 Label L; 3651 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD); 3652 __ jcc(Assembler::notEqual, L); 3653 __ should_not_reach_here(); 3654 __ bind(L); 3655 #endif // ASSERT 3656 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 3657 3658 3659 // codeBlob framesize is in words (not VMRegImpl::slot_size) 3660 RuntimeStub* stub = 3661 RuntimeStub::new_runtime_stub(name, 3662 &code, 3663 frame_complete, 3664 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 3665 oop_maps, false); 3666 return stub->entry_point(); 3667 } 3668 3669 void StubGenerator::create_control_words() { 3670 // Round to nearest, 64-bit mode, exceptions masked 3671 StubRoutines::x86::_mxcsr_std = 0x1F80; 3672 } 3673 3674 // Initialization 3675 void StubGenerator::generate_initial() { 3676 // Generates all stubs and initializes the entry points 3677 3678 // This platform-specific settings are needed by generate_call_stub() 3679 create_control_words(); 3680 3681 // entry points that exist in all platforms Note: This is code 3682 // that could be shared among different platforms - however the 3683 // benefit seems to be smaller than the disadvantage of having a 3684 // much more complicated generator structure. See also comment in 3685 // stubRoutines.hpp. 3686 3687 StubRoutines::_forward_exception_entry = generate_forward_exception(); 3688 3689 // Generate these first because they are called from other stubs 3690 if (InlineTypeReturnedAsFields) { 3691 StubRoutines::_load_inline_type_fields_in_regs = 3692 generate_return_value_stub(CAST_FROM_FN_PTR(address, SharedRuntime::load_inline_type_fields_in_regs), 3693 "load_inline_type_fields_in_regs", false); 3694 StubRoutines::_store_inline_type_fields_to_buf = 3695 generate_return_value_stub(CAST_FROM_FN_PTR(address, SharedRuntime::store_inline_type_fields_to_buf), 3696 "store_inline_type_fields_to_buf", true); 3697 } 3698 3699 StubRoutines::_call_stub_entry = 3700 generate_call_stub(StubRoutines::_call_stub_return_address); 3701 3702 // is referenced by megamorphic call 3703 StubRoutines::_catch_exception_entry = generate_catch_exception(); 3704 3705 // atomic calls 3706 StubRoutines::_fence_entry = generate_orderaccess_fence(); 3707 3708 // platform dependent 3709 StubRoutines::x86::_get_previous_sp_entry = generate_get_previous_sp(); 3710 3711 StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr(); 3712 3713 StubRoutines::x86::_f2i_fixup = generate_f2i_fixup(); 3714 StubRoutines::x86::_f2l_fixup = generate_f2l_fixup(); 3715 StubRoutines::x86::_d2i_fixup = generate_d2i_fixup(); 3716 StubRoutines::x86::_d2l_fixup = generate_d2l_fixup(); 3717 3718 StubRoutines::x86::_float_sign_mask = generate_fp_mask("float_sign_mask", 0x7FFFFFFF7FFFFFFF); 3719 StubRoutines::x86::_float_sign_flip = generate_fp_mask("float_sign_flip", 0x8000000080000000); 3720 StubRoutines::x86::_double_sign_mask = generate_fp_mask("double_sign_mask", 0x7FFFFFFFFFFFFFFF); 3721 StubRoutines::x86::_double_sign_flip = generate_fp_mask("double_sign_flip", 0x8000000000000000); 3722 3723 // Build this early so it's available for the interpreter. 3724 StubRoutines::_throw_StackOverflowError_entry = 3725 generate_throw_exception("StackOverflowError throw_exception", 3726 CAST_FROM_FN_PTR(address, 3727 SharedRuntime:: 3728 throw_StackOverflowError)); 3729 StubRoutines::_throw_delayed_StackOverflowError_entry = 3730 generate_throw_exception("delayed StackOverflowError throw_exception", 3731 CAST_FROM_FN_PTR(address, 3732 SharedRuntime:: 3733 throw_delayed_StackOverflowError)); 3734 if (UseCRC32Intrinsics) { 3735 // set table address before stub generation which use it 3736 StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table; 3737 StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32(); 3738 } 3739 3740 if (UsePolyIntrinsics) { 3741 StubRoutines::_poly1305_processBlocks = generate_poly1305_processBlocks(); 3742 } 3743 3744 if (UseCRC32CIntrinsics) { 3745 bool supports_clmul = VM_Version::supports_clmul(); 3746 StubRoutines::x86::generate_CRC32C_table(supports_clmul); 3747 StubRoutines::_crc32c_table_addr = (address)StubRoutines::x86::_crc32c_table; 3748 StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C(supports_clmul); 3749 } 3750 3751 if (UseAdler32Intrinsics) { 3752 StubRoutines::_updateBytesAdler32 = generate_updateBytesAdler32(); 3753 } 3754 3755 generate_libm_stubs(); 3756 } 3757 3758 // Call here from the interpreter or compiled code to either load 3759 // multiple returned values from the inline type instance being 3760 // returned to registers or to store returned values to a newly 3761 // allocated inline type instance. 3762 // Register is a class, but it would be assigned numerical value. 3763 // "0" is assigned for xmm0. Thus we need to ignore -Wnonnull. 3764 PRAGMA_DIAG_PUSH 3765 PRAGMA_NONNULL_IGNORED 3766 address StubGenerator::generate_return_value_stub(address destination, const char* name, bool has_res) { 3767 // We need to save all registers the calling convention may use so 3768 // the runtime calls read or update those registers. This needs to 3769 // be in sync with SharedRuntime::java_return_convention(). 3770 enum layout { 3771 pad_off = frame::arg_reg_save_area_bytes/BytesPerInt, pad_off_2, 3772 rax_off, rax_off_2, 3773 j_rarg5_off, j_rarg5_2, 3774 j_rarg4_off, j_rarg4_2, 3775 j_rarg3_off, j_rarg3_2, 3776 j_rarg2_off, j_rarg2_2, 3777 j_rarg1_off, j_rarg1_2, 3778 j_rarg0_off, j_rarg0_2, 3779 j_farg0_off, j_farg0_2, 3780 j_farg1_off, j_farg1_2, 3781 j_farg2_off, j_farg2_2, 3782 j_farg3_off, j_farg3_2, 3783 j_farg4_off, j_farg4_2, 3784 j_farg5_off, j_farg5_2, 3785 j_farg6_off, j_farg6_2, 3786 j_farg7_off, j_farg7_2, 3787 rbp_off, rbp_off_2, 3788 return_off, return_off_2, 3789 3790 framesize 3791 }; 3792 3793 CodeBuffer buffer(name, 1000, 512); 3794 MacroAssembler* _masm = new MacroAssembler(&buffer); 3795 3796 int frame_size_in_bytes = align_up(framesize*BytesPerInt, 16); 3797 assert(frame_size_in_bytes == framesize*BytesPerInt, "misaligned"); 3798 int frame_size_in_slots = frame_size_in_bytes / BytesPerInt; 3799 int frame_size_in_words = frame_size_in_bytes / wordSize; 3800 3801 OopMapSet *oop_maps = new OopMapSet(); 3802 OopMap* map = new OopMap(frame_size_in_slots, 0); 3803 3804 map->set_callee_saved(VMRegImpl::stack2reg(rax_off), rax->as_VMReg()); 3805 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg5_off), j_rarg5->as_VMReg()); 3806 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg4_off), j_rarg4->as_VMReg()); 3807 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg3_off), j_rarg3->as_VMReg()); 3808 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg2_off), j_rarg2->as_VMReg()); 3809 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg1_off), j_rarg1->as_VMReg()); 3810 map->set_callee_saved(VMRegImpl::stack2reg(j_rarg0_off), j_rarg0->as_VMReg()); 3811 map->set_callee_saved(VMRegImpl::stack2reg(j_farg0_off), j_farg0->as_VMReg()); 3812 map->set_callee_saved(VMRegImpl::stack2reg(j_farg1_off), j_farg1->as_VMReg()); 3813 map->set_callee_saved(VMRegImpl::stack2reg(j_farg2_off), j_farg2->as_VMReg()); 3814 map->set_callee_saved(VMRegImpl::stack2reg(j_farg3_off), j_farg3->as_VMReg()); 3815 map->set_callee_saved(VMRegImpl::stack2reg(j_farg4_off), j_farg4->as_VMReg()); 3816 map->set_callee_saved(VMRegImpl::stack2reg(j_farg5_off), j_farg5->as_VMReg()); 3817 map->set_callee_saved(VMRegImpl::stack2reg(j_farg6_off), j_farg6->as_VMReg()); 3818 map->set_callee_saved(VMRegImpl::stack2reg(j_farg7_off), j_farg7->as_VMReg()); 3819 3820 int start = __ offset(); 3821 3822 __ subptr(rsp, frame_size_in_bytes - 8 /* return address*/); 3823 3824 __ movptr(Address(rsp, rbp_off * BytesPerInt), rbp); 3825 __ movdbl(Address(rsp, j_farg7_off * BytesPerInt), j_farg7); 3826 __ movdbl(Address(rsp, j_farg6_off * BytesPerInt), j_farg6); 3827 __ movdbl(Address(rsp, j_farg5_off * BytesPerInt), j_farg5); 3828 __ movdbl(Address(rsp, j_farg4_off * BytesPerInt), j_farg4); 3829 __ movdbl(Address(rsp, j_farg3_off * BytesPerInt), j_farg3); 3830 __ movdbl(Address(rsp, j_farg2_off * BytesPerInt), j_farg2); 3831 __ movdbl(Address(rsp, j_farg1_off * BytesPerInt), j_farg1); 3832 __ movdbl(Address(rsp, j_farg0_off * BytesPerInt), j_farg0); 3833 3834 __ movptr(Address(rsp, j_rarg0_off * BytesPerInt), j_rarg0); 3835 __ movptr(Address(rsp, j_rarg1_off * BytesPerInt), j_rarg1); 3836 __ movptr(Address(rsp, j_rarg2_off * BytesPerInt), j_rarg2); 3837 __ movptr(Address(rsp, j_rarg3_off * BytesPerInt), j_rarg3); 3838 __ movptr(Address(rsp, j_rarg4_off * BytesPerInt), j_rarg4); 3839 __ movptr(Address(rsp, j_rarg5_off * BytesPerInt), j_rarg5); 3840 __ movptr(Address(rsp, rax_off * BytesPerInt), rax); 3841 3842 int frame_complete = __ offset(); 3843 3844 __ set_last_Java_frame(noreg, noreg, NULL, rscratch1); 3845 3846 __ mov(c_rarg0, r15_thread); 3847 __ mov(c_rarg1, rax); 3848 3849 __ call(RuntimeAddress(destination)); 3850 3851 // Set an oopmap for the call site. 3852 3853 oop_maps->add_gc_map( __ offset() - start, map); 3854 3855 // clear last_Java_sp 3856 __ reset_last_Java_frame(false); 3857 3858 __ movptr(rbp, Address(rsp, rbp_off * BytesPerInt)); 3859 __ movdbl(j_farg7, Address(rsp, j_farg7_off * BytesPerInt)); 3860 __ movdbl(j_farg6, Address(rsp, j_farg6_off * BytesPerInt)); 3861 __ movdbl(j_farg5, Address(rsp, j_farg5_off * BytesPerInt)); 3862 __ movdbl(j_farg4, Address(rsp, j_farg4_off * BytesPerInt)); 3863 __ movdbl(j_farg3, Address(rsp, j_farg3_off * BytesPerInt)); 3864 __ movdbl(j_farg2, Address(rsp, j_farg2_off * BytesPerInt)); 3865 __ movdbl(j_farg1, Address(rsp, j_farg1_off * BytesPerInt)); 3866 __ movdbl(j_farg0, Address(rsp, j_farg0_off * BytesPerInt)); 3867 3868 __ movptr(j_rarg0, Address(rsp, j_rarg0_off * BytesPerInt)); 3869 __ movptr(j_rarg1, Address(rsp, j_rarg1_off * BytesPerInt)); 3870 __ movptr(j_rarg2, Address(rsp, j_rarg2_off * BytesPerInt)); 3871 __ movptr(j_rarg3, Address(rsp, j_rarg3_off * BytesPerInt)); 3872 __ movptr(j_rarg4, Address(rsp, j_rarg4_off * BytesPerInt)); 3873 __ movptr(j_rarg5, Address(rsp, j_rarg5_off * BytesPerInt)); 3874 __ movptr(rax, Address(rsp, rax_off * BytesPerInt)); 3875 3876 __ addptr(rsp, frame_size_in_bytes-8); 3877 3878 // check for pending exceptions 3879 Label pending; 3880 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); 3881 __ jcc(Assembler::notEqual, pending); 3882 3883 if (has_res) { 3884 __ get_vm_result(rax, r15_thread); 3885 } 3886 3887 __ ret(0); 3888 3889 __ bind(pending); 3890 3891 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset())); 3892 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 3893 3894 // ------------- 3895 // make sure all code is generated 3896 _masm->flush(); 3897 3898 RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, false); 3899 return stub->entry_point(); 3900 } 3901 3902 void StubGenerator::generate_phase1() { 3903 // Continuation stubs: 3904 StubRoutines::_cont_thaw = generate_cont_thaw(); 3905 StubRoutines::_cont_returnBarrier = generate_cont_returnBarrier(); 3906 StubRoutines::_cont_returnBarrierExc = generate_cont_returnBarrier_exception(); 3907 3908 JFR_ONLY(StubRoutines::_jfr_write_checkpoint_stub = generate_jfr_write_checkpoint();) 3909 JFR_ONLY(StubRoutines::_jfr_write_checkpoint = StubRoutines::_jfr_write_checkpoint_stub->entry_point();) 3910 } 3911 3912 void StubGenerator::generate_all() { 3913 // Generates all stubs and initializes the entry points 3914 3915 // These entry points require SharedInfo::stack0 to be set up in 3916 // non-core builds and need to be relocatable, so they each 3917 // fabricate a RuntimeStub internally. 3918 StubRoutines::_throw_AbstractMethodError_entry = 3919 generate_throw_exception("AbstractMethodError throw_exception", 3920 CAST_FROM_FN_PTR(address, 3921 SharedRuntime:: 3922 throw_AbstractMethodError)); 3923 3924 StubRoutines::_throw_IncompatibleClassChangeError_entry = 3925 generate_throw_exception("IncompatibleClassChangeError throw_exception", 3926 CAST_FROM_FN_PTR(address, 3927 SharedRuntime:: 3928 throw_IncompatibleClassChangeError)); 3929 3930 StubRoutines::_throw_NullPointerException_at_call_entry = 3931 generate_throw_exception("NullPointerException at call throw_exception", 3932 CAST_FROM_FN_PTR(address, 3933 SharedRuntime:: 3934 throw_NullPointerException_at_call)); 3935 3936 // entry points that are platform specific 3937 StubRoutines::x86::_vector_float_sign_mask = generate_vector_mask("vector_float_sign_mask", 0x7FFFFFFF7FFFFFFF); 3938 StubRoutines::x86::_vector_float_sign_flip = generate_vector_mask("vector_float_sign_flip", 0x8000000080000000); 3939 StubRoutines::x86::_vector_double_sign_mask = generate_vector_mask("vector_double_sign_mask", 0x7FFFFFFFFFFFFFFF); 3940 StubRoutines::x86::_vector_double_sign_flip = generate_vector_mask("vector_double_sign_flip", 0x8000000000000000); 3941 StubRoutines::x86::_vector_all_bits_set = generate_vector_mask("vector_all_bits_set", 0xFFFFFFFFFFFFFFFF); 3942 StubRoutines::x86::_vector_int_mask_cmp_bits = generate_vector_mask("vector_int_mask_cmp_bits", 0x0000000100000001); 3943 StubRoutines::x86::_vector_short_to_byte_mask = generate_vector_mask("vector_short_to_byte_mask", 0x00ff00ff00ff00ff); 3944 StubRoutines::x86::_vector_byte_perm_mask = generate_vector_byte_perm_mask("vector_byte_perm_mask"); 3945 StubRoutines::x86::_vector_int_to_byte_mask = generate_vector_mask("vector_int_to_byte_mask", 0x000000ff000000ff); 3946 StubRoutines::x86::_vector_int_to_short_mask = generate_vector_mask("vector_int_to_short_mask", 0x0000ffff0000ffff); 3947 StubRoutines::x86::_vector_32_bit_mask = generate_vector_custom_i32("vector_32_bit_mask", Assembler::AVX_512bit, 3948 0xFFFFFFFF, 0, 0, 0); 3949 StubRoutines::x86::_vector_64_bit_mask = generate_vector_custom_i32("vector_64_bit_mask", Assembler::AVX_512bit, 3950 0xFFFFFFFF, 0xFFFFFFFF, 0, 0); 3951 StubRoutines::x86::_vector_int_shuffle_mask = generate_vector_mask("vector_int_shuffle_mask", 0x0302010003020100); 3952 StubRoutines::x86::_vector_byte_shuffle_mask = generate_vector_byte_shuffle_mask("vector_byte_shuffle_mask"); 3953 StubRoutines::x86::_vector_short_shuffle_mask = generate_vector_mask("vector_short_shuffle_mask", 0x0100010001000100); 3954 StubRoutines::x86::_vector_long_shuffle_mask = generate_vector_mask("vector_long_shuffle_mask", 0x0000000100000000); 3955 StubRoutines::x86::_vector_long_sign_mask = generate_vector_mask("vector_long_sign_mask", 0x8000000000000000); 3956 StubRoutines::x86::_vector_iota_indices = generate_iota_indices("iota_indices"); 3957 StubRoutines::x86::_vector_count_leading_zeros_lut = generate_count_leading_zeros_lut("count_leading_zeros_lut"); 3958 StubRoutines::x86::_vector_reverse_bit_lut = generate_vector_reverse_bit_lut("reverse_bit_lut"); 3959 StubRoutines::x86::_vector_reverse_byte_perm_mask_long = generate_vector_reverse_byte_perm_mask_long("perm_mask_long"); 3960 StubRoutines::x86::_vector_reverse_byte_perm_mask_int = generate_vector_reverse_byte_perm_mask_int("perm_mask_int"); 3961 StubRoutines::x86::_vector_reverse_byte_perm_mask_short = generate_vector_reverse_byte_perm_mask_short("perm_mask_short"); 3962 3963 if (VM_Version::supports_avx2() && !VM_Version::supports_avx512_vpopcntdq()) { 3964 // lut implementation influenced by counting 1s algorithm from section 5-1 of Hackers' Delight. 3965 StubRoutines::x86::_vector_popcount_lut = generate_popcount_avx_lut("popcount_lut"); 3966 } 3967 3968 // support for verify_oop (must happen after universe_init) 3969 if (VerifyOops) { 3970 StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); 3971 } 3972 3973 // data cache line writeback 3974 StubRoutines::_data_cache_writeback = generate_data_cache_writeback(); 3975 StubRoutines::_data_cache_writeback_sync = generate_data_cache_writeback_sync(); 3976 3977 // arraycopy stubs used by compilers 3978 generate_arraycopy_stubs(); 3979 3980 generate_aes_stubs(); 3981 3982 generate_ghash_stubs(); 3983 3984 generate_chacha_stubs(); 3985 3986 if (UseMD5Intrinsics) { 3987 StubRoutines::_md5_implCompress = generate_md5_implCompress(false, "md5_implCompress"); 3988 StubRoutines::_md5_implCompressMB = generate_md5_implCompress(true, "md5_implCompressMB"); 3989 } 3990 if (UseSHA1Intrinsics) { 3991 StubRoutines::x86::_upper_word_mask_addr = generate_upper_word_mask(); 3992 StubRoutines::x86::_shuffle_byte_flip_mask_addr = generate_shuffle_byte_flip_mask(); 3993 StubRoutines::_sha1_implCompress = generate_sha1_implCompress(false, "sha1_implCompress"); 3994 StubRoutines::_sha1_implCompressMB = generate_sha1_implCompress(true, "sha1_implCompressMB"); 3995 } 3996 if (UseSHA256Intrinsics) { 3997 StubRoutines::x86::_k256_adr = (address)StubRoutines::x86::_k256; 3998 char* dst = (char*)StubRoutines::x86::_k256_W; 3999 char* src = (char*)StubRoutines::x86::_k256; 4000 for (int ii = 0; ii < 16; ++ii) { 4001 memcpy(dst + 32 * ii, src + 16 * ii, 16); 4002 memcpy(dst + 32 * ii + 16, src + 16 * ii, 16); 4003 } 4004 StubRoutines::x86::_k256_W_adr = (address)StubRoutines::x86::_k256_W; 4005 StubRoutines::x86::_pshuffle_byte_flip_mask_addr = generate_pshuffle_byte_flip_mask(); 4006 StubRoutines::_sha256_implCompress = generate_sha256_implCompress(false, "sha256_implCompress"); 4007 StubRoutines::_sha256_implCompressMB = generate_sha256_implCompress(true, "sha256_implCompressMB"); 4008 } 4009 if (UseSHA512Intrinsics) { 4010 StubRoutines::x86::_k512_W_addr = (address)StubRoutines::x86::_k512_W; 4011 StubRoutines::x86::_pshuffle_byte_flip_mask_addr_sha512 = generate_pshuffle_byte_flip_mask_sha512(); 4012 StubRoutines::_sha512_implCompress = generate_sha512_implCompress(false, "sha512_implCompress"); 4013 StubRoutines::_sha512_implCompressMB = generate_sha512_implCompress(true, "sha512_implCompressMB"); 4014 } 4015 4016 if (UseBASE64Intrinsics) { 4017 if(VM_Version::supports_avx2() && 4018 VM_Version::supports_avx512bw() && 4019 VM_Version::supports_avx512vl()) { 4020 StubRoutines::x86::_avx2_shuffle_base64 = base64_avx2_shuffle_addr(); 4021 StubRoutines::x86::_avx2_input_mask_base64 = base64_avx2_input_mask_addr(); 4022 StubRoutines::x86::_avx2_lut_base64 = base64_avx2_lut_addr(); 4023 } 4024 StubRoutines::x86::_encoding_table_base64 = base64_encoding_table_addr(); 4025 if (VM_Version::supports_avx512_vbmi()) { 4026 StubRoutines::x86::_shuffle_base64 = base64_shuffle_addr(); 4027 StubRoutines::x86::_lookup_lo_base64 = base64_vbmi_lookup_lo_addr(); 4028 StubRoutines::x86::_lookup_hi_base64 = base64_vbmi_lookup_hi_addr(); 4029 StubRoutines::x86::_lookup_lo_base64url = base64_vbmi_lookup_lo_url_addr(); 4030 StubRoutines::x86::_lookup_hi_base64url = base64_vbmi_lookup_hi_url_addr(); 4031 StubRoutines::x86::_pack_vec_base64 = base64_vbmi_pack_vec_addr(); 4032 StubRoutines::x86::_join_0_1_base64 = base64_vbmi_join_0_1_addr(); 4033 StubRoutines::x86::_join_1_2_base64 = base64_vbmi_join_1_2_addr(); 4034 StubRoutines::x86::_join_2_3_base64 = base64_vbmi_join_2_3_addr(); 4035 } 4036 StubRoutines::x86::_decoding_table_base64 = base64_decoding_table_addr(); 4037 StubRoutines::_base64_encodeBlock = generate_base64_encodeBlock(); 4038 StubRoutines::_base64_decodeBlock = generate_base64_decodeBlock(); 4039 } 4040 4041 BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod(); 4042 if (bs_nm != NULL) { 4043 StubRoutines::x86::_method_entry_barrier = generate_method_entry_barrier(); 4044 } 4045 #ifdef COMPILER2 4046 if (UseMultiplyToLenIntrinsic) { 4047 StubRoutines::_multiplyToLen = generate_multiplyToLen(); 4048 } 4049 if (UseSquareToLenIntrinsic) { 4050 StubRoutines::_squareToLen = generate_squareToLen(); 4051 } 4052 if (UseMulAddIntrinsic) { 4053 StubRoutines::_mulAdd = generate_mulAdd(); 4054 } 4055 if (VM_Version::supports_avx512_vbmi2()) { 4056 StubRoutines::_bigIntegerRightShiftWorker = generate_bigIntegerRightShift(); 4057 StubRoutines::_bigIntegerLeftShiftWorker = generate_bigIntegerLeftShift(); 4058 } 4059 if (UseMontgomeryMultiplyIntrinsic) { 4060 StubRoutines::_montgomeryMultiply 4061 = CAST_FROM_FN_PTR(address, SharedRuntime::montgomery_multiply); 4062 } 4063 if (UseMontgomerySquareIntrinsic) { 4064 StubRoutines::_montgomerySquare 4065 = CAST_FROM_FN_PTR(address, SharedRuntime::montgomery_square); 4066 } 4067 4068 // Get svml stub routine addresses 4069 void *libjsvml = NULL; 4070 char ebuf[1024]; 4071 char dll_name[JVM_MAXPATHLEN]; 4072 if (os::dll_locate_lib(dll_name, sizeof(dll_name), Arguments::get_dll_dir(), "jsvml")) { 4073 libjsvml = os::dll_load(dll_name, ebuf, sizeof ebuf); 4074 } 4075 if (libjsvml != NULL) { 4076 // SVML method naming convention 4077 // All the methods are named as __jsvml_op<T><N>_ha_<VV> 4078 // Where: 4079 // ha stands for high accuracy 4080 // <T> is optional to indicate float/double 4081 // Set to f for vector float operation 4082 // Omitted for vector double operation 4083 // <N> is the number of elements in the vector 4084 // 1, 2, 4, 8, 16 4085 // e.g. 128 bit float vector has 4 float elements 4086 // <VV> indicates the avx/sse level: 4087 // z0 is AVX512, l9 is AVX2, e9 is AVX1 and ex is for SSE2 4088 // e.g. __jsvml_expf16_ha_z0 is the method for computing 16 element vector float exp using AVX 512 insns 4089 // __jsvml_exp8_ha_z0 is the method for computing 8 element vector double exp using AVX 512 insns 4090 4091 log_info(library)("Loaded library %s, handle " INTPTR_FORMAT, JNI_LIB_PREFIX "jsvml" JNI_LIB_SUFFIX, p2i(libjsvml)); 4092 if (UseAVX > 2) { 4093 for (int op = 0; op < VectorSupport::NUM_SVML_OP; op++) { 4094 int vop = VectorSupport::VECTOR_OP_SVML_START + op; 4095 if ((!VM_Version::supports_avx512dq()) && 4096 (vop == VectorSupport::VECTOR_OP_LOG || vop == VectorSupport::VECTOR_OP_LOG10 || vop == VectorSupport::VECTOR_OP_POW)) { 4097 continue; 4098 } 4099 snprintf(ebuf, sizeof(ebuf), "__jsvml_%sf16_ha_z0", VectorSupport::svmlname[op]); 4100 StubRoutines::_vector_f_math[VectorSupport::VEC_SIZE_512][op] = (address)os::dll_lookup(libjsvml, ebuf); 4101 4102 snprintf(ebuf, sizeof(ebuf), "__jsvml_%s8_ha_z0", VectorSupport::svmlname[op]); 4103 StubRoutines::_vector_d_math[VectorSupport::VEC_SIZE_512][op] = (address)os::dll_lookup(libjsvml, ebuf); 4104 } 4105 } 4106 const char* avx_sse_str = (UseAVX >= 2) ? "l9" : ((UseAVX == 1) ? "e9" : "ex"); 4107 for (int op = 0; op < VectorSupport::NUM_SVML_OP; op++) { 4108 int vop = VectorSupport::VECTOR_OP_SVML_START + op; 4109 if (vop == VectorSupport::VECTOR_OP_POW) { 4110 continue; 4111 } 4112 snprintf(ebuf, sizeof(ebuf), "__jsvml_%sf4_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4113 StubRoutines::_vector_f_math[VectorSupport::VEC_SIZE_64][op] = (address)os::dll_lookup(libjsvml, ebuf); 4114 4115 snprintf(ebuf, sizeof(ebuf), "__jsvml_%sf4_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4116 StubRoutines::_vector_f_math[VectorSupport::VEC_SIZE_128][op] = (address)os::dll_lookup(libjsvml, ebuf); 4117 4118 snprintf(ebuf, sizeof(ebuf), "__jsvml_%sf8_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4119 StubRoutines::_vector_f_math[VectorSupport::VEC_SIZE_256][op] = (address)os::dll_lookup(libjsvml, ebuf); 4120 4121 snprintf(ebuf, sizeof(ebuf), "__jsvml_%s1_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4122 StubRoutines::_vector_d_math[VectorSupport::VEC_SIZE_64][op] = (address)os::dll_lookup(libjsvml, ebuf); 4123 4124 snprintf(ebuf, sizeof(ebuf), "__jsvml_%s2_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4125 StubRoutines::_vector_d_math[VectorSupport::VEC_SIZE_128][op] = (address)os::dll_lookup(libjsvml, ebuf); 4126 4127 snprintf(ebuf, sizeof(ebuf), "__jsvml_%s4_ha_%s", VectorSupport::svmlname[op], avx_sse_str); 4128 StubRoutines::_vector_d_math[VectorSupport::VEC_SIZE_256][op] = (address)os::dll_lookup(libjsvml, ebuf); 4129 } 4130 } 4131 #endif // COMPILER2 4132 4133 if (UseVectorizedMismatchIntrinsic) { 4134 StubRoutines::_vectorizedMismatch = generate_vectorizedMismatch(); 4135 } 4136 } 4137 4138 void StubGenerator_generate(CodeBuffer* code, int phase) { 4139 if (UnsafeCopyMemory::_table == NULL) { 4140 UnsafeCopyMemory::create_table(16); 4141 } 4142 StubGenerator g(code, phase); 4143 } 4144 4145 #undef __