[vlc-commits] [Git][videolan/vlc][master] access: jack: simplify previous power of 2 calculation

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Feb 16 15:51:34 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
a7c43747 by Tristan Matthews at 2023-02-16T08:21:38-05:00
access: jack: simplify previous power of 2 calculation

Note that there is a slight change in behaviour here, before if i_read was 1
greater than a power of 2 (e.g., 257), it would evaluate to the *previous*
previous power of 2 (e.g., 128). Now in those cases it will really be the
previous power of 2 (e.g., 256).

- - - - -


1 changed file:

- modules/access/jack.c


Changes:

=====================================
modules/access/jack.c
=====================================
@@ -467,15 +467,8 @@ static block_t *GrabJack( demux_t *p_demux )
         return 0;
     }
 
-    //Find the previous power of 2, this algo assumes size_t has the same size on all arch
-    i_read >>= 1;
-    i_read--;
-    i_read |= i_read >> 1;
-    i_read |= i_read >> 2;
-    i_read |= i_read >> 4;
-    i_read |= i_read >> 8;
-    i_read |= i_read >> 16;
-    i_read++;
+    /* Find the previous power of 2 */
+    i_read = 1 << ((sizeof(i_read)*8 - 1) - vlc_clz(i_read - 1));
 
     i_read = jack_ringbuffer_read( p_sys->p_jack_ringbuffer, ( char * ) p_block->p_buffer, i_read );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/a7c43747d2320fd8c6d1fef806e00a86af2c5813

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/a7c43747d2320fd8c6d1fef806e00a86af2c5813
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list