[x265-commits] [x265] rdcost: fix energy cost check, dc is already subtracted f...

Steve Borho steve at borho.org
Sun May 25 00:30:58 CEST 2014


details:   http://hg.videolan.org/x265/rev/5134e76aa729
branches:  
changeset: 6915:5134e76aa729
user:      Steve Borho <steve at borho.org>
date:      Thu May 22 21:46:21 2014 -0500
description:
rdcost: fix energy cost check, dc is already subtracted from the energy
Subject: [x265] cmake: re-split TLibCommon headers to fix VC9 builds

details:   http://hg.videolan.org/x265/rev/ade75817d892
branches:  
changeset: 6916:ade75817d892
user:      Steve Borho <steve at borho.org>
date:      Fri May 23 10:53:13 2014 -0500
description:
cmake: re-split TLibCommon headers to fix VC9 builds
Subject: [x265] vc9: define UINT64_MAX in our hacked stdint.h

details:   http://hg.videolan.org/x265/rev/a3f5a7b9f0fb
branches:  
changeset: 6917:a3f5a7b9f0fb
user:      Steve Borho <steve at borho.org>
date:      Fri May 23 11:21:16 2014 -0500
description:
vc9: define UINT64_MAX in our hacked stdint.h
Subject: [x265] rdcost: overflow check by integer

details:   http://hg.videolan.org/x265/rev/91330e7dddd7
branches:  
changeset: 6918:91330e7dddd7
user:      Satoshi Nakagawa <nakagawa424 at oki.com>
date:      Sat May 24 00:07:16 2014 +0900
description:
rdcost: overflow check by integer

diffstat:

 source/common/CMakeLists.txt |  53 +++++++++++++++++++++++++++++--------------
 source/compat/msvc/stdint.h  |  13 +++++++++-
 source/encoder/rdcost.h      |  14 ++++-------
 3 files changed, 51 insertions(+), 29 deletions(-)

diffs (152 lines):

