Linux wireless drivers development
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Joe Perches <joe@perches.com>, David Miller <davem@davemloft.net>,
	jeffrey.t.kirsher@intel.com, netdev@vger.kernel.org,
	linux-wireless <linux-wireless@vger.kernel.org>
Subject: RE: [PATCH net-next] drivers/net: Remove boolean comparisons to true/false
Date: Fri, 10 Feb 2012 14:04:22 +0100	[thread overview]
Message-ID: <1328879062.2443.16.camel@edumazet-laptop> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B6E65@saturn3.aculab.com>

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.



  parent reply	other threads:[~2012-02-10 13:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1328783282-17760-5-git-send-email-jeffrey.t.kirsher@intel.com>
     [not found] ` <AE90C24D6B3A694183C094C60CF0A2F6026B6E62@saturn3.aculab.com>
     [not found]   ` <20120209.133413.349832435589531136.davem@davemloft.net>
2012-02-09 21:17     ` [PATCH net-next] drivers/net: Remove boolean comparisons to true/false Joe Perches
2012-02-09 21:28       ` Jeff Kirsher
2012-02-09 22:36         ` Allan, Bruce W
2012-02-09 23:08           ` Joe Perches
2012-02-10  6:46             ` Julia Lawall
2012-02-10  9:32       ` David Laight
2012-02-10  9:50         ` Arend van Spriel
2012-02-10 13:04         ` Eric Dumazet [this message]
2012-02-13  5:50       ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328879062.2443.16.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=joe@perches.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox