Mercurial > hg > graal-jvmci-8
comparison src/cpu/x86/vm/stubGenerator_x86_64.cpp @ 17670:04d32e7fad07
8002074: Support for AES on SPARC
Summary: Add intrinsics/stub routines support for single-block and multi-block (as used by Cipher Block Chaining mode) AES encryption and decryption operations on the SPARC platform.
Reviewed-by: kvn, roland
Contributed-by: shrinivas.joshi@oracle.com
author | kvn |
---|---|
date | Tue, 14 Jan 2014 17:46:48 -0800 |
parents | 740e263c80c6 |
children | d8041d695d19 166d744df0de |
comparison
equal
deleted
inserted
replaced
17669:2996010c4820 | 17670:04d32e7fad07 |
---|---|
3215 // c_rarg1 - destination byte array address | 3215 // c_rarg1 - destination byte array address |
3216 // c_rarg2 - K (key) in little endian int array | 3216 // c_rarg2 - K (key) in little endian int array |
3217 // c_rarg3 - r vector byte array address | 3217 // c_rarg3 - r vector byte array address |
3218 // c_rarg4 - input length | 3218 // c_rarg4 - input length |
3219 // | 3219 // |
3220 // Output: | |
3221 // rax - input length | |
3222 // | |
3220 address generate_cipherBlockChaining_encryptAESCrypt() { | 3223 address generate_cipherBlockChaining_encryptAESCrypt() { |
3221 assert(UseAES, "need AES instructions and misaligned SSE support"); | 3224 assert(UseAES, "need AES instructions and misaligned SSE support"); |
3222 __ align(CodeEntryAlignment); | 3225 __ align(CodeEntryAlignment); |
3223 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt"); | 3226 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt"); |
3224 address start = __ pc(); | 3227 address start = __ pc(); |
3230 const Register rvec = c_rarg3; // r byte array initialized from initvector array address | 3233 const Register rvec = c_rarg3; // r byte array initialized from initvector array address |
3231 // and left with the results of the last encryption block | 3234 // and left with the results of the last encryption block |
3232 #ifndef _WIN64 | 3235 #ifndef _WIN64 |
3233 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) | 3236 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) |
3234 #else | 3237 #else |
3235 const Address len_mem(rsp, 6 * wordSize); // length is on stack on Win64 | 3238 const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64 |
3236 const Register len_reg = r10; // pick the first volatile windows register | 3239 const Register len_reg = r10; // pick the first volatile windows register |
3237 #endif | 3240 #endif |
3238 const Register pos = rax; | 3241 const Register pos = rax; |
3239 | 3242 |
3240 // xmm register assignments for the loops below | 3243 // xmm register assignments for the loops below |
3257 // save the xmm registers which must be preserved 6-15 | 3260 // save the xmm registers which must be preserved 6-15 |
3258 __ subptr(rsp, -rsp_after_call_off * wordSize); | 3261 __ subptr(rsp, -rsp_after_call_off * wordSize); |
3259 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { | 3262 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { |
3260 __ movdqu(xmm_save(i), as_XMMRegister(i)); | 3263 __ movdqu(xmm_save(i), as_XMMRegister(i)); |
3261 } | 3264 } |
3265 #else | |
3266 __ push(len_reg); // Save | |
3262 #endif | 3267 #endif |
3263 | 3268 |
3264 const XMMRegister xmm_key_shuf_mask = xmm_temp; // used temporarily to swap key bytes up front | 3269 const XMMRegister xmm_key_shuf_mask = xmm_temp; // used temporarily to swap key bytes up front |
3265 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); | 3270 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); |
3266 // load up xmm regs xmm2 thru xmm12 with key 0x00 - 0xa0 | 3271 // load up xmm regs xmm2 thru xmm12 with key 0x00 - 0xa0 |
3299 #ifdef _WIN64 | 3304 #ifdef _WIN64 |
3300 // restore xmm regs belonging to calling function | 3305 // restore xmm regs belonging to calling function |
3301 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { | 3306 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { |
3302 __ movdqu(as_XMMRegister(i), xmm_save(i)); | 3307 __ movdqu(as_XMMRegister(i), xmm_save(i)); |
3303 } | 3308 } |
3309 __ movl(rax, len_mem); | |
3310 #else | |
3311 __ pop(rax); // return length | |
3304 #endif | 3312 #endif |
3305 __ movl(rax, 0); // return 0 (why?) | |
3306 __ leave(); // required for proper stackwalking of RuntimeStub frame | 3313 __ leave(); // required for proper stackwalking of RuntimeStub frame |
3307 __ ret(0); | 3314 __ ret(0); |
3308 | 3315 |
3309 __ BIND(L_key_192_256); | 3316 __ BIND(L_key_192_256); |
3310 // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256) | 3317 // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256) |
3407 // c_rarg1 - destination byte array address | 3414 // c_rarg1 - destination byte array address |
3408 // c_rarg2 - K (key) in little endian int array | 3415 // c_rarg2 - K (key) in little endian int array |
3409 // c_rarg3 - r vector byte array address | 3416 // c_rarg3 - r vector byte array address |
3410 // c_rarg4 - input length | 3417 // c_rarg4 - input length |
3411 // | 3418 // |
3419 // Output: | |
3420 // rax - input length | |
3421 // | |
3412 | 3422 |
3413 address generate_cipherBlockChaining_decryptAESCrypt_Parallel() { | 3423 address generate_cipherBlockChaining_decryptAESCrypt_Parallel() { |
3414 assert(UseAES, "need AES instructions and misaligned SSE support"); | 3424 assert(UseAES, "need AES instructions and misaligned SSE support"); |
3415 __ align(CodeEntryAlignment); | 3425 __ align(CodeEntryAlignment); |
3416 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt"); | 3426 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt"); |
3425 const Register rvec = c_rarg3; // r byte array initialized from initvector array address | 3435 const Register rvec = c_rarg3; // r byte array initialized from initvector array address |
3426 // and left with the results of the last encryption block | 3436 // and left with the results of the last encryption block |
3427 #ifndef _WIN64 | 3437 #ifndef _WIN64 |
3428 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) | 3438 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) |
3429 #else | 3439 #else |
3430 const Address len_mem(rsp, 6 * wordSize); // length is on stack on Win64 | 3440 const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64 |
3431 const Register len_reg = r10; // pick the first volatile windows register | 3441 const Register len_reg = r10; // pick the first volatile windows register |
3432 #endif | 3442 #endif |
3433 const Register pos = rax; | 3443 const Register pos = rax; |
3434 | 3444 |
3435 // keys 0-10 preloaded into xmm2-xmm12 | 3445 // keys 0-10 preloaded into xmm2-xmm12 |
3446 // save the xmm registers which must be preserved 6-15 | 3456 // save the xmm registers which must be preserved 6-15 |
3447 __ subptr(rsp, -rsp_after_call_off * wordSize); | 3457 __ subptr(rsp, -rsp_after_call_off * wordSize); |
3448 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { | 3458 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { |
3449 __ movdqu(xmm_save(i), as_XMMRegister(i)); | 3459 __ movdqu(xmm_save(i), as_XMMRegister(i)); |
3450 } | 3460 } |
3461 #else | |
3462 __ push(len_reg); // Save | |
3451 #endif | 3463 #endif |
3464 | |
3452 // the java expanded key ordering is rotated one position from what we want | 3465 // the java expanded key ordering is rotated one position from what we want |
3453 // so we start from 0x10 here and hit 0x00 last | 3466 // so we start from 0x10 here and hit 0x00 last |
3454 const XMMRegister xmm_key_shuf_mask = xmm1; // used temporarily to swap key bytes up front | 3467 const XMMRegister xmm_key_shuf_mask = xmm1; // used temporarily to swap key bytes up front |
3455 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); | 3468 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); |
3456 // load up xmm regs 5 thru 15 with key 0x10 - 0xa0 - 0x00 | 3469 // load up xmm regs 5 thru 15 with key 0x10 - 0xa0 - 0x00 |
3552 #ifdef _WIN64 | 3565 #ifdef _WIN64 |
3553 // restore regs belonging to calling function | 3566 // restore regs belonging to calling function |
3554 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { | 3567 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { |
3555 __ movdqu(as_XMMRegister(i), xmm_save(i)); | 3568 __ movdqu(as_XMMRegister(i), xmm_save(i)); |
3556 } | 3569 } |
3570 __ movl(rax, len_mem); | |
3571 #else | |
3572 __ pop(rax); // return length | |
3557 #endif | 3573 #endif |
3558 __ movl(rax, 0); // return 0 (why?) | |
3559 __ leave(); // required for proper stackwalking of RuntimeStub frame | 3574 __ leave(); // required for proper stackwalking of RuntimeStub frame |
3560 __ ret(0); | 3575 __ ret(0); |
3561 | 3576 |
3562 | 3577 |
3563 __ BIND(L_key_192_256); | 3578 __ BIND(L_key_192_256); |