ref: a3df343cda2b6f3d554138ce5dae831e2f946d0c
parent: 3c8e04e93928b978dc6df84cf0f77939d7a2e64b
author: Ronald S. Bultje <[email protected]>
date: Tue Sep 8 10:26:42 EDT 2015
vp10: code sign bit before absolute value in non-arithcoded header. 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
--- a/vp10/decoder/decodeframe.c
+++ b/vp10/decoder/decodeframe.c
@@ -1095,17 +1095,17 @@
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,
--- a/vp10/encoder/bitstream.c
+++ b/vp10/encoder/bitstream.c
@@ -714,8 +714,7 @@
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 @@
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 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);
}
--- a/vpx_dsp/bitreader_buffer.c
+++ b/vpx_dsp/bitreader_buffer.c
@@ -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) {
@@ -38,4 +39,15 @@
int bits) {
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
}
--- a/vpx_dsp/bitreader_buffer.h
+++ b/vpx_dsp/bitreader_buffer.h
@@ -38,6 +38,8 @@
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
--- a/vpx_dsp/bitwriter_buffer.c
+++ b/vpx_dsp/bitwriter_buffer.c
@@ -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) {
@@ -33,4 +35,14 @@
int bit;
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
}
--- a/vpx_dsp/bitwriter_buffer.h
+++ b/vpx_dsp/bitwriter_buffer.h
@@ -28,6 +28,8 @@
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"