]> granicus.if.org Git - libvpx/commitdiff
Add a few branch hints to vp10_optimize_b.
authorGeza Lore <gezalore@gmail.com>
Fri, 8 Jul 2016 18:16:05 +0000 (19:16 +0100)
committerGeza Lore <gezalore@gmail.com>
Fri, 8 Jul 2016 18:20:35 +0000 (19:20 +0100)
vp10_optimize_b now takes between 40% to 60% of the TOTAL runtime
of the encoder, depending on bit-rate. It also contains 2/3 to 3/4
of the mispredicted branch instructions in the whole program.

Adding a few branch hints makes vp10_optimize_b around 2-5% faster
(dependig on bit-rate) when compiled with gcc/clang.

Change-Id: I1572733e18b4166bc10591b958c5018a9561fa2b

vp10/encoder/encodemb.c

index 33073936de07a342b3e7a991542891c00e0c449f..3810be5d61014e16d1da535abc1f64f87c8f73ee 100644 (file)
@@ -160,7 +160,7 @@ int vp10_optimize_b(MACROBLOCK *mb, int plane, int block,
     next_shortcut = shortcut;
 
     /* Only add a trellis state for non-zero coefficients. */
-    if (x) {
+    if (UNLIKELY(x)) {
       error0 = tokens[next][0].error;
       error1 = tokens[next][1].error;
       /* Evaluate the first possibility for this state. */
@@ -204,7 +204,7 @@ int vp10_optimize_b(MACROBLOCK *mb, int plane, int block,
       rate1 = tokens[next][1].rate;
 
       // The threshold of 3 is empirically obtained.
-      if (abs(x) > 3) {
+      if (UNLIKELY(abs(x) > 3)) {
         shortcut = 0;
       } else {
 #if CONFIG_NEW_QUANT
@@ -233,7 +233,7 @@ int vp10_optimize_b(MACROBLOCK *mb, int plane, int block,
         best_index[i][1] = best_index[i][0];
         next = i;
 
-        if (!(--band_left)) {
+        if (UNLIKELY(!(--band_left))) {
           --band_counts;
           band_left = *band_counts;
           --token_costs;
@@ -255,7 +255,7 @@ int vp10_optimize_b(MACROBLOCK *mb, int plane, int block,
       }
 
       if (next_shortcut) {
-        if (next < default_eob) {
+        if (LIKELY(next < default_eob)) {
           if (t0 != EOB_TOKEN) {
             token_cache[rc] = vp10_pt_energy_class[t0];
             pt = get_coef_context(nb, token_cache, i + 1);
@@ -350,7 +350,7 @@ int vp10_optimize_b(MACROBLOCK *mb, int plane, int block,
       /* Don't update next, because we didn't add a new node. */
     }
 
-    if (!(--band_left)) {
+    if (UNLIKELY(!(--band_left))) {
       --band_counts;
       band_left = *band_counts;
       --token_costs;