[FFmpeg-devel] [PATCH] intmath.h: add an ff_log2_nz

Rostislav Pehlivanov atomnuker at gmail.com
Thu Dec 17 21:44:38 CET 2015

On Thu, 2015-12-17 at 19:22 +0100, Michael Niedermayer wrote:
> On Thu, Dec 17, 2015 at 05:29:58PM +0000, Rostislav Pehlivanov wrote:
> > This commit adds a raw integer log2 function (which directly maps
> > to a
> > builtin). This was needed as the Daala entropy coding system
> > requires a
> > raw log2 and the existing ff_log2 OR'd the argument with 1.
> __builtin_clz(0) is undefined as ganesh pointed out elsewhere
> if i read the intend correctly though this function is added because
> of different behavior for 0, but IIUC its not different in a good w

No, this function is added because the OR'd argument in the current
ff_log2(x) completely breaks the entropy decoding system because for
example, (32|1)!=32.

The entropy decoding system doesn't depend on any undefined behavior
which occurs when the argument is 0 and in fact would assert should
this happen.

I don't think that in this case it's the job of the macro/alias to
check for whether the argument is 0, but rather it would be the
responsibility of anyone using it so they could instead decide what
happens rather than silently get the wrong value.

More information about the ffmpeg-devel mailing list