[FFmpeg-devel] [PATCH 2/3] adler32: use 2 sets of variables to break dependancy chains.

Michael Niedermayer michaelni at gmx.at
Fri Feb 3 22:20:19 CET 2012


This way more can get executed at once and the code is slightly
faster on modern CPUs.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavutil/adler32.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavutil/adler32.c b/libavutil/adler32.c
index 9ea639f..6cf780a 100644
--- a/libavutil/adler32.c
+++ b/libavutil/adler32.c
@@ -26,8 +26,8 @@
 
 #define BASE 65521L /* largest prime smaller than 65536 */
 
-#define DO1(buf)  { s1 += *buf++; s2 += s1; }
-#define DO4(buf)  DO1(buf); DO1(buf); DO1(buf); DO1(buf);
+#define DO1(buf, s1, s2)  { s1 += *buf++; s2 += s1; }
+#define DO4(buf)  DO1(buf,s1,a2); DO1(buf,b1,b2); DO1(buf,s1,a2); DO1(buf,b1,b2);
 #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
 
 unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
@@ -40,6 +40,8 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
         unsigned len2=(len-1) & ~15;
         if (len2 > 2048) len2 = 2048;
         if (len2) {
+            unsigned long a2=0;
+            unsigned long b1=0, b2=0;
             len -= len2;
 
 #if CONFIG_SMALL
@@ -53,8 +55,10 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
             len2 -= 16;
         }
 #endif
+            s1 += b1;
+            s2 += 2*(a2+b2) - b1;
         }
-        DO1(buf); len--;
+        DO1(buf, s1, s2); len--;
         s1 %= BASE;
         s2 %= BASE;
     }
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list