]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
utils: Make use of 128-bit integer support in memxor()
authorMartin Willi <martin@revosec.ch>
Thu, 19 Mar 2015 15:29:42 +0000 (16:29 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 09:41:55 +0000 (11:41 +0200)
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.

src/libstrongswan/utils/utils.h

index 8ee94ab091bb50f2b9d770789577aabf038ef277..e1dedc356ecf91451665a3bd870dee119ffc729d 100644 (file)
@@ -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];