Linux PARISC architecture development
 help / color / mirror / Atom feed
From: Grant Grundler <grundler@parisc-linux.org>
To: Joel Soete <soete.joel@tiscali.be>
Cc: parisc-linux@lists.parisc-linux.org
Subject: Re: [parisc-linux] some other small bitops.h suggestion?
Date: Wed, 13 Apr 2005 11:47:56 -0600	[thread overview]
Message-ID: <20050413174756.GA21641@colo.lackof.org> (raw)
In-Reply-To: <42134E6200012F70@mail-2-bnl.tiscali.it>

On Tue, Apr 05, 2005 at 11:28:26AM +0200, Joel Soete wrote:
> Here is some other change to suggest (even thought it doesn't fix anything
> :-( ):
...

Here is what I'd like to commit for include/parisc/bitops.h.

Summary of changes:
o uses generic_hweight64
o uses CONFIG_64BIT where neccessary
o make our __clear_bit and __set_bit look like ppc64 instead of sparc.
o simplify sched_find_first_bit()

Any comments before I commit this?

(Joel, additional changes can go in another commit please :^)

Beware, touching bitops.h will cause a full recompile.

thanks,
grant


Index: include/asm-parisc/bitops.h
===================================================================
RCS file: /var/cvs/linux-2.6/include/asm-parisc/bitops.h,v
retrieving revision 1.18
diff -u -p -r1.18 bitops.h
--- include/asm-parisc/bitops.h	4 Apr 2005 17:54:41 -0000	1.18
+++ include/asm-parisc/bitops.h	13 Apr 2005 17:44:13 -0000
@@ -12,7 +12,7 @@
  * to include/asm-i386/bitops.h or kerneldoc
  */
 
-#ifdef __LP64__
+#ifdef CONFIG_64BIT
 #   define SHIFT_PER_LONG 6
 #ifndef BITS_PER_LONG
 #   define BITS_PER_LONG 64
@@ -43,37 +43,29 @@ static __inline__ void set_bit(int nr, v
 	_atomic_spin_unlock_irqrestore(addr, flags);
 }
 
-static __inline__ void __set_bit(int nr, volatile unsigned long * address)
+static __inline__ void __set_bit(unsigned long nr, volatile unsigned long * addr)
 {
-	unsigned long mask;
-	unsigned long *addr = (unsigned long *) address;
+	volatile unsigned long *m = addr + (((unsigned) nr) >> SHIFT_PER_LONG);
 
-	addr += (nr >> SHIFT_PER_LONG);
-	mask = 1UL << CHOP_SHIFTCOUNT(nr);
-	*addr |= mask;
+	*m |= 1UL << CHOP_SHIFTCOUNT(nr);
 }
 
 static __inline__ void clear_bit(int nr, volatile unsigned long * address)
 {
-	unsigned long mask;
-	unsigned long *addr = (unsigned long *) address;
+	unsigned long mask = 1UL << CHOP_SHIFTCOUNT((unsigned int) nr);
+	volatile unsigned long *addr = address + (((unsigned int) nr) >> SHIFT_PER_LONG);
 	unsigned long flags;
 
-	addr += (nr >> SHIFT_PER_LONG);
-	mask = 1UL << CHOP_SHIFTCOUNT(nr);
 	_atomic_spin_lock_irqsave(addr, flags);
 	*addr &= ~mask;
 	_atomic_spin_unlock_irqrestore(addr, flags);
 }
 
-static __inline__ void __clear_bit(unsigned long nr, volatile unsigned long * address)
+static __inline__ void __clear_bit(unsigned long nr, volatile unsigned long * addr)
 {
-	unsigned long mask;
-	unsigned long *addr = (unsigned long *) address;
+	volatile unsigned long *m = addr + (nr >> SHIFT_PER_LONG);
 
-	addr += (nr >> SHIFT_PER_LONG);
-	mask = 1UL << CHOP_SHIFTCOUNT(nr);
-	*addr &= ~mask;
+	*m &= ~(1UL << CHOP_SHIFTCOUNT(nr));
 }
 
 static __inline__ void change_bit(int nr, volatile unsigned long * address)
@@ -89,14 +81,11 @@ static __inline__ void change_bit(int nr
 	_atomic_spin_unlock_irqrestore(addr, flags);
 }
 
-static __inline__ void __change_bit(int nr, volatile unsigned long * address)
+static __inline__ void __change_bit(unsigned long nr, volatile unsigned long * addr)
 {
-	unsigned long mask;
-	unsigned long *addr = (unsigned long *) address;
+	volatile unsigned long *m = addr + (nr >> SHIFT_PER_LONG);
 
-	addr += (nr >> SHIFT_PER_LONG);
-	mask = 1UL << CHOP_SHIFTCOUNT(nr);
-	*addr ^= mask;
+	*m ^= 1UL << CHOP_SHIFTCOUNT(nr);
 }
 
 static __inline__ int test_and_set_bit(int nr, volatile unsigned long * address)
@@ -229,7 +218,7 @@ static __inline__ unsigned long __ffs(un
 	unsigned long ret;
 
 	__asm__(
-#if BITS_PER_LONG > 32
+#ifdef CONFIG_64BIT
 		" ldi       63,%1\n"
 		" extrd,u,*<>  %0,63,32,%%r0\n"
 		" extrd,u,*TR  %0,31,32,%0\n"	/* move top 32-bits down */
@@ -304,14 +293,7 @@ static __inline__ int fls(int x)
  * hweightN: returns the hamming weight (i.e. the number
  * of bits set) of a N-bit word
  */
-#define hweight64(x)						\
-({								\
-	unsigned long __x = (x);				\
-	unsigned int __w;					\
-	__w = generic_hweight32((unsigned int) __x);		\
-	__w += generic_hweight32((unsigned int) (__x>>32));	\
-	__w;							\
-})
+#define hweight64(x) generic_hweight64(x)
 #define hweight32(x) generic_hweight32(x)
 #define hweight16(x) generic_hweight16(x)
 #define hweight8(x) generic_hweight8(x)
@@ -324,7 +306,13 @@ static __inline__ int fls(int x)
  */
 static inline int sched_find_first_bit(const unsigned long *b)
 {
-#ifndef __LP64__
+#ifdef CONFIG_64BIT
+	if (unlikely(b[0]))
+		return __ffs(b[0]);
+	if (unlikely(b[1]))
+		return __ffs(b[1]) + 64;
+	return __ffs(b[2]) + 128;
+#else
 	if (unlikely(b[0]))
 		return __ffs(b[0]);
 	if (unlikely(b[1]))
@@ -334,14 +322,6 @@ static inline int sched_find_first_bit(c
 	if (b[3])
 		return __ffs(b[3]) + 96;
 	return __ffs(b[4]) + 128;
-#else
-	if (unlikely(b[0]))
-		return __ffs(b[0]);
-	if (unlikely(((unsigned int)b[1])))
-		return __ffs(b[1]) + 64;
-	if (b[1] >> 32)
-		return __ffs(b[1] >> 32) + 96;
-	return __ffs(b[2]) + 128;
 #endif
 }
 
@@ -445,7 +425,7 @@ found_middle:
  * test_and_{set,clear}_bit guarantee atomicity without
  * disabling interrupts.
  */
-#ifdef __LP64__
+#ifdef CONFIG_64BIT
 #define ext2_set_bit(nr, addr)		__test_and_set_bit((nr) ^ 0x38, (unsigned long *)addr)
 #define ext2_set_bit_atomic(l,nr,addr)  test_and_set_bit((nr) ^ 0x38, (unsigned long *)addr)
 #define ext2_clear_bit(nr, addr)	__test_and_clear_bit((nr) ^ 0x38, (unsigned long *)addr)
_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

  parent reply	other threads:[~2005-04-13 17:47 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-03 14:32 [parisc-linux] pthread problems - test program Randolph Chung
2005-04-03 19:07 ` John David Anglin
2005-04-03 20:24 ` John David Anglin
2005-04-04  0:53   ` Randolph Chung
2005-04-03 20:41 ` John David Anglin
2005-04-04  0:50   ` Randolph Chung
2005-04-05  0:00     ` Carlos O'Donell
2005-04-05  0:02     ` Carlos O'Donell
2005-04-05  6:00       ` Carlos O'Donell
2005-04-06 20:12         ` John David Anglin
2005-04-06 20:25           ` Carlos O'Donell
2005-04-06 20:52             ` John David Anglin
2005-04-06 20:28           ` Carlos O'Donell
2005-04-07  2:45           ` John David Anglin
2005-04-08  2:56             ` John David Anglin
2005-04-08 21:29               ` Carlos O'Donell
2005-04-08 22:54                 ` John David Anglin
     [not found]                   ` <20050409055852.GM1833@baldric.uwo.ca>
2005-04-09  6:37                     ` Carlos O'Donell
2005-04-09 14:44                       ` John David Anglin
2005-04-09 14:48                         ` Randolph Chung
2005-04-09 23:44                       ` John David Anglin
2005-04-15 14:16                         ` Carlos O'Donell
2005-04-15 15:48                           ` John David Anglin
2005-04-09  0:13                 ` John David Anglin
2005-04-09  6:38                   ` Carlos O'Donell
2005-04-09 15:01                     ` John David Anglin
2005-04-15 14:16                       ` Carlos O'Donell
2005-04-06  1:21     ` John David Anglin
2005-04-06  4:59       ` Carlos O'Donell
2005-04-06  8:42         ` John David Anglin
2005-04-06 16:11           ` John David Anglin
2005-04-06 18:13             ` Carlos O'Donell
2005-04-06 18:37               ` John David Anglin
2005-04-06 19:36                 ` Carlos O'Donell
2005-04-06 19:36                 ` Carlos O'Donell
2005-04-05  9:28 ` [parisc-linux] some other small bitops.h suggestion? Joel Soete
2005-04-13  6:14   ` Grant Grundler
2005-04-13  6:58     ` Joel Soete
2005-04-13 17:47   ` Grant Grundler [this message]
     [not found]     ` <20050414013105.GB17749@tausq.org>
2005-04-14  1:33       ` Randolph Chung
2005-04-14  5:07       ` Grant Grundler
2005-04-14 14:39         ` John David Anglin
2005-04-15 19:27           ` Grant Grundler
2005-04-15 21:41             ` John David Anglin
2005-04-16 17:27               ` Grant Grundler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050413174756.GA21641@colo.lackof.org \
    --to=grundler@parisc-linux.org \
    --cc=parisc-linux@lists.parisc-linux.org \
    --cc=soete.joel@tiscali.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox