[x265] [PATCH 4 of 6] improve by convert arithmetic(signed) shift to logic(unsigned) shift

Min Chen chenm003 at 163.com
Wed Jun 17 01:31:17 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1434495249 25200
# Node ID 03f1e3d7a8ff3555850cad6e2f1a3c0293becc24
# Parent  712c963c589f1d5940d7de352fcee27469b3eb7f
improve by convert arithmetic(signed) shift to logic(unsigned) shift
---
 source/common/quant.h      |   12 ++++++------
 source/encoder/entropy.cpp |    2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff -r 712c963c589f -r 03f1e3d7a8ff source/common/quant.h
--- a/source/common/quant.h	Tue Jun 16 15:54:03 2015 -0700
+++ b/source/common/quant.h	Tue Jun 16 15:54:09 2015 -0700
@@ -126,9 +126,9 @@
         const uint32_t sigPos = (uint32_t)(sigCoeffGroupFlag64 >> (cgBlkPos + 1)); // just need lowest 7-bits valid
 
         // TODO: instruction BT is faster, but _bittest64 still generate instruction 'BT m, r' in VS2012
-        const uint32_t sigRight = ((int32_t)(cgPosX - (trSizeCG - 1)) >> 31) & (sigPos & 1);
-        const uint32_t sigLower = ((int32_t)(cgPosY - (trSizeCG - 1)) >> 31) & (sigPos >> (trSizeCG - 2)) & 2;
-        return sigRight + sigLower;
+        const uint32_t sigRight = ((uint32_t)(cgPosX - (trSizeCG - 1)) >> 31) & sigPos;
+        const uint32_t sigLower = ((uint32_t)(cgPosY - (trSizeCG - 1)) >> 31) & (sigPos >> (trSizeCG - 1));
+        return sigRight + sigLower * 2;
     }
 
     /* Context derivation process of coeff_abs_significant_flag */
@@ -137,10 +137,10 @@
         X265_CHECK(cgBlkPos < 64, "cgBlkPos is too large\n");
         // NOTE: unsafe shift operator, see NOTE in calcPatternSigCtx
         const uint32_t sigPos = (uint32_t)(cgGroupMask >> (cgBlkPos + 1)); // just need lowest 8-bits valid
-        const uint32_t sigRight = ((int32_t)(cgPosX - (trSizeCG - 1)) >> 31) & sigPos;
-        const uint32_t sigLower = ((int32_t)(cgPosY - (trSizeCG - 1)) >> 31) & (sigPos >> (trSizeCG - 1));
+        const uint32_t sigRight = ((uint32_t)(cgPosX - (trSizeCG - 1)) >> 31) & sigPos;
+        const uint32_t sigLower = ((uint32_t)(cgPosY - (trSizeCG - 1)) >> 31) & (sigPos >> (trSizeCG - 1));
 
-        return (sigRight | sigLower) & 1;
+        return (sigRight | sigLower);
     }
 
     /* static methods shared with entropy.cpp */
diff -r 712c963c589f -r 03f1e3d7a8ff source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Tue Jun 16 15:54:03 2015 -0700
+++ b/source/encoder/entropy.cpp	Tue Jun 16 15:54:09 2015 -0700
@@ -1589,7 +1589,7 @@
 
         // encode significant_coeffgroup_flag
         const int cgBlkPos = codingParameters.scanCG[subSet];
-        const int cgPosY   = cgBlkPos >> (log2TrSize - MLS_CG_LOG2_SIZE);
+        const int cgPosY   = (uint32_t)cgBlkPos >> (log2TrSize - MLS_CG_LOG2_SIZE);
         const int cgPosX   = cgBlkPos & ((1 << (log2TrSize - MLS_CG_LOG2_SIZE)) - 1);
         const uint64_t cgBlkPosMask = ((uint64_t)1 << cgBlkPos);
 



More information about the x265-devel mailing list