[x265] [PATCH] BitCost: Remove the abs and new/delete operation in BitCost
Ximing Cheng
chengximing1989 at gmail.com
Fri Oct 9 19:58:50 CEST 2015
The patch line in the email is not break, but in the Patchwork web page,
patch line mangled by the MTU, the next patch is the same.
I don't know why this happen. I will try to send a right patch tomorrow.
Thanks!
On Fri, Oct 9, 2015 at 11:53 PM, Steve Borho <steve at borho.org> wrote:
> On 10/09, Ximing Cheng 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
>
> ah, now I see what you meant
>
> > 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;
>
> in C++ new can never fail (it can throw an exception but it can't return
> NULL) but malloc can, so this becomes a risk. We'll have to check for
> malloc failures and abort the encode (and not try to free this pointer).
>
> > 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;
>
> the patch was line mangled by the MTU
>
> > }
> > }
> >
> > @@ -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);
>
> yeah, this should be a reasonable speedup
>
> > }
> >
> > static void destroy();
>
> > _______________________________________________
> > x265-devel mailing list
> > x265-devel at videolan.org
> > https://mailman.videolan.org/listinfo/x265-devel
>
>
> --
> Steve Borho
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20151010/bf459302/attachment.html>
More information about the x265-devel
mailing list