<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial"><DIV>At 2013-11-14 23:12:15,dnyaneshwar@multicorewareinc.com wrote:<BR>># HG changeset patch<BR>># User Dnyaneshwar Gorade <dnyaneshwar@multicorewareinc.com><BR>># Date 1384441865 -19800<BR>>#      Thu Nov 14 20:41:05 2013 +0530<BR>># Node ID d16bcb0416b43912fc8d69d98af89c9a17475c60<BR>># Parent  c4ca80d19105ccf1ba2ec14dd65915f2820a660d<BR>>primitive function for luma and chroma for loops in addAvg()<BR>><BR>>diff -r c4ca80d19105 -r d16bcb0416b4 source/Lib/TLibCommon/TComYuv.cpp<BR>>--- a/source/Lib/TLibCommon/TComYuv.cpp      Tue Nov 12 19:10:23 2013 +0530<BR>>+++ b/source/Lib/TLibCommon/TComYuv.cpp       Thu Nov 14 20:41:05 2013 +0530<BR>>@@ -590,7 +590,6 @@<BR>> <BR>> void TComYuv::addAvg(TShortYUV* srcYuv0, TShortYUV* srcYuv1, uint32_t partUnitIdx, uint32_t width, uint32_t height, bool bLuma, bool bChroma)<BR>> {<BR>>-    int x, y;<BR>>     uint32_t src0Stride, src1Stride, dststride;<BR>>     int shiftNum, offset;<BR>> <BR>>@@ -606,6 +605,8 @@<BR>>     Pel* dstU = getCbAddr(partUnitIdx);<BR>>     Pel* dstV = getCrAddr(partUnitIdx);<BR>> <BR>>+    int part = partitionFromSizes(width, height);<BR>>+<BR>>     if (bLuma)<BR>>     {<BR>>         src0Stride = srcYuv0->m_width;<BR>>@@ -614,20 +615,7 @@<BR>>         shiftNum = IF_INTERNAL_PREC + 1 - X265_DEPTH;<BR>>         offset = (1 << (shiftNum - 1)) + 2 * IF_INTERNAL_OFFS;<BR>> <BR>>-        for (y = 0; y < height; y++)<BR>>-        {<BR>>-            for (x = 0; x < width; x += 4)<BR>>-            {<BR>>-                dstY[x + 0] = ClipY((srcY0[x + 0] + srcY1[x + 0] + offset) >> shiftNum);<BR>>-                dstY[x + 1] = ClipY((srcY0[x + 1] + srcY1[x + 1] + offset) >> shiftNum);<BR>>-                dstY[x + 2] = ClipY((srcY0[x + 2] + srcY1[x + 2] + offset) >> shiftNum);<BR>>-                dstY[x + 3] = ClipY((srcY0[x + 3] + srcY1[x + 3] + offset) >> shiftNum);<BR>>-            }<BR>>-<BR>>-            srcY0 += src0Stride;<BR>>-            srcY1 += src1Stride;<BR>>-            dstY  += dststride;<BR>>-        }<BR>>+        primitives.addAvg_c[part](dstY, dststride, srcY0, src0Stride, srcY1, src1Stride);<BR>>     }<BR>>     if (bChroma)<BR>>     {<BR>>@@ -641,26 +629,8 @@<BR>>         width  >>= m_hChromaShift;<BR>>         height >>= m_vChromaShift;<BR>> <BR>>-        for (y = height - 1; y >= 0; y--)<BR>>-        {<BR>>-            for (x = width - 1; x >= 0; )<BR>>-            {<BR>>-                // note: chroma min width is 2<BR>>-                dstU[x] = ClipC((srcU0[x] + srcU1[x] + offset) >> shiftNum);<BR>>-                dstV[x] = ClipC((srcV0[x] + srcV1[x] + offset) >> shiftNum);<BR>>-                x--;<BR>>-                dstU[x] = ClipC((srcU0[x] + srcU1[x] + offset) >> shiftNum);<BR>>-                dstV[x] = ClipC((srcV0[x] + srcV1[x] + offset) >> shiftNum);<BR>>-                x--;<BR>>-            }<BR>>-<BR>>-            srcU0 += src0Stride;<BR>>-            srcU1 += src1Stride;<BR>>-            srcV0 += src0Stride;<BR>>-            srcV1 += src1Stride;<BR>>-            dstU  += dststride;<BR>>-            dstV  += dststride;<BR>>-        }<BR>>+        primitives.addAvg_c[part](dstU, dststride, srcU0, src0Stride, srcU1, src1Stride);<BR>>+        primitives.addAvg_c[part](dstV, dststride, srcV0, src0Stride, srcV1, src1Stride);<BR>I guess you use luma index here will be wrong size for chroma</DIV>
<DIV> </DIV>
<DIV>>     }<BR>> }<BR>> <BR>>diff -r c4ca80d19105 -r d16bcb0416b4 source/common/pixel.cpp<BR>>--- a/source/common/pixel.cpp      Tue Nov 12 19:10:23 2013 +0530<BR>>+++ b/source/common/pixel.cpp Thu Nov 14 20:41:05 2013 +0530<BR>>@@ -794,6 +794,27 @@<BR>>         a += dstride;<BR>>     }<BR>> }<BR>>+<BR>>+template<int bx, int by><BR>>+void addAvg_c(pixel* dst, intptr_t dstStride, int16_t* src0, intptr_t src0Stride, int16_t* src1, intptr_t src1Stride)<BR>>+{<BR>>+    int shiftNum, offset;<BR>>+    shiftNum = IF_INTERNAL_PREC + 1 - X265_DEPTH;<BR>>+    offset = (1 << (shiftNum - 1)) + 2 * IF_INTERNAL_OFFS;<BR>>+<BR>>+    for (int y = 0; y < by; y++)<BR>>+    {<BR>>+        for (int x = 0; x < bx; x += 2)<BR>>+        {<BR>>+            dst[x + 0] = ClipY((src0[x + 0] + src1[x + 0] + offset) >> shiftNum);<BR>>+            dst[x + 1] = ClipY((src0[x + 1] + src1[x + 1] + offset) >> shiftNum);<BR>>+        }<BR>>+<BR>>+        src0 += src0Stride;<BR>>+        src1 += src1Stride;<BR>>+        dst  += dstStride;<BR>>+    }<BR>>+}<BR>> }  // end anonymous namespace<BR>> <BR>> namespace x265 {<BR>>@@ -806,6 +827,7 @@<BR>>     SET_FUNC_PRIMITIVE_TABLE_C2(sad_x3)<BR>>     SET_FUNC_PRIMITIVE_TABLE_C2(sad_x4)<BR>>     SET_FUNC_PRIMITIVE_TABLE_C2(pixelavg_pp)<BR>>+    SET_FUNC_PRIMITIVE_TABLE_C2(addAvg_c)<BR>> <BR>>     // satd<BR>>     p.satd[LUMA_4x4]   = satd_4x4;<BR>>diff -r c4ca80d19105 -r d16bcb0416b4 source/common/primitives.h<BR>>--- a/source/common/primitives.h       Tue Nov 12 19:10:23 2013 +0530<BR>>+++ b/source/common/primitives.h      Thu Nov 14 20:41:05 2013 +0530<BR>>@@ -208,6 +208,8 @@<BR>> <BR>> typedef void (*pixel_sub_ps_t)(int16_t *dst, intptr_t dstride, pixel *src0, pixel *src1, intptr_t sstride0, intptr_t sstride1);<BR>> <BR>>+typedef void (*addAvg_t)(pixel* dst, intptr_t dstStride, int16_t* src0, intptr_t src0Stride, int16_t* src1, intptr_t src1Stride);<BR>>+<BR>> /* Define a structure containing function pointers to optimized encoder<BR>>  * primitives.  Each pointer can reference either an assembly routine,<BR>>  * a vectorized primitive, or a C function. */<BR>>@@ -288,6 +290,8 @@<BR>>     var_t           var[NUM_LUMA_PARTITIONS];<BR>>     ssim_4x4x2_core_t ssim_4x4x2_core;<BR>>     plane_copy_deinterleave_t plane_copy_deinterleave_c;<BR>>+<BR>>+    addAvg_t        addAvg_c[NUM_LUMA_PARTITIONS];<BR></DIV>
<DIV>name addAvg_c is for C reference code, here use addAvg is better</DIV>
<DIV> </DIV></div>