mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
rework pa_ulog2 and base it on __builtin_clz if available, make pa_make_power_of_two based on it
This commit is contained in:
parent
bb8263be6f
commit
6723699ef8
1 changed files with 24 additions and 18 deletions
|
|
@ -142,29 +142,35 @@ static inline int pa_is_power_of_two(unsigned n) {
|
||||||
return !(n & (n - 1));
|
return !(n & (n - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned pa_ulog2(unsigned n) {
|
||||||
|
|
||||||
|
if (n <= 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||||
|
return 8U * (unsigned) sizeof(unsigned) - (unsigned) __builtin_clz(n) - 1;
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
unsigned r = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
n = n >> 1;
|
||||||
|
|
||||||
|
if (!n)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline unsigned pa_make_power_of_two(unsigned n) {
|
static inline unsigned pa_make_power_of_two(unsigned n) {
|
||||||
unsigned j = n;
|
|
||||||
|
|
||||||
if (pa_is_power_of_two(n))
|
if (pa_is_power_of_two(n))
|
||||||
return n;
|
return n;
|
||||||
|
|
||||||
while (j) {
|
return 1U << (pa_ulog2(n) + 1);
|
||||||
j = j >> 1;
|
|
||||||
n = n | j;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline unsigned pa_ulog2(unsigned n) {
|
|
||||||
unsigned r = 0;
|
|
||||||
|
|
||||||
while (n) {
|
|
||||||
r++;
|
|
||||||
n = n >> 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_close_pipe(int fds[2]);
|
void pa_close_pipe(int fds[2]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue