Pass n to get_msb in the primitive_quniform funcs. The functions this CL modifies were added in the following two CLs: https://aomedia-review.googlesource.com/c/aom/+/8789 https://aomedia-review.googlesource.com/c/aom/+/20820 These functions pass n - 1 to get_msb(). I believe these functions implement the ns(n) and NS(n) descriptors of the AV1 spec. ns(n) and NS(n) pass n, not n - 1, to FloorLog2(). (FloorLog2() is the same as libaom's get_msb() function.) A careful analysis of the code shows passing n instead of n - 1 to get_msb() results in the same outcome for these functions. Passing n matches the AV1 spec and is slightly more efficient when n is a power of 2. Change-Id: Ibeff837059e9c9de2b4ab9cb857a2ea60b1c4767
diff --git a/aom_dsp/binary_codes_reader.c b/aom_dsp/binary_codes_reader.c index 23e6121..0108801 100644 --- a/aom_dsp/binary_codes_reader.c +++ b/aom_dsp/binary_codes_reader.c
@@ -36,7 +36,7 @@ uint16_t aom_read_primitive_quniform_(aom_reader *r, uint16_t n ACCT_STR_PARAM) { if (n <= 1) return 0; - const int l = get_msb(n - 1) + 1; + const int l = get_msb(n) + 1; const int m = (1 << l) - n; const int v = aom_read_literal(r, l - 1, ACCT_STR_NAME); return v < m ? v : (v << 1) - m + aom_read_bit(r, ACCT_STR_NAME); @@ -45,7 +45,7 @@ static uint16_t aom_rb_read_primitive_quniform(struct aom_read_bit_buffer *rb, uint16_t n) { if (n <= 1) return 0; - const int l = get_msb(n - 1) + 1; + const int l = get_msb(n) + 1; const int m = (1 << l) - n; const int v = aom_rb_read_literal(rb, l - 1); return v < m ? v : (v << 1) - m + aom_rb_read_bit(rb);
diff --git a/aom_dsp/binary_codes_writer.c b/aom_dsp/binary_codes_writer.c index 4e53b15..ee7a9f5 100644 --- a/aom_dsp/binary_codes_writer.c +++ b/aom_dsp/binary_codes_writer.c
@@ -59,7 +59,7 @@ // Encodes a value v in [0, n-1] quasi-uniformly void aom_write_primitive_quniform(aom_writer *w, uint16_t n, uint16_t v) { if (n <= 1) return; - const int l = get_msb(n - 1) + 1; + const int l = get_msb(n) + 1; const int m = (1 << l) - n; if (v < m) { aom_write_literal(w, v, l - 1); @@ -72,7 +72,7 @@ static void aom_wb_write_primitive_quniform(struct aom_write_bit_buffer *wb, uint16_t n, uint16_t v) { if (n <= 1) return; - const int l = get_msb(n - 1) + 1; + const int l = get_msb(n) + 1; const int m = (1 << l) - n; if (v < m) { aom_wb_write_literal(wb, v, l - 1); @@ -84,7 +84,7 @@ int aom_count_primitive_quniform(uint16_t n, uint16_t v) { if (n <= 1) return 0; - const int l = get_msb(n - 1) + 1; + const int l = get_msb(n) + 1; const int m = (1 << l) - n; return v < m ? l - 1 : l; }