This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 8dccb380cf956813eaa34793f1c1972a5b05af35 Author: Rémi Denis-Courmont <[email protected]> AuthorDate: Sun Dec 14 11:06:13 2025 +0200 Commit: Rémi Denis-Courmont <[email protected]> CommitDate: Fri Dec 19 19:50:56 2025 +0200 lavc/mathops: simplify mid_pred() This reduces the minimum instruction emission for mid_pred() (i.e. median of 3) down to: - 3 comparisons and 4 conditional moves, or - 4 min/max. With that the compiler can eliminate any branch. This optimal situation is attainable with Clang 21 on Arm64, RVA22 and x86, with GCC 15 on Arm64 and x86 (RVA22 goes from 2 to 1 branch). These optimisations also work on Arm32 and LoongArch. The same algorithm is already implemented via inline assembler for some architectures such as x86 and Arm32, but notably not Arm64 and RVA22. Besides, using C code allows the compiler to schedule instruction properly. Even on architectures with neither conditional moves nor min/max, this leads to a visible performance improvement for C code, as seen here for RVA20 code running on SiFive-U74: Before: sub_median_pred_c: 1657.5 ( 1.00x) sub_median_pred_rvb_b: 875.9 ( 1.89x) After: sub_median_pred_c: 1331.9 ( 1.00x) sub_median_pred_rvb_b: 881.8 ( 1.51x) Note that this commit leaves the x86 and Arm32 code intact so it has no effects on those ISA's. --- libavcodec/mathops.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h index aa0bdfe956..4411d138b4 100644 --- a/libavcodec/mathops.h +++ b/libavcodec/mathops.h @@ -93,23 +93,24 @@ static av_always_inline unsigned UMULH(unsigned a, unsigned b){ #endif /* median of 3 */ -#ifndef mid_pred -#define mid_pred mid_pred -static inline av_const int mid_pred(int a, int b, int c) +static inline av_const int median3_c(int a, int b, int c) { - if(a>b){ - if(c>b){ - if(c>a) b=a; - else b=c; - } - }else{ - if(b>c){ - if(c>a) b=c; - else b=a; - } + int max2, min2, m; + + if (a >= b) { + max2 = a; + min2 = b; + } else { + max2 = b; + min2 = a; } - return b; + m = (c >= max2) ? max2 : c; + + return (m >= min2) ? m : min2; } + +#ifndef mid_pred +#define mid_pred median3_c #endif #ifndef median4 _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
