mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-07 12:35:28 +00:00
Remove the bitops helpers
We don't have any use for the bitops today, we'll resurrect this in simpler form if it's needed again. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sparse.h"
|
||||
#include "util.h"
|
||||
#include "bitops.h"
|
||||
|
||||
#if (__SIZEOF_LONG__ == 8)
|
||||
typedef __le64 lelong;
|
||||
#define lelong_to_cpu le64_to_cpu
|
||||
|
||||
#elif (__SIZEOF_LONG__ == 4)
|
||||
typedef __le32 lelong;
|
||||
#define lelong_to_cpu le32_to_cpu
|
||||
|
||||
#else
|
||||
#error "no sizeof long define?"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* I'd have used ffsl(), but defining _GNU_SOURCE caused build errors
|
||||
* in glibc. The gcc builtin has the added bonus of returning 0 for the
|
||||
* least significant bit instead of 1.
|
||||
*/
|
||||
#define ctzl __builtin_ctzl
|
||||
|
||||
int find_next_bit_le(void *addr, long size, int start)
|
||||
{
|
||||
lelong * __packed longs = addr;
|
||||
unsigned long off = 0;
|
||||
unsigned long masked;
|
||||
|
||||
/* skip past whole longs before start */
|
||||
if (start >= BITS_PER_LONG) {
|
||||
longs += start / BITS_PER_LONG;
|
||||
off = start & ~(BITS_PER_LONG - 1);
|
||||
start -= off;
|
||||
}
|
||||
|
||||
/* mask off low bits if start isn't aligned */
|
||||
if (start) {
|
||||
masked = lelong_to_cpu(*longs) & ~((1 << (start)) - 1);
|
||||
if (masked)
|
||||
return min(ctzl(masked), size);
|
||||
|
||||
off += BITS_PER_LONG;
|
||||
longs++;
|
||||
}
|
||||
|
||||
/* then search remaining longs */
|
||||
while (off < size) {
|
||||
if (*longs)
|
||||
return min(off + ctzl(lelong_to_cpu(*longs)), size);
|
||||
longs++;
|
||||
off += BITS_PER_LONG;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#ifndef _BITOPS_H_
|
||||
#define _BITOPS_H_
|
||||
|
||||
/*
|
||||
* Implement little endian bitmaps in terms of native longs. __packed
|
||||
* is used to avoid unaligned accesses.
|
||||
*/
|
||||
|
||||
typedef unsigned long * __packed ulong_ptr;
|
||||
|
||||
#define BITS_PER_LONG (sizeof(long) * 8)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define BITOP_LE_SWIZZLE 0
|
||||
#else
|
||||
#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
|
||||
#endif
|
||||
|
||||
static inline ulong_ptr nr_word(int nr, ulong_ptr longs)
|
||||
{
|
||||
return &longs[nr / BITS_PER_LONG];
|
||||
}
|
||||
|
||||
static inline unsigned long nr_mask(int nr)
|
||||
{
|
||||
return 1UL << (nr % BITS_PER_LONG);
|
||||
}
|
||||
|
||||
static inline int test_bit(int nr, ulong_ptr longs)
|
||||
{
|
||||
return !!(*nr_word(nr, longs) & nr_mask(nr));
|
||||
}
|
||||
|
||||
static inline void set_bit(int nr, ulong_ptr longs)
|
||||
{
|
||||
*nr_word(nr, longs) |= nr_mask(nr);
|
||||
}
|
||||
|
||||
static inline void clear_bit(int nr, ulong_ptr longs)
|
||||
{
|
||||
*nr_word(nr, longs) &= ~nr_mask(nr);
|
||||
}
|
||||
|
||||
static inline int test_bit_le(int nr, void *addr)
|
||||
{
|
||||
return test_bit(nr ^ BITOP_LE_SWIZZLE, addr);
|
||||
}
|
||||
|
||||
static inline int test_and_set_bit_le(int nr, void *addr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
nr ^= BITOP_LE_SWIZZLE;
|
||||
ret = test_bit(nr, addr);
|
||||
set_bit(nr, addr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void set_bit_le(int nr, void *addr)
|
||||
{
|
||||
set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
|
||||
}
|
||||
|
||||
static inline void clear_bit_le(int nr, void *addr)
|
||||
{
|
||||
clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
|
||||
}
|
||||
|
||||
static inline int test_and_clear_bit_le(int nr, void *addr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
nr ^= BITOP_LE_SWIZZLE;
|
||||
ret = test_bit(nr, addr);
|
||||
clear_bit(nr, addr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int find_next_bit_le(void *addr, long size, int start);
|
||||
|
||||
#endif
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "crc.h"
|
||||
#include "rand.h"
|
||||
#include "dev.h"
|
||||
#include "bitops.h"
|
||||
#include "buddy.h"
|
||||
#include "item.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user