diff -r 0c05e3b298a5 -r 91330e7dddd7 source/common/CMakeLists.txt
--- a/source/common/CMakeLists.txt	Thu May 22 21:28:11 2014 -0500
+++ b/source/common/CMakeLists.txt	Sat May 24 00:07:16 2014 +0900
@@ -1,28 +1,45 @@
 # vim: syntax=cmake
 set(LIBCOMMON_SRC
+    ../Lib/TLibCommon/TComBitStream.cpp
+    ../Lib/TLibCommon/TComDataCU.cpp
+    ../Lib/TLibCommon/TComLoopFilter.cpp
+    ../Lib/TLibCommon/TComMotionInfo.cpp
+    ../Lib/TLibCommon/TComPattern.cpp
+    ../Lib/TLibCommon/TComPic.cpp
+    ../Lib/TLibCommon/TComPicSym.cpp
+    ../Lib/TLibCommon/TComPicYuv.cpp
+    ../Lib/TLibCommon/TComPicYuvMD5.cpp
+    ../Lib/TLibCommon/TComPrediction.cpp
+    ../Lib/TLibCommon/TComRom.cpp
+    ../Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
+    ../Lib/TLibCommon/TComSlice.cpp
+    ../Lib/TLibCommon/TComTrQuant.cpp
+    ../Lib/TLibCommon/TComWeightPrediction.cpp
+    ../Lib/TLibCommon/TComYuv.cpp)
+set(LIBCOMMON_HDR
     ../Lib/TLibCommon/NAL.h
     ../Lib/TLibCommon/SEI.h
     ../Lib/TLibCommon/TComBitCounter.h
     ../Lib/TLibCommon/CommonDef.h
     ../Lib/TLibCommon/TypeDef.h
     ../Lib/TLibCommon/ContextTables.h
-    ../Lib/TLibCommon/TComBitStream.cpp            ../Lib/TLibCommon/TComBitStream.h
-    ../Lib/TLibCommon/TComDataCU.cpp               ../Lib/TLibCommon/TComDataCU.h
-    ../Lib/TLibCommon/TComLoopFilter.cpp           ../Lib/TLibCommon/TComLoopFilter.h
-    ../Lib/TLibCommon/TComMotionInfo.cpp           ../Lib/TLibCommon/TComMotionInfo.h
-    ../Lib/TLibCommon/TComPattern.cpp              ../Lib/TLibCommon/TComPattern.h
-    ../Lib/TLibCommon/TComPic.cpp                  ../Lib/TLibCommon/TComPic.h
-    ../Lib/TLibCommon/TComPicSym.cpp               ../Lib/TLibCommon/TComPicSym.h
-    ../Lib/TLibCommon/TComPicYuv.cpp               ../Lib/TLibCommon/TComPicYuv.h
-    ../Lib/TLibCommon/TComPicYuvMD5.cpp
-    ../Lib/TLibCommon/TComPrediction.cpp           ../Lib/TLibCommon/TComPrediction.h
-    ../Lib/TLibCommon/TComRom.cpp                  ../Lib/TLibCommon/TComRom.h
-    ../Lib/TLibCommon/TComSampleAdaptiveOffset.cpp ../Lib/TLibCommon/TComSampleAdaptiveOffset.h
-    ../Lib/TLibCommon/TComSlice.cpp                ../Lib/TLibCommon/TComSlice.h
-    ../Lib/TLibCommon/TComTrQuant.cpp              ../Lib/TLibCommon/TComTrQuant.h
-    ../Lib/TLibCommon/TComWeightPrediction.cpp     ../Lib/TLibCommon/TComWeightPrediction.h
-    ../Lib/TLibCommon/TComYuv.cpp                  ../Lib/TLibCommon/TComYuv.h)
-source_group(TLibCommon FILES ${LIBCOMMON_SRC})
+    ../Lib/TLibCommon/TComBitStream.h
+    ../Lib/TLibCommon/TComDataCU.h
+    ../Lib/TLibCommon/TComLoopFilter.h
+    ../Lib/TLibCommon/TComMotionInfo.h
+    ../Lib/TLibCommon/TComPattern.h
+    ../Lib/TLibCommon/TComPic.h
+    ../Lib/TLibCommon/TComPicSym.h
+    ../Lib/TLibCommon/TComPicYuv.h
+    ../Lib/TLibCommon/TComPrediction.h
+    ../Lib/TLibCommon/TComRom.h
+    ../Lib/TLibCommon/TComSampleAdaptiveOffset.h
+    ../Lib/TLibCommon/TComSlice.h
+    ../Lib/TLibCommon/TComTrQuant.h
+    ../Lib/TLibCommon/TComWeightPrediction.h
+    ../Lib/TLibCommon/TComYuv.h)
+
+source_group(TLibCommon FILES ${LIBCOMMON_SRC} ${LIBCOMMON_HDR})
 if(GCC)
     set_source_files_properties(${LIBCOMMON_SRC} PROPERTIES COMPILE_FLAGS 
         "-Wno-sign-compare")
