* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
[not found] <20100821141750.770348530@efficios.com>
@ 2010-08-21 14:17 ` Mathieu Desnoyers
2010-08-21 18:26 ` Alexey Dobriyan
2010-08-22 19:27 ` Andi Kleen
2010-08-21 14:17 ` [PATCH for -tip 2/2] Create generic alignment API (v9) Mathieu Desnoyers
1 sibling, 2 replies; 9+ messages in thread
From: Mathieu Desnoyers @ 2010-08-21 14:17 UTC (permalink / raw)
To: linux-arm-kernel
An embedded and charset-unspecified text was scrubbed...
Name: kernel-h-add-maybe-build-bug-on-not-power-of-2.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100821/1d53d384/attachment.ksh>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 2/2] Create generic alignment API (v9)
[not found] <20100821141750.770348530@efficios.com>
2010-08-21 14:17 ` [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Mathieu Desnoyers
@ 2010-08-21 14:17 ` Mathieu Desnoyers
1 sibling, 0 replies; 9+ messages in thread
From: Mathieu Desnoyers @ 2010-08-21 14:17 UTC (permalink / raw)
To: linux-arm-kernel
An embedded and charset-unspecified text was scrubbed...
Name: create-generic-alignment-api.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100821/f3db84e4/attachment.ksh>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-21 14:17 ` [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Mathieu Desnoyers
@ 2010-08-21 18:26 ` Alexey Dobriyan
2010-08-21 18:40 ` Mathieu Desnoyers
2010-08-22 19:27 ` Andi Kleen
1 sibling, 1 reply; 9+ messages in thread
From: Alexey Dobriyan @ 2010-08-21 18:26 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, Aug 21, 2010 at 10:17:51AM -0400, Mathieu Desnoyers wrote:
> +/* Force a compilation error if condition is constant and not a power of 2 */
> +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
Sorry, this is tasteless macro.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-21 18:26 ` Alexey Dobriyan
@ 2010-08-21 18:40 ` Mathieu Desnoyers
2010-08-21 19:44 ` Alexey Dobriyan
0 siblings, 1 reply; 9+ messages in thread
From: Mathieu Desnoyers @ 2010-08-21 18:40 UTC (permalink / raw)
To: linux-arm-kernel
* Alexey Dobriyan (adobriyan at gmail.com) wrote:
> On Sat, Aug 21, 2010 at 10:17:51AM -0400, Mathieu Desnoyers wrote:
> > +/* Force a compilation error if condition is constant and not a power of 2 */
> > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> > + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
>
> Sorry, this is tasteless macro.
Let's look at the surrounding where I added this macro in kernel.h:
/* Force a compilation error if condition is true */
#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
/* Force a compilation error if condition is constant and true */
#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
/* Force a compilation error if a constant expression is not a power of 2 */
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
/* Force a compilation error if condition is true, but also produce a
result (of value 0 and type size_t), so the expression can be used
e.g. in a structure initializer (or where-ever else comma expressions
aren't permitted). */
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
So I am guessing that you plan to rewrite all of these ? Or perharps you have
other suggestions ? Commit cc8ef6eb21e964b1c5eb97b2d0e8ac9893e1bf86 introduced
"BUILD_BUG_ON_NOT_POWER_OF_2()" btw.
Thanks,
Mathieu
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-21 18:40 ` Mathieu Desnoyers
@ 2010-08-21 19:44 ` Alexey Dobriyan
0 siblings, 0 replies; 9+ messages in thread
From: Alexey Dobriyan @ 2010-08-21 19:44 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, Aug 21, 2010 at 02:40:15PM -0400, Mathieu Desnoyers wrote:
> * Alexey Dobriyan (adobriyan at gmail.com) wrote:
> > On Sat, Aug 21, 2010 at 10:17:51AM -0400, Mathieu Desnoyers wrote:
> > > +/* Force a compilation error if condition is constant and not a power of 2 */
> > > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> > > + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
> >
> > Sorry, this is tasteless macro.
>
> Let's look at the surrounding where I added this macro in kernel.h:
>
>
> /* Force a compilation error if condition is true */
> #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
>
> /* Force a compilation error if condition is constant and true */
> #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
>
> /* Force a compilation error if a constant expression is not a power of 2 */
> #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
>
> /* Force a compilation error if condition is true, but also produce a
> result (of value 0 and type size_t), so the expression can be used
> e.g. in a structure initializer (or where-ever else comma expressions
> aren't permitted). */
> #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
> #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
>
>
> So I am guessing that you plan to rewrite all of these ?
Of course not.
> Or perharps you have other suggestions ?
Learn that n & (n - 1) is idiomatic way to check for power of two in C.
Done that, encoding that information in identifier won't make sense.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-21 14:17 ` [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Mathieu Desnoyers
2010-08-21 18:26 ` Alexey Dobriyan
@ 2010-08-22 19:27 ` Andi Kleen
2010-08-22 19:38 ` Mathieu Desnoyers
1 sibling, 1 reply; 9+ messages in thread
From: Andi Kleen @ 2010-08-22 19:27 UTC (permalink / raw)
To: linux-arm-kernel
> +/* Force a compilation error if condition is constant and not a power of 2 */
> +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
Looks super-ugly. IMHO just writing MAYBE_BUILD_BUG_ON(!n || n & (n - 1)) directly
would be clear enough. If you really think that's unclear define a generic
is_power_of_two() macro.
-Andi
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-22 19:27 ` Andi Kleen
@ 2010-08-22 19:38 ` Mathieu Desnoyers
2010-08-22 20:16 ` Anca Emanuel
0 siblings, 1 reply; 9+ messages in thread
From: Mathieu Desnoyers @ 2010-08-22 19:38 UTC (permalink / raw)
To: linux-arm-kernel
* Andi Kleen (andi at firstfloor.org) wrote:
> > +/* Force a compilation error if condition is constant and not a power of 2 */
> > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> > + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
>
> Looks super-ugly. IMHO just writing MAYBE_BUILD_BUG_ON(!n || n & (n - 1)) directly
> would be clear enough. If you really think that's unclear define a generic
> is_power_of_two() macro.
There is already a is_power_of_two macro in log2.h, but I fear it might
incorrectly interact with "MAYBE_BUILD_BUG_ON" (for some reason passing the
constant result of a static inline is not treated as a constant by the macro,
and thus it always "passes" the test).
So if everyone object to this new macro, I'd be tempted to just go with your
suggestion. However the fact that we already have BUILD_BUG_ON_NOT_POWER_OF_2(n)
made me think that some people prefer to have it done as a macro.
Other opinions ?
Thanks,
Mathieu
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-22 19:38 ` Mathieu Desnoyers
@ 2010-08-22 20:16 ` Anca Emanuel
2010-08-22 21:03 ` Mathieu Desnoyers
0 siblings, 1 reply; 9+ messages in thread
From: Anca Emanuel @ 2010-08-22 20:16 UTC (permalink / raw)
To: linux-arm-kernel
I think about some test at the last bit if it is on, the number is not
a power of 2
On Sun, Aug 22, 2010 at 10:38 PM, Mathieu Desnoyers
<mathieu.desnoyers@efficios.com> wrote:
> * Andi Kleen (andi at firstfloor.org) wrote:
>> > +/* Force a compilation error if condition is constant and not a power of 2 */
>> > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) ? ? ? ? ? ? ? \
>> > + ? MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
>>
>> Looks super-ugly. IMHO just writing MAYBE_BUILD_BUG_ON(!n || n & (n - 1)) directly
>> would be clear enough. If you really think that's unclear define a generic
>> is_power_of_two() macro.
>
> There is already a is_power_of_two macro in log2.h, but I fear it might
> incorrectly interact with "MAYBE_BUILD_BUG_ON" (for some reason passing the
> constant result of a static inline is not treated as a constant by the macro,
> and thus it always "passes" the test).
>
> So if everyone object to this new macro, I'd be tempted to just go with your
> suggestion. However the fact that we already have BUILD_BUG_ON_NOT_POWER_OF_2(n)
> made me think that some people prefer to have it done as a macro.
>
> Other opinions ?
>
> Thanks,
>
> Mathieu
>
>
> --
> Mathieu Desnoyers
> Operating System Efficiency R&D Consultant
> EfficiOS Inc.
> http://www.efficios.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at ?http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2
2010-08-22 20:16 ` Anca Emanuel
@ 2010-08-22 21:03 ` Mathieu Desnoyers
0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Desnoyers @ 2010-08-22 21:03 UTC (permalink / raw)
To: linux-arm-kernel
* Anca Emanuel (anca.emanuel at gmail.com) wrote:
> I think about some test at the last bit if it is on, the number is not
> a power of 2
Can you give an example, along with the types you have in mind ?
Thanks,
Mathieu
>
> On Sun, Aug 22, 2010 at 10:38 PM, Mathieu Desnoyers
> <mathieu.desnoyers@efficios.com> wrote:
> > * Andi Kleen (andi at firstfloor.org) wrote:
> >> > +/* Force a compilation error if condition is constant and not a power of 2 */
> >> > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) ? ? ? ? ? ? ? \
> >> > + ? MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
> >>
> >> Looks super-ugly. IMHO just writing MAYBE_BUILD_BUG_ON(!n || n & (n - 1)) directly
> >> would be clear enough. If you really think that's unclear define a generic
> >> is_power_of_two() macro.
> >
> > There is already a is_power_of_two macro in log2.h, but I fear it might
> > incorrectly interact with "MAYBE_BUILD_BUG_ON" (for some reason passing the
> > constant result of a static inline is not treated as a constant by the macro,
> > and thus it always "passes" the test).
> >
> > So if everyone object to this new macro, I'd be tempted to just go with your
> > suggestion. However the fact that we already have BUILD_BUG_ON_NOT_POWER_OF_2(n)
> > made me think that some people prefer to have it done as a macro.
> >
> > Other opinions ?
> >
> > Thanks,
> >
> > Mathieu
> >
> >
> > --
> > Mathieu Desnoyers
> > Operating System Efficiency R&D Consultant
> > EfficiOS Inc.
> > http://www.efficios.com
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo at vger.kernel.org
> > More majordomo info at ?http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at ?http://www.tux.org/lkml/
> >
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-08-22 21:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20100821141750.770348530@efficios.com>
2010-08-21 14:17 ` [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Mathieu Desnoyers
2010-08-21 18:26 ` Alexey Dobriyan
2010-08-21 18:40 ` Mathieu Desnoyers
2010-08-21 19:44 ` Alexey Dobriyan
2010-08-22 19:27 ` Andi Kleen
2010-08-22 19:38 ` Mathieu Desnoyers
2010-08-22 20:16 ` Anca Emanuel
2010-08-22 21:03 ` Mathieu Desnoyers
2010-08-21 14:17 ` [PATCH for -tip 2/2] Create generic alignment API (v9) Mathieu Desnoyers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).