[x265] [PATCH] entropy: improve exp-Golomb code by CLZ

Ximing Cheng chengximing1989 at foxmail.com
Tue Nov 10 09:47:42 CET 2015


# HG changeset patch
# User Ximing Cheng <ximingcheng at tencent.com>
# Date 1447145224 -28800
#      Tue Nov 10 16:47:04 2015 +0800
# Node ID 73414b349436eb0b4793021e4d130b1ac48177b5
# Parent  f11b17b4656a85a15dc82fd04485fbf920848e4d
entropy: improve exp-Golomb code by CLZ

diff -r f11b17b4656a -r 73414b349436 source/common/bitstream.cpp
--- a/source/common/bitstream.cpp	Fri Nov 06 16:04:23 2015 +0800
+++ b/source/common/bitstream.cpp	Tue Nov 10 16:47:04 2015 +0800
@@ -1,5 +1,6 @@
 #include "common.h"
 #include "bitstream.h"
+#include "threading.h"
 
 using namespace X265_NS;
 
@@ -112,16 +113,13 @@
 
 void SyntaxElementWriter::writeUvlc(uint32_t code)
 {
-    uint32_t length = 1;
-    uint32_t temp = ++code;
+    ++code;
 
-    X265_CHECK(temp, "writing -1 code, will cause infinite loop\n");
+    X265_CHECK(code, "writing -1 code, will cause infinite loop\n");
 
-    while (1 != temp)
-    {
-        temp >>= 1;
-        length += 2;
-    }
+    unsigned long idx;
+    CLZ(idx, code);
+    uint32_t length = 1 + (uint32_t)(idx << 1);
 
     // Take care of cases where length > 32
     m_bitIf->write(0, length >> 1);




More information about the x265-devel mailing list