@@ -123,7 +140,7 @@ set_source_files_properties(version.cpp 
 
 add_library(common OBJECT
     ${ASM_PRIMITIVES} ${VEC_PRIMITIVES}
-    ${LIBCOMMON_SRC} ${WINXP}
+    ${LIBCOMMON_SRC} ${LIBCOMMON_HDR} ${WINXP}
     primitives.cpp primitives.h
     pixel.cpp dct.cpp ipfilter.cpp intrapred.cpp
     cpu.cpp cpu.h version.cpp
diff -r 0c05e3b298a5 -r 91330e7dddd7 source/compat/msvc/stdint.h
--- a/source/compat/msvc/stdint.h	Thu May 22 21:28:11 2014 -0500
+++ b/source/compat/msvc/stdint.h	Sat May 24 00:07:16 2014 +0900
@@ -1,6 +1,16 @@
 #pragma once
 
-/* a minimal set of C99 types for use with MSVC */
+#ifndef _MSC_VER
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif
+
+#include <crtdefs.h> // for intptr_t
+#if !defined(UINT64_MAX)
+#include <limits.h>
+#define UINT64_MAX _UI64_MAX
+#endif
+
+/* a minimal set of C99 types for use with MSVC (VC9) */
 
 typedef signed char int8_t;
 typedef short int int16_t;
@@ -12,4 +22,3 @@ typedef unsigned short int uint16_t;
 typedef unsigned int uint32_t;
 typedef unsigned __int64 uint64_t;
 
-#include <crtdefs.h> // for intptr_t
diff -r 0c05e3b298a5 -r 91330e7dddd7 source/encoder/rdcost.h
--- a/source/encoder/rdcost.h	Thu May 22 21:28:11 2014 -0500
+++ b/source/encoder/rdcost.h	Sat May 24 00:07:16 2014 +0900
@@ -75,8 +75,7 @@ public:
 
     inline uint64_t calcRdCost(uint32_t distortion, uint32_t bits)
     {
-        X265_CHECK(abs((float)((bits * m_lambdaSSE + 128) >> 8) -
-                       (float)bits * m_lambdaSSE / 256.0) < 2,
+        X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambdaSSE,
                    "calcRdCost wrap detected dist: %d, bits %d, lambda: %d\n", distortion, bits, (int)m_lambdaSSE);
         return distortion + ((bits * m_lambdaSSE + 128) >> 8);
     }
@@ -90,7 +89,7 @@ public:
         int rdc = primitives.sad_square[size](recon, rstride, (pixel*)zeroPel, MAX_CU_SIZE) >> 2;
         int rEnergy = primitives.sa8d[size](recon, rstride, (pixel*)zeroPel, MAX_CU_SIZE) - rdc;
 
-        X265_CHECK(sdc <= sEnergy && rdc <= rEnergy, "DC component of energy is more than total cost\n")
+        X265_CHECK(sEnergy >= 0 && rEnergy >= 0, "DC component of energy is more than total cost\n")
         return abs(sEnergy - rEnergy);
     }
 
@@ -105,8 +104,7 @@ public:
 
     inline uint64_t calcRdSADCost(uint32_t sadCost, uint32_t bits)
     {
-        X265_CHECK(abs((float)((bits * m_lambdaSAD + 128) >> 8) -
-                       (float)bits * m_lambdaSAD / 256.0) < 2,
+        X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambdaSAD,
                    "calcRdSADCost wrap detected dist: %d, bits %d, lambda: "X265_LL"\n", sadCost, bits, m_lambdaSAD);
         return sadCost + ((bits * m_lambdaSAD + 128) >> 8);
     }
@@ -118,16 +116,14 @@ public:
 
     inline uint32_t scaleChromaDistCb(uint32_t dist)
     {
-        X265_CHECK(abs((float)((dist * m_cbDistortionWeight + 128) >> 8) -
-                       (float)dist * m_cbDistortionWeight / 256.0) < 2,
+        X265_CHECK(dist <= (UINT64_MAX - 128) / m_cbDistortionWeight,
                    "scaleChromaDistCb wrap detected dist: %d, lambda: "X265_LL"\n", dist, m_cbDistortionWeight);
         return (uint32_t)(((dist * m_cbDistortionWeight) + 128) >> 8);
     }
 
     inline uint32_t scaleChromaDistCr(uint32_t dist)
     {
-        X265_CHECK(abs((float)((dist * m_crDistortionWeight + 128) >> 8) -
-                       (float)dist * m_crDistortionWeight / 256.0) < 2,
+        X265_CHECK(dist <= (UINT64_MAX - 128) / m_crDistortionWeight,
                    "scaleChromaDistCr wrap detected dist: %d, lambda: "X265_LL"\n", dist, m_crDistortionWeight);
         return (uint32_t)(((dist * m_crDistortionWeight) + 128) >> 8);
     }


More information about the x265-commits mailing list