[vlc-devel] vlc_math.h ?
Rémi Denis-Courmont
remi at remlab.net
Mon Dec 14 11:56:38 CET 2015
Le 2015-12-11 19:13, Francois Cartegnie a écrit :
> Le 11/12/2015 11:22, Rémi Denis-Courmont a écrit :
>> Le 2015-12-11 00:59, Francois Cartegnie a écrit :
>>> I need log2 and log2_ceil which are already duplicated in some
>>> modules:
>>
>> log2 is a standard function so you can use it, so I fail to see why
>> you
>> would need to wrap that.
>> log2_ceil is best implemented with clz family of functions, rather
>> than
>> floating point maths.
>>
>
> moving
>
> static inline uint8_t vlc_log2( uint32_t val )
> {
> return 31 - clz(val);
> }
You make it sound like a replacement of log2(), which this is
definitely *not*. Also the principle of least surprise is defeated by
failure to handle larger than 32-bits values. All in all I don't really
see the point in adding such a trivial function.
> static inline uint8_t vlc_ceil_log2( uint32_t val )
> {
> uint8_t n = vlc_log2( val );
> if ((1U << n) != val)
> n++;
> return n;
> }
And this seems even more trivial.
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list