Thread (1 message) 1 message, 1 author, 2012-02-10

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

flat view

From: Eric Dumazet <hidden>
Date: 2012-02-10 13:04:22
Also in: linux-wireless

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help