ffmpeg | branch: master | Michael Niedermayer <mich...@niedermayer.cc> | Mon 
Oct 19 10:20:26 2020 +0200| [4e9514e99bf77bb3d1437e992c3e08ca7d1ebc46] | 
committer: Michael Niedermayer

avutil/common: Implement av_sat_add64_c() with fewer branches

No benchmark because this is not used in any speed relevant pathes nor is it
used where __builtin_add_overflow is available.
So I do not know how to realistically benchmark it.

Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc>

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

 libavutil/common.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index 92b721a59c..b9fbcc4d60 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -303,11 +303,10 @@ static av_always_inline int64_t av_sat_add64_c(int64_t a, 
int64_t b) {
     int64_t tmp;
     return !__builtin_add_overflow(a, b, &tmp) ? tmp : (tmp < 0 ? INT64_MAX : 
INT64_MIN);
 #else
-    if (b >= 0 && a >= INT64_MAX - b)
-        return INT64_MAX;
-    if (b <= 0 && a <= INT64_MIN - b)
-        return INT64_MIN;
-    return a + b;
+    int64_t s = a+(uint64_t)b;
+    if ((int64_t)(a^b | ~s^b) >= 0)
+        return INT64_MAX ^ (b >> 63);
+    return s;
 #endif
 }
 

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to