# RE: \[PATCH net-next\] drivers/net: Remove boolean comparisons to true/false

- From: Eric Dumazet \<hidden\>
- Date: 2012-02-10 13:04:22 
- List: netdev
- Page: https://ratatoskr.run/netdev/2012/02/10888434
- Thread: https://ratatoskr.run/linux-wireless/2012/02/10888434/t.md

```text
Le vendredi 10 février 2012 à 09:32 +0000, David Laight a écrit :

> The generated code is particularly horrid for boolean arithmetic.
> IIRC:
>    bool_var &= bool_var_1;
> typically requires a sequence of compare and branch instructions.
> 

I suggest you try to upgrade your old compiler and/or always check your
assertions before posting on netdev such claims.

	bool_var &= bool_var_1;

generates a single AND instruction, no compare, no branch.
It would be a failure from compiler optimizer if that was the case.

And (bool_var ? 1 : 0) or (!!bool_var) are NOP for a compiler as well.

(Only one movzbl instruction to convert a byte to a word if context
requires this)

Only difference for bool or unsigned int vars is type promotion, and
fact that compiler knows that 'bool' only can be 0 or 1, so allows more
optimisations than plain "unsigned int".

Really, bools are not evil if well used.


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
```
