[FFmpeg-devel] & vs. &&

Måns Rullgård mans
Mon Oct 12 18:58:10 CEST 2009

Uoti Urpala <uoti.urpala at pp1.inet.fi> writes:

> On Mon, 2009-10-12 at 16:19 +0100, M?ns Rullg?rd wrote:
>> >> >> if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
>> The thing here is that the RHS of the && operator must not be
>> evaluated if the LHS is false.  This means the compiler will have to
>> use some kind of conditional code, probably a branch, to avoid reading
>> is_coded[i] if is_intra[i] is non-zero.  A single read followed by a
>> bitwise and is almost certainly faster than a conditional branch,
>> especially if it is hard to predict.
> The compiler can evaluate the right side; it must only make sure there
> are no side effects. Here the only possible side effect would be
> crashing the program in case "is_coded[i]" references an invalid
> address, but since "is_coded" is a local variable and "i" is a loop
> variable less than the size of that local array it's not hard for the
> compiler to show that evaluating it is safe.

So... does it?  I'm not counting on it.

M?ns Rullg?rd
mans at mansr.com

More information about the ffmpeg-devel mailing list