Commit 553b1735bd for aom

commit 553b1735bdfec25a9f7458d8b9d58ddbec432f2f
Author: Frank Galligan <fgalligan@google.com>
Date:   Thu Nov 12 01:59:07 2026 -0800

    txb_rdopt: defer non_skip_cost to epilogue

    Defer loading non_skip_cost and skip_cost from the entry of
    av1_optimize_txb_multi() into the rare sharpness == 0 update_skip()
    branch and the non-skip epilogue. This frees registers across the
    main trellis optimization loops and avoids loading non_skip_cost when
    update_skip() lowers eob to zero.

    Speedup vs origin/main (AMD EPYC 7B13, --cpu-used=6, x86_64 AVX2,
    bit-exact):
      -0.22% (1T) / -0.54% (8T) 720p allintra, -0.61% 1080p allintra (8T),
      -0.34% 720p good (1T).
    Binary size (x86_64 -O3): libaom.a .text +0.1 KiB (+0.00%),
      .rodata +0.1 KiB (+0.01%); stripped aomenc +0.0 KiB (+0.00%).
    Memory (peak RSS, 1080p allintra): 1T +296 KiB (+0.70%),
      8T +524 KiB (+1.21%) (allocator variance; no allocations added).

    TAG=agy
    CONV=b929a630-a6cd-45a0-979c-1767c30178ee

    Change-Id: I798e57ccd54cb5f3c95bbcbbbfff6e295c4ec04f

diff --git a/av1/encoder/txb_rdopt.c b/av1/encoder/txb_rdopt.c
index c3673495c0..be698df8c1 100644
--- a/av1/encoder/txb_rdopt.c
+++ b/av1/encoder/txb_rdopt.c
@@ -719,8 +719,6 @@ int av1_optimize_txb_multi(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
   const LV_MAP_EOB_COST *txb_eob_costs =
       &coeff_costs->eob_costs[eob_multi_size][plane_type];

-  const int non_skip_cost = txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][0];
-  const int skip_cost = txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][1];
   const int eob_cost = get_eob_cost(eob, txb_eob_costs, txb_costs, tx_class);
   int accu_rate = eob_cost;
   int64_t accu_dist = 0;
@@ -818,9 +816,19 @@ int av1_optimize_txb_multi(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
           update_coeff_eob_nz(0, 0, qc_dc, coeff_ctx, tx_class, ctx_ptr);
     }
     if (ctx_ptr->nz_num <= max_nz_num && sharpness == 0) {
+      const int *const txb_skip_cost =
+          txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx];
+      const int non_skip_cost = txb_skip_cost[0];
+      const int skip_cost = txb_skip_cost[1];
       update_skip(&ctx_ptr->accu_rate, ctx_ptr->accu_dist, &ctx_ptr->eob,
                   ctx_ptr->nz_num, nz_ci, rdmult, skip_cost, non_skip_cost,
                   qcoeff, dqcoeff);
+      if (ctx_ptr->eob == 0) {
+        p->eobs[block] = 0;
+        p->txb_entropy_ctx[block] = 0;
+        *rate_cost = ctx_ptr->accu_rate + skip_cost;
+        return 0;
+      }
     }
   } else {
     assert(si == 0);
@@ -834,16 +842,12 @@ int av1_optimize_txb_multi(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
   eob = ctx_ptr->eob;

   p->eobs[block] = eob;
-  if (eob == 0) {
-    accu_rate += skip_cost;
-    p->txb_entropy_ctx[block] = 0;
-  } else {
-    const int tx_type_cost = get_tx_type_cost(x, xd, plane, tx_size, tx_type,
-                                              cm->features.reduced_tx_set_used);
-    accu_rate += non_skip_cost + tx_type_cost;
-    p->txb_entropy_ctx[block] =
-        av1_get_txb_entropy_context(qcoeff, scan_order, eob);
-  }
+  const int tx_type_cost = get_tx_type_cost(x, xd, plane, tx_size, tx_type,
+                                            cm->features.reduced_tx_set_used);
+  accu_rate +=
+      txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][0] + tx_type_cost;
+  p->txb_entropy_ctx[block] =
+      av1_get_txb_entropy_context(qcoeff, scan_order, eob);

   *rate_cost = accu_rate;
   return eob;