Subsume bit-depth scaling of sse in RDCOST_DBL macro

The bit-depth based scaling of sse for rd cost computation is subsumed
inside RDCOST_DBL() macro, which has been renamed appropriately.

Change-Id: Ibcd58b7bb16e88b16bfbc28a4759d0cb181896b8
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index d146829..d452b0b 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2770,8 +2770,8 @@
     const int64_t this_sse = superres_sses[this_index];
     const int64_t this_rate = superres_rates[this_index];
     const int this_largest_tile_id = superres_largest_tile_ids[this_index];
-    const double this_rdcost = RDCOST_DBL(
-        rdmult, this_rate, this_sse >> (2 * (cm->seq_params.bit_depth - 8)));
+    const double this_rdcost = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+        rdmult, this_rate, this_sse, cm->seq_params.bit_depth);
     if (this_rdcost < proj_rdcost1) {
       sse1 = this_sse;
       rate1 = this_rate;
@@ -2781,11 +2781,11 @@
     }
   }
 #else
-  const double proj_rdcost1 =
-      RDCOST_DBL(rdmult, rate1, sse1 >> (2 * (cm->seq_params.bit_depth - 8)));
+  const double proj_rdcost1 = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      rdmult, rate1, sse1, cm->seq_params.bit_depth);
 #endif  // SUPERRES_RECODE_ALL_RATIOS
-  const double proj_rdcost2 =
-      RDCOST_DBL(rdmult, rate2, sse2 >> (2 * (cm->seq_params.bit_depth - 8)));
+  const double proj_rdcost2 = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      rdmult, rate2, sse2, cm->seq_params.bit_depth);
 
   // Re-encode with superres if it's better.
   if (proj_rdcost1 < proj_rdcost2) {
diff --git a/av1/encoder/picklpf.c b/av1/encoder/picklpf.c
index cbb093c..0384118 100644
--- a/av1/encoder/picklpf.c
+++ b/av1/encoder/picklpf.c
@@ -202,10 +202,10 @@
 
   // Update best error
   best_err = ss_err[filt_best];
-  const int sse_shift = 2 * (cm->seq_params.bit_depth - 8);
 
   if (best_cost_ret)
-    *best_cost_ret = RDCOST_DBL(x->rdmult, 0, ((best_err >> sse_shift) << 4));
+    *best_cost_ret = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+        x->rdmult, 0, (best_err << 4), cm->seq_params.bit_depth);
   return filt_best;
 }
 
diff --git a/av1/encoder/pickrst.c b/av1/encoder/pickrst.c
index 6548926..ade81b0 100644
--- a/av1/encoder/pickrst.c
+++ b/av1/encoder/pickrst.c
@@ -922,11 +922,10 @@
   const int64_t bits_sgr = x->mode_costs.sgrproj_restore_cost[1] +
                            (count_sgrproj_bits(&rusi->sgrproj, &rsc->sgrproj)
                             << AV1_PROB_COST_SHIFT);
-  const int sse_shift = 2 * (bit_depth - 8);
-  double cost_none = RDCOST_DBL(x->rdmult, bits_none >> 4,
-                                rusi->sse[RESTORE_NONE] >> sse_shift);
-  double cost_sgr = RDCOST_DBL(x->rdmult, bits_sgr >> 4,
-                               rusi->sse[RESTORE_SGRPROJ] >> sse_shift);
+  double cost_none = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      x->rdmult, bits_none >> 4, rusi->sse[RESTORE_NONE], bit_depth);
+  double cost_sgr = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      x->rdmult, bits_sgr >> 4, rusi->sse[RESTORE_SGRPROJ], bit_depth);
   if (rusi->sgrproj.ep < 10)
     cost_sgr *=
         (1 + DUAL_SGR_PENALTY_MULT * rsc->lpf_sf->dual_sgr_penalty_level);
@@ -1571,11 +1570,12 @@
       (count_wiener_bits(wiener_win, &rusi->wiener, &rsc->wiener)
        << AV1_PROB_COST_SHIFT);
 
-  const int sse_shift = 2 * (rsc->cm->seq_params.bit_depth - 8);
-  double cost_none = RDCOST_DBL(x->rdmult, bits_none >> 4,
-                                rusi->sse[RESTORE_NONE] >> sse_shift);
-  double cost_wiener = RDCOST_DBL(x->rdmult, bits_wiener >> 4,
-                                  rusi->sse[RESTORE_WIENER] >> sse_shift);
+  double cost_none = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      x->rdmult, bits_none >> 4, rusi->sse[RESTORE_NONE],
+      rsc->cm->seq_params.bit_depth);
+  double cost_wiener = RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      x->rdmult, bits_wiener >> 4, rusi->sse[RESTORE_WIENER],
+      rsc->cm->seq_params.bit_depth);
 
   RestorationType rtype =
       (cost_wiener < cost_none) ? RESTORE_WIENER : RESTORE_NONE;
@@ -1658,8 +1658,8 @@
     }
     const int64_t coeff_bits = coeff_pcost << AV1_PROB_COST_SHIFT;
     const int64_t bits = x->mode_costs.switchable_restore_cost[r] + coeff_bits;
-    const int sse_shift = 2 * (rsc->cm->seq_params.bit_depth - 8);
-    double cost = RDCOST_DBL(x->rdmult, bits >> 4, sse >> sse_shift);
+    double cost = RDCOST_DBL_WITH_NATIVE_BD_DIST(x->rdmult, bits >> 4, sse,
+                                                 rsc->cm->seq_params.bit_depth);
     if (r == RESTORE_SGRPROJ && rusi->sgrproj.ep < 10)
       cost *= (1 + DUAL_SGR_PENALTY_MULT * rsc->lpf_sf->dual_sgr_penalty_level);
     if (r == 0 || cost < best_cost) {
@@ -1698,8 +1698,8 @@
 
   av1_foreach_rest_unit_in_plane(rsc->cm, rsc->plane, funs[rtype], rsc,
                                  &rsc->tile_rect, rsc->cm->rst_tmpbuf, NULL);
-  return RDCOST_DBL(rsc->x->rdmult, rsc->bits >> 4,
-                    rsc->sse >> (2 * (rsc->cm->seq_params.bit_depth - 8)));
+  return RDCOST_DBL_WITH_NATIVE_BD_DIST(
+      rsc->x->rdmult, rsc->bits >> 4, rsc->sse, rsc->cm->seq_params.bit_depth);
 }
 
 static int rest_tiles_in_plane(const AV1_COMMON *cm, int plane) {
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h
index 548fccf..0f0062b 100644
--- a/av1/encoder/rd.h
+++ b/av1/encoder/rd.h
@@ -35,9 +35,9 @@
   (((D) * (1 << RDDIV_BITS)) - \
    ROUND_POWER_OF_TWO(((int64_t)(R)) * (RM), AV1_PROB_COST_SHIFT))
 
-#define RDCOST_DBL(RM, R, D)                                       \
+#define RDCOST_DBL_WITH_NATIVE_BD_DIST(RM, R, D, BD)               \
   (((((double)(R)) * (RM)) / (double)(1 << AV1_PROB_COST_SHIFT)) + \
-   ((double)(D) * (1 << RDDIV_BITS)))
+   ((double)((D) >> (2 * (BD - 8))) * (1 << RDDIV_BITS)))
 
 #define QIDX_SKIP_THRESH 115