lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Sun, 1 Sep 2013 13:03:32 -0700
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	Steven Rostedt <rostedt@...dmis.org>
Cc:	"Theodore Ts'o" <tytso@....edu>,
	George Spelvin <linux@...izon.com>,
	linux-fsdevel <linux-fsdevel@...r.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
	Al Viro <viro@...iv.linux.org.uk>,
	Waiman Long <waiman.long@...com>,
	Frederic Weisbecker <fweisbec@...il.com>
Subject: Re: [PATCH v7 1/4] spinlock: A new lockref structure for lockless
 update of refcount

On Sun, Sep 1, 2013 at 11:11 AM, Steven Rostedt <rostedt@...dmis.org> wrote:
>
> I've been told that gcc works better with 'bool' than with an int.
> Should I replace those bools with bit fields in the structure?

I think bitfields are a better idea in a struct, yes. They take less
space, and there's a possibility to generate better code with a
bitfield test than with a bool, especially if you have multiple values
and you test them together.

If it's a single bool in a structure, it really doesn't matter. It's
going to take up at least a char (and usually more due to padding of
other fields) regardless of bool-vs-bitfield issues. But I'd much
rather see bitfields in structs because they *can* work better, and
they are more flexible than "bool" anyway.

Bools generally should generate the same code as "char", and yes, that
can be better than "int". On x86, for example, the "setcc" instruction
always sets a char, so if you use an "int" for boolean values, the
compiler usually generates something like "xor %eax,%eax; test ..;
setne %al" or similar. A bool or a char will skip the "xor", because
the "setne" will set the low bits that are sufficient. That said, it's
not actually noticeable in practice, and most routines that return
true/false will just do plain "return 0" or whatever, so there's no
use for "setcc" to begin with.

         Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