Skip to content

Commit fc491b4

Browse files
committed
backport 2f728d0cbb366b98158ca8b2acf4b6f58df2fd52
1 parent b45cab6 commit fc491b4

4 files changed

Lines changed: 55 additions & 50 deletions

File tree

src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,8 +3806,8 @@ class StubGenerator: public StubCodeGenerator {
38063806
//
38073807
// Inputs:
38083808
// c_rarg0 - byte[] source+offset
3809-
// c_rarg1 - byte[] SHA.state
3810-
// c_rarg2 - int digest_length
3809+
// c_rarg1 - byte[] SHA.state
3810+
// c_rarg2 - int block_size
38113811
// c_rarg3 - int offset
38123812
// c_rarg4 - int limit
38133813
//
@@ -3829,12 +3829,12 @@ class StubGenerator: public StubCodeGenerator {
38293829

38303830
Register buf = c_rarg0;
38313831
Register state = c_rarg1;
3832-
Register digest_length = c_rarg2;
3832+
Register block_size = c_rarg2;
38333833
Register ofs = c_rarg3;
38343834
Register limit = c_rarg4;
38353835

38363836
Label sha3_loop, rounds24_loop;
3837-
Label sha3_512, sha3_384_or_224, sha3_256;
3837+
Label sha3_512_or_sha3_384, shake128;
38383838

38393839
__ stpd(v8, v9, __ pre(sp, -64));
38403840
__ stpd(v10, v11, Address(sp, 16));
@@ -3870,46 +3870,54 @@ class StubGenerator: public StubCodeGenerator {
38703870
__ eor(v5, __ T8B, v5, v30);
38713871
__ eor(v6, __ T8B, v6, v31);
38723872

3873-
// digest_length == 64, SHA3-512
3874-
__ tbnz(digest_length, 6, sha3_512);
3873+
// block_size == 72, SHA3-512; block_size == 104, SHA3-384
3874+
__ tbz(block_size, 7, sha3_512_or_sha3_384);
38753875

38763876
__ ld1(v25, v26, v27, v28, __ T8B, __ post(buf, 32));
3877-
__ ld1(v29, v30, __ T8B, __ post(buf, 16));
3877+
__ ld1(v29, v30, v31, __ T8B, __ post(buf, 24));
38783878
__ eor(v7, __ T8B, v7, v25);
38793879
__ eor(v8, __ T8B, v8, v26);
38803880
__ eor(v9, __ T8B, v9, v27);
38813881
__ eor(v10, __ T8B, v10, v28);
38823882
__ eor(v11, __ T8B, v11, v29);
38833883
__ eor(v12, __ T8B, v12, v30);
3884+
__ eor(v13, __ T8B, v13, v31);
38843885

3885-
// digest_length == 28, SHA3-224; digest_length == 48, SHA3-384
3886-
__ tbnz(digest_length, 4, sha3_384_or_224);
3887-
3888-
// SHA3-256
3889-
__ ld1(v25, v26, v27, v28, __ T8B, __ post(buf, 32));
3890-
__ eor(v13, __ T8B, v13, v25);
3891-
__ eor(v14, __ T8B, v14, v26);
3892-
__ eor(v15, __ T8B, v15, v27);
3893-
__ eor(v16, __ T8B, v16, v28);
3894-
__ b(rounds24_loop);
3886+
__ ld1(v25, v26, v27, __ T8B, __ post(buf, 24));
3887+
__ eor(v14, __ T8B, v14, v25);
3888+
__ eor(v15, __ T8B, v15, v26);
3889+
__ eor(v16, __ T8B, v16, v27);
38953890

3896-
__ BIND(sha3_384_or_224);
3897-
__ tbz(digest_length, 2, rounds24_loop); // bit 2 cleared? SHA-384
3891+
// block_size == 136, bit4 == 0 and bit5 == 0, SHA3-256 or SHAKE256
3892+
__ andw(c_rarg5, block_size, 48);
3893+
__ cbzw(c_rarg5, rounds24_loop);
38983894

3899-
// SHA3-224
3900-
__ ld1(v25, v26, v27, v28, __ T8B, __ post(buf, 32));
3901-
__ ld1(v29, __ T8B, __ post(buf, 8));
3902-
__ eor(v13, __ T8B, v13, v25);
3903-
__ eor(v14, __ T8B, v14, v26);
3904-
__ eor(v15, __ T8B, v15, v27);
3905-
__ eor(v16, __ T8B, v16, v28);
3906-
__ eor(v17, __ T8B, v17, v29);
3895+
__ tbnz(block_size, 5, shake128);
3896+
// block_size == 144, bit5 == 0, SHA3-244
3897+
__ ldrd(v28, __ post(buf, 8));
3898+
__ eor(v17, __ T8B, v17, v28);
39073899
__ b(rounds24_loop);
39083900

3909-
__ BIND(sha3_512);
3901+
__ BIND(shake128);
3902+
__ ld1(v28, v29, v30, v31, __ T8B, __ post(buf, 32));
3903+
__ eor(v17, __ T8B, v17, v28);
3904+
__ eor(v18, __ T8B, v18, v29);
3905+
__ eor(v19, __ T8B, v19, v30);
3906+
__ eor(v20, __ T8B, v20, v31);
3907+
__ b(rounds24_loop); // block_size == 168, SHAKE128
3908+
3909+
__ BIND(sha3_512_or_sha3_384);
39103910
__ ld1(v25, v26, __ T8B, __ post(buf, 16));
39113911
__ eor(v7, __ T8B, v7, v25);
39123912
__ eor(v8, __ T8B, v8, v26);
3913+
__ tbz(block_size, 5, rounds24_loop); // SHA3-512
3914+
3915+
// SHA3-384
3916+
__ ld1(v27, v28, v29, v30, __ T8B, __ post(buf, 32));
3917+
__ eor(v9, __ T8B, v9, v27);
3918+
__ eor(v10, __ T8B, v10, v28);
3919+
__ eor(v11, __ T8B, v11, v29);
3920+
__ eor(v12, __ T8B, v12, v30);
39133921

39143922
__ BIND(rounds24_loop);
39153923
__ subw(rscratch2, rscratch2, 1);
@@ -3994,10 +4002,7 @@ class StubGenerator: public StubCodeGenerator {
39944002
__ cbnzw(rscratch2, rounds24_loop);
39954003

39964004
if (multi_block) {
3997-
// block_size = 200 - 2 * digest_length, ofs += block_size
3998-
__ add(ofs, ofs, 200);
3999-
__ sub(ofs, ofs, digest_length, Assembler::LSL, 1);
4000-
4005+
__ add(ofs, ofs, block_size);
40014006
__ cmp(ofs, limit);
40024007
__ br(Assembler::LE, sha3_loop);
40034008
__ mov(c_rarg0, ofs); // return ofs

src/hotspot/share/opto/library_call.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6578,7 +6578,7 @@ bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
65786578
src = must_be_not_null(src, true);
65796579
Node* src_start = array_element_address(src, ofs, src_elem);
65806580
Node* state = nullptr;
6581-
Node* digest_length = nullptr;
6581+
Node* block_size = nullptr;
65826582
address stubAddr;
65836583
const char *stubName;
65846584

@@ -6612,8 +6612,8 @@ bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
66126612
state = get_state_from_digest_object(digestBase_obj, T_BYTE);
66136613
stubAddr = StubRoutines::sha3_implCompress();
66146614
stubName = "sha3_implCompress";
6615-
digest_length = get_digest_length_from_digest_object(digestBase_obj);
6616-
if (digest_length == nullptr) return false;
6615+
block_size = get_block_size_from_digest_object(digestBase_obj);
6616+
if (block_size == nullptr) return false;
66176617
break;
66186618
default:
66196619
fatal_unexpected_iid(id);
@@ -6626,14 +6626,14 @@ bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
66266626

66276627
// Call the stub.
66286628
Node* call;
6629-
if (digest_length == nullptr) {
6629+
if (block_size == nullptr) {
66306630
call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(false),
66316631
stubAddr, stubName, TypePtr::BOTTOM,
66326632
src_start, state);
66336633
} else {
66346634
call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(true),
66356635
stubAddr, stubName, TypePtr::BOTTOM,
6636-
src_start, state, digest_length);
6636+
src_start, state, block_size);
66376637
}
66386638

66396639
return true;
@@ -6745,15 +6745,15 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciIn
67456745
Node* state = get_state_from_digest_object(digest_obj, elem_type);
67466746
if (state == nullptr) return false;
67476747

6748-
Node* digest_length = nullptr;
6748+
Node* block_size = nullptr;
67496749
if (strcmp("sha3_implCompressMB", stubName) == 0) {
6750-
digest_length = get_digest_length_from_digest_object(digest_obj);
6751-
if (digest_length == nullptr) return false;
6750+
block_size = get_block_size_from_digest_object(digest_obj);
6751+
if (block_size == nullptr) return false;
67526752
}
67536753

67546754
// Call the stub.
67556755
Node* call;
6756-
if (digest_length == nullptr) {
6756+
if (block_size == nullptr) {
67576757
call = make_runtime_call(RC_LEAF|RC_NO_FP,
67586758
OptoRuntime::digestBase_implCompressMB_Type(false),
67596759
stubAddr, stubName, TypePtr::BOTTOM,
@@ -6762,7 +6762,7 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciIn
67626762
call = make_runtime_call(RC_LEAF|RC_NO_FP,
67636763
OptoRuntime::digestBase_implCompressMB_Type(true),
67646764
stubAddr, stubName, TypePtr::BOTTOM,
6765-
src_start, state, digest_length, ofs, limit);
6765+
src_start, state, block_size, ofs, limit);
67666766
}
67676767

67686768
// return ofs (int)
@@ -6790,11 +6790,11 @@ Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicTy
67906790
return state;
67916791
}
67926792

6793-
//------------------------------get_digest_length_from_sha3_object----------------------------------
6794-
Node * LibraryCallKit::get_digest_length_from_digest_object(Node *digest_object) {
6795-
Node* digest_length = load_field_from_object(digest_object, "digestLength", "I");
6796-
assert (digest_length != nullptr, "sanity");
6797-
return digest_length;
6793+
//------------------------------get_block_size_from_sha3_object----------------------------------
6794+
Node * LibraryCallKit::get_block_size_from_digest_object(Node *digest_object) {
6795+
Node* block_size = load_field_from_object(digest_object, "digestLength", "I");
6796+
assert (block_size != nullptr, "sanity");
6797+
return block_size;
67986798
}
67996799

68006800
//----------------------------inline_digestBase_implCompressMB_predicate----------------------------

src/hotspot/share/opto/library_call.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class LibraryCallKit : public GraphKit {
284284
BasicType elem_type, address stubAddr, const char *stubName,
285285
Node* src_start, Node* ofs, Node* limit);
286286
Node* get_state_from_digest_object(Node *digestBase_object, BasicType elem_type);
287-
Node* get_digest_length_from_digest_object(Node *digestBase_object);
287+
Node* get_block_size_from_digest_object(Node *digestBase_object);
288288
Node* inline_digestBase_implCompressMB_predicate(int predicate);
289289
bool inline_encodeISOArray(bool ascii);
290290
bool inline_updateCRC32();

src/hotspot/share/opto/runtime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ const TypeFunc* OptoRuntime::digestBase_implCompress_Type(bool is_sha3) {
966966
int argp = TypeFunc::Parms;
967967
fields[argp++] = TypePtr::NOTNULL; // buf
968968
fields[argp++] = TypePtr::NOTNULL; // state
969-
if (is_sha3) fields[argp++] = TypeInt::INT; // digest_length
969+
if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
970970
assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
971971
const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
972972

@@ -988,7 +988,7 @@ const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type(bool is_sha3) {
988988
int argp = TypeFunc::Parms;
989989
fields[argp++] = TypePtr::NOTNULL; // buf
990990
fields[argp++] = TypePtr::NOTNULL; // state
991-
if (is_sha3) fields[argp++] = TypeInt::INT; // digest_length
991+
if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
992992
fields[argp++] = TypeInt::INT; // ofs
993993
fields[argp++] = TypeInt::INT; // limit
994994
assert(argp == TypeFunc::Parms+argcnt, "correct decoding");

0 commit comments

Comments
 (0)