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

Ximing Cheng chengximing1989 at foxmail.com
Tue Nov 10 17:34:57 CET 2015


# HG changeset patch
# User Ximing Cheng <ximingcheng at tencent.com>
# Date 1447173277 -28800
#      Wed Nov 11 00:34:37 2015 +0800
# Node ID 0590d13a9b93f8d05eac736e881c008245115f07
# Parent  f11b17b4656a85a15dc82fd04485fbf920848e4d
entropy: improve exp-Golomb code by CLZ

diff -r f11b17b4656a -r 0590d13a9b93 source/common/bitstream.cpp
--- a/source/common/bitstream.cpp	Fri Nov 06 16:04:23 2015 +0800
+++ b/source/common/bitstream.cpp	Wed Nov 11 00:34:37 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 = (uint32_t)(1 + idx * 2);
 
     // Take care of cases where length > 32
     m_bitIf->write(0, length >> 1);




More information about the x265-devel mailing list