diff --git a/source/Lib/CommonLib/ChromaFormat.h b/source/Lib/CommonLib/ChromaFormat.h
index 0400084e1fe7f02773ac735ed6be8b28f905e0e4..d6930043d5874c106e77635830897ce52d41bb5c 100644
--- a/source/Lib/CommonLib/ChromaFormat.h
+++ b/source/Lib/CommonLib/ChromaFormat.h
@@ -110,7 +110,7 @@ static inline uint64_t getTotalFracBits(const uint32_t width, const uint32_t hei
 
 static inline int getTransformShift(const int channelBitDepth, const Size size, const int maxLog2TrDynamicRange)
 {
-  return maxLog2TrDynamicRange - channelBitDepth - ( ( g_aucLog2[size.width] + g_aucLog2[size.height] ) >> 1 );
+  return maxLog2TrDynamicRange - channelBitDepth - ( ( floorLog2(size.width) + floorLog2(size.height) ) >> 1 );
 }
 
 
diff --git a/source/Lib/CommonLib/CodingStructure.cpp b/source/Lib/CommonLib/CodingStructure.cpp
index 9f350676e7b7fdefed07b78d7272920fe5a671fa..01e16a9d916b995172af64ca2c384db7b6c25168 100644
--- a/source/Lib/CommonLib/CodingStructure.cpp
+++ b/source/Lib/CommonLib/CodingStructure.cpp
@@ -1613,7 +1613,7 @@ const CodingUnit* CodingStructure::getCURestricted( const Position &pos, const C
   // exists       same slice and tile                  cu precedes curCu in encoding order
   //                                                  (thus, is either from parent CS in RD-search or its index is lower)
   const bool wavefrontsEnabled = curCu.slice->getPPS()->getEntropyCodingSyncEnabledFlag();
-  int ctuSizeBit = g_aucLog2[curCu.cs->sps->getMaxCUWidth()];
+  int ctuSizeBit = floorLog2(curCu.cs->sps->getMaxCUWidth());
   int xNbY  = pos.x << getChannelTypeScaleX( _chType, curCu.chromaFormat );
   int xCurr = curCu.blocks[_chType].x << getChannelTypeScaleX( _chType, curCu.chromaFormat );
   bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
@@ -1631,7 +1631,7 @@ const CodingUnit* CodingStructure::getCURestricted( const Position &pos, const P
 {
   const CodingUnit* cu = getCU( pos, _chType );
   const bool wavefrontsEnabled = this->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
-  int ctuSizeBit = g_aucLog2[this->sps->getMaxCUWidth()];
+  int ctuSizeBit = floorLog2(this->sps->getMaxCUWidth());
   int xNbY  = pos.x << getChannelTypeScaleX( _chType, this->area.chromaFormat );
   int xCurr = curPos.x << getChannelTypeScaleX( _chType, this->area.chromaFormat );
   bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
@@ -1644,7 +1644,7 @@ const PredictionUnit* CodingStructure::getPURestricted( const Position &pos, con
   // exists       same slice and tile                  pu precedes curPu in encoding order
   //                                                  (thus, is either from parent CS in RD-search or its index is lower)
   const bool wavefrontsEnabled = curPu.cu->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
-  int ctuSizeBit = g_aucLog2[curPu.cs->sps->getMaxCUWidth()];
+  int ctuSizeBit = floorLog2(curPu.cs->sps->getMaxCUWidth());
   int xNbY  = pos.x << getChannelTypeScaleX( _chType, curPu.chromaFormat );
   int xCurr = curPu.blocks[_chType].x << getChannelTypeScaleX( _chType, curPu.chromaFormat );
   bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
@@ -1664,7 +1664,7 @@ const TransformUnit* CodingStructure::getTURestricted( const Position &pos, cons
   // exists       same slice and tile                  tu precedes curTu in encoding order
   //                                                  (thus, is either from parent CS in RD-search or its index is lower)
   const bool wavefrontsEnabled = curTu.cu->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
-  int ctuSizeBit = g_aucLog2[curTu.cs->sps->getMaxCUWidth()];
+  int ctuSizeBit = floorLog2(curTu.cs->sps->getMaxCUWidth());
   int xNbY  = pos.x << getChannelTypeScaleX( _chType, curTu.chromaFormat );
   int xCurr = curTu.blocks[_chType].x << getChannelTypeScaleX( _chType, curTu.chromaFormat );
   bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h
index 600cf39626d83133d42e7526cb01c0bbabc8d7cc..c42ec4f9b2c843444b231f544c499dd2131ec1e7 100644
--- a/source/Lib/CommonLib/CommonDef.h
+++ b/source/Lib/CommonLib/CommonDef.h
@@ -58,6 +58,8 @@
 #if _MSC_VER < 1900
 #error "MS Visual Studio version not supported. Please upgrade to Visual Studio 2015 or higher (or use other compilers)"
 #endif
+
+#include <intrin.h>
 #endif
 
 //! \ingroup CommonLib
@@ -683,10 +685,16 @@ static inline int floorLog2(uint32_t x)
 {
   if (x == 0)
   {
+    // note: ceilLog2() expects -1 as return value
     return -1;
   }
 #ifdef __GNUC__
   return 31 - __builtin_clz(x);
+#else
+#ifdef _MSC_VER
+  unsigned long r = 0;
+  _BitScanReverse(&r, x);
+  return r;
 #else
   int result = 0;
   if (x & 0xffff0000)
@@ -716,8 +724,15 @@ static inline int floorLog2(uint32_t x)
   }
   return result;
 #endif
+#endif
 }
 
+static inline int ceilLog2(uint32_t x)
+{
+  return (x==0) ? -1 : floorLog2(x - 1) + 1;
+}
+
+
 //CASE-BREAK for breakpoints
 #if defined ( _MSC_VER ) && defined ( _DEBUG )
 #define _CASE(_x) if(_x)
diff --git a/source/Lib/CommonLib/ContextModelling.cpp b/source/Lib/CommonLib/ContextModelling.cpp
index f15da527510930023b04df36487b312fc3ec40ba..901806cb4aeedf84202472eb2c0d42dc2c1b0c47 100644
--- a/source/Lib/CommonLib/ContextModelling.cpp
+++ b/source/Lib/CommonLib/ContextModelling.cpp
@@ -46,13 +46,13 @@ CoeffCodingContext::CoeffCodingContext( const TransformUnit& tu, ComponentID com
   , m_chType                    (toChannelType(m_compID))
   , m_width                     (tu.block(m_compID).width)
   , m_height                    (tu.block(m_compID).height)
-  , m_log2CGWidth               ( g_log2SbbSize[ g_aucLog2[m_width] ][ g_aucLog2[m_height] ][0] )
-  , m_log2CGHeight              ( g_log2SbbSize[ g_aucLog2[m_width] ][ g_aucLog2[m_height] ][1] )
+  , m_log2CGWidth               ( g_log2SbbSize[ floorLog2(m_width) ][ floorLog2(m_height) ][0] )
+  , m_log2CGHeight              ( g_log2SbbSize[ floorLog2(m_width) ][ floorLog2(m_height) ][1] )
   , m_log2CGSize                (m_log2CGWidth + m_log2CGHeight)
   , m_widthInGroups(std::min<unsigned>(JVET_C0024_ZERO_OUT_TH, m_width) >> m_log2CGWidth)
   , m_heightInGroups(std::min<unsigned>(JVET_C0024_ZERO_OUT_TH, m_height) >> m_log2CGHeight)
-  , m_log2BlockWidth            (g_aucLog2[m_width])
-  , m_log2BlockHeight           (g_aucLog2[m_height])
+  , m_log2BlockWidth            ((unsigned)floorLog2(m_width))
+  , m_log2BlockHeight           ((unsigned)floorLog2(m_height))
   , m_maxNumCoeff               (m_width * m_height)
   , m_signHiding                (signHide)
   , m_extendedPrecision         (tu.cs->sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag())
@@ -279,7 +279,7 @@ unsigned DeriveCtx::CtxQtCbf( const ComponentID compID, const unsigned trDepth,
 
 unsigned DeriveCtx::CtxInterDir( const PredictionUnit& pu )
 {
-  return ( 7 - ((g_aucLog2[pu.lumaSize().width] + g_aucLog2[pu.lumaSize().height] + 1) >> 1) );
+  return ( 7 - ((floorLog2(pu.lumaSize().width) + floorLog2(pu.lumaSize().height) + 1) >> 1) );
 }
 
 unsigned DeriveCtx::CtxAffineFlag( const CodingUnit& cu )
diff --git a/source/Lib/CommonLib/DepQuant.cpp b/source/Lib/CommonLib/DepQuant.cpp
index e68667607998254737fdca20a8e34e0f724cee4a..1aacb46fe1eba60a98192a18915589ce8f5bd89f 100644
--- a/source/Lib/CommonLib/DepQuant.cpp
+++ b/source/Lib/CommonLib/DepQuant.cpp
@@ -138,7 +138,7 @@ namespace DQIntern
     const NbInfoOut*    getNbInfoOut( int hd, int vd ) const { return m_scanId2NbInfoOutArray[hd][vd]; }
     const TUParameters* getTUPars   ( const CompArea& area, const ComponentID compID ) const
     {
-      return m_tuParameters[g_aucLog2[area.width]][g_aucLog2[area.height]][toChannelType(compID)];
+      return m_tuParameters[floorLog2(area.width)][floorLog2(area.height)][toChannelType(compID)];
     }
   private:
     void  xInitScanArrays   ();
@@ -347,8 +347,10 @@ namespace DQIntern
     const uint32_t nonzeroWidth  = std::min<uint32_t>(JVET_C0024_ZERO_OUT_TH, m_width);
     const uint32_t nonzeroHeight = std::min<uint32_t>(JVET_C0024_ZERO_OUT_TH, m_height);
     m_numCoeff                   = nonzeroWidth * nonzeroHeight;
-    m_log2SbbWidth        = g_log2SbbSize[ g_aucLog2[m_width] ][ g_aucLog2[m_height] ][0];
-    m_log2SbbHeight       = g_log2SbbSize[ g_aucLog2[m_width] ][ g_aucLog2[m_height] ][1];
+    const int log2W       = floorLog2( m_width  );
+    const int log2H       = floorLog2( m_height );
+    m_log2SbbWidth        = g_log2SbbSize[ log2W ][ log2H ][0];
+    m_log2SbbHeight       = g_log2SbbSize[ log2W ][ log2H ][1];
     m_log2SbbSize         = m_log2SbbWidth + m_log2SbbHeight;
     m_sbbSize             = ( 1 << m_log2SbbSize );
     m_sbbMask             = m_sbbSize - 1;
@@ -362,8 +364,6 @@ namespace DQIntern
     SizeType        vsId  = gp_sizeIdxInfo->idxFrom( m_height );
     m_scanSbbId2SbbPos    = g_scanOrder     [ SCAN_UNGROUPED   ][ m_scanType ][ hsbb ][ vsbb ];
     m_scanId2BlkPos       = g_scanOrder     [ SCAN_GROUPED_4x4 ][ m_scanType ][ hsId ][ vsId ];
-    int log2W             = g_aucLog2[ m_width  ];
-    int log2H             = g_aucLog2[ m_height ];
     m_scanId2NbInfoSbb    = rom.getNbInfoSbb( log2W, log2H );
     m_scanId2NbInfoOut    = rom.getNbInfoOut( log2W, log2H );
     m_scanInfo            = new ScanInfo[ m_numCoeff ];
@@ -504,7 +504,7 @@ namespace DQIntern
       {
         bool rootCbfSoFar = false;
         bool isLastSubPartition = CU::isISPLast(*tu.cu, tu.Y(), compID);
-        uint32_t nTus = tu.cu->ispMode == HOR_INTRA_SUBPARTITIONS ? tu.cu->lheight() >> g_aucLog2[tu.lheight()] : tu.cu->lwidth() >> g_aucLog2[tu.lwidth()];
+        uint32_t nTus = tu.cu->ispMode == HOR_INTRA_SUBPARTITIONS ? tu.cu->lheight() >> floorLog2(tu.lheight()) : tu.cu->lwidth() >> floorLog2(tu.lwidth());
         if( isLastSubPartition )
         {
           TransformUnit* tuPointer = tu.cu->firstTU;
@@ -546,7 +546,7 @@ namespace DQIntern
       int32_t             bitOffset   = ( xy ? cbfDeltaBits : 0 );
       int32_t*            lastBits    = ( xy ? m_lastBitsY : m_lastBitsX );
       const unsigned      size        = ( xy ? tuPars.m_height : tuPars.m_width );
-      const unsigned      log2Size    = g_aucNextLog2[ size ];
+      const unsigned      log2Size    = ceilLog2( size );
       const bool          useYCtx     = ( xy != 0 );
       const CtxSet&       ctxSetLast  = ( useYCtx ? Ctx::LastY : Ctx::LastX )[ chType ];
       const unsigned      lastShift   = ( compID == COMPONENT_Y ? (log2Size+1)>>2 : Clip3<unsigned>(0,2,size>>3) );
@@ -1769,8 +1769,8 @@ void DepQuant::quant( TransformUnit &tu, const ComponentID &compID, const CCoeff
     const int         height          = rect.height;
     uint32_t          scalingListType = getScalingListType(tu.cu->predMode, compID);
     CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list");
-    const uint32_t    log2TrWidth     = g_aucLog2[width];
-    const uint32_t    log2TrHeight    = g_aucLog2[height];
+    const uint32_t    log2TrWidth     = floorLog2(width);
+    const uint32_t    log2TrHeight    = floorLog2(height);
     const bool        enableScalingLists = getUseScalingList(width, height, (tu.mtsIdx == MTS_SKIP && isLuma(compID)));
     static_cast<DQIntern::DepQuant*>(p)->quant( tu, pSrc, compID, cQP, Quant::m_dLambda, ctx, uiAbsSum, enableScalingLists, Quant::getQuantCoeff(scalingListType, qpRem, log2TrWidth, log2TrHeight) );
   }
@@ -1796,8 +1796,8 @@ void DepQuant::dequant( const TransformUnit &tu, CoeffBuf &dstCoeff, const Compo
     const int         height          = rect.height;
     uint32_t          scalingListType = getScalingListType(tu.cu->predMode, compID);
     CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list");
-    const uint32_t    log2TrWidth  = g_aucLog2[width];
-    const uint32_t    log2TrHeight = g_aucLog2[height];
+    const uint32_t    log2TrWidth  = floorLog2(width);
+    const uint32_t    log2TrHeight = floorLog2(height);
 
     const bool enableScalingLists = getUseScalingList(width, height, (tu.mtsIdx == MTS_SKIP && isLuma(compID)));
     static_cast<DQIntern::DepQuant*>(p)->dequant( tu, dstCoeff, compID, cQP, enableScalingLists, Quant::getDequantCoeff(scalingListType, qpRem, log2TrWidth, log2TrHeight) );
diff --git a/source/Lib/CommonLib/Hash.cpp b/source/Lib/CommonLib/Hash.cpp
index eabddfdc3f27fbb6bb36a6e3d45b0791e3bc8a80..17c78ff83e172815c6a19573b08b5c07b2ea69f1 100644
--- a/source/Lib/CommonLib/Hash.cpp
+++ b/source/Lib/CommonLib/Hash.cpp
@@ -343,7 +343,7 @@ void TComHash::addToHashMapByRowWithPrecalData(uint32_t* picHash[2], bool* picIs
   addValue <<= m_CRCBits;
   int crcMask = 1 << m_CRCBits;
   crcMask -= 1;
-  int blockIdx = g_aucLog2[width] - 2;
+  int blockIdx = floorLog2(width) - 2;
 
   for (int xPos = 0; xPos < xEnd; xPos++)
   {
diff --git a/source/Lib/CommonLib/Hash.h b/source/Lib/CommonLib/Hash.h
index 502c2575309e1233f66270ce9694da98290030d5..d2af0c31c3ce12bcdeca04425edcb040e5383575 100644
--- a/source/Lib/CommonLib/Hash.h
+++ b/source/Lib/CommonLib/Hash.h
@@ -105,7 +105,7 @@ public:
   void addToHashMapByRowWithPrecalData(uint32_t* srcHash[2], bool* srcIsSame, int picWidth, int picHeight, int width, int height);
   bool isInitial() { return tableHasContent; }
   void setInitial() { tableHasContent = true; }
-  uint16_t* getHashPic(int baseSize) const { return hashPic[g_aucLog2[baseSize] - 2]; }
+  uint16_t* getHashPic(int baseSize) const { return hashPic[floorLog2(baseSize) - 2]; }
 
 
 public:
diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp
index 3c41f4d1d6a038491a30a1d74b3a239547c3bdc6..538373017c97932f074e0bf809e6d1fae202302c 100644
--- a/source/Lib/CommonLib/InterPrediction.cpp
+++ b/source/Lib/CommonLib/InterPrediction.cpp
@@ -945,12 +945,12 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
 
   const int iBit = MAX_CU_DEPTH;
   int iDMvHorX, iDMvHorY, iDMvVerX, iDMvVerY;
-  iDMvHorX = (mvRT - mvLT).getHor() << (iBit - g_aucLog2[cxWidth]);
-  iDMvHorY = (mvRT - mvLT).getVer() << (iBit - g_aucLog2[cxWidth]);
+  iDMvHorX = (mvRT - mvLT).getHor() << (iBit - floorLog2(cxWidth));
+  iDMvHorY = (mvRT - mvLT).getVer() << (iBit - floorLog2(cxWidth));
   if ( pu.cu->affineType == AFFINEMODEL_6PARAM )
   {
-    iDMvVerX = (mvLB - mvLT).getHor() << (iBit - g_aucLog2[cxHeight]);
-    iDMvVerY = (mvLB - mvLT).getVer() << (iBit - g_aucLog2[cxHeight]);
+    iDMvVerX = (mvLB - mvLT).getHor() << (iBit - floorLog2(cxHeight));
+    iDMvVerY = (mvLB - mvLT).getVer() << (iBit - floorLog2(cxHeight));
   }
   else
   {
@@ -1650,12 +1650,12 @@ void InterPrediction::xApplyBiPROF(const PredictionUnit &pu, const CPelBuf& pcYu
       Mv mvLB = pu.mvAffi[list][2];
 
       int dMvHorX, dMvHorY, dMvVerX, dMvVerY;
-      dMvHorX = (mvRT - mvLT).getHor() << (bit - g_aucLog2[width]);
-      dMvHorY = (mvRT - mvLT).getVer() << (bit - g_aucLog2[width]);
+      dMvHorX = (mvRT - mvLT).getHor() << (bit - floorLog2(width));
+      dMvHorY = (mvRT - mvLT).getVer() << (bit - floorLog2(width));
       if (pu.cu->affineType == AFFINEMODEL_6PARAM)
       {
-        dMvVerX = (mvLB - mvLT).getHor() << (bit - g_aucLog2[height]);
-        dMvVerY = (mvLB - mvLT).getVer() << (bit - g_aucLog2[height]);
+        dMvVerX = (mvLB - mvLT).getHor() << (bit - floorLog2(height));
+        dMvVerY = (mvLB - mvLT).getVer() << (bit - floorLog2(height));
       }
       else
       {
@@ -2893,7 +2893,7 @@ void InterPrediction::xFillIBCBuffer(CodingUnit &cu)
 
       const unsigned int lcuWidth = cu.cs->slice->getSPS()->getMaxCUWidth();
       const int shiftSample = ::getComponentScaleX(area.compID, cu.chromaFormat);
-      const int ctuSizeLog2 = g_aucLog2[lcuWidth] - shiftSample;
+      const int ctuSizeLog2 = floorLog2(lcuWidth) - shiftSample;
       const int pux = area.x & ((m_IBCBufferWidth >> shiftSample) - 1);
       const int puy = area.y & (( 1 << ctuSizeLog2 ) - 1);
       const CompArea dstArea = CompArea(area.compID, cu.chromaFormat, Position(pux, puy), Size(area.width, area.height));
@@ -2909,7 +2909,7 @@ void InterPrediction::xIntraBlockCopy(PredictionUnit &pu, PelUnitBuf &predBuf, c
 {
   const unsigned int lcuWidth = pu.cs->slice->getSPS()->getMaxCUWidth();
   int shiftSample = ::getComponentScaleX(compID, pu.chromaFormat);
-  const int ctuSizeLog2 = g_aucLog2[lcuWidth] - shiftSample;
+  const int ctuSizeLog2 = floorLog2(lcuWidth) - shiftSample;
   pu.bv = pu.mv[REF_PIC_LIST_0];
   pu.bv.changePrecision(MV_PRECISION_INTERNAL, MV_PRECISION_INT);
   int refx, refy;
@@ -3153,4 +3153,4 @@ bool InterPrediction::xPredInterBlkRPR( const ComponentID& compID, const Predict
 
   return scaled;
 }
-#endif
\ No newline at end of file
+#endif
diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index 8cbee9eecdb3468403b960c3611de33eda1cf340..078b281208a9c67d1b432a4c4a22ef7efaa6f594 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -254,7 +254,7 @@ Pel IntraPrediction::xGetPredValDc( const CPelBuf &pSrc, const Size &dstSize )
   const int width  = dstSize.width;
   const int height = dstSize.height;
   const auto denom     = (width == height) ? (width << 1) : std::max(width,height);
-  const auto divShift  = g_aucLog2[denom];
+  const auto divShift  = floorLog2(denom);
   const auto divOffset = (denom >> 1);
 
   if ( width >= height )
@@ -289,7 +289,7 @@ int IntraPrediction::getWideAngle( int width, int height, int predMode )
   if ( predMode > DC_IDX && predMode <= VDIA_IDX )
   {
     int modeShift[] = { 0, 6, 10, 12, 14, 15 };
-    int deltaSize = abs(g_aucLog2[width] - g_aucLog2[height]);
+    int deltaSize = abs(floorLog2(width) - floorLog2(height));
     if (width > height && predMode < 2 + modeShift[deltaSize])
     {
       predMode += (VDIA_IDX - 1);
@@ -321,8 +321,8 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
   const int            iHeight      = piPred.height;
   const uint32_t       uiDirMode    = isLuma( compId ) && pu.cu->bdpcmMode ? BDPCM_IDX : PU::getFinalIntraMode( pu, channelType );
 
-  CHECK( g_aucLog2[iWidth] < 2 && pu.cs->pcv->noChroma2x2, "Size not allowed" );
-  CHECK( g_aucLog2[iWidth] > 7, "Size not allowed" );
+  CHECK( floorLog2(iWidth) < 2 && pu.cs->pcv->noChroma2x2, "Size not allowed" );
+  CHECK( floorLog2(iWidth) > 7, "Size not allowed" );
 
   const int multiRefIdx = m_ipaParam.multiRefIndex;
 #if JVET_O0364_PADDING
@@ -354,7 +354,7 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
   if (m_ipaParam.applyPDPC)
   {
     PelBuf dstBuf = piPred;
-    const int scale = ((g_aucLog2[iWidth] - 2 + g_aucLog2[iHeight] - 2 + 2) >> 2);
+    const int scale = ((floorLog2(iWidth) - 2 + floorLog2(iHeight) - 2 + 2) >> 2);
     CHECK(scale < 0 || scale > 31, "PDPC: scale < 0 || scale > 31");
 
 #if JVET_O0364_PDPC_DC
@@ -427,8 +427,8 @@ void IntraPrediction::xPredIntraPlanar( const CPelBuf &pSrc, PelBuf &pDst )
 {
   const uint32_t width  = pDst.width;
   const uint32_t height = pDst.height;
-  const uint32_t log2W  = g_aucLog2[width  < 2 ? 2 : width];
-  const uint32_t log2H  = g_aucLog2[height < 2 ? 2 : height];
+  const uint32_t log2W  = floorLog2(width  < 2 ? 2 : width);
+  const uint32_t log2H  = floorLog2(height < 2 ? 2 : height);
 
   int leftColumn[MAX_CU_SIZE + 1], topRow[MAX_CU_SIZE + 1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
   const uint32_t offset = 1 << (log2W + log2H);
@@ -544,9 +544,9 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
       const int maxScale = 2;
 
 #if JVET_O0364_PADDING
-      m_ipaParam.angularScale = std::min(maxScale, g_aucLog2[sideSize] - (floorLog2(3 * m_ipaParam.invAngle - 2) - 8));
+      m_ipaParam.angularScale = std::min(maxScale, floorLog2(sideSize) - (floorLog2(3 * m_ipaParam.invAngle - 2) - 8));
 #else
-      m_ipaParam.angularScale = std::min(maxScale, g_aucLog2[sideSize] - (floorLog2(3 * m_ipaParam.invAngle - 2) - 7));
+      m_ipaParam.angularScale = std::min(maxScale, floorLog2(sideSize) - (floorLog2(3 * m_ipaParam.invAngle - 2) - 7));
 #endif
       m_ipaParam.applyPDPC &= m_ipaParam.angularScale >= 0;
     }
@@ -597,7 +597,7 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
 #else
       const int diff = std::min<int>( abs( dirMode - HOR_IDX ), abs( dirMode - VER_IDX ) );
 #endif
-      const int log2Size = ((g_aucLog2[puSize.width] + g_aucLog2[puSize.height]) >> 1);
+      const int log2Size = ((floorLog2(puSize.width) + floorLog2(puSize.height)) >> 1);
       CHECK( log2Size >= MAX_INTRA_FILTER_DEPTHS, "Size not supported" );
       filterFlag = (diff > m_aucIntraFilter[log2Size]);
     }
@@ -715,7 +715,7 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
     refSide = bIsModeVer ? refLeft : refAbove;
 
     // Extend main reference to right using replication
-    const int log2Ratio = g_aucLog2[width] - g_aucLog2[height];
+    const int log2Ratio = floorLog2(width) - floorLog2(height);
     const int s         = std::max<int>(0, bIsModeVer ? log2Ratio : -log2Ratio);
     const int maxIndex  = (multiRefIdx << s) + 2;
     const int refLength = bIsModeVer ? m_topRefLength : m_leftRefLength;
@@ -770,7 +770,7 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
 
       if (m_ipaParam.applyPDPC)
       {
-        const int scale   = (g_aucLog2[width] + g_aucLog2[height] - 2) >> 2;
+        const int scale   = (floorLog2(width) + floorLog2(height) - 2) >> 2;
         const Pel topLeft = refMain[0];
         const Pel left    = refSide[1 + y];
         for (int x = 0; x < std::min(3 << scale, width); x++)
@@ -864,7 +864,7 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
         }
       }
 #else
-      const int scale = ((g_aucLog2[width] - 2 + g_aucLog2[height] - 2 + 2) >> 2);
+      const int scale = ((floorLog2(width) - 2 + floorLog2(height) - 2 + 2) >> 2);
       CHECK(scale < 0 || scale > 31, "PDPC: scale < 0 || scale > 31");
       if (m_ipaParam.applyPDPC)
       {
@@ -2182,7 +2182,7 @@ void IntraPrediction::predIntraMip( const ComponentID compId, PelBuf &piPred, co
 #else
   CHECK( pu.lwidth() > MIP_MAX_WIDTH || pu.lheight() > MIP_MAX_HEIGHT, "Error: block size not supported for MIP" );
 #endif
-  CHECK( pu.lwidth() != (1 << g_aucLog2[pu.lwidth()]) || pu.lheight() != (1 << g_aucLog2[pu.lheight()]), "Error: expecting blocks of size 2^M x 2^N" );
+  CHECK( pu.lwidth() != (1 << floorLog2(pu.lwidth())) || pu.lheight() != (1 << floorLog2(pu.lheight())), "Error: expecting blocks of size 2^M x 2^N" );
 
   // generate mode-specific prediction
   const int bitDepth = pu.cu->slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
diff --git a/source/Lib/CommonLib/MatrixIntraPrediction.cpp b/source/Lib/CommonLib/MatrixIntraPrediction.cpp
index abe883cb639da7d4bd51e8840525e633f4cc33b7..78e18d77268623f25fd5312f49a0528ccb833f66 100644
--- a/source/Lib/CommonLib/MatrixIntraPrediction.cpp
+++ b/source/Lib/CommonLib/MatrixIntraPrediction.cpp
@@ -1,4 +1,4 @@
-/* The copyright in this software is being made available under the BSD
+/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
 * granted under this license.
@@ -325,7 +325,7 @@ void MatrixIntraPrediction::doDownsampling(int* dst, const int* src, const SizeT
   const SizeType downsmpFactor = srcLen / dstLen;
   CHECKD( srcLen != dstLen * downsmpFactor, "Need integer downsampling factor." );
   CHECKD( ( downsmpFactor & ( downsmpFactor - 1 ) ) != 0, "Need power of two downsampling factor." );
-  const int log2DownsmpFactor = g_aucLog2[ downsmpFactor ];
+  const int log2DownsmpFactor = floorLog2( downsmpFactor );
 #if JVET_O0925_MIP_SIMPLIFICATIONS
   const int roundingOffset = ( 1 << ( log2DownsmpFactor - 1 ) );
 #else
@@ -408,7 +408,7 @@ void MatrixIntraPrediction::predictionUpsampling1D(int* const dst, const int* co
 #if !JVET_O0925_MIP_SIMPLIFICATIONS
   // TODO: Check if src and dst can ever be negative. If not assign unsigned type and simplify rounding.
 #endif
-  const int log2UpsmpFactor = g_aucLog2[ upsmpFactor ];
+  const int log2UpsmpFactor = floorLog2( upsmpFactor );
   CHECKD( upsmpFactor <= 1, "Upsampling factor must be at least 2." );
 #if JVET_O0925_MIP_SIMPLIFICATIONS
   const int roundingOffset = 1 << (log2UpsmpFactor - 1);
diff --git a/source/Lib/CommonLib/Quant.cpp b/source/Lib/CommonLib/Quant.cpp
index c94ce387e49f45ca927d9eb8491174f03bcac6d8..a34a4faf019b8f2259d61db02f99a2484b77cf4d 100644
--- a/source/Lib/CommonLib/Quant.cpp
+++ b/source/Lib/CommonLib/Quant.cpp
@@ -480,8 +480,8 @@ void Quant::dequant(const TransformUnit &tu,
     const Intermediate_Int inputMinimum        = -(1 << (targetInputBitDepth - 1));
     const Intermediate_Int inputMaximum        =  (1 << (targetInputBitDepth - 1)) - 1;
 
-    const uint32_t uiLog2TrWidth  = g_aucLog2[uiWidth];
-    const uint32_t uiLog2TrHeight = g_aucLog2[uiHeight];
+    const uint32_t uiLog2TrWidth  = floorLog2(uiWidth);
+    const uint32_t uiLog2TrHeight = floorLog2(uiHeight);
     int *piDequantCoef        = getDequantCoeff(scalingListType, QP_rem, uiLog2TrWidth, uiLog2TrHeight);
 
     if(rightShift > 0)
@@ -673,7 +673,7 @@ void Quant::xSetScalingListEnc(ScalingList *scalingList, uint32_t listId, uint32
   int *coeff  = scalingList->getScalingListAddress(sizeId,listId);
   quantcoeff  = getQuantCoeff(listId, qp, sizeId, sizeId);
 
-  const bool blockIsNotPowerOf4 = ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1;
+  const bool blockIsNotPowerOf4 = ((floorLog2(width) + floorLog2(height)) & 1) == 1;
   int quantScales = g_quantScales[blockIsNotPowerOf4?1:0][qp];
 
   processScalingListEnc(coeff,
@@ -701,7 +701,7 @@ void Quant::xSetScalingListDec(const ScalingList &scalingList, uint32_t listId,
 
   dequantcoeff = getDequantCoeff(listId, qp, sizeId, sizeId);
 
-  const bool blockIsNotPowerOf4 = ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1;
+  const bool blockIsNotPowerOf4 = ((floorLog2(width) + floorLog2(height)) & 1) == 1;
   int invQuantScale = g_invQuantScales[blockIsNotPowerOf4?1:0][qp];
 
   processScalingListDec(coeff,
@@ -729,7 +729,7 @@ void Quant::xSetRecScalingListEnc(ScalingList *scalingList, uint32_t listId, uin
   int *quantcoeff;
   int *coeff = scalingList->getScalingListAddress(largeSideId, listId);//4x4, 8x8
   quantcoeff = getQuantCoeff(listId, qp, sizeIdw, sizeIdh);//final quantCoeff (downsample)
-  const bool blockIsNotPowerOf4 = ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1;
+  const bool blockIsNotPowerOf4 = ((floorLog2(width) + floorLog2(height)) & 1) == 1;
   int quantScales = g_quantScales[blockIsNotPowerOf4?1:0][qp];
 
   processScalingListEnc(coeff,
@@ -757,7 +757,7 @@ void Quant::xSetRecScalingListDec(const ScalingList &scalingList, uint32_t listI
   const int *coeff = scalingList.getScalingListAddress(largeSideId, listId);
   int *dequantcoeff;
   dequantcoeff = getDequantCoeff(listId, qp, sizeIdw, sizeIdh);
-  const bool blockIsNotPowerOf4 = ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1;
+  const bool blockIsNotPowerOf4 = ((floorLog2(width) + floorLog2(height)) & 1) == 1;
   int invQuantScale = g_invQuantScales[blockIsNotPowerOf4 ? 1 : 0][qp];
   processScalingListDec(coeff,
                         dequantcoeff,
@@ -800,7 +800,7 @@ void Quant::xSetFlatScalingList(uint32_t list, uint32_t sizeX, uint32_t sizeY, i
   int *quantcoeff;
   int *dequantcoeff;
 
-  const bool blockIsNotPowerOf4 = ((g_aucLog2[g_scalingListSizeX[sizeX]] + g_aucLog2[g_scalingListSizeX[sizeY]]) & 1) == 1;
+  const bool blockIsNotPowerOf4 = ((floorLog2(g_scalingListSizeX[sizeX]) + floorLog2(g_scalingListSizeX[sizeY])) & 1) == 1;
   int quantScales    = g_quantScales   [blockIsNotPowerOf4?1:0][qp];
   int invQuantScales = g_invQuantScales[blockIsNotPowerOf4?1:0][qp] << 4;
 
@@ -1014,8 +1014,8 @@ void Quant::quant(TransformUnit &tu, const ComponentID &compID, const CCoeffBuf
     TCoeff deltaU[MAX_TB_SIZEY * MAX_TB_SIZEY];
     int scalingListType = getScalingListType(tu.cu->predMode, compID);
     CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list");
-    const uint32_t uiLog2TrWidth = g_aucLog2[uiWidth];
-    const uint32_t uiLog2TrHeight = g_aucLog2[uiHeight];
+    const uint32_t uiLog2TrWidth = floorLog2(uiWidth);
+    const uint32_t uiLog2TrHeight = floorLog2(uiHeight);
 #if JVET_O0919_TS_MIN_QP
     int *piQuantCoeff = getQuantCoeff(scalingListType, cQP.rem(useTransformSkip), uiLog2TrWidth, uiLog2TrHeight);
 #else
@@ -1104,8 +1104,8 @@ bool Quant::xNeedRDOQ(TransformUnit &tu, const ComponentID &compID, const CCoeff
   int scalingListType = getScalingListType(tu.cu->predMode, compID);
   CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list");
 
-  const uint32_t uiLog2TrWidth  = g_aucLog2[uiWidth];
-  const uint32_t uiLog2TrHeight = g_aucLog2[uiHeight];
+  const uint32_t uiLog2TrWidth  = floorLog2(uiWidth);
+  const uint32_t uiLog2TrHeight = floorLog2(uiHeight);
 #if JVET_O0919_TS_MIN_QP
   int *piQuantCoeff         = getQuantCoeff(scalingListType, cQP.rem(useTransformSkip), uiLog2TrWidth, uiLog2TrHeight);
 #else
@@ -1179,8 +1179,8 @@ void Quant::transformSkipQuantOneSample(TransformUnit &tu, const ComponentID &co
 
   CHECK( scalingListType >= SCALING_LIST_NUM, "Invalid scaling list" );
 
-  const uint32_t uiLog2TrWidth      = g_aucLog2[uiWidth];
-  const uint32_t uiLog2TrHeight     = g_aucLog2[uiHeight];
+  const uint32_t uiLog2TrWidth      = floorLog2(uiWidth);
+  const uint32_t uiLog2TrHeight     = floorLog2(uiHeight);
 #if JVET_O0919_TS_MIN_QP
   const int *const piQuantCoeff = getQuantCoeff(scalingListType, cQP.rem(useTransformSkip), uiLog2TrWidth, uiLog2TrHeight);
 #else
@@ -1266,8 +1266,8 @@ void Quant::invTrSkipDeQuantOneSample(TransformUnit &tu, const ComponentID &comp
     const Intermediate_Int inputMinimum = -(1 << (targetInputBitDepth - 1));
     const Intermediate_Int inputMaximum =  (1 << (targetInputBitDepth - 1)) - 1;
 
-    const uint32_t uiLog2TrWidth  = g_aucLog2[uiWidth];
-    const uint32_t uiLog2TrHeight = g_aucLog2[uiHeight];
+    const uint32_t uiLog2TrWidth  = floorLog2(uiWidth);
+    const uint32_t uiLog2TrHeight = floorLog2(uiHeight);
     int *piDequantCoef        = getDequantCoeff(scalingListType, QP_rem, uiLog2TrWidth, uiLog2TrHeight);
 
     if (rightShift > 0)
diff --git a/source/Lib/CommonLib/QuantRDOQ.cpp b/source/Lib/CommonLib/QuantRDOQ.cpp
index d5f9e52e31fb62ed47734681eaeae3545eb79c89..3cc4462700c57d81734e15b1f1834bd7ba00c51b 100644
--- a/source/Lib/CommonLib/QuantRDOQ.cpp
+++ b/source/Lib/CommonLib/QuantRDOQ.cpp
@@ -416,7 +416,7 @@ void QuantRDOQ::xSetErrScaleCoeff( uint32_t list, uint32_t sizeX, uint32_t sizeY
 
   double dErrScale = (double)( 1 << SCALE_BITS );                                // Compensate for scaling of bitcount in Lagrange cost function
 
-  const bool needsSqrt2 = ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1;
+  const bool needsSqrt2 = ((floorLog2(width) + floorLog2(height)) & 1) == 1;
   double dTransShift = (double)iTransformShift + ( needsSqrt2 ? -0.5 : 0.0 );
   dErrScale = dErrScale*pow( 2.0, ( -2.0*dTransShift ) );                     // Compensate for scaling through forward transform
 
@@ -605,8 +605,8 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
   }
 
   double     d64BlockUncodedCost               = 0;
-  const uint32_t uiLog2BlockWidth                  = g_aucLog2[uiWidth];
-  const uint32_t uiLog2BlockHeight                 = g_aucLog2[uiHeight];
+  const uint32_t uiLog2BlockWidth                  = floorLog2(uiWidth);
+  const uint32_t uiLog2BlockHeight                 = floorLog2(uiHeight);
   const uint32_t uiMaxNumCoeff                     = rect.area();
 
   CHECK(compID >= MAX_NUM_TBLOCKS, "Invalid component ID");
@@ -965,7 +965,7 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
     {
       bool rootCbfSoFar       = false;
       bool isLastSubPartition = CU::isISPLast(*tu.cu, tu.Y(), compID);
-      uint32_t nTus = tu.cu->ispMode == HOR_INTRA_SUBPARTITIONS ? tu.cu->lheight() >> g_aucLog2[tu.lheight()] : tu.cu->lwidth() >> g_aucLog2[tu.lwidth()];
+      uint32_t nTus = tu.cu->ispMode == HOR_INTRA_SUBPARTITIONS ? tu.cu->lheight() >> floorLog2(tu.lheight()) : tu.cu->lwidth() >> floorLog2(tu.lwidth());
       if( isLastSubPartition )
       {
         TransformUnit* tuPointer = tu.cu->firstTU;
diff --git a/source/Lib/CommonLib/RdCost.cpp b/source/Lib/CommonLib/RdCost.cpp
index 5f0dcb193150ccb19f50ee26b84bda5aac8103c5..8a786feb02bc5b3f4d75647a9268b9188bb3ac53 100644
--- a/source/Lib/CommonLib/RdCost.cpp
+++ b/source/Lib/CommonLib/RdCost.cpp
@@ -232,7 +232,7 @@ void RdCost::setDistParam( DistParam &rcDP, const CPelBuf &org, const Pel* piRef
     }
     else if( isPowerOf2( org.width ) )
     {
-      rcDP.distFunc = m_afpDistortFunc[ DF_SAD + DFOffset + g_aucLog2[ org.width ] ];
+      rcDP.distFunc = m_afpDistortFunc[ DF_SAD + DFOffset + floorLog2( org.width ) ];
     }
     else
     {
@@ -241,7 +241,7 @@ void RdCost::setDistParam( DistParam &rcDP, const CPelBuf &org, const Pel* piRef
   }
   else if( isPowerOf2( org.width ) )
   {
-    rcDP.distFunc = m_afpDistortFunc[ DF_HAD + DFOffset + g_aucLog2[ org.width ] ];
+    rcDP.distFunc = m_afpDistortFunc[ DF_HAD + DFOffset + floorLog2( org.width ) ];
   }
   else
   {
@@ -306,7 +306,7 @@ void RdCost::setDistParam( DistParam &rcDP, const CPelBuf &org, const CPelBuf &c
     }
     else if( isPowerOf2( org.width) )
     {
-      rcDP.distFunc = m_afpDistortFunc[ DF_SAD + DFOffset + g_aucLog2[ org.width ] ];
+      rcDP.distFunc = m_afpDistortFunc[ DF_SAD + DFOffset + floorLog2( org.width ) ];
     }
     else
     {
@@ -315,7 +315,7 @@ void RdCost::setDistParam( DistParam &rcDP, const CPelBuf &org, const CPelBuf &c
   }
   else
   {
-    rcDP.distFunc = m_afpDistortFunc[ DF_HAD + DFOffset + g_aucLog2[ org.width ] ];
+    rcDP.distFunc = m_afpDistortFunc[ DF_HAD + DFOffset + floorLog2( org.width ) ];
   }
 
   rcDP.maximumDistortionForEarlyExit = std::numeric_limits<Distortion>::max();
@@ -359,7 +359,7 @@ void RdCost::setDistParam( DistParam &rcDP, const Pel* pOrg, const Pel* piRefY,
   }
   else
   {
-    rcDP.distFunc = m_afpDistortFunc[ DF_SAD + g_aucLog2[ width ] ];
+    rcDP.distFunc = m_afpDistortFunc[ DF_SAD + floorLog2( width ) ];
   }
 }
 
@@ -395,7 +395,7 @@ Distortion RdCost::getDistPart( const CPelBuf &org, const CPelBuf &cur, int bitD
 
   if( isPowerOf2( org.width ) )
   {
-    cDtParam.distFunc = m_afpDistortFunc[eDFunc + g_aucLog2[org.width]];
+    cDtParam.distFunc = m_afpDistortFunc[eDFunc + floorLog2(org.width)];
   }
   else
   {
diff --git a/source/Lib/CommonLib/RdCost.h b/source/Lib/CommonLib/RdCost.h
index 9e7b16df679dfe23af66379092de5c265593f70f..e6421d8b7c6f84ced1b89807b89db8923cdcfb5e 100644
--- a/source/Lib/CommonLib/RdCost.h
+++ b/source/Lib/CommonLib/RdCost.h
@@ -289,7 +289,7 @@ public:
       uiTemp2  >>=   MAX_CU_DEPTH;
     }
 
-    return uiLength2 + ( g_aucPrevLog2[uiTemp2] << 1 );
+    return uiLength2 + ( floorLog2(uiTemp2) << 1 );
   }
   Distortion     getCostOfVectorWithPredictor( const int x, const int y, const unsigned imvShift )  { return Distortion( m_motionLambda * getBitsOfVectorWithPredictor(x, y, imvShift )); }
   uint32_t           getBitsOfVectorWithPredictor( const int x, const int y, const unsigned imvShift )  { return xGetExpGolombNumberOfBits(((x << m_iCostScale) - m_mvPredictor.getHor())>>imvShift) + xGetExpGolombNumberOfBits(((y << m_iCostScale) - m_mvPredictor.getVer())>>imvShift); }
diff --git a/source/Lib/CommonLib/Reshape.cpp b/source/Lib/CommonLib/Reshape.cpp
index 754af0b4573ddb3671c04e508683f9e01c1e80f9..107b8b23889c8c8ba5df2ff0dd83fbba4df1a9b3 100644
--- a/source/Lib/CommonLib/Reshape.cpp
+++ b/source/Lib/CommonLib/Reshape.cpp
@@ -158,7 +158,7 @@ int  Reshape::calculateChromaAdjVpduNei(TransformUnit &tu, const CompArea &areaY
   int yPos = areaY.lumaPos().y;
   int ctuSize = cs.sps->getCTUSize();
   int numNeighbor = std::min(64, ctuSize);
-  int numNeighborLog = g_aucLog2[numNeighbor];
+  int numNeighborLog = floorLog2(numNeighbor);
   if (ctuSize == 128)
   {
     xPos = xPos / 64 * 64;
diff --git a/source/Lib/CommonLib/Rom.cpp b/source/Lib/CommonLib/Rom.cpp
index 4d032d0ec8cf106545fd8ce04cbeeb4cf9b0090b..1f26dd1b538eefef56f835388ec5492efa30023a 100644
--- a/source/Lib/CommonLib/Rom.cpp
+++ b/source/Lib/CommonLib/Rom.cpp
@@ -262,27 +262,6 @@ uint32_t g_log2SbbSize[MAX_CU_DEPTH + 1][MAX_CU_DEPTH + 1][2] =
 // initialize ROM variables
 void initROM()
 {
-  int c;
-
-  // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ...
-  // g_aucLog2[ x ]: log2(x), if x=1 -> 0, x=2 -> 1, x=4 -> 2, x=8 -> 3, x=16 -> 4, ...
-  ::memset(g_aucLog2, 0, sizeof(g_aucLog2));
-  c = 0;
-  for( int i = 0, n = 0; i <= MAX_CU_SIZE; i++ )
-  {
-    g_aucNextLog2[i] = i <= 1 ? 0 : c + 1;
-
-    if( i == ( 1 << n ) )
-    {
-      c = n;
-      n++;
-    }
-
-    g_aucPrevLog2[i] = c;
-    g_aucLog2    [i] = c;
-  }
-
-
   gp_sizeIdxInfo = new SizeIndexInfoLog2();
   gp_sizeIdxInfo->init(MAX_CU_SIZE);
 
@@ -337,7 +316,7 @@ void initROM()
       //--------------------------------------------------------------------------------------------------
 
       //grouped scan orders
-      const uint32_t* log2Sbb        = g_log2SbbSize[g_aucLog2[blockWidth]][g_aucLog2[blockHeight]];
+      const uint32_t* log2Sbb        = g_log2SbbSize[floorLog2(blockWidth)][floorLog2(blockHeight)];
       const uint32_t  log2CGWidth    = log2Sbb[0];
       const uint32_t  log2CGHeight   = log2Sbb[1];
 
@@ -629,9 +608,6 @@ const int g_sortedMipMpms[3][NUM_MPM_MIP] =
 // Misc.
 // ====================================================================================================================
 SizeIndexInfo*           gp_sizeIdxInfo = NULL;
-int8_t                    g_aucLog2    [MAX_CU_SIZE + 1];
-int8_t                    g_aucNextLog2[MAX_CU_SIZE + 1];
-int8_t                    g_aucPrevLog2[MAX_CU_SIZE + 1];
 
 #if JVET_O0105_ICT
 const int                 g_ictModes[2][4] = { { 0, 3, 1, 2 }, { 0, -3, -1, -2 } };
diff --git a/source/Lib/CommonLib/Rom.h b/source/Lib/CommonLib/Rom.h
index 478c418a4a99e297650df548aecadcf2c9617cac..7dc2170d4dab6bffa1c8366f8ff0e47d3d816e0a 100644
--- a/source/Lib/CommonLib/Rom.h
+++ b/source/Lib/CommonLib/Rom.h
@@ -145,9 +145,6 @@ extern const     uint8_t  g_lfnstLut[ NUM_INTRA_MODE + NUM_EXT_LUMA_MODE - 1 ];
 // Misc.
 // ====================================================================================================================
 extern SizeIndexInfo* gp_sizeIdxInfo;
-extern int8_t          g_aucLog2                       [MAX_CU_SIZE + 1];
-extern int8_t          g_aucNextLog2        [MAX_CU_SIZE + 1];
-extern int8_t          g_aucPrevLog2        [MAX_CU_SIZE + 1];
 
 #if JVET_O0105_ICT
 extern const int       g_ictModes[2][4];
@@ -155,22 +152,22 @@ extern const int       g_ictModes[2][4];
 
 inline bool is34( const SizeType& size )
 {
-  return ( size & ( ( int64_t ) 1 << ( g_aucLog2[size] - 1 ) ) );
+  return ( size & ( ( int64_t ) 1 << ( floorLog2(size) - 1 ) ) );
 }
 
 inline bool is58( const SizeType& size )
 {
-  return ( size & ( ( int64_t ) 1 << ( g_aucLog2[size] - 2 ) ) );
+  return ( size & ( ( int64_t ) 1 << ( floorLog2(size) - 2 ) ) );
 }
 
 inline bool isNonLog2BlockSize( const Size& size )
 {
-  return ( ( 1 << g_aucLog2[size.width] ) != size.width ) || ( ( 1 << g_aucLog2[size.height] ) != size.height );
+  return ( ( 1 << floorLog2(size.width) ) != size.width ) || ( ( 1 << floorLog2(size.height) ) != size.height );
 }
 
 inline bool isNonLog2Size( const SizeType& size )
 {
-  return ( ( 1 << g_aucLog2[size] ) != size );
+  return ( ( 1 << floorLog2(size) ) != size );
 }
 
 extern UnitScale     g_miScaling; // scaling object for motion scaling
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index 73418619d90ec055df519e0e74ad7a12fa894225..934bd9613e051221adf7648806dc4dc1e1d55662 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -2233,12 +2233,12 @@ public:
     , maxCUHeight         ( sps.getMaxCUHeight() )
     , maxCUWidthMask      ( maxCUWidth  - 1 )
     , maxCUHeightMask     ( maxCUHeight - 1 )
-    , maxCUWidthLog2      ( g_aucLog2[ maxCUWidth  ] )
-    , maxCUHeightLog2     ( g_aucLog2[ maxCUHeight ] )
+    , maxCUWidthLog2      ( floorLog2( maxCUWidth  ) )
+    , maxCUHeightLog2     ( floorLog2( maxCUHeight ) )
     , minCUWidth          ( sps.getMaxCUWidth()  >> sps.getMaxCodingDepth() )
     , minCUHeight         ( sps.getMaxCUHeight() >> sps.getMaxCodingDepth() )
-    , minCUWidthLog2      ( g_aucLog2[ minCUWidth  ] )
-    , minCUHeightLog2     ( g_aucLog2[ minCUHeight ] )
+    , minCUWidthLog2      ( floorLog2( minCUWidth  ) )
+    , minCUHeightLog2     ( floorLog2( minCUHeight ) )
     , partsInCtuWidth     ( 1 << sps.getMaxCodingDepth() )
     , partsInCtuHeight    ( 1 << sps.getMaxCodingDepth() )
     , partsInCtu          ( 1 << (sps.getMaxCodingDepth() << 1) )
diff --git a/source/Lib/CommonLib/TrQuant.cpp b/source/Lib/CommonLib/TrQuant.cpp
index 152e23bad9a6d489ba569932cdbaf28bc9e13aa0..e498dd0fdd3475f223349897fb976034d93631e0 100644
--- a/source/Lib/CommonLib/TrQuant.cpp
+++ b/source/Lib/CommonLib/TrQuant.cpp
@@ -837,8 +837,8 @@ void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel
   const unsigned maxLog2TrDynamicRange  = tu.cs->sps->getMaxLog2TrDynamicRange( toChannelType( compID ) );
   const unsigned bitDepth               = tu.cs->sps->getBitDepth(              toChannelType( compID ) );
   const int      TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_FORWARD];
-  const uint32_t transformWidthIndex    = g_aucLog2[width ] - 1;  // nLog2WidthMinus1, since transform start from 2-point
-  const uint32_t transformHeightIndex   = g_aucLog2[height] - 1;  // nLog2HeightMinus1, since transform start from 2-point
+  const uint32_t transformWidthIndex    = floorLog2(width ) - 1;  // nLog2WidthMinus1, since transform start from 2-point
+  const uint32_t transformHeightIndex   = floorLog2(height) - 1;  // nLog2HeightMinus1, since transform start from 2-point
 
 
   int trTypeHor = DCT2;
@@ -889,8 +889,8 @@ void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel
 
   if( width > 1 && height > 1 ) // 2-D transform
   {
-    const int      shift_1st              = ((g_aucLog2[width ]) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
-    const int      shift_2nd              =  (g_aucLog2[height])            + TRANSFORM_MATRIX_SHIFT                          + COM16_C806_TRANS_PREC;
+    const int      shift_1st              = ((floorLog2(width )) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
+    const int      shift_2nd              =  (floorLog2(height))            + TRANSFORM_MATRIX_SHIFT                          + COM16_C806_TRANS_PREC;
     CHECK( shift_1st < 0, "Negative shift" );
     CHECK( shift_2nd < 0, "Negative shift" );
   TCoeff *tmp = ( TCoeff * ) alloca( width * height * sizeof( TCoeff ) );
@@ -900,14 +900,14 @@ void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel
   }
   else if( height == 1 ) //1-D horizontal transform
   {
-    const int      shift              = ((g_aucLog2[width ]) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
+    const int      shift              = ((floorLog2(width )) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
     CHECK( shift < 0, "Negative shift" );
     CHECKD( ( transformWidthIndex < 0 ), "There is a problem with the width." );
     fastFwdTrans[trTypeHor][transformWidthIndex]( block, dstCoeff.buf, shift, 1, 0, skipWidth );
   }
   else //if (iWidth == 1) //1-D vertical transform
   {
-    int shift = ( ( g_aucLog2[height] ) + bitDepth + TRANSFORM_MATRIX_SHIFT ) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
+    int shift = ( ( floorLog2(height) ) + bitDepth + TRANSFORM_MATRIX_SHIFT ) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
     CHECK( shift < 0, "Negative shift" );
     CHECKD( ( transformHeightIndex < 0 ), "There is a problem with the height." );
     fastFwdTrans[trTypeVer][transformHeightIndex]( block, dstCoeff.buf, shift, 1, 0, skipHeight );
@@ -923,8 +923,8 @@ void TrQuant::xIT( const TransformUnit &tu, const ComponentID &compID, const CCo
   const int      TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_INVERSE];
   const TCoeff   clipMinimum            = -( 1 << maxLog2TrDynamicRange );
   const TCoeff   clipMaximum            =  ( 1 << maxLog2TrDynamicRange ) - 1;
-  const uint32_t transformWidthIndex    = g_aucLog2[width ] - 1;                                // nLog2WidthMinus1, since transform start from 2-point
-  const uint32_t transformHeightIndex   = g_aucLog2[height] - 1;                                // nLog2HeightMinus1, since transform start from 2-point
+  const uint32_t transformWidthIndex    = floorLog2(width ) - 1;                                // nLog2WidthMinus1, since transform start from 2-point
+  const uint32_t transformHeightIndex   = floorLog2(height) - 1;                                // nLog2HeightMinus1, since transform start from 2-point
 
 
   int trTypeHor = DCT2;
@@ -1096,7 +1096,7 @@ void TrQuant::transformNxN( TransformUnit &tu, const ComponentID &compID, const
     }
 
     double scaleSAD=1.0;
-    if (isLuma(compID) && tu.mtsIdx==MTS_SKIP && ((g_aucLog2[width] + g_aucLog2[height]) & 1) == 1 )
+    if (isLuma(compID) && tu.mtsIdx==MTS_SKIP && ((floorLog2(width) + floorLog2(height)) & 1) == 1 )
     {
       scaleSAD=1.0/1.414213562; // compensate for not scaling transform skip coefficients by 1/sqrt(2)
     }
@@ -1111,7 +1111,7 @@ void TrQuant::transformNxN( TransformUnit &tu, const ComponentID &compID, const
 #endif
   int numTests = 0;
   std::vector<TrCost>::iterator itC = trCosts.begin();
-  const double fac   = facBB[g_aucLog2[std::max(width, height)]-2];
+  const double fac   = facBB[floorLog2(std::max(width, height))-2];
   const double thr   = fac * trCosts.begin()->first;
   const double thrTS = trCosts.begin()->first;
   while( itC != trCosts.end() )
@@ -1242,7 +1242,7 @@ void TrQuant::xGetCoeffEnergy( TransformUnit &tu, const ComponentID &compID, con
   {
     const int width   = tu.cu->blocks[compID].width;
     const int height  = tu.cu->blocks[compID].height;
-    const int log2Sl  = width <= height ? g_aucLog2[height >> g_aucLog2[width]] : g_aucLog2[width >> g_aucLog2[height]];
+    const int log2Sl  = width <= height ? floorLog2(height >> floorLog2(width)) : floorLog2(width >> floorLog2(height));
     const int diPos1  = width <= height ? width  : height;
     const int diPos2  = width <= height ? height : width;
     const int ofsPos1 = width <= height ? 1 : coeffs.stride;
diff --git a/source/Lib/CommonLib/UnitPartitioner.cpp b/source/Lib/CommonLib/UnitPartitioner.cpp
index 5b95b3a7cdb06e19d529abedb63588ecd8a06bc4..9f3180d40494130f580409a41a7ffb705c4aeffb 100644
--- a/source/Lib/CommonLib/UnitPartitioner.cpp
+++ b/source/Lib/CommonLib/UnitPartitioner.cpp
@@ -176,7 +176,7 @@ void Partitioner::copyState( const Partitioner& other )
 void AdaptiveDepthPartitioner::setMaxMinDepth( unsigned& minDepth, unsigned& maxDepth, const CodingStructure& cs ) const
 {
   unsigned          stdMinDepth = 0;
-  unsigned          stdMaxDepth = ( g_aucLog2[cs.sps->getCTUSize()] - g_aucLog2[cs.sps->getMinQTSize( cs.slice->getSliceType(), chType )]);
+  unsigned          stdMaxDepth = ( floorLog2(cs.sps->getCTUSize()) - floorLog2(cs.sps->getMinQTSize( cs.slice->getSliceType(), chType )));
   const Position    pos         = currArea().blocks[chType].pos();
   const unsigned    curSliceIdx = cs.slice->getIndependentSliceIdx();
   const unsigned    curTileIdx  = cs.picture->brickMap->getBrickIdxRsMap( currArea().lumaPos() );
@@ -988,7 +988,7 @@ void PartitionerImpl::getTUIntraSubPartitions( Partitioning &sub, const UnitArea
 
   if( splitType == TU_1D_HORZ_SPLIT )
   {
-    nPartitions = tuArea.lumaSize().height >> g_aucLog2[splitDimensionSize];
+    nPartitions = tuArea.lumaSize().height >> floorLog2(splitDimensionSize);
 
     sub.resize( nPartitions );
 
@@ -1005,7 +1005,7 @@ void PartitionerImpl::getTUIntraSubPartitions( Partitioning &sub, const UnitArea
   }
   else if( splitType == TU_1D_VERT_SPLIT )
   {
-    nPartitions = tuArea.lumaSize().width >> g_aucLog2[splitDimensionSize];
+    nPartitions = tuArea.lumaSize().width >> floorLog2(splitDimensionSize);
 
     sub.resize( nPartitions );
 
diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp
index 87512e90ffbd6e5adcbd88237a8bc8af485ba4cd..5c59c68dd71c359a2759f39343c2287966afe1e4 100755
--- a/source/Lib/CommonLib/UnitTools.cpp
+++ b/source/Lib/CommonLib/UnitTools.cpp
@@ -178,7 +178,7 @@ bool CU::isSameSliceAndTile(const CodingUnit& cu, const CodingUnit& cu2)
 
 bool CU::isSameCtu(const CodingUnit& cu, const CodingUnit& cu2)
 {
-  uint32_t ctuSizeBit = g_aucLog2[cu.cs->sps->getMaxCUWidth()];
+  uint32_t ctuSizeBit = floorLog2(cu.cs->sps->getMaxCUWidth());
 
   Position pos1Ctu(cu.lumaPos().x  >> ctuSizeBit, cu.lumaPos().y  >> ctuSizeBit);
   Position pos2Ctu(cu2.lumaPos().x >> ctuSizeBit, cu2.lumaPos().y >> ctuSizeBit);
@@ -312,7 +312,7 @@ bool CU::firstTestISPHorSplit( const int width, const int height, const Componen
 {
   //this function decides which split mode (horizontal or vertical) is tested first (encoder only)
   //we check the logarithmic aspect ratios of the block
-  int aspectRatio = g_aucLog2[width] - g_aucLog2[height];
+  int aspectRatio = floorLog2(width) - floorLog2(height);
   if( aspectRatio > 0 )
   {
     return true;
@@ -332,18 +332,18 @@ bool CU::firstTestISPHorSplit( const int width, const int height, const Componen
     const int cuAbove1dSplit = cuAbove != nullptr && cuAbove->predMode == MODE_INTRA ? cuAbove->ispMode               :  0;
     if( cuLeftWidth != -1 && cuAboveWidth == -1 )
     {
-      int cuLeftAspectRatio = g_aucLog2[cuLeftWidth] - g_aucLog2[cuLeftHeight];
+      int cuLeftAspectRatio = floorLog2(cuLeftWidth) - floorLog2(cuLeftHeight);
       return cuLeftAspectRatio < 0 ? false : cuLeftAspectRatio > 0 ? true : cuLeft1dSplit == VER_INTRA_SUBPARTITIONS ? false : true;
     }
     else if( cuLeftWidth == -1 && cuAboveWidth != -1 )
     {
-      int cuAboveAspectRatio = g_aucLog2[cuAboveWidth] - g_aucLog2[cuAboveHeight];
+      int cuAboveAspectRatio = floorLog2(cuAboveWidth) - floorLog2(cuAboveHeight);
       return cuAboveAspectRatio < 0 ? false : cuAboveAspectRatio > 0 ? true : cuAbove1dSplit == VER_INTRA_SUBPARTITIONS ? false : true;
     }
     else if( cuLeftWidth != -1 && cuAboveWidth != -1 )
     {
-      int cuLeftAspectRatio = g_aucLog2[cuLeftWidth] - g_aucLog2[cuLeftHeight];
-      int cuAboveAspectRatio = g_aucLog2[cuAboveWidth] - g_aucLog2[cuAboveHeight];
+      int cuLeftAspectRatio = floorLog2(cuLeftWidth) - floorLog2(cuLeftHeight);
+      int cuAboveAspectRatio = floorLog2(cuAboveWidth) - floorLog2(cuAboveHeight);
       if( cuLeftAspectRatio < 0 && cuAboveAspectRatio < 0 )
       {
         return false;
@@ -426,7 +426,7 @@ bool CU::canUseISP( const CodingUnit &cu, const ComponentID compID )
 
 bool CU::canUseISP( const int width, const int height, const int maxTrSize )
 {
-  bool  notEnoughSamplesToSplit = ( g_aucLog2[width] + g_aucLog2[height] <= ( g_aucLog2[MIN_TB_SIZEY] << 1 ) );
+  bool  notEnoughSamplesToSplit = ( floorLog2(width) + floorLog2(height) <= ( floorLog2(MIN_TB_SIZEY) << 1 ) );
   bool  cuSizeLargerThanMaxTrSize = width > maxTrSize || height > maxTrSize;
   if ( notEnoughSamplesToSplit || cuSizeLargerThanMaxTrSize )
   {
@@ -451,11 +451,11 @@ uint32_t CU::getISPSplitDim( const int width, const int height, const PartSplit
     nonSplitDimensionSize = height;
   }
 
-  const int minNumberOfSamplesPerCu = 1 << ( ( g_aucLog2[MIN_TB_SIZEY] << 1 ) );
-  const int factorToMinSamples = nonSplitDimensionSize < minNumberOfSamplesPerCu ? minNumberOfSamplesPerCu >> g_aucLog2[nonSplitDimensionSize] : 1;
+  const int minNumberOfSamplesPerCu = 1 << ( ( floorLog2(MIN_TB_SIZEY) << 1 ) );
+  const int factorToMinSamples = nonSplitDimensionSize < minNumberOfSamplesPerCu ? minNumberOfSamplesPerCu >> floorLog2(nonSplitDimensionSize) : 1;
   partitionSize = ( splitDimensionSize >> divShift ) < factorToMinSamples ? factorToMinSamples : ( splitDimensionSize >> divShift );
 
-  CHECK( g_aucLog2[partitionSize] + g_aucLog2[nonSplitDimensionSize] < g_aucLog2[minNumberOfSamplesPerCu], "A partition has less than the minimum amount of samples!" );
+  CHECK( floorLog2(partitionSize) + floorLog2(nonSplitDimensionSize) < floorLog2(minNumberOfSamplesPerCu), "A partition has less than the minimum amount of samples!" );
   return partitionSize;
 }
 
@@ -468,7 +468,7 @@ bool CU::allLumaCBFsAreZero(const CodingUnit& cu)
   }
   else
   {
-    int numTotalTUs = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> g_aucLog2[cu.firstTU->lheight()] : cu.lwidth() >> g_aucLog2[cu.firstTU->lwidth()];
+    int numTotalTUs = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> floorLog2(cu.firstTU->lheight()) : cu.lwidth() >> floorLog2(cu.firstTU->lwidth());
     TransformUnit* tuPtr = cu.firstTU;
     for (int tuIdx = 0; tuIdx < numTotalTUs; tuIdx++)
     {
@@ -974,7 +974,7 @@ int PU::getWideAngIntraMode( const TransformUnit &tu, const uint32_t dirMode, co
   int              width        = int( pred.width );
   int              height       = int( pred.height );
   int              modeShift[ ] = { 0, 6, 10, 12, 14, 15 };
-  int              deltaSize    = abs( g_aucLog2[ width ] - g_aucLog2[ height ] );
+  int              deltaSize    = abs( floorLog2( width ) - floorLog2( height ) );
   int              predMode     = dirMode;
 
   if( width > height && dirMode < 2 + modeShift[ deltaSize ] )
@@ -1786,7 +1786,7 @@ bool PU::checkDMVRCondition(const PredictionUnit& pu)
 // for ibc pu validation
 bool PU::isBlockVectorValid(PredictionUnit& pu, int xPos, int yPos, int width, int height, int picWidth, int picHeight, int xStartInCU, int yStartInCU, int xBv, int yBv, int ctuSize)
 {
-  const int ctuSizeLog2 = g_aucLog2[ctuSize];
+  const int ctuSizeLog2 = floorLog2(ctuSize);
 
   int refRightX = xPos + xBv + width - 1;
   int refBottomY = yPos + yBv + height - 1;
@@ -2122,8 +2122,8 @@ void PU::getIbcMVPsEncOnly(PredictionUnit &pu, Mv* mvPred, int& nbPred)
   const PreCalcValues   &pcv = *pu.cs->pcv;
   const int  cuWidth = pu.blocks[COMPONENT_Y].width;
   const int  cuHeight = pu.blocks[COMPONENT_Y].height;
-  const int  log2UnitWidth = g_aucLog2[pcv.minCUWidth];
-  const int  log2UnitHeight = g_aucLog2[pcv.minCUHeight];
+  const int  log2UnitWidth = floorLog2(pcv.minCUWidth);
+  const int  log2UnitHeight = floorLog2(pcv.minCUHeight);
   const int  totalAboveUnits = (cuWidth >> log2UnitWidth) + 1;
   const int  totalLeftUnits = (cuHeight >> log2UnitHeight) + 1;
 
@@ -2526,12 +2526,12 @@ void PU::xInheritedAffineMv( const PredictionUnit &pu, const PredictionUnit* puN
   int shift = MAX_CU_DEPTH;
   int iDMvHorX, iDMvHorY, iDMvVerX, iDMvVerY;
 
-  iDMvHorX = (mvRT - mvLT).getHor() << (shift - g_aucLog2[neiW]);
-  iDMvHorY = (mvRT - mvLT).getVer() << (shift - g_aucLog2[neiW]);
+  iDMvHorX = (mvRT - mvLT).getHor() << (shift - floorLog2(neiW));
+  iDMvHorY = (mvRT - mvLT).getVer() << (shift - floorLog2(neiW));
   if ( puNeighbour->cu->affineType == AFFINEMODEL_6PARAM && !isTopCtuBoundary )
   {
-    iDMvVerX = (mvLB - mvLT).getHor() << (shift - g_aucLog2[neiH]);
-    iDMvVerY = (mvLB - mvLT).getVer() << (shift - g_aucLog2[neiH]);
+    iDMvVerX = (mvLB - mvLT).getHor() << (shift - floorLog2(neiH));
+    iDMvVerY = (mvLB - mvLT).getVer() << (shift - floorLog2(neiH));
   }
   else
   {
@@ -2942,7 +2942,7 @@ void PU::getAffineControlPointCand(const PredictionUnit &pu, MotionInfo mi[4], i
   int cuH = pu.Y().height;
   int vx, vy;
   int shift = MAX_CU_DEPTH;
-  int shiftHtoW = shift + g_aucLog2[cuW] - g_aucLog2[cuH];
+  int shiftHtoW = shift + floorLog2(cuW) - floorLog2(cuH);
 
   // motion info
   Mv cMv[2][4];
@@ -3518,13 +3518,13 @@ void PU::setAllAffineMv(PredictionUnit& pu, Mv affLT, Mv affRT, Mv affLB, RefPic
     }
   }
   int deltaMvHorX, deltaMvHorY, deltaMvVerX, deltaMvVerY;
-  deltaMvHorX = (affRT - affLT).getHor() << (shift - g_aucLog2[width]);
-  deltaMvHorY = (affRT - affLT).getVer() << (shift - g_aucLog2[width]);
+  deltaMvHorX = (affRT - affLT).getHor() << (shift - floorLog2(width));
+  deltaMvHorY = (affRT - affLT).getVer() << (shift - floorLog2(width));
   int height = pu.Y().height;
   if ( pu.cu->affineType == AFFINEMODEL_6PARAM )
   {
-    deltaMvVerX = (affLB - affLT).getHor() << (shift - g_aucLog2[height]);
-    deltaMvVerY = (affLB - affLT).getVer() << (shift - g_aucLog2[height]);
+    deltaMvVerX = (affLB - affLT).getHor() << (shift - floorLog2(height));
+    deltaMvVerY = (affLB - affLT).getVer() << (shift - floorLog2(height));
   }
   else
   {
@@ -3580,7 +3580,7 @@ void PU::setAllAffineMv(PredictionUnit& pu, Mv affLT, Mv affRT, Mv affLB, RefPic
 void clipColPos(int& posX, int& posY, const PredictionUnit& pu)
 {
   Position puPos = pu.lumaPos();
-  int log2CtuSize = g_aucLog2[pu.cs->sps->getCTUSize()];
+  int log2CtuSize = floorLog2(pu.cs->sps->getCTUSize());
   int ctuX = ((puPos.x >> log2CtuSize) << log2CtuSize);
   int ctuY = ((puPos.y >> log2CtuSize) << log2CtuSize);
 #if JVET_O1164_PS
@@ -4103,8 +4103,8 @@ void PU::spanTriangleMotionInfo( PredictionUnit &pu, MergeCtx &triangleMrgCtx, c
 #endif
   }
 
-  int32_t idxW  = (int32_t)(g_aucLog2[pu.lwidth() ] - MIN_CU_LOG2);
-  int32_t idxH  = (int32_t)(g_aucLog2[pu.lheight()] - MIN_CU_LOG2);
+  int32_t idxW  = (int32_t)(floorLog2(pu.lwidth() ) - MIN_CU_LOG2);
+  int32_t idxH  = (int32_t)(floorLog2(pu.lheight()) - MIN_CU_LOG2);
   for( int32_t y = 0; y < mb.height; y++ )
   {
     for( int32_t x = 0; x < mb.width; x++ )
@@ -4652,7 +4652,7 @@ bool TU::needsSqrt2Scale( const TransformUnit &tu, const ComponentID &compID )
 {
   const Size &size=tu.blocks[compID];
   const bool isTransformSkip = tu.mtsIdx==MTS_SKIP && isLuma(compID);
-  return (!isTransformSkip) && (((g_aucLog2[size.width] + g_aucLog2[size.height]) & 1) == 1);
+  return (!isTransformSkip) && (((floorLog2(size.width) + floorLog2(size.height)) & 1) == 1);
 }
 
 bool TU::needsBlockSizeTrafoScale( const TransformUnit &tu, const ComponentID &compID )
diff --git a/source/Lib/CommonLib/dtrace_blockstatistics.cpp b/source/Lib/CommonLib/dtrace_blockstatistics.cpp
index d46c39b717b1e0882fa7a4e37cbf27bcfca51d6c..61406e1b5951f7ebc5f76c51045874a024961041 100644
--- a/source/Lib/CommonLib/dtrace_blockstatistics.cpp
+++ b/source/Lib/CommonLib/dtrace_blockstatistics.cpp
@@ -277,8 +277,8 @@ void retrieveTriangularMvInfo(const PredictionUnit& pu, MotionInfo& mi0, MotionI
   CMotionBuf mb = pu.getMotionBuf();
   bool foundMv[2] = { false, false };
   bool foundBi = false;
-  int32_t idxW  = (int32_t)(g_aucLog2[pu.lwidth() ] - MIN_CU_LOG2);
-  int32_t idxH  = (int32_t)(g_aucLog2[pu.lheight()] - MIN_CU_LOG2);
+  int32_t idxW  = (int32_t)(floorLog2(pu.lwidth() ) - MIN_CU_LOG2);
+  int32_t idxH  = (int32_t)(floorLog2(pu.lheight()) - MIN_CU_LOG2);
   for (int32_t y = 0; y < mb.height; y++)
   {
     for (int32_t x = 0; x < mb.width; x++)
diff --git a/source/Lib/CommonLib/x86/InterpolationFilterX86.h b/source/Lib/CommonLib/x86/InterpolationFilterX86.h
index 0d7421f2abd9850fddcfa308b2b077dc8ed3298d..04116b8e74e73cd28b80552371ceee897580bd8c 100644
--- a/source/Lib/CommonLib/x86/InterpolationFilterX86.h
+++ b/source/Lib/CommonLib/x86/InterpolationFilterX86.h
@@ -1228,8 +1228,8 @@ void xWeightedTriangleBlk_SSE(const PredictionUnit &pu, const uint32_t width, co
   int32_t strideSrc0 = predSrc0.get(compIdx).stride;
   int32_t strideSrc1 = predSrc1.get(compIdx).stride;
 
-  int8_t log2Width = g_aucLog2[width] - 1;
-  int8_t log2Height = g_aucLog2[height] - 1;
+  int8_t log2Width = floorLog2(width) - 1;
+  int8_t log2Height = floorLog2(height) - 1;
   const char    log2WeightBase = 3;
   const ClpRng  clpRng = pu.cu->slice->clpRngs().comp[compIdx];
   const int32_t shiftWeighted = std::max<int>(2, (IF_INTERNAL_PREC - clpRng.bd)) + log2WeightBase;
diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp
index 238596fd48c68b00ba8e26e255e3b0b83b0a4be5..06bcfca22d049ec16f20aaac53d77149c105aac5 100644
--- a/source/Lib/DecoderLib/CABACReader.cpp
+++ b/source/Lib/DecoderLib/CABACReader.cpp
@@ -3158,7 +3158,7 @@ void CABACReader::transform_tree( CodingStructure &cs, Partitioner &partitioner,
         bool lastCbfIsInferred = false;
         if( cu.ispMode )
         {
-          uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> g_aucLog2[tu.lheight()] : cu.lwidth() >> g_aucLog2[tu.lwidth()];
+          uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> floorLog2(tu.lheight()) : cu.lwidth() >> floorLog2(tu.lwidth());
           if( subTuCounter == nTus - 1 )
           {
             TransformUnit* tuPointer = cu.firstTU;
@@ -3353,7 +3353,7 @@ void CABACReader::transform_unit( TransformUnit& tu, CUCtx& cuCtx, ChromaCbfs& c
       bool lastCbfIsInferred = false;
       if (cu.ispMode)
       {
-        uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> g_aucLog2[tu.lheight()] : cu.lwidth() >> g_aucLog2[tu.lwidth()];
+        uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> floorLog2(tu.lheight()) : cu.lwidth() >> floorLog2(tu.lwidth());
         if (subTuCounter == nTus - 1)
         {
           TransformUnit* tuPointer = cu.firstTU;
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 1fe4f556917106ea6f5dc54e40017ae0d4caff5c..ac9997d2eecb1cd5699d3aca2612c4e3ef4fa154 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -546,7 +546,7 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS, ParameterSetManager *parameterSetMana
       const uint32_t tileRowsMinus1 = pcPPS->getNumTileRowsMinus1();
       const uint32_t numSlicesInPic = pcPPS->getNumSlicesInPicMinus1() + 1;
       const uint32_t numTilesInPic = (tileColumnsMinus1 + 1) * (tileRowsMinus1 + 1);
-      int codeLength = (int)ceil(log2(numTilesInPic));
+      int codeLength = ceilLog2(numTilesInPic);
       int codeLength2 = codeLength;
       if (numSlicesInPic > 0)
       {
@@ -559,7 +559,7 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS, ParameterSetManager *parameterSetMana
           {
             READ_CODE( codeLength, uiCode, "top_left_brick_idx" );
             topLeft[i] = uiCode;
-            codeLength2 = (int)ceil(log2((numTilesInPic - topLeft[i] < 2) ? 2 : numTilesInPic - topLeft[i]));  //Bugfix
+            codeLength2 = ceilLog2((numTilesInPic - topLeft[i] < 2) ? 2 : numTilesInPic - topLeft[i]);
           }
           READ_CODE( codeLength2, uiCode, "bottom_right_brick_idx_delta");
           bottomRight[i] = topLeft[i] + uiCode;
@@ -652,7 +652,7 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS, ParameterSetManager *parameterSetMana
 #else
     uint32_t picWidth = parameterSetManager->getSPS( pcPPS->getSPSId() )->getPicWidthInLumaSamples(); // pcPPS->getPicWidthInLumaSamples();
 #endif
-    int numBits = (int)ceil(log2(picWidth) - 3);
+    int numBits = ceilLog2(picWidth) - 3;
     for( unsigned i = 0; i < pcPPS->getNumVerVirtualBoundaries(); i++ )
     {
       READ_CODE( numBits, uiCode, "pps_virtual_boundaries_pos_x" ); pcPPS->setVirtualBoundariesPosX( uiCode << 3, i );
@@ -663,7 +663,7 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS, ParameterSetManager *parameterSetMana
 #else
     uint32_t picHeight = parameterSetManager->getSPS( pcPPS->getSPSId() )->getPicHeightInLumaSamples(); // pcPPS->getPicHeightInLumaSamples();
 #endif
-    numBits = (int)ceil(log2(picHeight) - 3);
+    numBits = ceilLog2(picHeight) - 3;
     for( unsigned i = 0; i < pcPPS->getNumHorVirtualBoundaries(); i++ )
     {
       READ_CODE( numBits, uiCode, "pps_virtual_boundaries_pos_y" ); pcPPS->setVirtualBoundariesPosY( uiCode << 3, i );
@@ -855,7 +855,7 @@ void HLSyntaxReader::parseAlfAps( APS* aps )
     if (param.numLumaFilters > 1)
     {
 #if JVET_O0491_HLS_CLEANUP
-      const int length =  (int)ceil(log2(param.numLumaFilters));
+      const int length =  ceilLog2(param.numLumaFilters);
 #endif
       for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++)
       {
@@ -1790,7 +1790,7 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para
       {
         if (sps->getNumRPL0() > 1)
         {
-          int numBits = (int)ceil(log2(sps->getNumRPL0()));
+          int numBits = ceilLog2(sps->getNumRPL0());
           READ_CODE(numBits, uiCode, "ref_pic_list_idx[0]");
           pcSlice->setRPL0idx(uiCode);
           pcSlice->setRPL0(sps->getRPLList0()->getReferencePictureList(uiCode));
@@ -1845,7 +1845,7 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para
         {
           if (sps->getNumRPL1() > 1)
           {
-            int numBits = (int)ceil(log2(sps->getNumRPL1()));
+            int numBits = ceilLog2(sps->getNumRPL1());
             READ_CODE(numBits, uiCode, "ref_pic_list_idx[1]");
             pcSlice->setRPL1idx(uiCode);
             pcSlice->setRPL1(sps->getRPLList1()->getReferencePictureList(uiCode));
diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp
index 6c3f5cba968265571ec699d0f2faaf18e0e32dcd..c07ab10fb53a69d83394b8629c0a5c2dae49a896 100644
--- a/source/Lib/EncoderLib/CABACWriter.cpp
+++ b/source/Lib/EncoderLib/CABACWriter.cpp
@@ -2922,7 +2922,7 @@ void CABACWriter::transform_tree( const CodingStructure& cs, Partitioner& partit
         bool lastCbfIsInferred = false;
         if( cu.ispMode )
         {
-          uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> g_aucLog2[tu.lheight()] : cu.lwidth() >> g_aucLog2[tu.lwidth()];
+          uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> floorLog2(tu.lheight()) : cu.lwidth() >> floorLog2(tu.lwidth());
           if( subTuCounter == nTus - 1 )
           {
             TransformUnit* tuPointer = cu.firstTU;
@@ -3137,7 +3137,7 @@ void CABACWriter::transform_unit( const TransformUnit& tu, CUCtx& cuCtx, ChromaC
       bool lastCbfIsInferred = false;
       if (cu.ispMode)
       {
-        uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> g_aucLog2[tu.lheight()] : cu.lwidth() >> g_aucLog2[tu.lwidth()];
+        uint32_t nTus = cu.ispMode == HOR_INTRA_SUBPARTITIONS ? cu.lheight() >> floorLog2(tu.lheight()) : cu.lwidth() >> floorLog2(tu.lwidth());
         if (subTuCounter == nTus - 1)
         {
           TransformUnit* tuPointer = cu.firstTU;
diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp
index a840d58bbad8b6f0f356e16c837c104113da6ac3..7b4282223fa5062e17ffd285edfda66c6bb6d072 100644
--- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp
+++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp
@@ -1618,7 +1618,7 @@ int EncAdaptiveLoopFilter::getNonFilterCoeffRate( AlfParam& alfParam )
   if( alfParam.numLumaFilters > 1 )
   {
 #if JVET_O0491_HLS_CLEANUP
-    const int coeffLength = (int)ceil(log2(alfParam.numLumaFilters));
+    const int coeffLength = ceilLog2(alfParam.numLumaFilters);
 #endif
     for( int i = 0; i < MAX_NUM_ALF_CLASSES; i++ )
     {
diff --git a/source/Lib/EncoderLib/EncCu.cpp b/source/Lib/EncoderLib/EncCu.cpp
index 343329c65c01f87338ad0520043ef36e16f1ed7c..508360570e7dc38216653192fa4cd077966c6575 100644
--- a/source/Lib/EncoderLib/EncCu.cpp
+++ b/source/Lib/EncoderLib/EncCu.cpp
@@ -1769,7 +1769,7 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
     if( m_pcEncCfg->getUseFastLCTU() )
     {
       unsigned minDepth = 0;
-      unsigned maxDepth = g_aucLog2[tempCS->sps->getCTUSize()] - g_aucLog2[tempCS->sps->getMinQTSize(slice.getSliceType(), partitioner.chType)];
+      unsigned maxDepth = floorLog2(tempCS->sps->getCTUSize()) - floorLog2(tempCS->sps->getMinQTSize(slice.getSliceType(), partitioner.chType));
 
       if( auto ad = dynamic_cast<AdaptiveDepthPartitioner*>( &partitioner ) )
       {
@@ -2168,7 +2168,7 @@ void EncCu::xCheckRDCostIntra( CodingStructure *&tempCS, CodingStructure *&bestC
                 CodingUnit &cu = *bestCS->cus.front();
                 if( cu.firstTU->mtsIdx == MTS_SKIP )
                 {
-                  if( ( g_aucLog2[ cu.firstTU->blocks[ COMPONENT_Y ].width ] + g_aucLog2[ cu.firstTU->blocks[ COMPONENT_Y ].height ] ) >= 6 )
+                  if( ( floorLog2( cu.firstTU->blocks[ COMPONENT_Y ].width ) + floorLog2( cu.firstTU->blocks[ COMPONENT_Y ].height ) ) >= 6 )
                   {
                     endLfnstIdx = 0;
                   }
@@ -2189,7 +2189,7 @@ void EncCu::xCheckRDCostIntra( CodingStructure *&tempCS, CodingStructure *&bestC
 #if JVET_O0502_ISP_CLEANUP
               double threshold = 1.4;
 #else
-              double nSamples  = ( double ) ( cu.lwidth() << g_aucLog2[ cu.lheight() ] );
+              double nSamples  = ( double ) ( cu.lwidth() << floorLog2( cu.lheight() ) );
               double threshold = 1 + 1.4 / sqrt( nSamples );
 #endif
 
@@ -3280,7 +3280,7 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru
 
     PredictionUnit &pu  = tempCS->addPU( cu, partitioner.chType );
 
-    if( abs(g_aucLog2[cu.lwidth()] - g_aucLog2[cu.lheight()]) >= 2 )
+    if( abs(floorLog2(cu.lwidth()) - floorLog2(cu.lheight())) >= 2 )
     {
       numTriangleCandidate = 30;
     }
diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp
index f755988ba2463776a8f6b097fc8895d8f014a4dd..fe1ab579211044436c5fa141faea09b88bc53292 100644
--- a/source/Lib/EncoderLib/EncGOP.cpp
+++ b/source/Lib/EncoderLib/EncGOP.cpp
@@ -2447,9 +2447,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic,
     {
       const PreCalcValues &pcv = *pcPic->cs->pcv;
 #if MAX_TB_SIZE_SIGNALLING
-      const unsigned   mtsLog2 = (unsigned)g_aucLog2[std::min (pcPic->cs->sps->getMaxTbSize(), pcv.maxCUWidth)];
+      const unsigned   mtsLog2 = (unsigned)floorLog2(std::min (pcPic->cs->sps->getMaxTbSize(), pcv.maxCUWidth));
 #else
-      const unsigned   mtsLog2 = (unsigned)g_aucLog2[std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth)];
+      const unsigned   mtsLog2 = (unsigned)floorLog2(std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth));
 #endif
       pcPic->m_subCtuQP.resize ((pcv.maxCUWidth >> mtsLog2) * (pcv.maxCUHeight >> mtsLog2));
     }
diff --git a/source/Lib/EncoderLib/EncModeCtrl.cpp b/source/Lib/EncoderLib/EncModeCtrl.cpp
index da2b08387bb911a308f332f4583de7a01d1e552b..585a7d1e47647127614b8bb162fb06a0be1feaee 100644
--- a/source/Lib/EncoderLib/EncModeCtrl.cpp
+++ b/source/Lib/EncoderLib/EncModeCtrl.cpp
@@ -1147,7 +1147,7 @@ void EncModeCtrlMTnoRQT::initCULevel( Partitioner &partitioner, const CodingStru
 {
   // Min/max depth
   unsigned minDepth = 0;
-  unsigned maxDepth = g_aucLog2[cs.sps->getCTUSize()] - g_aucLog2[cs.sps->getMinQTSize( m_slice->getSliceType(), partitioner.chType )];
+  unsigned maxDepth = floorLog2(cs.sps->getCTUSize()) - floorLog2(cs.sps->getMinQTSize( m_slice->getSliceType(), partitioner.chType ));
   if( m_pcEncCfg->getUseFastLCTU() )
   {
     if( auto adPartitioner = dynamic_cast<AdaptiveDepthPartitioner*>( &partitioner ) )
@@ -1218,9 +1218,9 @@ void EncModeCtrlMTnoRQT::initCULevel( Partitioner &partitioner, const CodingStru
       {
         const Position    &pos = partitioner.currQgPos;
 #if MAX_TB_SIZE_SIGNALLING
-        const unsigned mtsLog2 = (unsigned)g_aucLog2[std::min (cs.sps->getMaxTbSize(), pcv.maxCUWidth)];
+        const unsigned mtsLog2 = (unsigned)floorLog2(std::min (cs.sps->getMaxTbSize(), pcv.maxCUWidth));
 #else
-        const unsigned mtsLog2 = (unsigned)g_aucLog2[std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth)];
+        const unsigned mtsLog2 = (unsigned)floorLog2(std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth));
 #endif
         const unsigned  stride = pcv.maxCUWidth >> mtsLog2;
 
diff --git a/source/Lib/EncoderLib/EncReshape.cpp b/source/Lib/EncoderLib/EncReshape.cpp
index 5a4b1bbd4569aa14372c4e603eba22ba314e153e..710dbf2559492342c6effa9667da404d2dbe831e 100644
--- a/source/Lib/EncoderLib/EncReshape.cpp
+++ b/source/Lib/EncoderLib/EncReshape.cpp
@@ -2196,7 +2196,7 @@ void EncReshape::adjustLmcsPivot()
   int bdShift = m_lumaBD - 10;
   int totCW = bdShift != 0 ? (bdShift > 0 ? m_reshapeLUTSize / (1 << bdShift) : m_reshapeLUTSize * (1 << (-bdShift))) : m_reshapeLUTSize;
   int orgCW = totCW / PIC_CODE_CW_BINS;
-  int log2SegSize = g_aucLog2[LMCS_SEG_SIZE];
+  int log2SegSize = floorLog2(LMCS_SEG_SIZE);
 
   m_reshapePivot[0] = 0;
   for (int i = 0; i < PIC_CODE_CW_BINS; i++)
diff --git a/source/Lib/EncoderLib/EncSlice.cpp b/source/Lib/EncoderLib/EncSlice.cpp
index 3f3d7199bf716f0b3476aac035778c25018b9d88..690a187a9cadd5ee5daf84bd8b97907ba6cdb010 100644
--- a/source/Lib/EncoderLib/EncSlice.cpp
+++ b/source/Lib/EncoderLib/EncSlice.cpp
@@ -1091,7 +1091,7 @@ static int applyQPAdaptationSubCtu (CodingStructure &cs, const UnitArea ctuArea,
 #else
     const unsigned     mts = std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth);
 #endif
-    const unsigned mtsLog2 = (unsigned)g_aucLog2[mts];
+    const unsigned mtsLog2 = (unsigned)floorLog2(mts);
     const unsigned  stride = pcv.maxCUWidth >> mtsLog2;
     unsigned numAct = 0;    // number of block activities
     double   sumAct = 0.0; // sum of all block activities
diff --git a/source/Lib/EncoderLib/InterSearch.cpp b/source/Lib/EncoderLib/InterSearch.cpp
index a4733f50917e3a4728baae9f1088d3c6d249bd6f..6d54e9e9fac378047584f3adc412593e08294d10 100644
--- a/source/Lib/EncoderLib/InterSearch.cpp
+++ b/source/Lib/EncoderLib/InterSearch.cpp
@@ -1447,7 +1447,7 @@ void InterSearch::xSetIntraSearchRange(PredictionUnit& pu, int iRoiWidth, int iR
   const int cuPelY = pu.Y().y;
 
   const int lcuWidth = pu.cs->slice->getSPS()->getMaxCUWidth();
-  const int ctuSizeLog2 = g_aucLog2[lcuWidth];
+  const int ctuSizeLog2 = floorLog2(lcuWidth);
   int numLeftCTUs = (1 << ((7 - ctuSizeLog2) << 1)) - ((ctuSizeLog2 < 7) ? 1 : 0);
 
   srLeft = -(numLeftCTUs * lcuWidth + (cuPelX % lcuWidth));
@@ -1840,12 +1840,12 @@ bool InterSearch::xRectHashInterEstimation(PredictionUnit& pu, RefPicList& bestR
   if (height < width)
   {
     isHorizontal = true;
-    baseNum = 1 << (g_aucLog2[width] - g_aucLog2[height]);
+    baseNum = 1 << (floorLog2(width) - floorLog2(height));
   }
   else
   {
     isHorizontal = false;
-    baseNum = 1 << (g_aucLog2[height] - g_aucLog2[width]);
+    baseNum = 1 << (floorLog2(height) - floorLog2(width));
   }
 
   int xPos = pu.cu->lumaPos().x;
@@ -4906,8 +4906,8 @@ void InterSearch::xPredAffineInterSearch( PredictionUnit&       pu,
           int mvScaleHor = nbMv[0].getHor() << shift;
           int mvScaleVer = nbMv[0].getVer() << shift;
           Mv dMv = nbMv[1] - nbMv[0];
-          dMvHorX = dMv.getHor() << (shift - g_aucLog2[mvInfo->w]);
-          dMvHorY = dMv.getVer() << (shift - g_aucLog2[mvInfo->w]);
+          dMvHorX = dMv.getHor() << (shift - floorLog2(mvInfo->w));
+          dMvHorY = dMv.getVer() << (shift - floorLog2(mvInfo->w));
           dMvVerX = -dMvHorY;
           dMvVerY = dMvHorX;
           vx = mvScaleHor + dMvHorX * (pu.Y().x - mvInfo->x) + dMvVerX * (pu.Y().y - mvInfo->y);
@@ -4954,8 +4954,8 @@ void InterSearch::xPredAffineInterSearch( PredictionUnit&       pu,
         mvAffine4Para[iRefList][iRefIdxTemp][1].roundAffinePrecInternal2Amvr(pu.cu->imv);
 
         int shift = MAX_CU_DEPTH;
-        int vx2 = (mvFour[0].getHor() << shift) - ((mvFour[1].getVer() - mvFour[0].getVer()) << (shift + g_aucLog2[pu.lheight()] - g_aucLog2[pu.lwidth()]));
-        int vy2 = (mvFour[0].getVer() << shift) + ((mvFour[1].getHor() - mvFour[0].getHor()) << (shift + g_aucLog2[pu.lheight()] - g_aucLog2[pu.lwidth()]));
+        int vx2 = (mvFour[0].getHor() << shift) - ((mvFour[1].getVer() - mvFour[0].getVer()) << (shift + floorLog2(pu.lheight()) - floorLog2(pu.lwidth())));
+        int vy2 = (mvFour[0].getVer() << shift) + ((mvFour[1].getHor() - mvFour[0].getHor()) << (shift + floorLog2(pu.lheight()) - floorLog2(pu.lwidth())));
         int offset = (1 << (shift - 1));
         vx2 = (vx2 + offset - (vx2 >= 0)) >> shift;
         vy2 = (vy2 + offset - (vy2 >= 0)) >> shift;
@@ -8232,7 +8232,7 @@ uint64_t InterSearch::xCalcPuMeBits(PredictionUnit& pu)
 #if JVET_O1170_IBC_VIRTUAL_BUFFER
 bool InterSearch::searchBv(PredictionUnit& pu, int xPos, int yPos, int width, int height, int picWidth, int picHeight, int xBv, int yBv, int ctuSize)
 {
-  const int ctuSizeLog2 = g_aucLog2[ctuSize];
+  const int ctuSizeLog2 = floorLog2(ctuSize);
 
   int refRightX = xPos + xBv + width - 1;
   int refBottomY = yPos + yBv + height - 1;
diff --git a/source/Lib/EncoderLib/IntraSearch.cpp b/source/Lib/EncoderLib/IntraSearch.cpp
index ff4ee005fdc8f054affc44e19ce7330ac97088f5..4c72706cfc6697d96294961fec455dec7f3cb81e 100644
--- a/source/Lib/EncoderLib/IntraSearch.cpp
+++ b/source/Lib/EncoderLib/IntraSearch.cpp
@@ -290,8 +290,8 @@ bool IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
 {
   CodingStructure       &cs            = *cu.cs;
   const SPS             &sps           = *cs.sps;
-  const uint32_t             uiWidthBit    = g_aucLog2[partitioner.currArea().lwidth() ];
-  const uint32_t             uiHeightBit   =                   g_aucLog2[partitioner.currArea().lheight()];
+  const uint32_t             uiWidthBit    = floorLog2(partitioner.currArea().lwidth() );
+  const uint32_t             uiHeightBit   =                   floorLog2(partitioner.currArea().lheight());
 
   // Lambda calculation at equivalent Qp of 4 is recommended because at that Qp, the quantization divisor is 1.
   const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda(cu.transQuantBypass) * FRAC_BITS_SCALE;
@@ -366,8 +366,8 @@ bool IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
     m_regIntraRDListWithCosts.clear();
     m_ispTestedModes.clear();
     //save the number of subpartitions
-    m_ispTestedModes.numTotalParts[0] = (int)height >> g_aucLog2[CU::getISPSplitDim(width, height, TU_1D_HORZ_SPLIT)];
-    m_ispTestedModes.numTotalParts[1] = (int)width >> g_aucLog2[CU::getISPSplitDim(width, height, TU_1D_VERT_SPLIT)];
+    m_ispTestedModes.numTotalParts[0] = (int)height >> floorLog2(CU::getISPSplitDim(width, height, TU_1D_HORZ_SPLIT));
+    m_ispTestedModes.numTotalParts[1] = (int)width >> floorLog2(CU::getISPSplitDim(width, height, TU_1D_VERT_SPLIT));
 #else
     //variables for the full RD list without MRL modes
     m_rdModeListWithoutMrl      .clear();
@@ -469,9 +469,9 @@ bool IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
         if( testMip)
         {
 #if JVET_O0925_MIP_SIMPLIFICATIONS
-          numModesForFullRD += fastMip? std::max(numModesForFullRD, g_aucLog2[std::min(pu.lwidth(), pu.lheight())] - 1) : numModesForFullRD;
+          numModesForFullRD += fastMip? std::max(numModesForFullRD, floorLog2(std::min(pu.lwidth(), pu.lheight())) - 1) : numModesForFullRD;
 #else
-          numModesForFullRD += fastMip? std::max(2, g_aucLog2[std::min(pu.lwidth(), pu.lheight())] - 1) : numModesForFullRD;
+          numModesForFullRD += fastMip? std::max(2, floorLog2(std::min(pu.lwidth(), pu.lheight())) - 1) : numModesForFullRD;
 #endif
         }
         const int numHadCand = (testMip ? 2 : 1) * 3;
@@ -2484,7 +2484,7 @@ void IntraSearch::xEncSubdivCbfQT( CodingStructure &cs, Partitioner &partitioner
       if( ispType != TU_NO_ISP )
       {
         bool rootCbfSoFar = false;
-        uint32_t nTus = currCU.ispMode == HOR_INTRA_SUBPARTITIONS ? currCU.lheight() >> g_aucLog2[currTU.lheight()] : currCU.lwidth() >> g_aucLog2[currTU.lwidth()];
+        uint32_t nTus = currCU.ispMode == HOR_INTRA_SUBPARTITIONS ? currCU.lheight() >> floorLog2(currTU.lheight()) : currCU.lwidth() >> floorLog2(currTU.lwidth());
         if( subTuCounter == nTus - 1 )
         {
           TransformUnit* tuPointer = currCU.firstTU;
@@ -3711,7 +3711,7 @@ bool IntraSearch::xRecurIntraCodingLumaQT( CodingStructure &cs, Partitioner &par
         {
           //more restrictive exit condition
           bool tuIsDividedInRows = CU::divideTuInRows( cu );
-          int nSubPartitions = tuIsDividedInRows ? cu.lheight() >> g_aucLog2[cu.firstTU->lheight()] : cu.lwidth() >> g_aucLog2[cu.firstTU->lwidth()];
+          int nSubPartitions = tuIsDividedInRows ? cu.lheight() >> floorLog2(cu.firstTU->lheight()) : cu.lwidth() >> floorLog2(cu.firstTU->lwidth());
           double threshold = nSubPartitions == 2 ? 0.95 : subTuCounter == 1 ? 0.83 : 0.91;
           if( subTuCounter < nSubPartitions && csSplit->cost > bestCostSoFar*threshold )
           {
@@ -4563,7 +4563,7 @@ void IntraSearch::xGetNextISPMode(ModeInfo& modeInfo, const ModeInfo* lastMode,
       const int angWindowSize = 5;
       int       numSubPartsLeftMode, numSubPartsRightMode, numSubPartsRefMode, leftIntraMode = -1, rightIntraMode = -1;
       int       windowSize = candidate.modeId > DC_IDX ? angWindowSize : 1;
-      int       numSamples = cuSize.width << g_aucLog2[cuSize.height];
+      int       numSamples = cuSize.width << floorLog2(cuSize.height);
       int       numSubPartsLimit = numSamples >= 256 ? maxNumSubPartitions - 1 : 2;
 
       xFindAlreadyTestedNearbyIntraModes((int)candidate.modeId, &leftIntraMode, &rightIntraMode, (ISPType)candidate.ispMod, windowSize);
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 327f3fa486f047927334987725cce1bb57ec61cf..a6f1441865057249fcd4c209ff8b3ab7efb0b8b6 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -322,14 +322,14 @@ void HLSWriter::codePPS( const PPS* pcPPS )
       WRITE_UVLC( pcPPS->getNumSlicesInPicMinus1(), "num_slices_in_pic_minus1" );
       int numSlicesInPic = pcPPS->getNumSlicesInPicMinus1() + 1;
       int numTilesInPic = (pcPPS->getNumTileColumnsMinus1() + 1) * (pcPPS->getNumTileRowsMinus1() + 1);
-      int codeLength = (int)ceil(log2(numTilesInPic));
+      int codeLength = ceilLog2(numTilesInPic);
       int codeLength2 = codeLength;
       for (int i = 0; i < numSlicesInPic; ++i)
       {
         if (i > 0)
         {
           WRITE_CODE(pcPPS->getTopLeftBrickIdx(i), codeLength, "top_left_brick_idx ");
-          codeLength2 = (int)ceil(log2((numTilesInPic - pcPPS->getTopLeftBrickIdx(i) < 2) ? 2 : numTilesInPic - pcPPS->getTopLeftBrickIdx(i)));
+          codeLength2 = ceilLog2((numTilesInPic - pcPPS->getTopLeftBrickIdx(i) < 2) ? 2 : numTilesInPic - pcPPS->getTopLeftBrickIdx(i));
         }
         WRITE_CODE(pcPPS->getBottomRightBrickIdx(i) - pcPPS->getTopLeftBrickIdx(i), codeLength2, "bottom_right_brick_idx_delta");
       }
@@ -383,13 +383,13 @@ void HLSWriter::codePPS( const PPS* pcPPS )
   if( pcPPS->getLoopFilterAcrossVirtualBoundariesDisabledFlag() )
   {
     WRITE_CODE( pcPPS->getNumVerVirtualBoundaries(), 2,                              "pps_num_ver_virtual_boundaries");
-    int numBits = (int)ceil(log2(pcPPS->pcv->lumaWidth) - 3);
+    int numBits = ceilLog2(pcPPS->pcv->lumaWidth) - 3;
     for( unsigned i = 0; i < pcPPS->getNumVerVirtualBoundaries(); i++ )
     {
       WRITE_CODE( pcPPS->getVirtualBoundariesPosX( i ) >> 3, numBits,                "pps_virtual_boundaries_pos_x" );
     }
     WRITE_CODE( pcPPS->getNumHorVirtualBoundaries(), 2,                              "pps_num_hor_virtual_boundaries");
-    numBits = (int)ceil(log2(pcPPS->pcv->lumaHeight) - 3);
+    numBits = ceilLog2(pcPPS->pcv->lumaHeight) - 3;
     for( unsigned i = 0; i < pcPPS->getNumHorVirtualBoundaries(); i++ )
     {
       WRITE_CODE( pcPPS->getVirtualBoundariesPosY( i ) >> 3, numBits,                "pps_virtual_boundaries_pos_y" );
@@ -535,7 +535,7 @@ void HLSWriter::codeAlfAps( APS* pcAPS )
     if (param.numLumaFilters > 1)
     {
 #if JVET_O0491_HLS_CLEANUP
-      const int length =  (int)ceil(log2( param.numLumaFilters));
+      const int length =  ceilLog2( param.numLumaFilters);
 #endif
       for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++)
       {
@@ -836,34 +836,34 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
   }
   WRITE_FLAG(pcSPS->getUseDualITree(), "qtbtt_dual_tree_intra_flag");
 #if JVET_O0526_MIN_CTU_SIZE
-  WRITE_CODE(g_aucLog2[pcSPS->getCTUSize()] - 5, 2, "log2_ctu_size_minus5");
+  WRITE_CODE(floorLog2(pcSPS->getCTUSize()) - 5, 2, "log2_ctu_size_minus5");
 #else
-  WRITE_UVLC(g_aucLog2[pcSPS->getCTUSize()] - MIN_CU_LOG2, "log2_ctu_size_minus2");
+  WRITE_UVLC(floorLog2(pcSPS->getCTUSize()) - MIN_CU_LOG2, "log2_ctu_size_minus2");
 #endif
   WRITE_UVLC(pcSPS->getLog2MinCodingBlockSize() - 2, "log2_min_luma_coding_block_size_minus2");
   WRITE_FLAG(pcSPS->getSplitConsOverrideEnabledFlag(), "partition_constraints_override_enabled_flag");
-  WRITE_UVLC(g_aucLog2[pcSPS->getMinQTSize(I_SLICE)] - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_intra_slice_luma");
-  WRITE_UVLC(g_aucLog2[pcSPS->getMinQTSize(B_SLICE)] - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_inter_slice");
+  WRITE_UVLC(floorLog2(pcSPS->getMinQTSize(I_SLICE)) - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_intra_slice_luma");
+  WRITE_UVLC(floorLog2(pcSPS->getMinQTSize(B_SLICE)) - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_inter_slice");
   WRITE_UVLC(pcSPS->getMaxBTDepth(), "sps_max_mtt_hierarchy_depth_inter_slice");
   WRITE_UVLC(pcSPS->getMaxBTDepthI(), "sps_max_mtt_hierarchy_depth_intra_slice_luma");
   if (pcSPS->getMaxBTDepthI() != 0)
   {
-    WRITE_UVLC(g_aucLog2[pcSPS->getMaxBTSizeI()] - g_aucLog2[pcSPS->getMinQTSize(I_SLICE)], "sps_log2_diff_max_bt_min_qt_intra_slice_luma");
-    WRITE_UVLC(g_aucLog2[pcSPS->getMaxTTSizeI()] - g_aucLog2[pcSPS->getMinQTSize(I_SLICE)], "sps_log2_diff_max_tt_min_qt_intra_slice_luma");
+    WRITE_UVLC(floorLog2(pcSPS->getMaxBTSizeI()) - floorLog2(pcSPS->getMinQTSize(I_SLICE)), "sps_log2_diff_max_bt_min_qt_intra_slice_luma");
+    WRITE_UVLC(floorLog2(pcSPS->getMaxTTSizeI()) - floorLog2(pcSPS->getMinQTSize(I_SLICE)), "sps_log2_diff_max_tt_min_qt_intra_slice_luma");
   }
   if (pcSPS->getMaxBTDepth() != 0)
   {
-    WRITE_UVLC(g_aucLog2[pcSPS->getMaxBTSize()] - g_aucLog2[pcSPS->getMinQTSize(B_SLICE)], "sps_log2_diff_max_bt_min_qt_inter_slice");
-    WRITE_UVLC(g_aucLog2[pcSPS->getMaxTTSize()] - g_aucLog2[pcSPS->getMinQTSize(B_SLICE)], "sps_log2_diff_max_tt_min_qt_inter_slice");
+    WRITE_UVLC(floorLog2(pcSPS->getMaxBTSize()) - floorLog2(pcSPS->getMinQTSize(B_SLICE)), "sps_log2_diff_max_bt_min_qt_inter_slice");
+    WRITE_UVLC(floorLog2(pcSPS->getMaxTTSize()) - floorLog2(pcSPS->getMinQTSize(B_SLICE)), "sps_log2_diff_max_tt_min_qt_inter_slice");
   }
   if (pcSPS->getUseDualITree())
   {
-    WRITE_UVLC(g_aucLog2[pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)] - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_intra_slice_chroma");
+    WRITE_UVLC(floorLog2(pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)) - pcSPS->getLog2MinCodingBlockSize(), "sps_log2_diff_min_qt_min_cb_intra_slice_chroma");
     WRITE_UVLC(pcSPS->getMaxBTDepthIChroma(), "sps_max_mtt_hierarchy_depth_intra_slice_chroma");
     if (pcSPS->getMaxBTDepthIChroma() != 0)
     {
-      WRITE_UVLC(g_aucLog2[pcSPS->getMaxBTSizeIChroma()] - g_aucLog2[pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)], "sps_log2_diff_max_bt_min_qt_intra_slice_chroma");
-      WRITE_UVLC(g_aucLog2[pcSPS->getMaxTTSizeIChroma()] - g_aucLog2[pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)], "sps_log2_diff_max_tt_min_qt_intra_slice_chroma");
+      WRITE_UVLC(floorLog2(pcSPS->getMaxBTSizeIChroma()) - floorLog2(pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)), "sps_log2_diff_max_bt_min_qt_intra_slice_chroma");
+      WRITE_UVLC(floorLog2(pcSPS->getMaxTTSizeIChroma()) - floorLog2(pcSPS->getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA)), "sps_log2_diff_max_tt_min_qt_intra_slice_chroma");
     }
   }
 
@@ -1514,27 +1514,27 @@ void HLSWriter::codeSliceHeader         ( Slice* pcSlice )
       WRITE_FLAG(pcSlice->getSplitConsOverrideFlag() ? 1 : 0, "partition_constrainst_override_flag");
       if (pcSlice->getSplitConsOverrideFlag())
       {
-        WRITE_UVLC(g_aucLog2[pcSlice->getMinQTSize()] - pcSlice->getSPS()->getLog2MinCodingBlockSize(), "log2_diff_min_qt_min_cb");
+        WRITE_UVLC(floorLog2(pcSlice->getMinQTSize()) - pcSlice->getSPS()->getLog2MinCodingBlockSize(), "log2_diff_min_qt_min_cb");
         WRITE_UVLC(pcSlice->getMaxBTDepth(), "max_bt_depth");
         if (pcSlice->getMaxBTDepth() != 0)
         {
           CHECK(pcSlice->getMaxBTSize() < pcSlice->getMinQTSize(), "maxBtSize is smaller than minQtSize");
-          WRITE_UVLC(g_aucLog2[pcSlice->getMaxBTSize()] - g_aucLog2[pcSlice->getMinQTSize()], "log2_diff_max_bt_min_qt");
+          WRITE_UVLC(floorLog2(pcSlice->getMaxBTSize()) - floorLog2(pcSlice->getMinQTSize()), "log2_diff_max_bt_min_qt");
           CHECK(pcSlice->getMaxTTSize() < pcSlice->getMinQTSize(), "maxTtSize is smaller than minQtSize");
-          WRITE_UVLC(g_aucLog2[pcSlice->getMaxTTSize()] - g_aucLog2[pcSlice->getMinQTSize()], "log2_diff_max_tt_min_qt");
+          WRITE_UVLC(floorLog2(pcSlice->getMaxTTSize()) - floorLog2(pcSlice->getMinQTSize()), "log2_diff_max_tt_min_qt");
         }
         if (
           pcSlice->isIntra() && pcSlice->getSPS()->getUseDualITree()
           )
         {
-          WRITE_UVLC(g_aucLog2[pcSlice->getMinQTSizeIChroma()] - pcSlice->getSPS()->getLog2MinCodingBlockSize(), "log2_diff_min_qt_min_cb_chroma");
+          WRITE_UVLC(floorLog2(pcSlice->getMinQTSizeIChroma()) - pcSlice->getSPS()->getLog2MinCodingBlockSize(), "log2_diff_min_qt_min_cb_chroma");
           WRITE_UVLC(pcSlice->getMaxBTDepthIChroma(), "max_mtt_hierarchy_depth_chroma");
           if (pcSlice->getMaxBTDepthIChroma() != 0)
           {
             CHECK(pcSlice->getMaxBTSizeIChroma() < pcSlice->getMinQTSizeIChroma(), "maxBtSizeC is smaller than minQtSizeC");
-            WRITE_UVLC(g_aucLog2[pcSlice->getMaxBTSizeIChroma()] - g_aucLog2[pcSlice->getMinQTSizeIChroma()], "log2_diff_max_bt_min_qt_chroma");
+            WRITE_UVLC(floorLog2(pcSlice->getMaxBTSizeIChroma()) - floorLog2(pcSlice->getMinQTSizeIChroma()), "log2_diff_max_bt_min_qt_chroma");
             CHECK(pcSlice->getMaxTTSizeIChroma() < pcSlice->getMinQTSizeIChroma(), "maxTtSizeC is smaller than minQtSizeC");
-            WRITE_UVLC(g_aucLog2[pcSlice->getMaxTTSizeIChroma()] - g_aucLog2[pcSlice->getMinQTSizeIChroma()], "log2_diff_max_tt_min_qt_chroma");
+            WRITE_UVLC(floorLog2(pcSlice->getMaxTTSizeIChroma()) - floorLog2(pcSlice->getMinQTSizeIChroma()), "log2_diff_max_tt_min_qt_chroma");
           }
         }
       }