From f8489a5facac1b885bd2040f53fdbabac01f8ef7 Mon Sep 17 00:00:00 2001
From: Frank Bossen <fbossen@gmail.com>
Date: Fri, 17 Jan 2020 15:29:30 +0100
Subject: [PATCH] remove macro JVET_P0090_32BIT_MVD

---
 source/Lib/CommonLib/TypeDef.h        |   1 -
 source/Lib/DecoderLib/BinDecoder.cpp  |  46 ------------
 source/Lib/DecoderLib/BinDecoder.h    |   4 --
 source/Lib/DecoderLib/CABACReader.cpp |  24 -------
 source/Lib/EncoderLib/BinEncoder.cpp  | 100 --------------------------
 source/Lib/EncoderLib/BinEncoder.h    |  18 -----
 source/Lib/EncoderLib/CABACWriter.cpp |  24 -------
 7 files changed, 217 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index d0d6c39de..393dbf961 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -100,7 +100,6 @@
 
 
 
-#define JVET_P0090_32BIT_MVD                              1 // JVET-P0090: Limitation of abs_mvd_min2 binarization within 32-bit
 
 #define JVET_P0298_DISABLE_LEVELMAPPING_IN_BYPASS         1 // JVET-P0298: Disable level mapping in bypass mode
 
diff --git a/source/Lib/DecoderLib/BinDecoder.cpp b/source/Lib/DecoderLib/BinDecoder.cpp
index ec1de1fea..81d4783ba 100644
--- a/source/Lib/DecoderLib/BinDecoder.cpp
+++ b/source/Lib/DecoderLib/BinDecoder.cpp
@@ -180,7 +180,6 @@ unsigned BinDecoderBase::decodeBinsEP( unsigned numBins )
   return bins;
 }
 
-#if JVET_P0090_32BIT_MVD
 unsigned BinDecoderBase::decodeRemAbsEP(unsigned goRicePar, unsigned cutoff, int maxLog2TrDynamicRange)
 {
   unsigned prefix = 0;
@@ -209,51 +208,6 @@ unsigned BinDecoderBase::decodeRemAbsEP(unsigned goRicePar, unsigned cutoff, int
   }
   return offset + decodeBinsEP(length);
 }
-#else
-unsigned BinDecoderBase::decodeRemAbsEP( unsigned goRicePar, bool useLimitedPrefixLength, int maxLog2TrDynamicRange )
-{
-  unsigned cutoff = COEF_REMAIN_BIN_REDUCTION;
-  unsigned prefix = 0;
-  useLimitedPrefixLength = true;
-  if( useLimitedPrefixLength )
-  {
-    const unsigned  maxPrefix = 32 - maxLog2TrDynamicRange;
-    unsigned        codeWord  = 0;
-    do
-    {
-      prefix++;
-      codeWord = decodeBinEP();
-    }
-    while( codeWord && prefix < maxPrefix );
-    prefix -= 1 - codeWord;
-  }
-  else
-  {
-    while( decodeBinEP() )
-    {
-      prefix++;
-    }
-  }
-  unsigned length = goRicePar, offset;
-  if( prefix < cutoff )
-  {
-    offset    = prefix << goRicePar;
-  }
-  else
-  {
-    offset    = ( ( ( 1 << ( prefix - cutoff ) ) + cutoff - 1 ) << goRicePar );
-    if( useLimitedPrefixLength )
-    {
-      length += ( prefix == ( 32 - maxLog2TrDynamicRange ) ? maxLog2TrDynamicRange - goRicePar : prefix - COEF_REMAIN_BIN_REDUCTION );
-    }
-    else
-    {
-      length += ( prefix - cutoff );
-    }
-  }
-  return offset + decodeBinsEP( length );
-}
-#endif
 
 
 unsigned BinDecoderBase::decodeBinTrm()
diff --git a/source/Lib/DecoderLib/BinDecoder.h b/source/Lib/DecoderLib/BinDecoder.h
index 9bd283843..11a426097 100644
--- a/source/Lib/DecoderLib/BinDecoder.h
+++ b/source/Lib/DecoderLib/BinDecoder.h
@@ -71,11 +71,7 @@ public:
 public:
   unsigned          decodeBinEP         ();
   unsigned          decodeBinsEP        ( unsigned numBins  );
-#if JVET_P0090_32BIT_MVD
   unsigned          decodeRemAbsEP      ( unsigned goRicePar, unsigned cutoff, int maxLog2TrDynamicRange );
-#else
-  unsigned          decodeRemAbsEP      ( unsigned goRicePar, bool useLimitedPrefixLength, int maxLog2TrDynamicRange );
-#endif
   unsigned          decodeBinTrm        ();
   void              align               ();
   unsigned          getNumBitsRead      () { return m_Bitstream->getNumBitsRead() + m_bitsNeeded; }
diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp
index 7e7a059f4..387e38ced 100644
--- a/source/Lib/DecoderLib/CABACReader.cpp
+++ b/source/Lib/DecoderLib/CABACReader.cpp
@@ -1790,11 +1790,7 @@ void CABACReader::cu_palette_info(CodingUnit& cu, ComponentID compBegin, uint32_
   if (indexMaxSize > 1)
   {
     uint32_t currParam = 3 + ((indexMaxSize) >> 3);
-#if JVET_P0090_32BIT_MVD
     numIndices = m_BinDecoder.decodeRemAbsEP(currParam, COEF_REMAIN_BIN_REDUCTION, MAX_NUM_CHANNEL_TYPE); // JC: number of indices (INDEX RUN)
-#else
-    numIndices = m_BinDecoder.decodeRemAbsEP(currParam, false, MAX_NUM_CHANNEL_TYPE); // JC: number of indices (INDEX RUN)
-#endif
     numIndices++;
     numCopyIndexRuns = numIndices;
     while (numIndices--)
@@ -2956,11 +2952,7 @@ void CABACReader::mvd_coding( Mv &rMvd )
   {
     if (horAbs > 1)
     {
-#if JVET_P0090_32BIT_MVD
       horAbs += m_BinDecoder.decodeRemAbsEP(1, 0, MV_BITS - 1);
-#else
-      horAbs += exp_golomb_eqprob(1 );
-#endif
     }
     if (m_BinDecoder.decodeBinEP())
     {
@@ -2971,11 +2963,7 @@ void CABACReader::mvd_coding( Mv &rMvd )
   {
     if (verAbs > 1)
     {
-#if JVET_P0090_32BIT_MVD
       verAbs += m_BinDecoder.decodeRemAbsEP(1, 0, MV_BITS - 1);
-#else
-      verAbs += exp_golomb_eqprob(1 );
-#endif
     }
     if (m_BinDecoder.decodeBinEP())
     {
@@ -3644,11 +3632,7 @@ void CABACReader::residual_coding_subblock( CoeffCodingContext& cctx, TCoeff* co
     if( tcoeff >= 4 )
     {
       RExt__DECODER_DEBUG_BIT_STATISTICS_SET( ctype_escs );
-#if JVET_P0090_32BIT_MVD
       int       rem     = m_BinDecoder.decodeRemAbsEP( ricePar, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-      int       rem     = m_BinDecoder.decodeRemAbsEP( ricePar, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
       DTRACE( g_trace_ctx, D_SYNTAX_RESI, "rem_val() bin=%d ctx=%d\n", rem, ricePar );
       tcoeff += (rem<<1);
     }
@@ -3665,11 +3649,7 @@ void CABACReader::residual_coding_subblock( CoeffCodingContext& cctx, TCoeff* co
     int       pos0      = g_auiGoRicePosCoeff0[std::max(0, state - 1)][sumAll];
 #endif
     RExt__DECODER_DEBUG_BIT_STATISTICS_SET(ctype_escs);
-#if JVET_P0090_32BIT_MVD
     int       rem       = m_BinDecoder.decodeRemAbsEP( rice, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-    int       rem       = m_BinDecoder.decodeRemAbsEP( rice, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
     DTRACE( g_trace_ctx, D_SYNTAX_RESI, "rem_val() bin=%d ctx=%d\n", rem, rice );
     TCoeff    tcoeff  = ( rem == pos0 ? 0 : rem < pos0 ? rem+1 : rem );
     state = ( stateTransTable >> ((state<<2)+((tcoeff&1)<<1)) ) & 3;
@@ -3952,11 +3932,7 @@ void CABACReader::residual_coding_subblockTS( CoeffCodingContext& cctx, TCoeff*
     if( tcoeff >= cutoffVal )
     {
       int       rice = cctx.templateAbsSumTS( scanPos, coeff );
-#if JVET_P0090_32BIT_MVD
       int       rem  = m_BinDecoder.decodeRemAbsEP( rice, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-      int       rem  = m_BinDecoder.decodeRemAbsEP( rice, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
       DTRACE( g_trace_ctx, D_SYNTAX_RESI, "ts_rem_val() bin=%d ctx=%d sp=%d\n", rem, rice, scanPos );
 #if JVET_P0072_SIMPLIFIED_TSRC
       tcoeff += (scanPos <= lastScanPosPass1) ? (rem << 1) : rem;
diff --git a/source/Lib/EncoderLib/BinEncoder.cpp b/source/Lib/EncoderLib/BinEncoder.cpp
index ba12649a0..2d94f7765 100644
--- a/source/Lib/EncoderLib/BinEncoder.cpp
+++ b/source/Lib/EncoderLib/BinEncoder.cpp
@@ -205,7 +205,6 @@ void BinEncoderBase::encodeBinsEP( unsigned bins, unsigned numBins )
   }
 }
 
-#if JVET_P0090_32BIT_MVD
 void BinEncoderBase::encodeRemAbsEP(unsigned bins, unsigned goRicePar, unsigned cutoff, int maxLog2TrDynamicRange)
 {
   const unsigned threshold = cutoff << goRicePar;
@@ -243,60 +242,6 @@ void BinEncoderBase::encodeRemAbsEP(unsigned bins, unsigned goRicePar, unsigned
     encodeBinsEP(suffix, suffixLength); //separator, suffix, and rParam bits
   }
 }
-#else
-void BinEncoderBase::encodeRemAbsEP( unsigned bins, unsigned goRicePar, bool useLimitedPrefixLength, int maxLog2TrDynamicRange )
-{
-  const unsigned threshold = COEF_REMAIN_BIN_REDUCTION << goRicePar;
-  useLimitedPrefixLength = true;
-  if( bins < threshold )
-  {
-    const unsigned bitMask  = ( 1 << goRicePar ) - 1;
-    const unsigned length   = ( bins >> goRicePar ) + 1;
-    encodeBinsEP( ( 1 << length ) - 2,  length );
-    encodeBinsEP( bins & bitMask,       goRicePar);
-  }
-  else if (useLimitedPrefixLength)
-  {
-    const unsigned  maxPrefixLength = 32 - COEF_REMAIN_BIN_REDUCTION - maxLog2TrDynamicRange;
-    unsigned        prefixLength    = 0;
-    unsigned        codeValue       = ( bins >> goRicePar ) - COEF_REMAIN_BIN_REDUCTION;
-    unsigned        suffixLength;
-    if( codeValue >=  ( ( 1 << maxPrefixLength ) - 1 ) )
-    {
-      prefixLength = maxPrefixLength;
-      suffixLength = maxLog2TrDynamicRange;
-    }
-    else
-    {
-      while( codeValue > ( ( 2 << prefixLength ) - 2 ) )
-      {
-        prefixLength++;
-      }
-      suffixLength = prefixLength + goRicePar + 1; //+1 for the separator bit
-    }
-    const unsigned totalPrefixLength  = prefixLength + COEF_REMAIN_BIN_REDUCTION;
-    const unsigned bitMask            = ( 1 << goRicePar ) - 1;
-    const unsigned prefix             = ( 1 << totalPrefixLength ) - 1;
-    const unsigned suffix             = ( ( codeValue - ( (1 << prefixLength ) - 1 ) ) << goRicePar ) | ( bins & bitMask );
-    encodeBinsEP( prefix, totalPrefixLength ); //prefix
-    encodeBinsEP( suffix, suffixLength      ); //separator, suffix, and rParam bits
-  }
-  else
-  {
-    unsigned length = goRicePar;
-    unsigned delta  = 1 << length;
-    bins           -= threshold;
-    while (bins >= delta )
-    {
-      bins -= delta;
-      delta = 1 << (++length);
-    }
-    unsigned numBin = COEF_REMAIN_BIN_REDUCTION + length + 1 - goRicePar;
-    encodeBinsEP( ( 1 << numBin ) - 2, numBin );
-    encodeBinsEP( bins,                length );
-  }
-}
-#endif
 
 void BinEncoderBase::encodeBinTrm( unsigned bin )
 {
@@ -467,7 +412,6 @@ BitEstimatorBase::BitEstimatorBase( const BinProbModel* dummy )
   m_EstFracBits = 0;
 }
 
-#if JVET_P0090_32BIT_MVD
 void BitEstimatorBase::encodeRemAbsEP(unsigned bins, unsigned goRicePar, unsigned cutoff, int maxLog2TrDynamicRange)
 {
   const unsigned threshold = cutoff << goRicePar;
@@ -497,50 +441,6 @@ void BitEstimatorBase::encodeRemAbsEP(unsigned bins, unsigned goRicePar, unsigne
     m_EstFracBits += BinProbModelBase::estFracBitsEP(cutoff + prefixLength + suffixLength);
   }
 }
-#else
-void BitEstimatorBase::encodeRemAbsEP( unsigned bins, unsigned goRicePar, bool useLimitedPrefixLength, int maxLog2TrDynamicRange )
-{
-  const unsigned threshold = COEF_REMAIN_BIN_REDUCTION << goRicePar;
-  useLimitedPrefixLength = true;
-  if( bins < threshold )
-  {
-    m_EstFracBits += BinProbModelBase::estFracBitsEP( ( bins >> goRicePar ) + 1 + goRicePar );
-  }
-  else if (useLimitedPrefixLength)
-  {
-    const unsigned  maxPrefixLength = 32 - COEF_REMAIN_BIN_REDUCTION - maxLog2TrDynamicRange;
-    unsigned        prefixLength    = 0;
-    unsigned        codeValue       = ( bins >> goRicePar ) - COEF_REMAIN_BIN_REDUCTION;
-    unsigned        suffixLength;
-    if( codeValue >=  ( ( 1 << maxPrefixLength ) - 1 ) )
-    {
-      prefixLength = maxPrefixLength;
-      suffixLength = maxLog2TrDynamicRange;
-    }
-    else
-    {
-      while( codeValue > ( ( 2 << prefixLength ) - 2 ) )
-      {
-        prefixLength++;
-      }
-      suffixLength = prefixLength + goRicePar + 1; //+1 for the separator bit
-    }
-    m_EstFracBits += BinProbModelBase::estFracBitsEP( COEF_REMAIN_BIN_REDUCTION + prefixLength + suffixLength );
-  }
-  else
-  {
-    unsigned length = goRicePar;
-    unsigned delta  = 1 << length;
-    bins           -= threshold;
-    while (bins >= delta )
-    {
-      bins -= delta;
-      delta = 1 << (++length);
-    }
-    m_EstFracBits += BinProbModelBase::estFracBitsEP(COEF_REMAIN_BIN_REDUCTION + 1 + (length << 1) - goRicePar);
-  }
-}
-#endif
 
 void BitEstimatorBase::align()
 {
diff --git a/source/Lib/EncoderLib/BinEncoder.h b/source/Lib/EncoderLib/BinEncoder.h
index ef2246346..67500723e 100644
--- a/source/Lib/EncoderLib/BinEncoder.h
+++ b/source/Lib/EncoderLib/BinEncoder.h
@@ -118,11 +118,7 @@ public:
   virtual void      encodeBinsEP      ( unsigned bins,  unsigned numBins  ) = 0;
   virtual void      encodeRemAbsEP    ( unsigned bins,
                                         unsigned goRicePar,
-#if JVET_P0090_32BIT_MVD
                                         unsigned cutoff,
-#else
-                                        bool     useLimitedPrefixLength,
-#endif
                                         int      maxLog2TrDynamicRange    ) = 0;
   virtual void      encodeBinTrm      ( unsigned bin                      ) = 0;
   virtual void      align             ()                                    = 0;
@@ -183,17 +179,10 @@ public:
 public:
   void      encodeBinEP         ( unsigned bin                      );
   void      encodeBinsEP        ( unsigned bins,  unsigned numBins  );
-#if JVET_P0090_32BIT_MVD
   void      encodeRemAbsEP      ( unsigned bins,
                                   unsigned goRicePar,
                                   unsigned cutoff,
                                   int      maxLog2TrDynamicRange    );
-#else
-  void      encodeRemAbsEP      ( unsigned bins,
-                                  unsigned goRicePar,
-                                  bool     useLimitedPrefixLength,
-                                  int      maxLog2TrDynamicRange    );
-#endif
   void      encodeBinTrm        ( unsigned bin                      );
   void      align               ();
   unsigned  getNumWrittenBits   () { return ( m_Bitstream->getNumberOfWrittenBits() + 8 * m_numBufferedBytes + 23 - m_bitsLeft ); }
@@ -256,17 +245,10 @@ public:
 public:
   void      encodeBinEP         ( unsigned bin                      ) { m_EstFracBits += BinProbModelBase::estFracBitsEP (); }
   void      encodeBinsEP        ( unsigned bins,  unsigned numBins  ) { m_EstFracBits += BinProbModelBase::estFracBitsEP ( numBins ); }
-#if JVET_P0090_32BIT_MVD
   void      encodeRemAbsEP      ( unsigned bins,
                                   unsigned goRicePar,
                                   unsigned cutoff,
                                   int      maxLog2TrDynamicRange    );
-#else
-  void      encodeRemAbsEP      ( unsigned bins,
-                                  unsigned goRicePar,
-                                  bool     useLimitedPrefixLength,
-                                  int      maxLog2TrDynamicRange    );
-#endif
   void      align               ();
 public:
   uint32_t  getNumBins          ()                                      { THROW("Not supported"); return 0; }
diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp
index b08f5193a..272020cc4 100644
--- a/source/Lib/EncoderLib/CABACWriter.cpp
+++ b/source/Lib/EncoderLib/CABACWriter.cpp
@@ -1536,11 +1536,7 @@ void CABACWriter::cu_palette_info(const CodingUnit& cu, ComponentID compBegin, u
     assert(numIndices);
     assert(numIndices > 0);
     mappedValue = numIndices - 1;
-#if JVET_P0090_32BIT_MVD
     m_BinEncoder.encodeRemAbsEP(mappedValue, currParam, COEF_REMAIN_BIN_REDUCTION, MAX_NUM_CHANNEL_TYPE); // JC: code number of indices (PLT_RUN_INDEX)
-#else
-    m_BinEncoder.encodeRemAbsEP(mappedValue, currParam, false, MAX_NUM_CHANNEL_TYPE); // JC: code number of indices (PLT_RUN_INDEX)
-#endif
     auto idxPosEnd = idxPos.end();
     for (auto iter = idxPos.begin(); iter != idxPosEnd; ++iter)
     {
@@ -2646,11 +2642,7 @@ void CABACWriter::mvd_coding( const Mv &rMvd, int8_t imv )
   {
     if( horAbs > 1 )
     {
-#if JVET_P0090_32BIT_MVD
       m_BinEncoder.encodeRemAbsEP(horAbs - 2, 1, 0, MV_BITS - 1);
-#else
-      exp_golomb_eqprob( horAbs - 2, 1 );
-#endif
     }
     m_BinEncoder.encodeBinEP( (horMvd < 0) );
   }
@@ -2658,11 +2650,7 @@ void CABACWriter::mvd_coding( const Mv &rMvd, int8_t imv )
   {
     if( verAbs > 1 )
     {
-#if JVET_P0090_32BIT_MVD
       m_BinEncoder.encodeRemAbsEP(verAbs - 2, 1, 0, MV_BITS - 1);
-#else
-      exp_golomb_eqprob( verAbs - 2, 1 );
-#endif
     }
     m_BinEncoder.encodeBinEP( (verMvd < 0) );
   }
@@ -3318,11 +3306,7 @@ void CABACWriter::residual_coding_subblock( CoeffCodingContext& cctx, const TCoe
     if( absLevel >= 4 )
     {
       unsigned rem      = ( absLevel - 4 ) >> 1;
-#if JVET_P0090_32BIT_MVD
       m_BinEncoder.encodeRemAbsEP( rem, ricePar, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-      m_BinEncoder.encodeRemAbsEP( rem, ricePar, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
       DTRACE( g_trace_ctx, D_SYNTAX_RESI, "rem_val() bin=%d ctx=%d\n", rem, ricePar );
     }
   }
@@ -3340,11 +3324,7 @@ void CABACWriter::residual_coding_subblock( CoeffCodingContext& cctx, const TCoe
     int       pos0      = g_auiGoRicePosCoeff0[std::max(0, state - 1)][sumAll];
 #endif
     unsigned  rem       = ( absLevel == 0 ? pos0 : absLevel <= pos0 ? absLevel-1 : absLevel );
-#if JVET_P0090_32BIT_MVD
     m_BinEncoder.encodeRemAbsEP( rem, rice, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-    m_BinEncoder.encodeRemAbsEP( rem, rice, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
     DTRACE( g_trace_ctx, D_SYNTAX_RESI, "rem_val() bin=%d ctx=%d\n", rem, rice );
     state = ( stateTransTable >> ((state<<2)+((absLevel&1)<<1)) ) & 3;
     if( absLevel )
@@ -3598,11 +3578,7 @@ void CABACWriter::residual_coding_subblockTS( CoeffCodingContext& cctx, const TC
 #else
       unsigned  rem  = ( absLevel - cutoffVal ) >> 1;
 #endif
-#if JVET_P0090_32BIT_MVD
       m_BinEncoder.encodeRemAbsEP( rem, rice, COEF_REMAIN_BIN_REDUCTION, cctx.maxLog2TrDRange() );
-#else
-      m_BinEncoder.encodeRemAbsEP( rem, rice, cctx.extPrec(), cctx.maxLog2TrDRange() );
-#endif
       DTRACE( g_trace_ctx, D_SYNTAX_RESI, "ts_rem_val() bin=%d ctx=%d sp=%d\n", rem, rice, scanPos );
 
 #if JVET_P0072_SIMPLIFIED_TSRC
-- 
GitLab