Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Mathieu Desnoyers <mathieu.desnoyers@...>
Cc: john stultz <johnstul@...>, Steven Rostedt <rostedt@...>, LKML <linux-kernel@...>, Ingo Molnar <mingo@...>, Andrew Morton <akpm@...>, Peter Zijlstra <a.p.zijlstra@...>, Christoph Hellwig <hch@...>, Gregory Haskins <ghaskins@...>, Arnaldo Carvalho de Melo <acme@...>, Thomas Gleixner <tglx@...>, Tim Bird <tim.bird@...>, Sam Ravnborg <sam@...>, Frank Ch. Eigler <fche@...>, Steven Rostedt <srostedt@...>, Paul Mackerras <paulus@...>, Daniel Walker <dwalker@...>
Date: Wednesday, January 16, 2008 - 9:03 pm

On Wed, 16 Jan 2008, Mathieu Desnoyers wrote:

Incorrect.

!0 _is_ necessarily 1. It's how all C logical operators work. If you find 
a compiler that turns !x into anything but 0/1, you found a compiler for 
another language than C.

It's true that any non-zero value counts as "true", but the that does not 
mean that a logical operator can return any non-zero value for true. As a 
return value of the logical operations in C, true is *always* 1.

So !, ||, &&, when used as values, will *always* return either 0 or 1 (but 
when used as part of a conditional, the compiler will often optimize out 
unnecessary stuff, so the CPU may not actually ever see a 0/1 value, if 
the value itself was never used, only branched upon).

So doing "!cs->base_num" to turn 0->1 and 1->0 is perfectly fine.

That's not to say it's necessarily the *best* way.

If you *know* that you started with 0/1 in the first place, the best way 
to flip it tends to be to do (1-x) (or possibly (x^1)).

And if you can't guarantee that, !x is probably better than x ? 0 : 1, 
but you might also decide to use ((x+1)&1) for example.

And obviously, the compiler may sometimes surprise you, and if *it* also 
knows it's always 0/1 (for something like the source being a single-bit 
bitfield for example), it may end up doing something else than you coded 
that is equivalent. And the particular choice of operation the compiler 
chooses may well depend on the code _around_ that sequence.

(One reason to potentially prefer (1-x) over (x^1) is that it's often 
easier to combine a subtraction with other operations, while an xor seldom 
combines with anything around it)

		Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 9, 7:29 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Tue Jan 15, 5:46 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Tue Jan 15, 6:01 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Tue Jan 15, 6:03 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Tue Jan 15, 6:08 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Tue Jan 15, 9:38 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Tue Jan 15, 11:17 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 9:17 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 10:56 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 11:06 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 11:28 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 11:58 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 1:00 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 3:43 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 4:17 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Thu Jan 17, 4:08 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Frank Ch. Eigler, (Thu Jan 17, 4:37 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Thu Jan 17, 5:03 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Fri Jan 18, 6:26 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Fri Jan 18, 6:49 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Frank Ch. Eigler, (Fri Jan 18, 11:32 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Fri Jan 18, 7:19 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Frank Ch. Eigler, (Fri Jan 18, 11:36 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Fri Jan 18, 11:55 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Frank Ch. Eigler, (Sat Jan 19, 12:23 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Sat Jan 19, 11:29 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 4:49 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 1:49 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, john stultz, (Wed Jan 16, 6:36 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, john stultz, (Wed Jan 16, 6:51 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 7:33 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, john stultz, (Wed Jan 16, 10:28 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 10:40 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 10:51 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 10:50 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 11:02 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Paul Mackerras, (Wed Jan 16, 11:21 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 11:39 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Thu Jan 17, 12:25 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Thu Jan 17, 12:22 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Thu Jan 17, 12:14 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Linus Torvalds, (Thu Jan 17, 1:46 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Thu Jan 17, 11:22 am)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 7:39 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 7:50 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Steven Rostedt, (Wed Jan 16, 8:36 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Linus Torvalds, (Wed Jan 16, 9:03 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 9:35 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, john stultz, (Wed Jan 16, 10:20 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 10:35 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, john stultz, (Wed Jan 16, 8:33 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Mathieu Desnoyers, (Wed Jan 16, 10:20 pm)
Re: [RFC PATCH 16/22 -v2] add get_monotonic_cycles, Daniel Walker, (Wed Jan 9, 11:28 pm)