[FFmpeg-devel] [PATCH] md5: try combining the bswap and memcpy for the common case.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Fri May 17 21:01:20 CEST 2013


This really needs to be tested and benchmarked on
a bigendian machine, if it doesn't gain much it might
not be worth the ugliness.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavutil/md5.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavutil/md5.c b/libavutil/md5.c
index 7375ce5..97fb9be 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -92,7 +92,7 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
         a = b + (a << t | a >> (32 - t));                               \
     } while (0)
 
-static void body(uint32_t ABCD[4], uint32_t X[16])
+static void body(uint32_t ABCD[4], const uint32_t Xin[16])
 {
     int i av_unused;
     uint32_t t;
@@ -102,8 +102,11 @@ static void body(uint32_t ABCD[4], uint32_t X[16])
     uint32_t d = ABCD[0];
 
 #if HAVE_BIGENDIAN
+    uint32_t X[16];
     for (i = 0; i < 16; i++)
-        X[i] = av_bswap32(X[i]);
+        X[i] = AV_RL32(Xin + i);
+#else
+#define X Xin
 #endif
 
 #if CONFIG_SMALL
@@ -158,15 +161,15 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
     }
 
     end = src + (len & ~63);
-    if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) {
+    if (!HAVE_BIGENDIAN && !HAVE_FAST_UNALIGNED && ((intptr_t)src & 3)) {
        while (src < end) {
            memcpy(ctx->block, src, 64);
-           body(ctx->ABCD, (uint32_t *) ctx->block);
+           body(ctx->ABCD, (const uint32_t *) ctx->block);
            src += 64;
         }
     } else {
         while (src < end) {
-            body(ctx->ABCD, (uint32_t *)src);
+            body(ctx->ABCD, (const uint32_t *)src);
             src += 64;
         }
     }
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list