[FFmpeg-cvslog] xtea: invert branch and loop precedence

Luca Barbato git at videolan.org
Thu Jul 5 21:58:37 CEST 2012


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Thu Jul  5 09:52:04 2012 +0200| [f6687bf5f8989d397cdef6d9d05bcb13a7ef8c4f] | committer: Luca Barbato

xtea: invert branch and loop precedence

Should slightly improve performance depending on the compiler used.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f6687bf5f8989d397cdef6d9d05bcb13a7ef8c4f
---

 libavutil/xtea.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavutil/xtea.c b/libavutil/xtea.c
index 138657f..07a66e5 100644
--- a/libavutil/xtea.c
+++ b/libavutil/xtea.c
@@ -71,8 +71,8 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
 {
     int i;
 
-    while (count > 0) {
-        if (decrypt) {
+    if (decrypt) {
+        while (count > 0) {
             xtea_crypt_ecb(ctx, dst, src, decrypt);
 
             if (iv) {
@@ -80,7 +80,13 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
                     dst[i] = dst[i] ^ iv[i];
                 memcpy(iv, src, 8);
             }
-        } else {
+
+            src   += 8;
+            dst   += 8;
+            count -= 8;
+        }
+    } else {
+        while (count > 0) {
             if (iv) {
                 for (i = 0; i < 8; i++)
                     dst[i] = src[i] ^ iv[i];
@@ -89,11 +95,10 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
             } else {
                 xtea_crypt_ecb(ctx, dst, src, decrypt);
             }
+            src   += 8;
+            dst   += 8;
+            count -= 8;
         }
-
-        src   += 8;
-        dst   += 8;
-        count -= 8;
     }
 }
 



More information about the ffmpeg-cvslog mailing list