From: Simon Kagstrom <simon.kagstrom@netinsight.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 2/4]: arm: Make arm bitops endianness-independent
Date: Mon, 24 Aug 2009 09:10:03 +0200 [thread overview]
Message-ID: <20090824091003.0b8a631f@marrow.netinsight.se> (raw)
In-Reply-To: <20090824090605.37715546@marrow.netinsight.se>
arm: Make arm bitops endianness-independent
Bring over the bitop implementations from the Linux
include/asm-generic/bitops/non-atomic.h to provide
endianness-independence.
Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
ChangeLog:
v2: Use generic __set_bit and __clear_bit for ARM
include/asm-arm/bitops.h | 47 ++++++++++++++++++---------------------------
1 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/include/asm-arm/bitops.h b/include/asm-arm/bitops.h
index 1549da1..854e225 100644
--- a/include/asm-arm/bitops.h
+++ b/include/asm-arm/bitops.h
@@ -25,61 +25,52 @@
*/
extern void set_bit(int nr, volatile void * addr);
-static inline void __set_bit(int nr, volatile void *addr)
-{
- ((unsigned char *) addr)[nr >> 3] |= (1U << (nr & 7));
-}
-#define __set_bit
-
extern void clear_bit(int nr, volatile void * addr);
-static inline void __clear_bit(int nr, volatile void *addr)
-{
- ((unsigned char *) addr)[nr >> 3] &= ~(1U << (nr & 7));
-}
-#define __clear_bit
-
extern void change_bit(int nr, volatile void * addr);
static inline void __change_bit(int nr, volatile void *addr)
{
- ((unsigned char *) addr)[nr >> 3] ^= (1U << (nr & 7));
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+
+ *p ^= mask;
}
extern int test_and_set_bit(int nr, volatile void * addr);
static inline int __test_and_set_bit(int nr, volatile void *addr)
{
- unsigned int mask = 1 << (nr & 7);
- unsigned int oldval;
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long old = *p;
- oldval = ((unsigned char *) addr)[nr >> 3];
- ((unsigned char *) addr)[nr >> 3] = oldval | mask;
- return oldval & mask;
+ *p = old | mask;
+ return (old & mask) != 0;
}
extern int test_and_clear_bit(int nr, volatile void * addr);
static inline int __test_and_clear_bit(int nr, volatile void *addr)
{
- unsigned int mask = 1 << (nr & 7);
- unsigned int oldval;
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long old = *p;
- oldval = ((unsigned char *) addr)[nr >> 3];
- ((unsigned char *) addr)[nr >> 3] = oldval & ~mask;
- return oldval & mask;
+ *p = old & ~mask;
+ return (old & mask) != 0;
}
extern int test_and_change_bit(int nr, volatile void * addr);
static inline int __test_and_change_bit(int nr, volatile void *addr)
{
- unsigned int mask = 1 << (nr & 7);
- unsigned int oldval;
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long old = *p;
- oldval = ((unsigned char *) addr)[nr >> 3];
- ((unsigned char *) addr)[nr >> 3] = oldval ^ mask;
- return oldval & mask;
+ *p = old ^ mask;
+ return (old & mask) != 0;
}
extern int find_first_zero_bit(void * addr, unsigned size);
--
1.6.0.4
next prev parent reply other threads:[~2009-08-24 7:10 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-24 7:06 [U-Boot] [PATCH v4 0/4]: bitops cleanup and fixes Simon Kagstrom
2009-08-24 7:09 ` [U-Boot] [PATCH v4 1/4]: Move __set/clear_bit from ubifs.h to bitops.h Simon Kagstrom
2009-09-15 20:31 ` Wolfgang Denk
2009-08-24 7:10 ` Simon Kagstrom [this message]
2009-09-15 20:34 ` [U-Boot] [PATCH v4 2/4]: arm: Make arm bitops endianness-independent Wolfgang Denk
2009-08-24 7:10 ` [U-Boot] [PATCH v4 3/4]: Define ffs/fls for all architectures Simon Kagstrom
2009-09-15 20:34 ` Wolfgang Denk
2009-09-16 19:19 ` Stefan Roese
2009-09-17 6:45 ` Simon Kagstrom
2009-09-17 6:56 ` Stefan Roese
2009-09-17 7:13 ` Simon Kagstrom
2009-09-17 7:19 ` Stefan Roese
2009-08-24 7:10 ` [U-Boot] [PATCH v4 4/4]: arm: Define test_and_set_bit and test_and_clear bit for ARM Simon Kagstrom
2009-09-04 21:27 ` Justin Waters
2009-09-06 14:59 ` Jean-Christophe PLAGNIOL-VILLARD
2009-09-07 6:26 ` Simon Kagstrom
2009-09-15 20:35 ` Wolfgang Denk
2009-08-31 9:32 ` [U-Boot] [PATCH v4 0/4]: bitops cleanup and fixes Simon Kagstrom
2009-09-04 20:14 ` Wolfgang Denk
2009-09-05 11:37 ` Jean-Christophe PLAGNIOL-VILLARD
2009-09-06 20:50 ` Wolfgang Denk
2009-09-06 23:01 ` Jean-Christophe PLAGNIOL-VILLARD
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=20090824091003.0b8a631f@marrow.netinsight.se \
--to=simon.kagstrom@netinsight.net \
--cc=u-boot@lists.denx.de \
/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