Skip to content

Commit

Permalink
m68k: introduce little-endian bitops
Browse files Browse the repository at this point in the history
Introduce little-endian bit operations by renaming native ext2 bit
operations and changing find_*_bit_le() to take a "void *".  The ext2 bit
operations are kept as wrapper macros using little-endian bit operations
to maintain bisectability until the conversions are finished.

Signed-off-by: Akinobu Mita <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Roman Zippel <[email protected]>
Cc: Andreas Schwab <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mita authored and torvalds committed Mar 24, 2011
1 parent f6b57e3 commit 3f5527f
Showing 1 changed file with 67 additions and 26 deletions.
93 changes: 67 additions & 26 deletions arch/m68k/include/asm/bitops_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,24 +359,45 @@ static inline int minix_test_bit(int nr, const void *vaddr)
return (p[nr >> 4] & (1U << (nr & 15))) != 0;
}

/* Bitmap functions for the ext2 filesystem. */
/* Bitmap functions for the little endian bitmap. */

static inline void __set_bit_le(int nr, void *addr)
{
__set_bit(nr ^ 24, addr);
}

#define ext2_set_bit(nr, addr) __test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_find_next_zero_bit(addr, size, offset) \
find_next_zero_bit_le((unsigned long *)addr, size, offset)
#define ext2_find_next_bit(addr, size, offset) \
find_next_bit_le((unsigned long *)addr, size, offset)
static inline void __clear_bit_le(int nr, void *addr)
{
__clear_bit(nr ^ 24, addr);
}

static inline int __test_and_set_bit_le(int nr, void *addr)
{
return __test_and_set_bit(nr ^ 24, addr);
}

static inline int test_and_set_bit_le(int nr, void *addr)
{
return test_and_set_bit(nr ^ 24, addr);
}

static inline int __test_and_clear_bit_le(int nr, void *addr)
{
return __test_and_clear_bit(nr ^ 24, addr);
}

static inline int ext2_test_bit(int nr, const void *vaddr)
static inline int test_and_clear_bit_le(int nr, void *addr)
{
return test_and_clear_bit(nr ^ 24, addr);
}

static inline int test_bit_le(int nr, const void *vaddr)
{
const unsigned char *p = vaddr;
return (p[nr >> 3] & (1U << (nr & 7))) != 0;
}

static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size)
static inline int find_first_zero_bit_le(const void *vaddr, unsigned size)
{
const unsigned long *p = vaddr, *addr = vaddr;
int res;
Expand All @@ -393,33 +414,36 @@ static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size)

--p;
for (res = 0; res < 32; res++)
if (!ext2_test_bit (res, p))
if (!test_bit_le(res, p))
break;
return (p - addr) * 32 + res;
}

static inline unsigned long find_next_zero_bit_le(const unsigned long *addr,
static inline unsigned long find_next_zero_bit_le(const void *addr,
unsigned long size, unsigned long offset)
{
const unsigned long *p = addr + (offset >> 5);
const unsigned long *p = addr;
int bit = offset & 31UL, res;

if (offset >= size)
return size;

p += offset >> 5;

if (bit) {
offset -= bit;
/* Look for zero in first longword */
for (res = bit; res < 32; res++)
if (!ext2_test_bit (res, p))
return (p - addr) * 32 + res;
if (!test_bit_le(res, p))
return offset + res;
p++;
offset += 32;
}
/* No zero yet, search remaining full bytes for a zero */
res = ext2_find_first_zero_bit (p, size - 32 * (p - addr));
return (p - addr) * 32 + res;
return offset + find_first_zero_bit_le(p, size - offset);
}

static inline int ext2_find_first_bit(const void *vaddr, unsigned size)
static inline int find_first_bit_le(const void *vaddr, unsigned size)
{
const unsigned long *p = vaddr, *addr = vaddr;
int res;
Expand All @@ -435,32 +459,49 @@ static inline int ext2_find_first_bit(const void *vaddr, unsigned size)

--p;
for (res = 0; res < 32; res++)
if (ext2_test_bit(res, p))
if (test_bit_le(res, p))
break;
return (p - addr) * 32 + res;
}

static inline unsigned long find_next_bit_le(const unsigned long *addr,
static inline unsigned long find_next_bit_le(const void *addr,
unsigned long size, unsigned long offset)
{
const unsigned long *p = addr + (offset >> 5);
const unsigned long *p = addr;
int bit = offset & 31UL, res;

if (offset >= size)
return size;

p += offset >> 5;

if (bit) {
offset -= bit;
/* Look for one in first longword */
for (res = bit; res < 32; res++)
if (ext2_test_bit(res, p))
return (p - addr) * 32 + res;
if (test_bit_le(res, p))
return offset + res;
p++;
offset += 32;
}
/* No set bit yet, search remaining full bytes for a set bit */
res = ext2_find_first_bit(p, size - 32 * (p - addr));
return (p - addr) * 32 + res;
return offset + find_first_bit_le(p, size - offset);
}

/* Bitmap functions for the ext2 filesystem. */

#define ext2_set_bit __test_and_set_bit_le
#define ext2_set_bit_atomic(lock, nr, addr) \
test_and_set_bit_le(nr, addr)
#define ext2_clear_bit __test_and_clear_bit_le
#define ext2_clear_bit_atomic(lock, nr, addr) \
test_and_clear_bit_le(nr, addr)
#define ext2_find_next_zero_bit find_next_zero_bit_le
#define ext2_find_next_bit find_next_bit_le
#define ext2_test_bit test_bit_le
#define ext2_find_first_zero_bit find_first_zero_bit_le
#define ext2_find_first_bit find_first_bit_le

#endif /* __KERNEL__ */

#endif /* _M68K_BITOPS_H */

0 comments on commit 3f5527f

Please sign in to comment.