[x265-commits] [x265] cmake: treat empty CMAKE_SYSTEM_PROCESSOR as x86 (fixes #25)

Steve Borho steve at borho.org
Mon Feb 3 17:02:28 CET 2014


details:   http://hg.videolan.org/x265/rev/900a13b0b50a
branches:  
changeset: 5983:900a13b0b50a
user:      Steve Borho <steve at borho.org>
date:      Mon Feb 03 09:00:34 2014 -0600
description:
cmake: treat empty CMAKE_SYSTEM_PROCESSOR as x86 (fixes #25)
Subject: [x265] common: change X265_MALLOC macro to return typed pointer

details:   http://hg.videolan.org/x265/rev/a260f55429e3
branches:  
changeset: 5984:a260f55429e3
user:      Steve Borho <steve at borho.org>
date:      Mon Feb 03 09:53:11 2014 -0600
description:
common: change X265_MALLOC macro to return typed pointer

One less opportunity for a stupid mistake

diffstat:

 source/CMakeLists.txt                    |   5 +-
 source/Lib/TLibCommon/CommonDef.h        |   2 +-
 source/Lib/TLibCommon/TComBitStream.cpp  |   4 +-
 source/Lib/TLibCommon/TComDataCU.cpp     |  54 ++++++++++++++++----------------
 source/Lib/TLibCommon/TComPicYuv.cpp     |   6 +-
 source/Lib/TLibCommon/TComPrediction.cpp |  20 +++++-----
 source/Lib/TLibCommon/TComTrQuant.cpp    |   2 +-
 source/Lib/TLibCommon/TComYuv.cpp        |   6 +-
 source/Lib/TLibEncoder/NALwrite.cpp      |   2 +-
 source/common/TShortYUV.cpp              |   6 +-
 source/common/common.cpp                 |   2 +-
 source/common/lowres.cpp                 |  16 ++++----
 source/encoder/frameencoder.cpp          |   8 ++--
 source/encoder/motion.cpp                |   2 +-
 source/encoder/reference.cpp             |   2 +-
 source/encoder/slicetype.h               |   2 +-
 source/encoder/weightPrediction.cpp      |   4 +-
 source/test/intrapredharness.cpp         |   4 +-
 source/test/ipfilterharness.cpp          |   8 ++--
 source/test/mbdstharness.cpp             |  28 ++++++++--------
 source/test/pixelharness.cpp             |  16 ++++----
 21 files changed, 100 insertions(+), 99 deletions(-)

diffs (truncated from 508 to 300 lines):

diff -r 898ccce491e9 -r a260f55429e3 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/CMakeLists.txt	Mon Feb 03 09:53:11 2014 -0600
@@ -27,8 +27,9 @@ SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_
 
 # System architecture detection
 string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC)
-if(${SYSPROC} STREQUAL "i386" OR ${SYSPROC} STREQUAL "amd64" OR
-   ${SYSPROC} STREQUAL "x86_64" OR ${SYSPROC} STREQUAL "x86")
+if("${SYSPROC}" STREQUAL "i386"   OR "${SYSPROC}" STREQUAL "amd64" OR
+   "${SYSPROC}" STREQUAL "x86_64" OR "${SYSPROC}" STREQUAL "x86"   OR
+   "${SYSPROC}" STREQUAL "")
     message(STATUS "Detected x86 system processor")
     set(X86 1)
     add_definitions(-DX265_ARCH_X86=1)
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/CommonDef.h
--- a/source/Lib/TLibCommon/CommonDef.h	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/CommonDef.h	Mon Feb 03 09:53:11 2014 -0600
@@ -139,7 +139,7 @@
 #define NOT_VALID                  -1
 
 // for use in HM, replaces old xMalloc/xFree macros
-#define X265_MALLOC(type, count)    x265_malloc(sizeof(type) * (count))
+#define X265_MALLOC(type, count)    (type*)x265_malloc(sizeof(type) * (count))
 #define X265_FREE(ptr)              x265_free(ptr)
 
 // ====================================================================================================================
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComBitStream.cpp
--- a/source/Lib/TLibCommon/TComBitStream.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComBitStream.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -53,7 +53,7 @@ using namespace x265;
 
 TComOutputBitstream::TComOutputBitstream()
 {
-    m_fifo = (uint8_t*)X265_MALLOC(uint8_t, MIN_FIFO_SIZE);
+    m_fifo = X265_MALLOC(uint8_t, MIN_FIFO_SIZE);
     clear();
 }
 
@@ -215,7 +215,7 @@ void TComOutputBitstream::push_back(uint
 
         /**  FIFO size is Reached into MIN_FIFO_SIZE then Reallocate the FIFO and Copy the fifo to new memory
         location and continue to push encoded bit streams */
-        uint8_t *temp = (uint8_t*)X265_MALLOC(uint8_t, buffsize);
+        uint8_t *temp = X265_MALLOC(uint8_t, buffsize);
 
         /** check Allocated buffer before copy the encoder bitstream and push into FIFO */
         if (temp)
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -121,10 +121,10 @@ void TComDataCU::create(uint32_t numPart
     tmp = g_convertToBit[tmp] + 2;
     m_unitMask = ~((1 << tmp) - 1);
 
-    m_qp     = (char*)X265_MALLOC(char,   numPartition);
-    m_depth  = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_width  = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_height = (UChar*)X265_MALLOC(UChar, numPartition);
+    m_qp     = X265_MALLOC(char,  numPartition);
+    m_depth  = X265_MALLOC(UChar, numPartition);
+    m_width  = X265_MALLOC(UChar, numPartition);
+    m_height = X265_MALLOC(UChar, numPartition);
 
     m_skipFlag = new bool[numPartition];
 
@@ -133,38 +133,38 @@ void TComDataCU::create(uint32_t numPart
     m_predModes = new char[numPartition];
     m_cuTransquantBypass = new bool[numPartition];
 
-    m_bMergeFlags     = (bool*)X265_MALLOC(bool,  numPartition);
-    m_mergeIndex      = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_lumaIntraDir    = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_chromaIntraDir  = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_interDir        = (UChar*)X265_MALLOC(UChar, numPartition);
-
-    m_trIdx            = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_transformSkip[0] = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_transformSkip[1] = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_transformSkip[2] = (UChar*)X265_MALLOC(UChar, numPartition);
-
-    m_cbf[0] = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_cbf[1] = (UChar*)X265_MALLOC(UChar, numPartition);
-    m_cbf[2] = (UChar*)X265_MALLOC(UChar, numPartition);
+    m_bMergeFlags     = X265_MALLOC(bool,  numPartition);
+    m_mergeIndex      = X265_MALLOC(UChar, numPartition);
+    m_lumaIntraDir    = X265_MALLOC(UChar, numPartition);
+    m_chromaIntraDir  = X265_MALLOC(UChar, numPartition);
+    m_interDir        = X265_MALLOC(UChar, numPartition);
+
+    m_trIdx            = X265_MALLOC(UChar, numPartition);
+    m_transformSkip[0] = X265_MALLOC(UChar, numPartition);
+    m_transformSkip[1] = X265_MALLOC(UChar, numPartition);
+    m_transformSkip[2] = X265_MALLOC(UChar, numPartition);
+
+    m_cbf[0] = X265_MALLOC(UChar, numPartition);
+    m_cbf[1] = X265_MALLOC(UChar, numPartition);
+    m_cbf[2] = X265_MALLOC(UChar, numPartition);
 
     m_mvpIdx[0] = new char[numPartition];
     m_mvpIdx[1] = new char[numPartition];
 
-    m_trCoeffY  = (TCoeff*)X265_MALLOC(TCoeff, width * height);
-    m_trCoeffCb = (TCoeff*)X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-    m_trCoeffCr = (TCoeff*)X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-
-    m_iPCMFlags   = (bool*)X265_MALLOC(bool, numPartition);
-    m_iPCMSampleY  = (Pel*)X265_MALLOC(Pel, width * height);
-    m_iPCMSampleCb = (Pel*)X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-    m_iPCMSampleCr = (Pel*)X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    m_trCoeffY  = X265_MALLOC(TCoeff, width * height);
+    m_trCoeffCb = X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    m_trCoeffCr = X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+
+    m_iPCMFlags   = X265_MALLOC(bool, numPartition);
+    m_iPCMSampleY  = X265_MALLOC(Pel, width * height);
+    m_iPCMSampleCb = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    m_iPCMSampleCr = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
 
     m_cuMvField[0].create(numPartition);
     m_cuMvField[1].create(numPartition);
 
     // create pattern memory
-    m_pattern = (TComPattern*)X265_MALLOC(TComPattern, 1);
+    m_pattern = X265_MALLOC(TComPattern, 1);
 }
 
 void TComDataCU::destroy()
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComPicYuv.cpp
--- a/source/Lib/TLibCommon/TComPicYuv.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -88,9 +88,9 @@ void TComPicYuv::create(int picWidth, in
     m_strideC = ((m_numCuInWidth * g_maxCUWidth) >> m_hChromaShift) + (m_chromaMarginX * 2);
     int maxHeight = m_numCuInHeight * g_maxCUHeight;
 
-    m_picBufY = (Pel*)X265_MALLOC(Pel, m_stride * (maxHeight + (m_lumaMarginY * 2)));
-    m_picBufU = (Pel*)X265_MALLOC(Pel, m_strideC * ((maxHeight >> m_vChromaShift) + (m_chromaMarginY * 2)));
-    m_picBufV = (Pel*)X265_MALLOC(Pel, m_strideC * ((maxHeight >> m_vChromaShift) + (m_chromaMarginY * 2)));
+    m_picBufY = X265_MALLOC(Pel, m_stride * (maxHeight + (m_lumaMarginY * 2)));
+    m_picBufU = X265_MALLOC(Pel, m_strideC * ((maxHeight >> m_vChromaShift) + (m_chromaMarginY * 2)));
+    m_picBufV = X265_MALLOC(Pel, m_strideC * ((maxHeight >> m_vChromaShift) + (m_chromaMarginY * 2)));
 
     m_picOrgY = m_picBufY + m_lumaMarginY   * getStride()  + m_lumaMarginX;
     m_picOrgU = m_picBufU + m_chromaMarginY * getCStride() + m_chromaMarginX;
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComPrediction.cpp
--- a/source/Lib/TLibCommon/TComPrediction.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComPrediction.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -66,7 +66,7 @@ TComPrediction::TComPrediction()
 
 TComPrediction::~TComPrediction()
 {
-    delete[] m_predBuf;
+    X265_FREE(m_predBuf);
     X265_FREE(m_predAllAngsBuf);
 
     X265_FREE(refAbove);
@@ -91,15 +91,15 @@ void TComPrediction::initTempBuff(int cs
 {
     if (m_predBuf == NULL)
     {
-        m_predBufHeight  = ((MAX_CU_SIZE + 2) << 4);
-        m_predBufStride = ((MAX_CU_SIZE  + 8) << 4);
-        m_predBuf = new Pel[m_predBufStride * m_predBufHeight];
-        m_predAllAngsBuf = (Pel*)X265_MALLOC(Pel, 33 * MAX_CU_SIZE * MAX_CU_SIZE);
+        m_predBufHeight = ((MAX_CU_SIZE + 2) << 4);
+        m_predBufStride = ((MAX_CU_SIZE + 8) << 4);
+        m_predBuf = X265_MALLOC(Pel, m_predBufStride * m_predBufHeight);
+        m_predAllAngsBuf = X265_MALLOC(Pel, 33 * MAX_CU_SIZE * MAX_CU_SIZE);
 
-        refAbove = (Pel*)X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
-        refAboveFlt = (Pel*)X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
-        refLeft = (Pel*)X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
-        refLeftFlt = (Pel*)X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
+        refAbove = X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
+        refAboveFlt = X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
+        refLeft = X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
+        refLeftFlt = X265_MALLOC(Pel, 3 * MAX_CU_SIZE);
 
         m_predYuv[0].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
         m_predYuv[1].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
@@ -107,7 +107,7 @@ void TComPrediction::initTempBuff(int cs
         m_predShortYuv[1].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
         m_predTempYuv.create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
 
-        m_immedVals = (int16_t*)X265_MALLOC(int16_t, 64 * (64 + NTAPS_LUMA - 1));
+        m_immedVals = X265_MALLOC(int16_t, 64 * (64 + NTAPS_LUMA - 1));
     }
 
     if (m_lumaRecStride != (MAX_CU_SIZE >> 1) + 1)
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -74,7 +74,7 @@ TComTrQuant::TComTrQuant()
 
     // allocate temporary buffers
     // OPT_ME: I may reduce this to short and output matched, but I am not sure it is right.
-    m_tmpCoeff = (int32_t*)X265_MALLOC(int, MAX_CU_SIZE * MAX_CU_SIZE);
+    m_tmpCoeff = X265_MALLOC(int32_t, MAX_CU_SIZE * MAX_CU_SIZE);
 
     // allocate bit estimation class (for RDOQ)
     m_estBitsSbac = new estBitsSbacStruct;
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibCommon/TComYuv.cpp
--- a/source/Lib/TLibCommon/TComYuv.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibCommon/TComYuv.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -68,9 +68,9 @@ void TComYuv::create(uint32_t width, uin
     m_vChromaShift = CHROMA_V_SHIFT(csp);
 
     // memory allocation (padded for SIMD reads)
-    m_bufY = (Pel*)X265_MALLOC(Pel, width * height);
-    m_bufU = (Pel*)X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift) + 8);
-    m_bufV = (Pel*)X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift) + 8);
+    m_bufY = X265_MALLOC(Pel, width * height);
+    m_bufU = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift) + 8);
+    m_bufV = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift) + 8);
 
     // set width and height
     m_width   = width;
diff -r 898ccce491e9 -r a260f55429e3 source/Lib/TLibEncoder/NALwrite.cpp
--- a/source/Lib/TLibEncoder/NALwrite.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/Lib/TLibEncoder/NALwrite.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -85,7 +85,7 @@ void write(uint8_t*& out, OutputNALUnit&
     uint32_t fsize = nalu.m_bitstream.getByteStreamLength();
     uint8_t* fifo = nalu.m_bitstream.getFIFO();
     uint32_t  emulationSize = fsize / 2;
-    uint8_t* emulation = (uint8_t*)X265_MALLOC(uint8_t, fsize + emulationSize);
+    uint8_t* emulation = X265_MALLOC(uint8_t, fsize + emulationSize);
     uint32_t nalsize = 0;
 
     if (emulation)
diff -r 898ccce491e9 -r a260f55429e3 source/common/TShortYUV.cpp
--- a/source/common/TShortYUV.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/common/TShortYUV.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -49,9 +49,9 @@ void TShortYUV::create(unsigned int widt
     m_hChromaShift = CHROMA_H_SHIFT(csp);
     m_vChromaShift = CHROMA_V_SHIFT(csp);
 
-    m_bufY  = (int16_t*)X265_MALLOC(int16_t, width * height);
-    m_bufCb = (int16_t*)X265_MALLOC(int16_t, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-    m_bufCr = (int16_t*)X265_MALLOC(int16_t, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    m_bufY  = X265_MALLOC(int16_t, width * height);
+    m_bufCb = X265_MALLOC(int16_t, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    m_bufCr = X265_MALLOC(int16_t, (width >> m_hChromaShift) * (height >> m_vChromaShift));
 
     // set width and height
     m_width  = width;
diff -r 898ccce491e9 -r a260f55429e3 source/common/common.cpp
--- a/source/common/common.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/common/common.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -752,7 +752,7 @@ char *x265_param2string(x265_param *p)
 {
     char *buf, *s;
 
-    buf = s = (char*)X265_MALLOC(char, 2000);
+    buf = s = X265_MALLOC(char, 2000);
     if (!buf)
         return NULL;
 
diff -r 898ccce491e9 -r a260f55429e3 source/common/lowres.cpp
--- a/source/common/lowres.cpp	Mon Feb 03 08:46:36 2014 -0600
+++ b/source/common/lowres.cpp	Mon Feb 03 09:53:11 2014 -0600
@@ -56,7 +56,7 @@ void Lowres::create(TComPicYuv *orig, in
     /* allocate lowres buffers */
     for (int i = 0; i < 4; i++)
     {
-        buffer[i] = (Pel*)X265_MALLOC(Pel, lumaStride * (lines + 2 * orig->getLumaMarginY()));
+        buffer[i] = X265_MALLOC(pixel, lumaStride * (lines + 2 * orig->getLumaMarginY()));
     }
 
     int padoffset = lumaStride * orig->getLumaMarginY() + orig->getLumaMarginX();
@@ -65,23 +65,23 @@ void Lowres::create(TComPicYuv *orig, in
     lowresPlane[2] = buffer[2] + padoffset;
     lowresPlane[3] = buffer[3] + padoffset;
 
-    intraCost = (int32_t*)X265_MALLOC(int32_t, cuCount);
+    intraCost = X265_MALLOC(int32_t, cuCount);
 
     for (int i = 0; i < bframes + 2; i++)
     {
         for (int j = 0; j < bframes + 2; j++)
         {
-            rowSatds[i][j] = (int32_t*)X265_MALLOC(int, cuHeight);
-            lowresCosts[i][j] = (uint16_t*)X265_MALLOC(uint16_t, cuCount);
+            rowSatds[i][j] = X265_MALLOC(int32_t, cuHeight);
+            lowresCosts[i][j] = X265_MALLOC(uint16_t, cuCount);
         }
     }
 
     for (int i = 0; i < bframes + 1; i++)
     {
-        lowresMvs[0][i] = (MV*)X265_MALLOC(MV, cuCount);
-        lowresMvs[1][i] = (MV*)X265_MALLOC(MV, cuCount);
-        lowresMvCosts[0][i] = (int32_t*)X265_MALLOC(int32_t, cuCount);
-        lowresMvCosts[1][i] = (int32_t*)X265_MALLOC(int32_t, cuCount);
+        lowresMvs[0][i] = X265_MALLOC(MV, cuCount);
+        lowresMvs[1][i] = X265_MALLOC(MV, cuCount);
+        lowresMvCosts[0][i] = X265_MALLOC(int32_t, cuCount);
+        lowresMvCosts[1][i] = X265_MALLOC(int32_t, cuCount);
     }
 }
 


More information about the x265-commits mailing list