Commit e15d71d095 for ffmpeg
commit e15d71d095dc977607f3a8049b5f548d5131f03f
Author: Ramiro Polla <ramiro.polla@gmail.com>
Date: Sun Nov 1 21:35:10 2026 +0100
avcodec/x86/cabac: use named operands in inline assembly
This makes the code easier to read and allows adding operands without
renumbering all existing ones. No functional change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h
index 371e668ec4..249c18f000 100644
--- a/libavcodec/x86/cabac.h
+++ b/libavcodec/x86/cabac.h
@@ -50,7 +50,7 @@
#endif
#ifdef BROKEN_RELOCATIONS
-#define TABLES_ARG , "r"(tables)
+#define TABLES_ARG , [tables]"r"(tables)
#ifdef __LZCNT__
/* renormalisation shift = lzcnt(range) - 23, refill shift = tzcnt(low) - 16 */
@@ -217,17 +217,17 @@ int get_cabac_inline_x86(CABACContext *c, uint8_t *const state)
#endif
__asm__ volatile(
- BRANCHLESS_GET_CABAC("%0", "%q0", "(%4)", "%1", "%w1",
- "%2", "%q2", "%3", "%b3",
- "%c6(%5)", "%c7(%5)",
+ BRANCHLESS_GET_CABAC("%[bit]", "%q[bit]", "(%[state])", "%[low]", "%w[low]",
+ "%[range]", "%q[range]", "%[tmp]", "%b[tmp]",
+ "%c[bs](%[c])", "%c[bsend](%[c])",
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
- "%8")
- : "=&r"(bit), "+&r"(c->low), "+&r"(c->range), "=&q"(tmp)
- : "r"(state), "r"(c),
- "i"(offsetof(CABACContext, bytestream)),
- "i"(offsetof(CABACContext, bytestream_end))
+ "%[tables]")
+ : [bit]"=&r"(bit), [low]"+&r"(c->low), [range]"+&r"(c->range), [tmp]"=&q"(tmp)
+ : [state]"r"(state), [c]"r"(c),
+ [bs]"i"(offsetof(CABACContext, bytestream)),
+ [bsend]"i"(offsetof(CABACContext, bytestream_end))
TABLES_ARG
: "%"FF_REG_c, "memory"
);
diff --git a/libavcodec/x86/h264_cabac.c b/libavcodec/x86/h264_cabac.c
index ac7d07780c..4f595ec05a 100644
--- a/libavcodec/x86/h264_cabac.c
+++ b/libavcodec/x86/h264_cabac.c
@@ -65,53 +65,53 @@ static int decode_significance_x86(CABACContext *c, int max_coeff,
__asm__ volatile(
"3: \n\t"
- BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
- "%5", "%q5", "%k0", "%b0",
- "%c11(%6)", "%c12(%6)",
+ BRANCHLESS_GET_CABAC("%[bit]", "%q[bit]", "(%[ctx])", "%[low]", "%w[low]",
+ "%[range]", "%q[range]", "%k[cnt]", "%b[cnt]",
+ "%c[bs](%[c])", "%c[bsend](%[c])",
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
- "%13")
+ "%[tables]")
- "test $1, %4 \n\t"
+ "test $1, %[bit] \n\t"
" jz 4f \n\t"
- "add %10, %1 \n\t"
+ "add %[last_off], %[ctx] \n\t"
- BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
- "%5", "%q5", "%k0", "%b0",
- "%c11(%6)", "%c12(%6)",
+ BRANCHLESS_GET_CABAC("%[bit]", "%q[bit]", "(%[ctx])", "%[low]", "%w[low]",
+ "%[range]", "%q[range]", "%k[cnt]", "%b[cnt]",
+ "%c[bs](%[c])", "%c[bsend](%[c])",
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
- "%13")
+ "%[tables]")
- "sub %10, %1 \n\t"
- "mov %2, %0 \n\t"
- "movl %7, %%ecx \n\t"
- "add %1, %%"FF_REG_c" \n\t"
- "movl %%ecx, (%0) \n\t"
+ "sub %[last_off], %[ctx] \n\t"
+ "mov %[index], %[cnt] \n\t"
+ "movl %[minusstart], %%ecx \n\t"
+ "add %[ctx], %%"FF_REG_c" \n\t"
+ "movl %%ecx, (%[cnt]) \n\t"
- "test $1, %4 \n\t"
+ "test $1, %[bit] \n\t"
" jnz 5f \n\t"
- "add"FF_OPSIZE" $4, %2 \n\t"
+ "add"FF_OPSIZE" $4, %[index] \n\t"
"4: \n\t"
- "add $1, %1 \n\t"
- "cmp %8, %1 \n\t"
+ "add $1, %[ctx] \n\t"
+ "cmp %[end], %[ctx] \n\t"
" jb 3b \n\t"
- "mov %2, %0 \n\t"
- "movl %7, %%ecx \n\t"
- "add %1, %%"FF_REG_c" \n\t"
- "movl %%ecx, (%0) \n\t"
+ "mov %[index], %[cnt] \n\t"
+ "movl %[minusstart], %%ecx \n\t"
+ "add %[ctx], %%"FF_REG_c" \n\t"
+ "movl %%ecx, (%[cnt]) \n\t"
"5: \n\t"
- "add %9, %k0 \n\t"
- "shr $2, %k0 \n\t"
- : "=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
- "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
- : "r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
- "i"(offsetof(CABACContext, bytestream)),
- "i"(offsetof(CABACContext, bytestream_end))
+ "add %[minusindex], %k[cnt] \n\t"
+ "shr $2, %k[cnt] \n\t"
+ : [cnt]"=&q"(coeff_count), [ctx]"+r"(significant_coeff_ctx_base), [index]"+m"(index),
+ [low]"+&r"(c->low), [bit]"=&r"(bit), [range]"+&r"(c->range)
+ : [c]"r"(c), [minusstart]"m"(minusstart), [end]"m"(end), [minusindex]"m"(minusindex), [last_off]"m"(last_off),
+ [bs]"i"(offsetof(CABACContext, bytestream)),
+ [bsend]"i"(offsetof(CABACContext, bytestream_end))
TABLES_ARG
: "%"FF_REG_c, "memory"
);
@@ -139,66 +139,67 @@ static int decode_significance_8x8_x86(CABACContext *c,
#endif
__asm__ volatile(
- "mov %1, %6 \n\t"
+ "mov %[last], %[state] \n\t"
"3: \n\t"
- "mov %10, %0 \n\t"
- "movzb (%0, %6), %6 \n\t"
- "add %9, %6 \n\t"
+ "mov %[sig_off], %[cnt] \n\t"
+ "movzb (%[cnt], %[state]), %[state] \n\t"
+ "add %[sig_base], %[state] \n\t"
- BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
- "%5", "%q5", "%k0", "%b0",
- "%c12(%7)", "%c13(%7)",
+ BRANCHLESS_GET_CABAC("%[bit]", "%q[bit]", "(%[state])", "%[low]", "%w[low]",
+ "%[range]", "%q[range]", "%k[cnt]", "%b[cnt]",
+ "%c[bs](%[c])", "%c[bsend](%[c])",
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
- "%15")
+ "%[tables]")
- "mov %1, %6 \n\t"
- "test $1, %4 \n\t"
+ "mov %[last], %[state] \n\t"
+ "test $1, %[bit] \n\t"
" jz 4f \n\t"
#ifdef BROKEN_RELOCATIONS
- "movzb %c14(%15, %q6), %6\n\t"
+ "movzb %c[lastoff](%[tables], %q[state]), %[state]\n\t"
#else
- "movzb "MANGLE(ff_h264_cabac_tables)"+%c14(%6), %6\n\t"
+ "movzb "MANGLE(ff_h264_cabac_tables)"+%c[lastoff](%[state]), %[state]\n\t"
#endif
- "add %11, %6 \n\t"
+ "add %[last_base], %[state] \n\t"
- BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
- "%5", "%q5", "%k0", "%b0",
- "%c12(%7)", "%c13(%7)",
+ BRANCHLESS_GET_CABAC("%[bit]", "%q[bit]", "(%[state])", "%[low]", "%w[low]",
+ "%[range]", "%q[range]", "%k[cnt]", "%b[cnt]",
+ "%c[bs](%[c])", "%c[bsend](%[c])",
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
- "%15")
+ "%[tables]")
- "mov %2, %0 \n\t"
- "mov %1, %6 \n\t"
- "mov %k6, (%0) \n\t"
+ "mov %[index], %[cnt] \n\t"
+ "mov %[last], %[state] \n\t"
+ "mov %k[state], (%[cnt]) \n\t"
- "test $1, %4 \n\t"
+ "test $1, %[bit] \n\t"
" jnz 5f \n\t"
- "add"FF_OPSIZE" $4, %2 \n\t"
+ "add"FF_OPSIZE" $4, %[index] \n\t"
"4: \n\t"
- "add $1, %6 \n\t"
- "mov %6, %1 \n\t"
- "cmp $63, %6 \n\t"
+ "add $1, %[state] \n\t"
+ "mov %[state], %[last] \n\t"
+ "cmp $63, %[state] \n\t"
" jb 3b \n\t"
- "mov %2, %0 \n\t"
- "mov %k6, (%0) \n\t"
+ "mov %[index], %[cnt] \n\t"
+ "mov %k[state], (%[cnt]) \n\t"
"5: \n\t"
- "addl %8, %k0 \n\t"
- "shr $2, %k0 \n\t"
- : "=&q"(coeff_count), "+"REG64(last), "+"REG64(index), "+&r"(c->low),
- "=&r"(bit), "+&r"(c->range), "=&r"(state)
- : "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
- REG64(sig_off), REG64(last_coeff_ctx_base),
- "i"(offsetof(CABACContext, bytestream)),
- "i"(offsetof(CABACContext, bytestream_end)),
- "i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
+ "addl %[minusindex], %k[cnt] \n\t"
+ "shr $2, %k[cnt] \n\t"
+ : [cnt]"=&q"(coeff_count), [last]"+"REG64(last), [index]"+"REG64(index), [low]"+&r"(c->low),
+ [bit]"=&r"(bit), [range]"+&r"(c->range), [state]"=&r"(state)
+ : [c]"r"(c), [minusindex]"m"(minusindex), [sig_base]"m"(significant_coeff_ctx_base),
+ [sig_off]REG64(sig_off), [last_base]REG64(last_coeff_ctx_base),
+ [bs]"i"(offsetof(CABACContext, bytestream)),
+ [bsend]"i"(offsetof(CABACContext, bytestream_end)),
+ [lastoff]"i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET)
+ TABLES_ARG
: "%"FF_REG_c, "memory"
);
return coeff_count;