Browse Source

Don't kick in AVX2/AVX512 VTEC unless the packet is larger than 256 bytes.

Adam Ierymenko 5 years ago
parent
commit
0c56d7c769
1 changed files with 3 additions and 3 deletions
  1. 3 3
      core/AES.cpp

+ 3 - 3
core/AES.cpp

@@ -705,7 +705,7 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
 		if (likely(len >= 64)) {
 		if (likely(len >= 64)) {
 
 
 #if defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
 #if defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
-			if (Utils::CPUID.vaes) {
+			if (Utils::CPUID.vaes && (len >= 256)) {
 				if (Utils::CPUID.avx512f) {
 				if (Utils::CPUID.avx512f) {
 					p_aesCtrInnerVAES512(len, _ctr[0], c1, in, out, k);
 					p_aesCtrInnerVAES512(len, _ctr[0], c1, in, out, k);
 				} else {
 				} else {
@@ -716,7 +716,7 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
 #endif
 #endif
 
 
 #if !defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
 #if !defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
-			if (Utils::CPUID.vaes) {
+			if (Utils::CPUID.vaes && (len >= 256)) {
 				p_aesCtrInnerVAES256(len, _ctr[0], c1, in, out, k);
 				p_aesCtrInnerVAES256(len, _ctr[0], c1, in, out, k);
 				goto skip_conventional_aesni_64;
 				goto skip_conventional_aesni_64;
 			}
 			}
@@ -897,7 +897,7 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
 		out += totalLen;
 		out += totalLen;
 		_len = totalLen + len;
 		_len = totalLen + len;
 
 
-		if (len >= 64) {
+		if (likely(len >= 64)) {
 			const uint32x4_t four = {0,0,0,4};
 			const uint32x4_t four = {0,0,0,4};
 			uint8x16_t dd1 = (uint8x16_t)vaddq_u32((uint32x4_t)dd, one);
 			uint8x16_t dd1 = (uint8x16_t)vaddq_u32((uint32x4_t)dd, one);
 			uint8x16_t dd2 = (uint8x16_t)vaddq_u32((uint32x4_t)dd1, one);
 			uint8x16_t dd2 = (uint8x16_t)vaddq_u32((uint32x4_t)dd1, one);