[x265] [PATCH] BitCost: Remove the abs and new/delete operation in BitCost

Ximing Cheng chengximing1989 at gmail.com
Mon Oct 12 04:16:04 CEST 2015


The patch in this email has line break at 78 chars, I have tested for
sending a right patch, as the bad network in China, I could not send a
patch by SMTP with gmail, I will send this patch by another email,
including the patch of rc: Remove the redundant calculation on
slidingWindow.

Thanks!

On Sat, Oct 10, 2015 at 11:06 AM, Ximing Cheng
<chengximing1989 at gmail.com> wrote:
> # HG changeset patch
> # User Ximing Cheng <ximingcheng at tencent.com>
> # Date 1444372125 -28800
> #      Fri Oct 09 14:28:45 2015 +0800
> # Node ID 4176ffb657db00f173ba15a8d54c821f6811f514
> # Parent  55a4a9b920ff0385fd0b65c73c4c3f63b8a8cc65
> Remove new/delete in BitCost, double the size of s_bitsizes to remove
> the abs operation in bitcost
>
> diff --git a/source/encoder/bitcost.cpp b/source/encoder/bitcost.cpp
> --- a/source/encoder/bitcost.cpp
> +++ b/source/encoder/bitcost.cpp
> @@ -41,7 +41,7 @@
>              x265_emms(); // just to be safe
>
>              CalculateLogs();
> -            s_costs[qp] = new uint16_t[4 * BC_MAX_MV + 1] + 2 * BC_MAX_MV;
> +            s_costs[qp] = X265_MALLOC(uint16_t, 4 * BC_MAX_MV + 1) +
> 2 * BC_MAX_MV;
>              double lambda = x265_lambda_tab[qp];
>
>              // estimate same cost for negative and positive MVD
> @@ -67,11 +67,11 @@
>  {
>      if (!s_bitsizes)
>      {
> -        s_bitsizes = new float[2 * BC_MAX_MV + 1];
> +        s_bitsizes = X265_MALLOC(float, 4 * BC_MAX_MV + 1) + 2 * BC_MAX_MV;
>          s_bitsizes[0] = 0.718f;
>          float log2_2 = 2.0f / log(2.0f);  // 2 x 1/log(2)
>          for (int i = 1; i <= 2 * BC_MAX_MV; i++)
> -            s_bitsizes[i] = log((float)(i + 1)) * log2_2 + 1.718f;
> +            s_bitsizes[i] = s_bitsizes[-i] = log((float)(i + 1)) *
> log2_2 + 1.718f;
>      }
>  }
>
> @@ -81,12 +81,12 @@
>      {
>          if (s_costs[i])
>          {
> -            delete [] (s_costs[i] - 2 * BC_MAX_MV);
> +            X265_FREE(s_costs[i] - 2 * BC_MAX_MV);
>
>              s_costs[i] = 0;
>          }
>      }
>
> -    delete [] s_bitsizes;
> +    X265_FREE(s_bitsizes - 2 * BC_MAX_MV);
>      s_bitsizes = 0;
>  }
> diff --git a/source/encoder/bitcost.h b/source/encoder/bitcost.h
> --- a/source/encoder/bitcost.h
> +++ b/source/encoder/bitcost.h
> @@ -47,14 +47,14 @@
>      // return bit cost of motion vector difference, without lambda
>      inline uint32_t bitcost(const MV& mv) const
>      {
> -        return (uint32_t)(s_bitsizes[abs(mv.x - m_mvp.x)] +
> -                          s_bitsizes[abs(mv.y - m_mvp.y)] + 0.5f);
> +        return (uint32_t)(s_bitsizes[mv.x - m_mvp.x] +
> +                          s_bitsizes[mv.y - m_mvp.y] + 0.5f);
>      }
>
>      static inline uint32_t bitcost(const MV& mv, const MV& mvp)
>      {
> -        return (uint32_t)(s_bitsizes[abs(mv.x - mvp.x)] +
> -                          s_bitsizes[abs(mv.y - mvp.y)] + 0.5f);
> +        return (uint32_t)(s_bitsizes[mv.x - mvp.x] +
> +                          s_bitsizes[mv.y - mvp.y] + 0.5f);
>      }
>
>      static void destroy();


More information about the x265-devel mailing list