This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 6179982c9c0ae6ff5092b4df3a173a79e2227785 Author: Charly Morgand-Poyac <[email protected]> AuthorDate: Mon Jul 6 00:25:11 2026 +0200 Commit: charlymp <[email protected]> CommitDate: Sat Jul 11 14:23:12 2026 +0000 avcodec/x86/cabac: compute renormalisation shifts with lzcnt The norm_shift loads sit on the serial range dependency chain and cost several cycles where lzcnt costs one. Builds targeting CPUs without LZCNT keep the exact original code. About 1.5% faster CABAC heavy H.264 and HEVC decoding. Signed-off-by: Charly Morgand-Poyac <[email protected]> --- libavcodec/x86/cabac.h | 93 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index ce2aefcbac..ce05f70988 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -77,6 +77,38 @@ "movslq "ret" , "retq" \n\t" #endif /* HAVE_FAST_CMOV */ +#ifdef __LZCNT__ +/* renormalisation shift = lzcnt(range) - 23, refill shift = tzcnt(low) - 16 */ +#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ + "lzcnt "range" , %%ecx \n\t"\ + "sub $23 , %%ecx \n\t" +#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ + "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ + "tzcnt "low" , %%ecx \n\t"\ + "bswap "tmp" \n\t"\ + "shr $15 , "tmp" \n\t"\ + "sub $16 , %%ecx \n\t"\ + "sub $0xFFFF , "tmp" \n\t"\ + "shl %%cl , "tmp" \n\t"\ + "add "tmp" , "low" \n\t" +#else /* __LZCNT__ */ +#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ + "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t" +#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ + "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ + "lea -1("low") , %%ecx \n\t"\ + "xor "low" , %%ecx \n\t"\ + "shr $15 , %%ecx \n\t"\ + "bswap "tmp" \n\t"\ + "shr $15 , "tmp" \n\t"\ + "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\ + "sub $0xFFFF , "tmp" \n\t"\ + "neg %%ecx \n\t"\ + "add $7 , %%ecx \n\t"\ + "shl %%cl , "tmp" \n\t"\ + "add "tmp" , "low" \n\t" +#endif /* __LZCNT__ */ + #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \ "movzbl "statep" , "ret" \n\t"\ "mov "range" , "tmp" \n\t"\ @@ -87,7 +119,7 @@ "mov "tmp" , %%ecx \n\t"\ "shl $17 , "tmp" \n\t"\ BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \ - "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"\ + BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ "shl %%cl , "range" \n\t"\ "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\ "shl %%cl , "low" \n\t"\ @@ -98,18 +130,7 @@ END_CHECK(end)\ "add"FF_OPSIZE" $2 , "byte" \n\t"\ "1: \n\t"\ - "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ - "lea -1("low") , %%ecx \n\t"\ - "xor "low" , %%ecx \n\t"\ - "shr $15 , %%ecx \n\t"\ - "bswap "tmp" \n\t"\ - "shr $15 , "tmp" \n\t"\ - "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\ - "sub $0xFFFF , "tmp" \n\t"\ - "neg %%ecx \n\t"\ - "add $7 , %%ecx \n\t"\ - "shl %%cl , "tmp" \n\t"\ - "add "tmp" , "low" \n\t"\ + BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ "2: \n\t" #else /* BROKEN_RELOCATIONS */ @@ -141,6 +162,37 @@ "xor "tmp" , "ret" \n\t" #endif /* HAVE_FAST_CMOV */ +#ifdef __LZCNT__ +#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ + "lzcnt "range" , %%ecx \n\t"\ + "sub $23 , %%ecx \n\t" +#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ + "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ + "tzcnt "low" , %%ecx \n\t"\ + "bswap "tmp" \n\t"\ + "shr $15 , "tmp" \n\t"\ + "sub $16 , %%ecx \n\t"\ + "sub $0xFFFF , "tmp" \n\t"\ + "shl %%cl , "tmp" \n\t"\ + "add "tmp" , "low" \n\t" +#else /* __LZCNT__ */ +#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ + "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t" +#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ + "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ + "lea -1("low") , %%ecx \n\t"\ + "xor "low" , %%ecx \n\t"\ + "shr $15 , %%ecx \n\t"\ + "bswap "tmp" \n\t"\ + "shr $15 , "tmp" \n\t"\ + "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\ + "sub $0xFFFF , "tmp" \n\t"\ + "neg %%ecx \n\t"\ + "add $7 , %%ecx \n\t"\ + "shl %%cl , "tmp" \n\t"\ + "add "tmp" , "low" \n\t" +#endif /* __LZCNT__ */ + #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \ "movzbl "statep" , "ret" \n\t"\ "mov "range" , "tmp" \n\t"\ @@ -148,7 +200,7 @@ "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\ "sub "range" , "tmp" \n\t"\ BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \ - "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"\ + BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \ "shl %%cl , "range" \n\t"\ "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\ "shl %%cl , "low" \n\t"\ @@ -159,18 +211,7 @@ END_CHECK(end)\ "add"FF_OPSIZE" $2 , "byte" \n\t"\ "1: \n\t"\ - "movzwl (%%"FF_REG_c") , "tmp" \n\t"\ - "lea -1("low") , %%ecx \n\t"\ - "xor "low" , %%ecx \n\t"\ - "shr $15 , %%ecx \n\t"\ - "bswap "tmp" \n\t"\ - "shr $15 , "tmp" \n\t"\ - "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\ - "sub $0xFFFF , "tmp" \n\t"\ - "neg %%ecx \n\t"\ - "add $7 , %%ecx \n\t"\ - "shl %%cl , "tmp" \n\t"\ - "add "tmp" , "low" \n\t"\ + BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \ "2: \n\t" #endif /* BROKEN_RELOCATIONS */ _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
