[vlc-commits] opengl: use ctz() instead of ffsll()

Rémi Denis-Courmont git at videolan.org
Sun Feb 25 20:40:05 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 25 21:30:40 2018 +0200| [1d95200c2fc7481852c913708c17f1a9bb7e68c1] | committer: Rémi Denis-Courmont

opengl: use ctz() instead of ffsll()

When manipulating bit fields, zero-based ctz() is generally simpler
than one-based ffs().

By definition: ffs(x) = x ? (ctz(x) + 1) : 0

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1d95200c2fc7481852c913708c17f1a9bb7e68c1
---

 modules/video_output/opengl/converter_sw.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/modules/video_output/opengl/converter_sw.c b/modules/video_output/opengl/converter_sw.c
index 78d6843fb5..16ebf0cb3c 100644
--- a/modules/video_output/opengl/converter_sw.c
+++ b/modules/video_output/opengl/converter_sw.c
@@ -276,26 +276,19 @@ persistent_map(const opengl_tex_converter_t *tc, picture_t *pic)
     return VLC_SUCCESS;
 }
 
-/** Find next (bit) set */
-static int fnsll(unsigned long long x, unsigned i)
-{
-    if (i >= CHAR_BIT * sizeof (x))
-        return 0;
-    return ffsll(x & ~((1ULL << i) - 1));
-}
-
 static void
 persistent_release_gpupics(const opengl_tex_converter_t *tc, bool force)
 {
     struct priv *priv = tc->priv;
+    unsigned long long list = priv->persistent.list;
 
     /* Release all pictures that are not used by the GPU anymore */
-    for (unsigned i = ffsll(priv->persistent.list); i;
-         i = fnsll(priv->persistent.list, i))
+    while (list != 0)
     {
-        assert(priv->persistent.pics[i - 1] != NULL);
+        int i = ctz(list);
+        assert(priv->persistent.pics[i] != NULL);
 
-        picture_t *pic = priv->persistent.pics[i - 1];
+        picture_t *pic = priv->persistent.pics[i];
         picture_sys_t *picsys = pic->p_sys;
 
         assert(picsys->fence != NULL);
@@ -307,10 +300,11 @@ persistent_release_gpupics(const opengl_tex_converter_t *tc, bool force)
             tc->vt->DeleteSync(picsys->fence);
             picsys->fence = NULL;
 
-            priv->persistent.list &= ~(1ULL << (i - 1));
-            priv->persistent.pics[i - 1] = NULL;
+            priv->persistent.list &= ~(1ULL << i);
+            priv->persistent.pics[i] = NULL;
             picture_Release(pic);
         }
+        list &= ~(1ULL << i);
     }
 }
 



More information about the vlc-commits mailing list