[FFmpeg-devel] & vs. &&

Uoti Urpala uoti.urpala
Mon Oct 12 18:30:52 CEST 2009


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.




More information about the ffmpeg-devel mailing list