[x265] [PATCH] weightsAnalyse: use CLZ to get a smaller denominator

Ximing Cheng chengximing1989 at foxmail.com
Sat May 7 16:16:31 CEST 2016


# HG changeset patch
# User Ximing Cheng <ximingcheng at tencent.com>
# Date 1462630574 -28800
#      Sat May 07 22:16:14 2016 +0800
# Node ID 1ca831b8f70601c740af3f41d679bfdec37dc091
# Parent  00ea3784bd36c164c5f799c998d7a09f2cb244bf
weightsAnalyse: use CLZ to get a smaller denominator

diff -r 00ea3784bd36 -r 1ca831b8f706 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Apr 28 09:59:30 2016 +0200
+++ b/source/encoder/slicetype.cpp	Sat May 07 22:16:14 2016 +0800
@@ -456,10 +456,13 @@
     COPY4_IF_LT(minscore, s, minscale, curScale, minoff, curOffset, found, 1);
 
     /* Use a smaller denominator if possible */
-    while (mindenom > 0 && !(minscale & 1))
+    if (mindenom > 0 && !(minscale & 1))
     {
-        mindenom--;
-        minscale >>= 1;
+        unsigned long idx;
+        CLZ(idx, minscale);
+        int shift = X265_MIN((int)idx, mindenom);
+        mindenom -= shift;
+        minscale >>= shift;
     }
 
     if (!found || (minscale == 1 << mindenom && minoff == 0) || (float)minscore / origscore > 0.998f)
diff -r 00ea3784bd36 -r 1ca831b8f706 source/encoder/weightPrediction.cpp
--- a/source/encoder/weightPrediction.cpp	Thu Apr 28 09:59:30 2016 +0200
+++ b/source/encoder/weightPrediction.cpp	Sat May 07 22:16:14 2016 +0800
@@ -31,6 +31,7 @@
 #include "slice.h"
 #include "mv.h"
 #include "bitstream.h"
+#include "threading.h"
 
 using namespace X265_NS;
 namespace {
@@ -456,10 +457,13 @@
             /* Use a smaller luma denominator if possible */
             if (!(plane || list))
             {
-                while (mindenom > 0 && !(minscale & 1))
+                if (mindenom > 0 && !(minscale & 1))
                 {
-                    mindenom--;
-                    minscale >>= 1;
+                    unsigned long idx;
+                    CLZ(idx, minscale);
+                    int shift = X265_MIN((int)idx, mindenom);
+                    mindenom -= shift;
+                    minscale >>= shift;
                 }
             }
 


More information about the x265-devel mailing list