Add bitops header for subsequent bloom filter implementation. This is borrowed from a part of the previous patch. See: https://lore.kernel.org/all/20230802091750.74181-3-jeffl...@linux.alibaba.com/.
Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com> --- v2: Rename the bitops functions. v1: https://lore.kernel.org/all/20240718054025.427439-1-hongz...@linux.alibaba.com/ --- include/erofs/bitops.h | 37 +++++++++++++++++++++++++++++++++++++ lib/Makefile.am | 1 + 2 files changed, 38 insertions(+) create mode 100644 include/erofs/bitops.h diff --git a/include/erofs/bitops.h b/include/erofs/bitops.h new file mode 100644 index 0000000..fa31934 --- /dev/null +++ b/include/erofs/bitops.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ +#ifndef __EROFS_BITOPS_H +#define __EROFS_BITOPS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "defs.h" + +static inline void __set_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p |= mask; +} + +static inline void __clear_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p &= ~mask; +} + +static inline int __test_bit(int nr, const volatile unsigned long *addr) +{ + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/Makefile.am b/lib/Makefile.am index 2cb4cab..6b52470 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,6 +20,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/io.h \ $(top_srcdir)/include/erofs/list.h \ $(top_srcdir)/include/erofs/print.h \ + $(top_srcdir)/include/erofs/bitops.h \ $(top_srcdir)/include/erofs/tar.h \ $(top_srcdir)/include/erofs/trace.h \ $(top_srcdir)/include/erofs/xattr.h \ -- 2.43.5