From: Martin Willi Date: Thu, 19 Mar 2015 15:29:42 +0000 (+0100) Subject: utils: Make use of 128-bit integer support in memxor() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63da7db13eae8e9c42972e21f9520a66c405d719;p=thirdparty%2Fstrongswan.git utils: Make use of 128-bit integer support in memxor() If inlined, this can improve memxor() performance significantly. This increases AES-GCM performance by ~20% when building with an instruction set supporting such words natively. --- diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h index 8ee94ab091..e1dedc356e 100644 --- a/src/libstrongswan/utils/utils.h +++ b/src/libstrongswan/utils/utils.h @@ -564,14 +564,22 @@ static inline void memxor_inline(u_int8_t dst[], u_int8_t src[], size_t n) int m, i; /* byte wise XOR until dst aligned */ - for (i = 0; (uintptr_t)&dst[i] % sizeof(long) && i < n; i++) + for (i = 0; (uintptr_t)&dst[i] % sizeof(MAX_INT_TYPE) && i < n; i++) { dst[i] ^= src[i]; } /* try to use words if src shares an aligment with dst */ - switch (((uintptr_t)&src[i] % sizeof(long))) + switch (((uintptr_t)&src[i] % sizeof(MAX_INT_TYPE))) { +#ifdef HAVE_INT128 case 0: + for (m = n - sizeof(int128_t); i <= m; i += sizeof(int128_t)) + { + *(int128_t*)&dst[i] ^= *(int128_t*)&src[i]; + } + break; +#endif + case sizeof(MAX_INT_TYPE) - sizeof(long): for (m = n - sizeof(long); i <= m; i += sizeof(long)) { *(long*)&dst[i] ^= *(long*)&src[i];