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_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; }