>From ef0d12868cacb41ed13705fcf28d35fd96d284a8 Mon Sep 17 00:00:00 2001 From: Vegard Nossum Date: Wed, 27 Aug 2008 18:37:16 +0200 Subject: [PATCH] bitfields: add bitfields API It turns out that there is an inherent conflict between the way GCC encodes bitfield operations and the way kmemcheck detects uses of uninitialized memory; since bitfields span one or more bytes, accessing only a single bit may generate a load of the whole byte. This happens regardless of whether we actually want to preserve the contents of the rest of the bitfield or not. The solution to the problem is to initialize all the fields at once, which means that GCC can now optimize out the initial load. This can actually even save a few bytes on certain architectures, although this is not the main purpose of the patch. On other architectures, the generated assembly code will be slightly longer; therefore, the patch should do nothing in those cases. This new header defines one macro for defining bitfields, DEFINE_BITFIELD, and one macro for annotating the places where the bitfield is being initialized, bitfield_begin_init. See the next patch in the series for an example of how to use these macros. Signed-off-by: Vegard Nossum --- include/linux/bitfield.h | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) create mode 100644 include/linux/bitfield.h diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h new file mode 100644 index 0000000..2d02ba3 --- /dev/null +++ b/include/linux/bitfield.h @@ -0,0 +1,26 @@ +#ifndef LINUX_BITFIELD_H +#define LINUX_BITFIELD_H + +#define DEFINE_BITFIELD(type, name, fields...) \ + union { \ + struct { \ + type _fields; \ + } name; \ + struct { \ + type fields; \ + }; \ + }; + +/* + * NOTE: This macro should NOT be used to initialize the bitfield! Its + * purpose is to inform the compiler that the bitfield is currently + * uninitialized and that the other bits do not have to be preserved on + * subsequent changes to the bitfield. + */ +#ifdef CONFIG_ARCH_WANT_BITFIELD_INITIALIZERS +#define bitfield_begin_init(name) ((name)._fields = 0) +#else +#define bitfield_begin_init(name) +#endif + +#endif -- 1.5.5.1