Skip to content

Commit 8f76f9c

Browse files
Vineet Guptaarndb
authored andcommitted
bitops/non-atomic: make @nr unsigned to avoid any DIV
signed math causes generation of costlier instructions such as DIV when they could be done by barrerl shifter. Worse part is this is not caught by things like bloat-o-meter since instruction length / symbols are typically same size. e.g. stock (signed math) __________________ 919b4614 <test_taint>: 919b4614: div r2,r0,0x20 ^^^ 919b4618: add2 r2,0x920f6050,r2 919b4620: ld_s r2,[r2,0] 919b4622: lsr r0,r2,r0 919b4626: j_s.d [blink] 919b4628: bmsk_s r0,r0,0 919b462a: nop_s (patched) unsigned math __________________ 919b4614 <test_taint>: 919b4614: lsr r2,r0,0x5 @nr/32 ^^^ 919b4618: add2 r2,0x920f6050,r2 919b4620: ld_s r2,[r2,0] 919b4622: lsr r0,r2,r0 #test_bit() 919b4626: j_s.d [blink] 919b4628: bmsk_s r0,r0,0 919b462a: nop_s Signed-off-by: Vineet Gupta <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent a71bfc0 commit 8f76f9c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/asm-generic/bitops/non-atomic.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* If it's called on the same region of memory simultaneously, the effect
1414
* may be that only one operation succeeds.
1515
*/
16-
static inline void __set_bit(int nr, volatile unsigned long *addr)
16+
static inline void __set_bit(unsigned int nr, volatile unsigned long *addr)
1717
{
1818
unsigned long mask = BIT_MASK(nr);
1919
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
2020

2121
*p |= mask;
2222
}
2323

24-
static inline void __clear_bit(int nr, volatile unsigned long *addr)
24+
static inline void __clear_bit(unsigned int nr, volatile unsigned long *addr)
2525
{
2626
unsigned long mask = BIT_MASK(nr);
2727
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -38,7 +38,7 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr)
3838
* If it's called on the same region of memory simultaneously, the effect
3939
* may be that only one operation succeeds.
4040
*/
41-
static inline void __change_bit(int nr, volatile unsigned long *addr)
41+
static inline void __change_bit(unsigned int nr, volatile unsigned long *addr)
4242
{
4343
unsigned long mask = BIT_MASK(nr);
4444
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -55,7 +55,7 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)
5555
* If two examples of this operation race, one can appear to succeed
5656
* but actually fail. You must protect multiple accesses with a lock.
5757
*/
58-
static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
58+
static inline int __test_and_set_bit(unsigned int nr, volatile unsigned long *addr)
5959
{
6060
unsigned long mask = BIT_MASK(nr);
6161
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -74,7 +74,7 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
7474
* If two examples of this operation race, one can appear to succeed
7575
* but actually fail. You must protect multiple accesses with a lock.
7676
*/
77-
static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
77+
static inline int __test_and_clear_bit(unsigned int nr, volatile unsigned long *addr)
7878
{
7979
unsigned long mask = BIT_MASK(nr);
8080
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
@@ -85,7 +85,7 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
8585
}
8686

8787
/* WARNING: non atomic and it can be reordered! */
88-
static inline int __test_and_change_bit(int nr,
88+
static inline int __test_and_change_bit(unsigned int nr,
8989
volatile unsigned long *addr)
9090
{
9191
unsigned long mask = BIT_MASK(nr);
@@ -101,7 +101,7 @@ static inline int __test_and_change_bit(int nr,
101101
* @nr: bit number to test
102102
* @addr: Address to start counting from
103103
*/
104-
static inline int test_bit(int nr, const volatile unsigned long *addr)
104+
static inline int test_bit(unsigned int nr, const volatile unsigned long *addr)
105105
{
106106
return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
107107
}

0 commit comments

Comments
 (0)