]> granicus.if.org Git - libvpx/commitdiff
vp10: code sign bit before absolute value in non-arithcoded header.
authorRonald S. Bultje <rsbultje@gmail.com>
Tue, 8 Sep 2015 18:26:42 +0000 (14:26 -0400)
committerRonald S. Bultje <rsbultje@gmail.com>
Wed, 16 Sep 2015 23:35:03 +0000 (19:35 -0400)
For reading, this makes the operation branchless, although it still
requires two shifts. For writing, this makes the operation as fast
as writing an unsigned value, branchlessly. This is also how other
codecs typically code signed, non-arithcoded bitstream elements.

See issue 1039.

Change-Id: I6a8182cc88a16842fb431688c38f6b52d7f24ead

vp10/decoder/decodeframe.c
vp10/encoder/bitstream.c
vpx_dsp/bitreader_buffer.c
vpx_dsp/bitreader_buffer.h
vpx_dsp/bitwriter_buffer.c
vpx_dsp/bitwriter_buffer.h

index d6a4e6f6afcca4fa128e36f245fe9731d58c8d6a..387204bfad81090524183a62e9e409d9207386a9 100644 (file)
@@ -1095,17 +1095,17 @@ static void setup_loopfilter(struct loopfilter *lf,
 
       for (i = 0; i < MAX_REF_FRAMES; i++)
         if (vpx_rb_read_bit(rb))
-          lf->ref_deltas[i] = vpx_rb_read_signed_literal(rb, 6);
+          lf->ref_deltas[i] = vpx_rb_read_inv_signed_literal(rb, 6);
 
       for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
         if (vpx_rb_read_bit(rb))
-          lf->mode_deltas[i] = vpx_rb_read_signed_literal(rb, 6);
+          lf->mode_deltas[i] = vpx_rb_read_inv_signed_literal(rb, 6);
     }
   }
 }
 
 static INLINE int read_delta_q(struct vpx_read_bit_buffer *rb) {
-  return vpx_rb_read_bit(rb) ? vpx_rb_read_signed_literal(rb, 4) : 0;
+  return vpx_rb_read_bit(rb) ? vpx_rb_read_inv_signed_literal(rb, 4) : 0;
 }
 
 static void setup_quantization(VP10_COMMON *const cm, MACROBLOCKD *const xd,
index 8d84a8590d5902a016a094c083e0106c43b9399c..c0a7d597ceaaad6e7d0afad4296c0f966a03a2fd 100644 (file)
@@ -714,8 +714,7 @@ static void encode_loopfilter(struct loopfilter *lf,
         vpx_wb_write_bit(wb, changed);
         if (changed) {
           lf->last_ref_deltas[i] = delta;
-          vpx_wb_write_literal(wb, abs(delta) & 0x3F, 6);
-          vpx_wb_write_bit(wb, delta < 0);
+          vpx_wb_write_inv_signed_literal(wb, delta, 6);
         }
       }
 
@@ -725,8 +724,7 @@ static void encode_loopfilter(struct loopfilter *lf,
         vpx_wb_write_bit(wb, changed);
         if (changed) {
           lf->last_mode_deltas[i] = delta;
-          vpx_wb_write_literal(wb, abs(delta) & 0x3F, 6);
-          vpx_wb_write_bit(wb, delta < 0);
+          vpx_wb_write_inv_signed_literal(wb, delta, 6);
         }
       }
     }
@@ -736,8 +734,7 @@ static void encode_loopfilter(struct loopfilter *lf,
 static void write_delta_q(struct vpx_write_bit_buffer *wb, int delta_q) {
   if (delta_q != 0) {
     vpx_wb_write_bit(wb, 1);
-    vpx_wb_write_literal(wb, abs(delta_q), 4);
-    vpx_wb_write_bit(wb, delta_q < 0);
+    vpx_wb_write_inv_signed_literal(wb, delta_q, 4);
   } else {
     vpx_wb_write_bit(wb, 0);
   }
index fb04ee634f4fdd761f44a330ab43ae65cbe79416..bb917263ebb0400f97d97aa10f58e8176cf914fb 100644 (file)
@@ -7,6 +7,7 @@
  *  in the file PATENTS.  All contributing project authors may
  *  be found in the AUTHORS file in the root of the source tree.
  */
+#include "./vpx_config.h"
 #include "./bitreader_buffer.h"
 
 size_t vpx_rb_bytes_read(struct vpx_read_bit_buffer *rb) {
@@ -39,3 +40,14 @@ int vpx_rb_read_signed_literal(struct vpx_read_bit_buffer *rb,
   const int value = vpx_rb_read_literal(rb, bits);
   return vpx_rb_read_bit(rb) ? -value : value;
 }
+
+int vpx_rb_read_inv_signed_literal(struct vpx_read_bit_buffer *rb,
+                                   int bits) {
+#if CONFIG_MISC_FIXES
+  const int nbits = sizeof(unsigned) * 8 - bits - 1;
+  const unsigned value = vpx_rb_read_literal(rb, bits + 1) << nbits;
+  return ((int) value) >> nbits;
+#else
+  return vpx_rb_read_signed_literal(rb, bits);
+#endif
+}
index 03b156ba20c17c800e0794ef65d18c5e228f5dd6..8a48a95ed1923775c0c21f6ba48498ab297f4f62 100644 (file)
@@ -38,6 +38,8 @@ int vpx_rb_read_literal(struct vpx_read_bit_buffer *rb, int bits);
 
 int vpx_rb_read_signed_literal(struct vpx_read_bit_buffer *rb, int bits);
 
+int vpx_rb_read_inv_signed_literal(struct vpx_read_bit_buffer *rb, int bits);
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
index 0dfb859db7ab0ac24f0fcc51759495db680b7b7d..6182a722218af880e9dd465d3c5b59605b2c3cf5 100644 (file)
@@ -9,7 +9,9 @@
  */
 
 #include <limits.h>
+#include <stdlib.h>
 
+#include "./vpx_config.h"
 #include "./bitwriter_buffer.h"
 
 size_t vpx_wb_bytes_written(const struct vpx_write_bit_buffer *wb) {
@@ -34,3 +36,13 @@ void vpx_wb_write_literal(struct vpx_write_bit_buffer *wb, int data, int bits) {
   for (bit = bits - 1; bit >= 0; bit--)
     vpx_wb_write_bit(wb, (data >> bit) & 1);
 }
+
+void vpx_wb_write_inv_signed_literal(struct vpx_write_bit_buffer *wb,
+                                     int data, int bits) {
+#if CONFIG_MISC_FIXES
+  vpx_wb_write_literal(wb, data, bits + 1);
+#else
+  vpx_wb_write_literal(wb, abs(data), bits);
+  vpx_wb_write_bit(wb, data < 0);
+#endif
+}
index 9397668ee3e71c4fe9b2a58705574abb43b9029c..a123a2fe8c940ff0354b871942d8b615cafdf4c7 100644 (file)
@@ -28,6 +28,8 @@ void vpx_wb_write_bit(struct vpx_write_bit_buffer *wb, int bit);
 
 void vpx_wb_write_literal(struct vpx_write_bit_buffer *wb, int data, int bits);
 
+void vpx_wb_write_inv_signed_literal(struct vpx_write_bit_buffer *wb, int data,
+                                     int bits);
 
 #ifdef __cplusplus
 }  // extern "C"