[x265] [PATCH] Main12: fix distortion data type
Divya Manivannan
divya at multicorewareinc.com
Mon Aug 10 10:46:54 CEST 2015
# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1438948368 -19800
# Fri Aug 07 17:22:48 2015 +0530
# Branch stable
# Node ID cde95cc521597fe7d90c1dd6a508a59141dc0248
# Parent 4781e6cef251006db10e107b2916741572f7760a
Main12: fix distortion data type
diff -r 4781e6cef251 -r cde95cc52159 source/common/pixel.cpp
--- a/source/common/pixel.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/common/pixel.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -137,6 +137,27 @@
return sum;
}
+template<int lx, int ly, class T1, class T2>
+uint64_t sse(const T1* pix1, intptr_t stride_pix1, const T2* pix2, intptr_t stride_pix2)
+{
+ uint64_t sum = 0;
+ int tmp;
+
+ for (int y = 0; y < ly; y++)
+ {
+ for (int x = 0; x < lx; x++)
+ {
+ tmp = pix1[x] - pix2[x];
+ sum += (tmp * tmp);
+ }
+
+ pix1 += stride_pix1;
+ pix2 += stride_pix2;
+ }
+
+ return sum;
+}
+
#define BITS_PER_SUM (8 * sizeof(sum_t))
#define HADAMARD4(d0, d1, d2, d3, s0, s1, s2, s3) { \
diff -r 4781e6cef251 -r cde95cc52159 source/common/primitives.cpp
--- a/source/common/primitives.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/common/primitives.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -74,7 +74,11 @@
/* at HIGH_BIT_DEPTH, pixel == short so we can alias many primitives */
for (int i = 0; i < NUM_CU_SIZES; i++)
{
+#if X265_DEPTH <= 10
p.cu[i].sse_pp = (pixelcmp_t)p.cu[i].sse_ss;
+#else
+ p.cu[i].sse_pp = (pixel_sse_t)p.cu[i].sse_ss;
+#endif
p.cu[i].copy_ps = (copy_ps_t)p.pu[i].copy_pp;
p.cu[i].copy_sp = (copy_sp_t)p.pu[i].copy_pp;
diff -r 4781e6cef251 -r cde95cc52159 source/common/primitives.h
--- a/source/common/primitives.h Fri Aug 07 12:29:40 2015 +0530
+++ b/source/common/primitives.h Fri Aug 07 17:22:48 2015 +0530
@@ -112,6 +112,10 @@
typedef int (*pixelcmp_t)(const pixel* fenc, intptr_t fencstride, const pixel* fref, intptr_t frefstride); // fenc is aligned
typedef int (*pixelcmp_ss_t)(const int16_t* fenc, intptr_t fencstride, const int16_t* fref, intptr_t frefstride);
+#if X265_DEPTH > 10
+typedef uint64_t (*pixel_sse_t)(const pixel* fenc, intptr_t fencstride, const pixel* fref, intptr_t frefstride); // fenc is aligned
+typedef uint64_t (*pixel_sse_ss_t)(const int16_t* fenc, intptr_t fencstride, const int16_t* fref, intptr_t frefstride);
+#endif
typedef int (*pixel_ssd_s_t)(const int16_t* fenc, intptr_t fencstride);
typedef void (*pixelcmp_x4_t)(const pixel* fenc, const pixel* fref0, const pixel* fref1, const pixel* fref2, const pixel* fref3, intptr_t frefstride, int32_t* res);
typedef void (*pixelcmp_x3_t)(const pixel* fenc, const pixel* fref0, const pixel* fref1, const pixel* fref2, intptr_t frefstride, int32_t* res);
@@ -253,8 +257,14 @@
copy_pp_t copy_pp; // alias to pu[].copy_pp
var_t var; // block internal variance
+
+#if X265_DEPTH <= 10
pixelcmp_t sse_pp; // Sum of Square Error (pixel, pixel) fenc alignment not assumed
pixelcmp_ss_t sse_ss; // Sum of Square Error (short, short) fenc alignment not assumed
+#else
+ pixel_sse_t sse_pp; // Sum of Square Error (pixel, pixel) fenc alignment not assumed
+ pixel_sse_ss_t sse_ss; // Sum of Square Error (short, short) fenc alignment not assumed
+#endif
pixelcmp_t psy_cost_pp; // difference in AC energy between two pixel blocks
pixelcmp_ss_t psy_cost_ss; // difference in AC energy between two signed residual blocks
pixel_ssd_s_t ssd_s; // Sum of Square Error (residual coeff to self)
@@ -358,7 +368,11 @@
struct CUChroma
{
pixelcmp_t sa8d; // if chroma CU is not multiple of 8x8, will use satd
+#if X265_DEPTH <= 10
pixelcmp_t sse_pp;
+#else
+ pixel_sse_t sse_pp;
+#endif
pixel_sub_ps_t sub_ps;
pixel_add_ps_t add_ps;
diff -r 4781e6cef251 -r cde95cc52159 source/common/x86/asm-primitives.cpp
--- a/source/common/x86/asm-primitives.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/common/x86/asm-primitives.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -998,6 +998,7 @@
p.cu[BLOCK_4x4].intra_pred[32] = PFX(intra_pred_ang4_32_sse2);
p.cu[BLOCK_4x4].intra_pred[33] = PFX(intra_pred_ang4_33_sse2);
+#if X265_DEPTH <= 10
p.cu[BLOCK_4x4].sse_ss = PFX(pixel_ssd_ss_4x4_mmx2);
ALL_LUMA_CU(sse_ss, pixel_ssd_ss, sse2);
@@ -1005,6 +1006,7 @@
p.chroma[X265_CSP_I422].cu[BLOCK_422_8x16].sse_pp = (pixelcmp_t)PFX(pixel_ssd_ss_8x16_sse2);
p.chroma[X265_CSP_I422].cu[BLOCK_422_16x32].sse_pp = (pixelcmp_t)PFX(pixel_ssd_ss_16x32_sse2);
p.chroma[X265_CSP_I422].cu[BLOCK_422_32x64].sse_pp = (pixelcmp_t)PFX(pixel_ssd_ss_32x64_sse2);
+#endif
p.cu[BLOCK_4x4].dct = PFX(dct4_sse2);
p.cu[BLOCK_8x8].dct = PFX(dct8_sse2);
@@ -1527,6 +1529,7 @@
p.cu[BLOCK_16x16].ssd_s = PFX(pixel_ssd_s_16_avx2);
p.cu[BLOCK_32x32].ssd_s = PFX(pixel_ssd_s_32_avx2);
+#if X265_DEPTH <= 10
p.cu[BLOCK_16x16].sse_ss = PFX(pixel_ssd_ss_16x16_avx2);
p.cu[BLOCK_32x32].sse_ss = PFX(pixel_ssd_ss_32x32_avx2);
p.cu[BLOCK_64x64].sse_ss = PFX(pixel_ssd_ss_64x64_avx2);
@@ -1538,6 +1541,7 @@
p.chroma[X265_CSP_I420].cu[BLOCK_420_32x32].sse_pp = PFX(pixel_ssd_32x32_avx2);
p.chroma[X265_CSP_I422].cu[BLOCK_422_16x32].sse_pp = (pixelcmp_t)PFX(pixel_ssd_ss_16x32_avx2);
p.chroma[X265_CSP_I422].cu[BLOCK_422_32x64].sse_pp = (pixelcmp_t)PFX(pixel_ssd_ss_32x64_avx2);
+#endif
p.quant = PFX(quant_avx2);
p.nquant = PFX(nquant_avx2);
diff -r 4781e6cef251 -r cde95cc52159 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/encoder/analysis.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -832,7 +832,13 @@
else if (m_param->rdLevel > 1)
updateModeCost(*splitPred);
else
+ {
+#if X265_DEPTH <= 10
splitPred->sa8dCost = m_rdCost.calcRdSADCost(splitPred->distortion, splitPred->sa8dBits);
+#else
+ splitPred->sa8dCost = m_rdCost.calcRdSADCost((uint32_t)splitPred->distortion, splitPred->sa8dBits);
+#endif
+ }
}
/* Split CUs
@@ -1418,7 +1424,11 @@
tempPred->distortion += primitives.chroma[m_csp].cu[sizeIdx].sa8d(fencYuv->m_buf[1], fencYuv->m_csize, tempPred->predYuv.m_buf[1], tempPred->predYuv.m_csize);
tempPred->distortion += primitives.chroma[m_csp].cu[sizeIdx].sa8d(fencYuv->m_buf[2], fencYuv->m_csize, tempPred->predYuv.m_buf[2], tempPred->predYuv.m_csize);
}
+#if X265_DEPTH <= 10
tempPred->sa8dCost = m_rdCost.calcRdSADCost(tempPred->distortion, tempPred->sa8dBits);
+#else
+ tempPred->sa8dCost = m_rdCost.calcRdSADCost((uint32_t)tempPred->distortion, tempPred->sa8dBits);
+#endif
if (tempPred->sa8dCost < bestPred->sa8dCost)
{
@@ -1634,7 +1644,11 @@
interMode.distortion += primitives.chroma[m_csp].cu[part].sa8d(fencYuv.m_buf[1], fencYuv.m_csize, predYuv.m_buf[1], predYuv.m_csize);
interMode.distortion += primitives.chroma[m_csp].cu[part].sa8d(fencYuv.m_buf[2], fencYuv.m_csize, predYuv.m_buf[2], predYuv.m_csize);
}
+#if X265_DEPTH <= 10
interMode.sa8dCost = m_rdCost.calcRdSADCost(interMode.distortion, interMode.sa8dBits);
+#else
+ interMode.sa8dCost = m_rdCost.calcRdSADCost((uint32_t)interMode.distortion, interMode.sa8dBits);
+#endif
if (m_param->analysisMode == X265_ANALYSIS_SAVE && m_reuseInterDataCTU)
{
@@ -1947,7 +1961,11 @@
else if (m_param->rdLevel <= 1)
{
mode.sa8dBits++;
+#if X265_DEPTH <= 10
mode.sa8dCost = m_rdCost.calcRdSADCost(mode.distortion, mode.sa8dBits);
+#else
+ mode.sa8dCost = m_rdCost.calcRdSADCost((uint32_t)mode.distortion, mode.sa8dBits);
+#endif
}
else
{
diff -r 4781e6cef251 -r cde95cc52159 source/encoder/rdcost.h
--- a/source/encoder/rdcost.h Fri Aug 07 12:29:40 2015 +0530
+++ b/source/encoder/rdcost.h Fri Aug 07 17:22:48 2015 +0530
@@ -88,12 +88,21 @@
m_lambda = (uint64_t)floor(256.0 * lambda);
}
+#if X265_DEPTH <= 10
inline uint64_t calcRdCost(uint32_t distortion, uint32_t bits) const
{
X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambda2,
"calcRdCost wrap detected dist: %u, bits %u, lambda: "X265_LL"\n", distortion, bits, m_lambda2);
return distortion + ((bits * m_lambda2 + 128) >> 8);
}
+#else
+ inline uint64_t calcRdCost(uint64_t distortion, uint32_t bits) const
+ {
+ X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambda2,
+ "calcRdCost wrap detected dist: %u, bits %u, lambda: "X265_LL"\n", distortion, bits, m_lambda2);
+ return distortion + ((bits * m_lambda2 + 128) >> 8);
+ }
+#endif
/* return the difference in energy between the source block and the recon block */
inline int psyCost(int size, const pixel* source, intptr_t sstride, const pixel* recon, intptr_t rstride) const
@@ -108,10 +117,17 @@
}
/* return the RD cost of this prediction, including the effect of psy-rd */
+#if X265_DEPTH <= 10
inline uint64_t calcPsyRdCost(uint32_t distortion, uint32_t bits, uint32_t psycost) const
{
return distortion + ((m_lambda * m_psyRd * psycost) >> 24) + ((bits * m_lambda2) >> 8);
}
+#else
+ inline uint64_t calcPsyRdCost(uint64_t distortion, uint32_t bits, uint32_t psycost) const
+ {
+ return distortion + ((m_lambda * m_psyRd * psycost) >> 24) + ((bits * m_lambda2) >> 8);
+ }
+#endif
inline uint64_t calcRdSADCost(uint32_t sadCost, uint32_t bits) const
{
diff -r 4781e6cef251 -r cde95cc52159 source/encoder/search.cpp
--- a/source/encoder/search.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/encoder/search.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -3436,7 +3436,11 @@
else if (m_param->rdLevel <= 1)
{
mode.sa8dBits++;
+#if X265_DEPTH <= 10
mode.sa8dCost = m_rdCost.calcRdSADCost(mode.distortion, mode.sa8dBits);
+#else
+ mode.sa8dCost = m_rdCost.calcRdSADCost((uint32_t)mode.distortion, mode.sa8dBits);
+#endif
}
else
{
@@ -3481,7 +3485,11 @@
else if (m_param->rdLevel <= 1)
{
mode.sa8dBits++;
+#if X265_DEPTH <= 10
mode.sa8dCost = m_rdCost.calcRdSADCost(mode.distortion, mode.sa8dBits);
+#else
+ mode.sa8dCost = m_rdCost.calcRdSADCost((uint32_t)mode.distortion, mode.sa8dBits);
+#endif
}
else
{
diff -r 4781e6cef251 -r cde95cc52159 source/encoder/search.h
--- a/source/encoder/search.h Fri Aug 07 12:29:40 2015 +0530
+++ b/source/encoder/search.h Fri Aug 07 17:22:48 2015 +0530
@@ -109,9 +109,15 @@
uint64_t sa8dCost; // sum of partition sa8d distortion costs (sa8d(fenc, pred) + lambda * bits)
uint32_t sa8dBits; // signal bits used in sa8dCost calculation
uint32_t psyEnergy; // sum of partition psycho-visual energy difference
+#if X265_DEPTH <= 10
uint32_t lumaDistortion;
uint32_t chromaDistortion;
uint32_t distortion; // sum of partition SSE distortion
+#else
+ uint64_t lumaDistortion;
+ uint64_t chromaDistortion;
+ uint64_t distortion; // sum of partition SSE distortion
+#endif
uint32_t totalBits; // sum of partition bits (mv + coeff)
uint32_t mvBits; // Mv bits + Ref + block type (or intra mode)
uint32_t coeffBits; // Texture bits (DCT Coeffs)
@@ -137,9 +143,15 @@
sa8dCost = UINT64_MAX / 2;
sa8dBits = MAX_UINT / 2;
psyEnergy = MAX_UINT / 2;
+#if X265_DEPTH <= 10
lumaDistortion = MAX_UINT / 2;
chromaDistortion = MAX_UINT / 2;
distortion = MAX_UINT / 2;
+#else
+ lumaDistortion = UINT64_MAX / 2;
+ chromaDistortion = UINT64_MAX / 2;
+ distortion = UINT64_MAX / 2;
+#endif
totalBits = MAX_UINT / 2;
mvBits = MAX_UINT / 2;
coeffBits = MAX_UINT / 2;
@@ -147,16 +159,29 @@
bool ok() const
{
+#if X265_DEPTH <= 10
+ return !(rdCost >= UINT64_MAX / 2 ||
+ sa8dCost >= UINT64_MAX / 2 ||
+ sa8dBits >= MAX_UINT / 2 ||
+ psyEnergy >= MAX_UINT / 2 ||
+ lumaDistortion >= MAX_UINT / 2 ||
+ chromaDistortion >= MAX_UINT / 2 ||
+ distortion >= MAX_UINT / 2 ||
+ totalBits >= MAX_UINT / 2 ||
+ mvBits >= MAX_UINT / 2 ||
+ coeffBits >= MAX_UINT / 2);
+#else
return !(rdCost >= UINT64_MAX / 2 ||
sa8dCost >= UINT64_MAX / 2 ||
sa8dBits >= MAX_UINT / 2 ||
psyEnergy >= MAX_UINT / 2 ||
- lumaDistortion >= MAX_UINT / 2 ||
- chromaDistortion >= MAX_UINT / 2 ||
- distortion >= MAX_UINT / 2 ||
+ lumaDistortion >= UINT64_MAX / 2 ||
+ chromaDistortion >= UINT64_MAX / 2 ||
+ distortion >= UINT64_MAX / 2 ||
totalBits >= MAX_UINT / 2 ||
mvBits >= MAX_UINT / 2 ||
coeffBits >= MAX_UINT / 2);
+#endif
}
void addSubCosts(const Mode& subMode)
diff -r 4781e6cef251 -r cde95cc52159 source/test/pixelharness.cpp
--- a/source/test/pixelharness.cpp Fri Aug 07 12:29:40 2015 +0530
+++ b/source/test/pixelharness.cpp Fri Aug 07 17:22:48 2015 +0530
@@ -1799,20 +1799,24 @@
{
if (opt.cu[part].sse_pp)
{
+#if X265_DEPTH <= 10
if (!check_pixelcmp(ref.cu[part].sse_pp, opt.cu[part].sse_pp))
{
printf("sse_pp[%s]: failed!\n", lumaPartStr[part]);
return false;
}
+#endif
}
if (opt.cu[part].sse_ss)
{
+#if X265_DEPTH <= 10
if (!check_pixelcmp_ss(ref.cu[part].sse_ss, opt.cu[part].sse_ss))
{
printf("sse_ss[%s]: failed!\n", lumaPartStr[part]);
return false;
}
+#endif
}
if (opt.cu[part].sub_ps)
@@ -1891,11 +1895,13 @@
{
if (opt.chroma[i].cu[part].sse_pp)
{
+#if X265_DEPTH <= 10
if (!check_pixelcmp(ref.chroma[i].cu[part].sse_pp, opt.chroma[i].cu[part].sse_pp))
{
printf("chroma_sse_pp[%s][%s]: failed!\n", x265_source_csp_names[i], chromaPartStr[i][part]);
return false;
}
+#endif
}
if (opt.chroma[i].cu[part].sub_ps)
{
More information about the x265-devel
mailing list