All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/buffer.c: change buffer_busy() to use logical-OR expression
@ 2010-10-23 17:06 Namhyung Kim
  2010-10-23 17:21 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2010-10-23 17:06 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel

Convert bitwise-OR operator to logical-OR in favor of short-circuit
evaluation. The end result would be same.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 fs/buffer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index f5755f7..4362e77 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3069,7 +3069,7 @@ EXPORT_SYMBOL(sync_dirty_buffer);
  */
 static inline int buffer_busy(struct buffer_head *bh)
 {
-	return atomic_read(&bh->b_count) |
+	return atomic_read(&bh->b_count) ||
 		(bh->b_state & ((1 << BH_Dirty) | (1 << BH_Lock)));
 }
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/buffer.c: change buffer_busy() to use logical-OR expression
  2010-10-23 17:06 [PATCH] fs/buffer.c: change buffer_busy() to use logical-OR expression Namhyung Kim
@ 2010-10-23 17:21 ` Al Viro
  2010-10-23 17:49   ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2010-10-23 17:21 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: linux-fsdevel, linux-kernel

On Sun, Oct 24, 2010 at 02:06:15AM +0900, Namhyung Kim wrote:
> Convert bitwise-OR operator to logical-OR in favor of short-circuit
> evaluation. The end result would be same.

It'll cost _more_.

Think of it:
	v = atomic_read(...)
	w = bh->b_state
	w &= constant
	v |= w
	return v
vs.
	v = atomic_read()
	branch to l if not equal to 0
	w = bh->b_state
	if w & constant is not 0, branch to l
	v = 0
	return v
l:	v = 1
	return v

That short-circuit won't win anything here.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/buffer.c: change buffer_busy() to use logical-OR expression
  2010-10-23 17:21 ` Al Viro
@ 2010-10-23 17:49   ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2010-10-23 17:49 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, linux-kernel

2010-10-23 (토), 18:21 +0100, Al Viro:
> On Sun, Oct 24, 2010 at 02:06:15AM +0900, Namhyung Kim wrote:
> > Convert bitwise-OR operator to logical-OR in favor of short-circuit
> > evaluation. The end result would be same.
> 
> It'll cost _more_.
> 
> Think of it:
> 	v = atomic_read(...)
> 	w = bh->b_state
> 	w &= constant
> 	v |= w
> 	return v
> vs.
> 	v = atomic_read()
> 	branch to l if not equal to 0
> 	w = bh->b_state
> 	if w & constant is not 0, branch to l
> 	v = 0
> 	return v
> l:	v = 1
> 	return v
> 
> That short-circuit won't win anything here.

I see. It adds expensive branch insns. I just checked that patched code
generated longer code, Cool. But what if I exchange the order of
evaluation, check the bitmask before atomic_read()? Isn't it helpful
either?

Thanks.


-- 
Regards,
Namhyung Kim



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-10-23 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-23 17:06 [PATCH] fs/buffer.c: change buffer_busy() to use logical-OR expression Namhyung Kim
2010-10-23 17:21 ` Al Viro
2010-10-23 17:49   ` Namhyung Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.