To use intrinsics to accelerate SHA operations on multiple blocks, it is
needed to pull a loop out of DigestBase.engineUpdate(byte[] b, int ofs, int len)
and make it a new method, implCompressMultiBlock(byte[] b, int ofs, int n),
which doesn't throw any exceptions so can be intrinsified.
It is believed that the compiler should inline this new method, so no
performance regression with the pure Java SUN provider is expected.
Here is the proposed change:
diff -r 43386cc9a017 src/share/classes/sun/security/provider/DigestBase.java
--- a/src/share/classes/sun/security/provider/DigestBase.java Thu Feb 06 17:35:19 2014 -0800
+++ b/src/share/classes/sun/security/provider/DigestBase.java Wed Feb 12 19:34:25 2014 -0800
@@ -122,11 +122,13 @@
}
}
// compress complete blocks
- while (len >= blockSize) {
- implCompress(b, ofs);
- len -= blockSize;
- ofs += blockSize;
+ if (len >= blockSize) {
+ int n = len/blockSize;
+ implCompressMultiBlock(b, ofs, n);
+ len -= n*blockSize;
+ ofs += n*blockSize;
}
+
// copy remainder to buffer
if (len > 0) {
System.arraycopy(b, ofs, buffer, 0, len);
@@ -134,6 +136,14 @@
}
}
+ // compress complete blocks
+ protected final void implCompressMultiBlock(byte[] b, int ofs, int n) {
+ for (int i = 0; i < n; i++) {
+ implCompress(b, ofs);
+ ofs += blockSize;
+ }
+ }
+
// reset this object. See JCA doc.
protected final void engineReset() {
if (bytesProcessed == 0) {