From e860c3545e16022d76a61ae7862452269dd5161c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 15 Nov 2023 11:24:03 +0100 Subject: [PATCH] C++17: use if constexpr() construct --- alg/gdalpansharpen.cpp | 31 ++--- alg/gdalwarpkernel.cpp | 8 +- gcore/gdal_priv_templates.hpp | 16 +-- gcore/gdalrasterband.cpp | 227 +++++++++++++++++----------------- gcore/overview.cpp | 2 +- 5 files changed, 146 insertions(+), 138 deletions(-) diff --git a/alg/gdalpansharpen.cpp b/alg/gdalpansharpen.cpp index 081cbe750c5f..65e5992d4827 100644 --- a/alg/gdalpansharpen.cpp +++ b/alg/gdalpansharpen.cpp @@ -541,7 +541,7 @@ void GDALPansharpenOperation::WeightedBroveyWithNoData( WorkDataType noData, validValue; GDALCopyWord(psOptions->dfNoData, noData); - if (!(std::numeric_limits::is_integer)) + if constexpr (!(std::numeric_limits::is_integer)) validValue = static_cast(noData + 1e-5); else if (noData == std::numeric_limits::min()) validValue = std::numeric_limits::min() + 1; @@ -655,8 +655,11 @@ void GDALPansharpenOperation::WeightedBrovey3( j]; WorkDataType nPansharpenedValue; GDALCopyWord(nRawValue * dfFactor, nPansharpenedValue); - if (bHasBitDepth && nPansharpenedValue > nMaxValue) - nPansharpenedValue = nMaxValue; + if constexpr (bHasBitDepth) + { + if (nPansharpenedValue > nMaxValue) + nPansharpenedValue = nMaxValue; + } GDALCopyWord(nPansharpenedValue, pDataBuf[i * nBandValues + j]); } } @@ -673,15 +676,15 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf, size_t nValues, size_t nBandValues, T nMaxValue) const { - CPL_STATIC_ASSERT(NINPUT == 3 || NINPUT == 4); - CPL_STATIC_ASSERT(NOUTPUT == 3 || NOUTPUT == 4); + static_assert(NINPUT == 3 || NINPUT == 4); + static_assert(NOUTPUT == 3 || NOUTPUT == 4); const XMMReg4Double w0 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 0); const XMMReg4Double w1 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 1); const XMMReg4Double w2 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 2); - const XMMReg4Double w3 = + [[maybe_unused]] const XMMReg4Double w3 = (NINPUT == 3) ? XMMReg4Double::Zero() : XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 3); @@ -703,7 +706,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( XMMReg4Double val2 = XMMReg4Double::Load4Val(pUpsampledSpectralBuffer + 2 * nBandValues + j); XMMReg4Double val3; - if (NINPUT == 4 || NOUTPUT == 4) + if constexpr (NINPUT == 4 || NOUTPUT == 4) { val3 = XMMReg4Double::Load4Val(pUpsampledSpectralBuffer + 3 * nBandValues + j); @@ -712,7 +715,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( pseudoPanchro += w0 * val0; pseudoPanchro += w1 * val1; pseudoPanchro += w2 * val2; - if (NINPUT == 4) + if constexpr (NINPUT == 4) pseudoPanchro += w3 * val3; /* Little trick to avoid use of ternary operator due to one of the @@ -724,14 +727,14 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( val0 = XMMReg4Double::Min(val0 * factor, maxValue); val1 = XMMReg4Double::Min(val1 * factor, maxValue); val2 = XMMReg4Double::Min(val2 * factor, maxValue); - if (NOUTPUT == 4) + if constexpr (NOUTPUT == 4) { val3 = XMMReg4Double::Min(val3 * factor, maxValue); } val0.Store4Val(pDataBuf + 0 * nBandValues + j); val1.Store4Val(pDataBuf + 1 * nBandValues + j); val2.Store4Val(pDataBuf + 2 * nBandValues + j); - if (NOUTPUT == 4) + if constexpr (NOUTPUT == 4) { val3.Store4Val(pDataBuf + 3 * nBandValues + j); } @@ -746,13 +749,13 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf, size_t nValues, size_t nBandValues, T nMaxValue) const { - // cppcheck-suppress knownConditionTrueFalse - CPLAssert(NINPUT == 3 || NINPUT == 4); + static_assert(NINPUT == 3 || NINPUT == 4); const double dfw0 = psOptions->padfWeights[0]; const double dfw1 = psOptions->padfWeights[1]; const double dfw2 = psOptions->padfWeights[2]; // cppcheck-suppress knownConditionTrueFalse - const double dfw3 = (NINPUT == 3) ? 0 : psOptions->padfWeights[3]; + [[maybe_unused]] const double dfw3 = + (NINPUT == 3) ? 0 : psOptions->padfWeights[3]; size_t j = 0; // Used after for. for (; j + 1 < nValues; j += 2) { @@ -772,7 +775,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( dfPseudoPanchro2 += dfw2 * pUpsampledSpectralBuffer[2 * nBandValues + j + 1]; - if (NINPUT == 4) + if constexpr (NINPUT == 4) { dfPseudoPanchro += dfw3 * pUpsampledSpectralBuffer[3 * nBandValues + j]; diff --git a/alg/gdalwarpkernel.cpp b/alg/gdalwarpkernel.cpp index 92cd175780e7..0ed56784ef51 100644 --- a/alg/gdalwarpkernel.cpp +++ b/alg/gdalwarpkernel.cpp @@ -5700,14 +5700,14 @@ static void GWKResampleNoMasksOrDstDensityOnlyThreadInternal(void *pData) for (int iBand = 0; iBand < poWK->nBands; iBand++) { T value = 0; - if (eResample == GRA_NearestNeighbour) + if constexpr (eResample == GRA_NearestNeighbour) { value = reinterpret_cast( poWK->papabySrcImage[iBand])[iSrcOffset]; } - else if (bUse4SamplesFormula) + else if constexpr (bUse4SamplesFormula) { - if (eResample == GRA_Bilinear) + if constexpr (eResample == GRA_Bilinear) GWKBilinearResampleNoMasks4SampleT( poWK, iBand, padfX[iDstX] - poWK->nSrcXOff, padfY[iDstX] - poWK->nSrcYOff, &value); @@ -5774,7 +5774,7 @@ static void GWKResampleNoMasksOrDstDensityOnlyHas4SampleThread(void *pData) { GWKJobStruct *psJob = static_cast(pData); GDALWarpKernel *poWK = psJob->poWK; - CPLAssert(eResample == GRA_Bilinear || eResample == GRA_Cubic); + static_assert(eResample == GRA_Bilinear || eResample == GRA_Cubic); const bool bUse4SamplesFormula = poWK->dfXScale >= 0.95 && poWK->dfYScale >= 0.95; if (bUse4SamplesFormula) diff --git a/gcore/gdal_priv_templates.hpp b/gcore/gdal_priv_templates.hpp index a7962bd7a498..337f6e8317a1 100644 --- a/gcore/gdal_priv_templates.hpp +++ b/gcore/gdal_priv_templates.hpp @@ -54,13 +54,13 @@ inline void GDALGetDataLimits(Tin &tMaxValue, Tin &tMinValue) tMinValue = std::numeric_limits::min(); // Compute the actual minimum value of Tout in terms of Tin. - if (std::numeric_limits::is_signed && - std::numeric_limits::is_integer) + if constexpr (std::numeric_limits::is_signed && + std::numeric_limits::is_integer) { // the minimum value is less than zero - if (std::numeric_limits::digits < - std::numeric_limits::digits || - !std::numeric_limits::is_integer) + if constexpr (std::numeric_limits::digits < + std::numeric_limits::digits || + !std::numeric_limits::is_integer) { // Tout is smaller than Tin, so we need to clamp values in input // to the range of Tout's min/max values @@ -71,12 +71,12 @@ inline void GDALGetDataLimits(Tin &tMaxValue, Tin &tMinValue) tMaxValue = static_cast(std::numeric_limits::max()); } } - else if (std::numeric_limits::is_integer) + else if constexpr (std::numeric_limits::is_integer) { // the output is unsigned, so we just need to determine the max /* coverity[same_on_both_sides] */ - if (std::numeric_limits::digits <= - std::numeric_limits::digits) + if constexpr (std::numeric_limits::digits <= + std::numeric_limits::digits) { // Tout is smaller than Tin, so we need to clamp the input values // to the range of Tout's max diff --git a/gcore/gdalrasterband.cpp b/gcore/gdalrasterband.cpp index d0ca7600a0e9..897d1561a565 100644 --- a/gcore/gdalrasterband.cpp +++ b/gcore/gdalrasterband.cpp @@ -4521,7 +4521,7 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount++; nSum += nValue; @@ -4531,7 +4531,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; } @@ -4539,43 +4539,42 @@ struct ComputeStatisticsInternalGeneric else if (nMin == std::numeric_limits::min() && nMax == std::numeric_limits::max()) { - if (!COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { - return; - } - // Optimization when there is no nodata and we know we have already - // reached the min and max - for (int iY = 0; iY < nYCheck; iY++) - { - int iX; - for (iX = 0; iX + 3 < nXCheck; iX += 4) - { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - const GUIntBig nValue2 = pData[iOffset + 1]; - const GUIntBig nValue3 = pData[iOffset + 2]; - const GUIntBig nValue4 = pData[iOffset + 3]; - nSum += nValue; - nSumSquare += nValue * nValue; - nSum += nValue2; - nSumSquare += nValue2 * nValue2; - nSum += nValue3; - nSumSquare += nValue3 * nValue3; - nSum += nValue4; - nSumSquare += nValue4 * nValue4; - } - for (; iX < nXCheck; ++iX) + // Optimization when there is no nodata and we know we have already + // reached the min and max + for (int iY = 0; iY < nYCheck; iY++) { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - nSum += nValue; - nSumSquare += nValue * nValue; + int iX; + for (iX = 0; iX + 3 < nXCheck; iX += 4) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUIntBig nValue = pData[iOffset]; + const GUIntBig nValue2 = pData[iOffset + 1]; + const GUIntBig nValue3 = pData[iOffset + 2]; + const GUIntBig nValue4 = pData[iOffset + 3]; + nSum += nValue; + nSumSquare += nValue * nValue; + nSum += nValue2; + nSumSquare += nValue2 * nValue2; + nSum += nValue3; + nSumSquare += nValue3 * nValue3; + nSum += nValue4; + nSumSquare += nValue4 * nValue4; + } + for (; iX < nXCheck; ++iX) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUIntBig nValue = pData[iOffset]; + nSum += nValue; + nSumSquare += nValue * nValue; + } } + nSampleCount += static_cast(nXCheck) * nYCheck; + nValidCount += static_cast(nXCheck) * nYCheck; } - nSampleCount += static_cast(nXCheck) * nYCheck; - nValidCount += static_cast(nXCheck) * nYCheck; } else { @@ -4602,7 +4601,7 @@ struct ComputeStatisticsInternalGeneric if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4632,7 +4631,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; nValidCount += static_cast(nXCheck) * nYCheck; @@ -4684,14 +4683,14 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount32bit++; nSum32bit += nValue; nSumSquare32bit += nValue * nValue; } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += nSampleCount32bit; nValidCount += nValidCount32bit; @@ -4703,52 +4702,52 @@ struct ComputeStatisticsInternalGeneric } else if (nMin == 0 && nMax == 255) { - if (!COMPUTE_OTHER_STATS) - return; - - // Optimization when there is no nodata and we know we have already - // reached the min and max - for (int iY = 0; iY < nYCheck; iY++) + if constexpr (COMPUTE_OTHER_STATS) { - int iX = 0; - for (int k = 0; k < nOuterLoops; k++) + // Optimization when there is no nodata and we know we have already + // reached the min and max + for (int iY = 0; iY < nYCheck; iY++) { - int iMax = iX + 65536; - if (iMax > nXCheck) - iMax = nXCheck; - GUInt32 nSum32bit = 0; - GUInt32 nSumSquare32bit = 0; - for (; iX + 3 < iMax; iX += 4) + int iX = 0; + for (int k = 0; k < nOuterLoops; k++) + { + int iMax = iX + 65536; + if (iMax > nXCheck) + iMax = nXCheck; + GUInt32 nSum32bit = 0; + GUInt32 nSumSquare32bit = 0; + for (; iX + 3 < iMax; iX += 4) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUInt32 nValue = pData[iOffset]; + const GUInt32 nValue2 = pData[iOffset + 1]; + const GUInt32 nValue3 = pData[iOffset + 2]; + const GUInt32 nValue4 = pData[iOffset + 3]; + nSum32bit += nValue; + nSumSquare32bit += nValue * nValue; + nSum32bit += nValue2; + nSumSquare32bit += nValue2 * nValue2; + nSum32bit += nValue3; + nSumSquare32bit += nValue3 * nValue3; + nSum32bit += nValue4; + nSumSquare32bit += nValue4 * nValue4; + } + nSum += nSum32bit; + nSumSquare += nSumSquare32bit; + } + for (; iX < nXCheck; ++iX) { const GPtrDiff_t iOffset = iX + static_cast(iY) * nBlockXSize; - const GUInt32 nValue = pData[iOffset]; - const GUInt32 nValue2 = pData[iOffset + 1]; - const GUInt32 nValue3 = pData[iOffset + 2]; - const GUInt32 nValue4 = pData[iOffset + 3]; - nSum32bit += nValue; - nSumSquare32bit += nValue * nValue; - nSum32bit += nValue2; - nSumSquare32bit += nValue2 * nValue2; - nSum32bit += nValue3; - nSumSquare32bit += nValue3 * nValue3; - nSum32bit += nValue4; - nSumSquare32bit += nValue4 * nValue4; + const GUIntBig nValue = pData[iOffset]; + nSum += nValue; + nSumSquare += nValue * nValue; } - nSum += nSum32bit; - nSumSquare += nSumSquare32bit; - } - for (; iX < nXCheck; ++iX) - { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - nSum += nValue; - nSumSquare += nValue * nValue; } + nSampleCount += static_cast(nXCheck) * nYCheck; + nValidCount += static_cast(nXCheck) * nYCheck; } - nSampleCount += static_cast(nXCheck) * nYCheck; - nValidCount += static_cast(nXCheck) * nYCheck; } else { @@ -4782,7 +4781,7 @@ struct ComputeStatisticsInternalGeneric if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum32bit += nValue; nSumSquare32bit += nValue * nValue; @@ -4790,7 +4789,7 @@ struct ComputeStatisticsInternalGeneric nSumSquare32bit += nValue2 * nValue2; } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nSum32bit; nSumSquare += nSumSquare32bit; @@ -4805,7 +4804,7 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4814,7 +4813,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; nValidCount += static_cast(nXCheck) * nYCheck; @@ -4882,7 +4881,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, GDALm256i ymm_min = GDALmm256_load_si256(reinterpret_cast(pData + i)); GDALm256i ymm_max = ymm_min; - const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); + [[maybe_unused]] const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); for (GPtrDiff_t k = 0; k < nOuterLoops; k++) { @@ -4890,8 +4889,9 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_sum = ZERO256; - GDALm256i ymm_sumsquare = ZERO256; // holds 8 uint32 sums + [[maybe_unused]] GDALm256i ymm_sum = ZERO256; + [[maybe_unused]] GDALm256i ymm_sumsquare = + ZERO256; // holds 8 uint32 sums for (; i + 31 < iMax; i += 32) { const GDALm256i ymm = GDALmm256_load_si256( @@ -4905,7 +4905,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, ymm_max = GDALmm256_max_epu8(ymm_max, ymm); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Extract even-8bit values const GDALm256i ymm_even = @@ -4931,7 +4931,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GDALmm256_store_si256(reinterpret_cast(panSum), ymm_sum); @@ -4946,24 +4946,24 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { GDALmm256_store_si256(reinterpret_cast(pabyMin), ymm_min); } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { GDALmm256_store_si256(reinterpret_cast(pabyMax), ymm_max); } - if (COMPUTE_MIN || COMPUTE_MAX) + if constexpr (COMPUTE_MIN || COMPUTE_MAX) { for (int j = 0; j < 32; j++) { - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { if (pabyMin[j] < nMin) nMin = pabyMin[j]; } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { if (pabyMax[j] > nMax) nMax = pabyMax[j]; @@ -4974,17 +4974,17 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, for (; i < nBlockPixels; i++) { const GUInt32 nValue = pData[i]; - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { if (nValue < nMin) nMin = nValue; } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4992,7 +4992,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nBlockPixels); nValidCount += static_cast(nBlockPixels); @@ -5047,7 +5047,8 @@ struct ComputeStatisticsInternal GDALmm256_set1_epi8(static_cast(nMin)); GDALm256i ymm_min = ymm_neutral; GDALm256i ymm_max = ymm_neutral; - const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); + [[maybe_unused]] const auto ymm_mask_8bits = + GDALmm256_set1_epi16(0xFF); const GUInt32 nMinThreshold = (nNoDataValue == 0) ? 1 : 0; const GUInt32 nMaxThreshold = (nNoDataValue == 255) ? 254 : 255; @@ -5060,11 +5061,11 @@ struct ComputeStatisticsInternal std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_sum = ZERO256; + [[maybe_unused]] GDALm256i ymm_sum = ZERO256; // holds 8 uint32 sums - GDALm256i ymm_sumsquare = ZERO256; + [[maybe_unused]] GDALm256i ymm_sumsquare = ZERO256; // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_count_nodata_mul_255 = ZERO256; + [[maybe_unused]] GDALm256i ymm_count_nodata_mul_255 = ZERO256; const auto iInit = i; for (; i + 31 < iMax; i += 32) { @@ -5074,7 +5075,7 @@ struct ComputeStatisticsInternal // Check which values are nodata const GDALm256i ymm_eq_nodata = GDALmm256_cmpeq_epi8(ymm, ymm_nodata); - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Count how many values are nodata (due to cmpeq // putting 255 when condition is met, this will actually @@ -5104,7 +5105,7 @@ struct ComputeStatisticsInternal GDALmm256_max_epu8(ymm_max, ymm_nodata_by_neutral); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Extract even-8bit values const GDALm256i ymm_even = GDALmm256_and_si256( @@ -5132,7 +5133,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUInt32 *panCoutNoDataMul255 = panSum; GDALmm256_store_si256( @@ -5176,7 +5177,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += nBlockPixels - i; } @@ -5189,7 +5190,7 @@ struct ComputeStatisticsInternal nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount++; nSum += nValue; @@ -5287,7 +5288,8 @@ struct ComputeStatisticsInternal reinterpret_cast(pData + i)); ymm_min = GDALmm256_add_epi16(ymm_min, ymm_m32768); GDALm256i ymm_max = ymm_min; - GDALm256i ymm_sumsquare = ZERO256; // holds 4 uint64 sums + [[maybe_unused]] GDALm256i ymm_sumsquare = + ZERO256; // holds 4 uint64 sums // Make sure that sum can fit on uint32 // * 8 since we can hold 8 sums per vector register @@ -5298,8 +5300,10 @@ struct ComputeStatisticsInternal nOuterLoops++; const bool bComputeMinMax = nMin > 0 || nMax < 65535; - const auto ymm_mask_16bits = GDALmm256_set1_epi32(0xFFFF); - const auto ymm_mask_32bits = GDALmm256_set1_epi64x(0xFFFFFFFF); + [[maybe_unused]] const auto ymm_mask_16bits = + GDALmm256_set1_epi32(0xFFFF); + [[maybe_unused]] const auto ymm_mask_32bits = + GDALmm256_set1_epi64x(0xFFFFFFFF); GUIntBig nSumThis = 0; for (int k = 0; k < nOuterLoops; k++) @@ -5307,7 +5311,8 @@ struct ComputeStatisticsInternal const auto iMax = std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); - GDALm256i ymm_sum = ZERO256; // holds 8 uint32 sums + [[maybe_unused]] GDALm256i ymm_sum = + ZERO256; // holds 8 uint32 sums for (; i + 15 < iMax; i += 16) { const GDALm256i ymm = GDALmm256_load_si256( @@ -5320,7 +5325,7 @@ struct ComputeStatisticsInternal ymm_max = GDALmm256_max_epi16(ymm_max, ymm_shifted); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Note: the int32 range can overflow for (0-32768)^2 + // (0-32768)^2 = 0x80000000, but as we know the result @@ -5342,7 +5347,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUInt32 anSum[8]; GDALmm256_storeu_si256(reinterpret_cast(anSum), @@ -5374,7 +5379,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUIntBig anSumSquare[4]; GDALmm256_storeu_si256( diff --git a/gcore/overview.cpp b/gcore/overview.cpp index 9ec9343431cb..cbf4e25ef023 100644 --- a/gcore/overview.cpp +++ b/gcore/overview.cpp @@ -3501,7 +3501,7 @@ static CPLErr GDALResampleChunk_ConvolutionT( size_t j = (nSrcLineStart - nChunkYOff) * static_cast(nDstXSize); #ifdef USE_SSE2 - if (eWrkDataType == GDT_Float32) + if constexpr (eWrkDataType == GDT_Float32) { #ifdef __AVX__ for (; iFilteredPixelOff + 15 < nDstXSize;