Some minor clean-ups on convolve functions

Some fixes and additions of asserts.

Change-Id: Ib5f706baf48acb2853f7fe55991efa95e6a848de
diff --git a/av1/common/convolve.c b/av1/common/convolve.c
index 8bc6f6d..4473f99 100644
--- a/av1/common/convolve.c
+++ b/av1/common/convolve.c
@@ -1169,7 +1169,8 @@
 #endif
 
   const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
-  if (conv_params->dst) {
+  if (conv_params->is_compound) {
+    assert(conv_params->dst != NULL);
     if (filter_params_y.taps < filter_params_x.taps) {
       uint16_t tr_src[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) *
                       (MAX_SB_SIZE + MAX_FILTER_TAP - 1)];
@@ -1262,8 +1263,10 @@
                              subpel_y_q4, conv_params, bd);
 #endif  // CONFIG_JNT_COMP
     // 0-bit rounding just to convert from int32 to uint16
+    const int rbits =
+        2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
     av1_highbd_convolve_rounding(tmp_dst, tmp_dst_stride, dst, dst_stride, w, h,
-                                 0, bd);
+                                 rbits, bd);
   }
 }
 
diff --git a/av1/common/convolve.h b/av1/common/convolve.h
index 7bbf220..7d4ae42 100644
--- a/av1/common/convolve.h
+++ b/av1/common/convolve.h
@@ -122,6 +122,7 @@
   ConvolveParams conv_params;
   conv_params.ref = ref;
   conv_params.do_average = do_average;
+  assert(IMPLIES(do_average, is_compound));
   conv_params.round = CONVOLVE_OPT_NO_ROUND;
   conv_params.is_compound = is_compound;
   conv_params.round_0 = ROUND0_BITS;
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index d752f6c..ac18606 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -86,13 +86,19 @@
                    pre_buf->buf0, pre_buf->width, pre_buf->height,
                    pre_buf->stride, dst, p_col, p_row, w, h, dst_stride,
                    pd->subsampling_x, pd->subsampling_y, conv_params);
+    assert(IMPLIES(conv_params->dst != NULL, conv_params->do_post_rounding));
+    assert(IMPLIES(conv_params->dst == NULL, !conv_params->do_post_rounding));
   } else if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
     highbd_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
                            sf, w, h, conv_params, interp_filters, xs, ys,
                            xd->bd);
+    assert(IMPLIES(conv_params->is_compound, conv_params->do_post_rounding));
+    assert(!(conv_params->is_compound && conv_params->dst == NULL));
   } else {
     inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y, sf, w,
                     h, conv_params, interp_filters, xs, ys);
+    assert(IMPLIES(conv_params->is_compound, conv_params->do_post_rounding));
+    assert(!(conv_params->is_compound && conv_params->dst == NULL));
   }
 }
 
@@ -974,6 +980,7 @@
     const int b8_w = block_size_wide[plane_bsize] >> ss_x;
     const int b8_h = block_size_high[plane_bsize] >> ss_y;
     int idx, idy;
+    assert(!is_compound);
 
     const int x_base = x;
     const int y_base = y;
@@ -1095,7 +1102,10 @@
                 (mi_y >> pd->subsampling_y) + y, plane, ref, mi, build_for_obmc,
                 xs, ys, xd);
         }  // for (ref = 0; ref < 1 + is_compound; ++ref)
+
         if (conv_params.do_post_rounding) {
+          assert(!is_masked_compound_type(mi->mbmi.interinter_compound_type));
+          assert(conv_params.dst != NULL);
           int round_bits = FILTER_BITS * 2 + is_compound - conv_params.round_0 -
                            conv_params.round_1;
 #if CONFIG_JNT_COMP
@@ -1190,7 +1200,7 @@
     }
 
     ConvolveParams conv_params = get_conv_params_no_round(
-        ref, ref, plane, tmp_dst, MAX_SB_SIZE, is_compound, xd->bd);
+        0, 0, plane, tmp_dst, MAX_SB_SIZE, is_compound, xd->bd);
 #if CONFIG_JNT_COMP
     av1_jnt_comp_weight_assign(cm, &mi->mbmi, 0, &conv_params.fwd_offset,
                                &conv_params.bck_offset,
@@ -1234,8 +1244,12 @@
             subpel_params[ref].ys, xd);
     }
 
+    // if (!is_masked_compound_type(mi->mbmi.interinter_compound_type))
+    //   assert(conv_params.do_post_rounding);
     // TODO(angiebird): This part needs optimization
     if (conv_params.do_post_rounding) {
+      assert(!is_masked_compound_type(mi->mbmi.interinter_compound_type));
+      assert(conv_params.dst != NULL);
       int round_bits = FILTER_BITS * 2 + is_compound - conv_params.round_0 -
                        conv_params.round_1;
 #if CONFIG_JNT_COMP
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index db5dfff..8cc805d3 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -148,7 +148,10 @@
       av1_highbd_convolve_2d_facade(src, src_stride, dst, dst_stride, w, h,
                                     interp_filters, subpel_x, xs, subpel_y, ys,
                                     0, conv_params, bd);
-      conv_params->do_post_rounding = 1;
+      if (conv_params->is_compound)
+        conv_params->do_post_rounding = 1;
+      else
+        conv_params->do_post_rounding = 0;
     } else {
       InterpFilterParams filter_params_x, filter_params_y;
 #if CONFIG_SHORT_FILTER
diff --git a/av1/common/x86/highbd_convolve_2d_avx2.c b/av1/common/x86/highbd_convolve_2d_avx2.c
index c28c63d..42f706e 100644
--- a/av1/common/x86/highbd_convolve_2d_avx2.c
+++ b/av1/common/x86/highbd_convolve_2d_avx2.c
@@ -35,8 +35,8 @@
   const uint16_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
 
   // Check that, even with 12-bit input, the intermediate values will fit
-  // into an unsigned 15-bit intermediate array.
-  assert(conv_params->round_0 >= 5);
+  // into an unsigned 16-bit intermediate array.
+  assert(bd + FILTER_BITS + 2 - conv_params->round_0 <= 16);
 
   /* Horizontal filter */
   {
diff --git a/av1/common/x86/highbd_convolve_2d_sse4.c b/av1/common/x86/highbd_convolve_2d_sse4.c
index 80adce9..f4b07df 100644
--- a/av1/common/x86/highbd_convolve_2d_sse4.c
+++ b/av1/common/x86/highbd_convolve_2d_sse4.c
@@ -41,8 +41,8 @@
   const __m128i wt1 = _mm_set1_epi32(w1);
 
   // Check that, even with 12-bit input, the intermediate values will fit
-  // into an unsigned 15-bit intermediate array.
-  assert(conv_params->round_0 >= 5);
+  // into an unsigned 16-bit intermediate array.
+  assert(bd + FILTER_BITS + 2 - conv_params->round_0 <= 16);
 
   /* Horizontal filter */
   {
diff --git a/av1/common/x86/highbd_convolve_2d_ssse3.c b/av1/common/x86/highbd_convolve_2d_ssse3.c
index 95055b0..2e91472 100644
--- a/av1/common/x86/highbd_convolve_2d_ssse3.c
+++ b/av1/common/x86/highbd_convolve_2d_ssse3.c
@@ -35,8 +35,8 @@
   const uint16_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
 
   // Check that, even with 12-bit input, the intermediate values will fit
-  // into an unsigned 15-bit intermediate array.
-  assert(conv_params->round_0 >= 5);
+  // into an unsigned 16-bit intermediate array.
+  assert(bd + FILTER_BITS + 2 - conv_params->round_0 <= 16);
 
   /* Horizontal filter */
   {