summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-05-25 23:06:50 -0400
committerJeffrey Walton <noloader@gmail.com>2021-05-25 23:06:50 -0400
commitb2571d47c6d316bf8e59dbda64daeeaafc395d01 (patch)
tree2ddab665909a17a914960d59fd814206974c7538
parent2ed2e19e8e2f926dbea974c08ec9692536f7b24d (diff)
downloadcryptopp-git-b2571d47c6d316bf8e59dbda64daeeaafc395d01.tar.gz
Add CRC32Wx4 and CRC32CWx4 for 4 blocks at a time
-rw-r--r--arm_simd.h74
-rw-r--r--crc_simd.cpp14
2 files changed, 58 insertions, 30 deletions
diff --git a/arm_simd.h b/arm_simd.h
index 00b4f9e2..45a2d62a 100644
--- a/arm_simd.h
+++ b/arm_simd.h
@@ -29,10 +29,9 @@ inline uint32_t CRC32B (uint32_t crc, uint8_t val)
#if defined(_MSC_VER)
return __crc32b(crc, val);
#else
- uint32_t r;
- __asm__ ("crc32b %w0, %w1, %w2 \n\t"
- :"=r" (r) : "r" (crc), "r" (val) );
- return r;
+ __asm__ ("crc32b %w0, %w0, %w1 \n\t"
+ :"+r" (crc) : "r" (val) );
+ return crc;
#endif
}
@@ -46,44 +45,83 @@ inline uint32_t CRC32W (uint32_t crc, uint32_t val)
#if defined(_MSC_VER)
return __crc32w(crc, val);
#else
- uint32_t r;
- __asm__ ("crc32w %w0, %w1, %w2 \n\t"
- :"=r" (r) : "r" (crc), "r" (val) );
- return r;
+ __asm__ ("crc32w %w0, %w0, %w1 \n\t"
+ :"+r" (crc) : "r" (val) );
+ return crc;
#endif
}
-/// \brief CRC32-C
+/// \brief CRC32
/// \param a the first value
/// \param b the second value
/// \return CRC32 value
/// \since Crypto++ 8.6
+inline uint32_t CRC32Wx4 (uint32_t crc, const uint32_t vals[4])
+{
+#if defined(_MSC_VER)
+ return __crc32w(__crc32w(__crc32w(__crc32w(
+ crc, vals[0]), vals[1]), vals[2]), vals[3]);
+#else
+ __asm__ ("crc32w %w0, %w0, %w1 \n\t"
+ "crc32w %w0, %w0, %w2 \n\t"
+ "crc32w %w0, %w0, %w3 \n\t"
+ "crc32w %w0, %w0, %w4 \n\t"
+ :"+r" (crc) : "r" (vals[0]), "r" (vals[1]),
+ "r" (vals[2]), "r" (vals[3]));
+ return crc;
+#endif
+}
+
+/// \brief CRC32-C
+/// \param a the first value
+/// \param b the second value
+/// \return CRC32-C value
+/// \since Crypto++ 8.6
inline uint32_t CRC32CB (uint32_t crc, uint8_t val)
{
#if defined(_MSC_VER)
return __crc32cb(crc, val);
#else
- uint32_t r;
- __asm__ ("crc32cb %w0, %w1, %w2 \n\t"
- :"=r" (r) : "r" (crc), "r" (val) );
- return r;
+ __asm__ ("crc32cb %w0, %w0, %w1 \n\t"
+ :"+r" (crc) : "r" (val) );
+ return crc;
#endif
}
/// \brief CRC32-C
/// \param a the first value
/// \param b the second value
-/// \return CRC32 value
+/// \return CRC32-C value
/// \since Crypto++ 8.6
inline uint32_t CRC32CW (uint32_t crc, uint32_t val)
{
#if defined(_MSC_VER)
return __crc32cw(crc, val);
#else
- uint32_t r;
- __asm__ ("crc32cw %w0, %w1, %w2 \n\t"
- :"=r" (r) : "r" (crc), "r" (val) );
- return r;
+ __asm__ ("crc32cw %w0, %w0, %w1 \n\t"
+ :"+r" (crc) : "r" (val) );
+ return crc;
+#endif
+}
+
+/// \brief CRC32-C
+/// \param a the first value
+/// \param b the second value
+/// \return CRC32-C value
+/// \since Crypto++ 8.6
+inline uint32_t CRC32CWx4 (uint32_t crc, const uint32_t vals[4])
+{
+#if defined(_MSC_VER)
+ return __crc32cw(__crc32cw(__crc32cw(__crc32cw(
+ crc, vals[0]), vals[1]), vals[2]), vals[3]);
+#else
+ __asm__ ("crc32cw %w0, %w0, %w1 \n\t"
+ "crc32cw %w0, %w0, %w2 \n\t"
+ "crc32cw %w0, %w0, %w3 \n\t"
+ "crc32cw %w0, %w0, %w4 \n\t"
+ :"+r" (crc) : "r" (vals[0]), "r" (vals[1]),
+ "r" (vals[2]), "r" (vals[3]));
+ return crc;
#endif
}
#endif // CRYPTOPP_ARM_CRC32_AVAILABLE
diff --git a/crc_simd.cpp b/crc_simd.cpp
index 1bbc8757..0355e9be 100644
--- a/crc_simd.cpp
+++ b/crc_simd.cpp
@@ -121,12 +121,7 @@ void CRC32_Update_ARMV8(const byte *s, size_t n, word32& c)
c = CRC32B(c, *s);
for(; n >= 16; s+=16, n-=16)
- {
- c = CRC32W(c, *(const word32 *)(void*)(s+ 0));
- c = CRC32W(c, *(const word32 *)(void*)(s+ 4));
- c = CRC32W(c, *(const word32 *)(void*)(s+ 8));
- c = CRC32W(c, *(const word32 *)(void*)(s+12));
- }
+ c = CRC32Wx4(c, (const word32 *)(void*)s);
for(; n >= 4; s+=4, n-=4)
c = CRC32W(c, *(const word32 *)(void*)s);
@@ -141,12 +136,7 @@ void CRC32C_Update_ARMV8(const byte *s, size_t n, word32& c)
c = CRC32CB(c, *s);
for(; n >= 16; s+=16, n-=16)
- {
- c = CRC32CW(c, *(const word32 *)(void*)(s+ 0));
- c = CRC32CW(c, *(const word32 *)(void*)(s+ 4));
- c = CRC32CW(c, *(const word32 *)(void*)(s+ 8));
- c = CRC32CW(c, *(const word32 *)(void*)(s+12));
- }
+ c = CRC32CWx4(c, (const word32 *)(void*)s);
for(; n >= 4; s+=4, n-=4)
c = CRC32CW(c, *(const word32 *)(void*)s);