[x265] [PATCH] entropy: add a mechanism to detect reads without writes in checked builds

Steve Borho steve at borho.org
Sun Oct 5 18:47:40 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1412527646 18000
#      Sun Oct 05 11:47:26 2014 -0500
# Node ID e34e0ddd2efcb41ab2a6ed29f0ec7fc5d6492a65
# Parent  34afcebca245fe8853c2aa4bc92ec4c01a5bfd49
entropy: add a mechanism to detect reads without writes in checked builds

diff -r 34afcebca245 -r e34e0ddd2efc source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Sun Oct 05 10:40:48 2014 -0500
+++ b/source/encoder/analysis.cpp	Sun Oct 05 11:47:26 2014 -0500
@@ -417,6 +417,18 @@
     Frame* pic = ctu->m_pic;
     uint32_t cuAddr = ctu->m_cuAddr;
 
+#if CHECKED_BUILD || _DEBUG
+    /* catch reads without previous writes */
+    for (int d = 0; d < NUM_FULL_DEPTH; d++)
+    {
+        m_rdContexts[d].cur.markInvalid();
+        m_rdContexts[d].next.markInvalid();
+        m_rdContexts[d].temp.markInvalid();
+        m_rdContexts[d].rqtRoot.markInvalid();
+        m_rdContexts[d].rqtTest.markInvalid();
+    }
+#endif
+
     m_rdContexts[0].cur.load(initialContext);
 
     if (ctu->m_slice->m_pps->bUseDQP)
diff -r 34afcebca245 -r e34e0ddd2efc source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Sun Oct 05 10:40:48 2014 -0500
+++ b/source/encoder/entropy.cpp	Sun Oct 05 11:47:26 2014 -0500
@@ -35,6 +35,7 @@
 
 Entropy::Entropy()
 {
+    markValid();
     m_fracBits = 0;
     X265_CHECK(sizeof(m_contextState) >= sizeof(m_contextState[0]) * MAX_OFF_CTX_MOD, "context state table is too small\n");
 }
@@ -1141,18 +1142,24 @@
 }
 
 // SBAC RD
-void  Entropy::loadIntraDirModeLuma(Entropy& src)
+void Entropy::loadIntraDirModeLuma(const Entropy& src)
 {
+    X265_CHECK(src.m_valid, "invalid copy source context\n");
+
     copyState(src);
 
     ::memcpy(&m_contextState[OFF_ADI_CTX], &src.m_contextState[OFF_ADI_CTX], sizeof(uint8_t) * NUM_ADI_CTX);
+    markValid();
 }
 
 void Entropy::copyFrom(const Entropy& src)
 {
+    X265_CHECK(src.m_valid, "invalid copy source context\n");
+
     copyState(src);
 
     memcpy(m_contextState, src.m_contextState, MAX_OFF_CTX_MOD * sizeof(uint8_t));
+    markValid();
 }
 
 void Entropy::codeMVPIdx(uint32_t symbol)
@@ -1925,7 +1932,10 @@
 /* Initialize our context information from the nominated source */
 void Entropy::copyContextsFrom(const Entropy& src)
 {
+    X265_CHECK(src.m_valid, "invalid copy source context\n");
+
     memcpy(m_contextState, src.m_contextState, MAX_OFF_CTX_MOD * sizeof(m_contextState[0]));
+    markValid();
 }
 
 void Entropy::start()
diff -r 34afcebca245 -r e34e0ddd2efc source/encoder/entropy.h
--- a/source/encoder/entropy.h	Sun Oct 05 10:40:48 2014 -0500
+++ b/source/encoder/entropy.h	Sun Oct 05 11:47:26 2014 -0500
@@ -124,15 +124,22 @@
         return uint32_t(m_fracBits >> 15);
     }
 
+#if CHECKED_BUILD || _DEBUG
+    bool m_valid;
+    void markInvalid()                 { m_valid = false; }
+    void markValid()                   { m_valid = true; }
+#else
+    void markValid()                   { }
+#endif
     void zeroFract()                   { m_fracBits = 0; }
     void resetBits();
     void resetEntropy(Slice *slice);
 
     // SBAC RD
     void load(const Entropy& src)            { copyFrom(src); }
-    void loadIntraDirModeLuma(Entropy& src);
     void store(Entropy& dest) const          { dest.copyFrom(*this); }
     void loadContexts(const Entropy& src)    { copyContextsFrom(src); }
+    void loadIntraDirModeLuma(const Entropy& src);
     void copyState(const Entropy& other);
 
     void codeVPS(VPS* vps);


More information about the x265-devel mailing list