linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 04/10] btrfs-progs: Implement find_*_bit_le operations
Date: Mon,  1 Oct 2018 17:46:15 +0300	[thread overview]
Message-ID: <1538405181-25231-5-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1538405181-25231-1-git-send-email-nborisov@suse.com>

This commit introduces explicit little endian bit operations. The only
difference with the existing bitops implementation is that bswap(32|64)
is called when the _le versions are invoked on a big-endian machine.
This is in preparation for adding free space tree conversion support.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 kernel-lib/bitops.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/kernel-lib/bitops.h b/kernel-lib/bitops.h
index 78256adf55be..5030bfa2815e 100644
--- a/kernel-lib/bitops.h
+++ b/kernel-lib/bitops.h
@@ -2,6 +2,7 @@
 #define _PERF_LINUX_BITOPS_H_
 
 #include <linux/kernel.h>
+#include <endian.h>
 #include "internal.h"
 
 #ifndef DIV_ROUND_UP
@@ -170,5 +171,86 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr,
 }
 
 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
+#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+
+static inline unsigned long ext2_swab(const unsigned long y)
+{
+#if BITS_PER_LONG == 64
+	return (unsigned long) bswap64((u64) y);
+#elif BITS_PER_LONG == 32
+	return (unsigned long) bswap32((u32) y);
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+
+static inline unsigned long _find_next_bit_le(const unsigned long *addr1,
+		const unsigned long *addr2, unsigned long nbits,
+		unsigned long start, unsigned long invert)
+{
+	unsigned long tmp;
+
+	if (start >= nbits)
+		return nbits;
+
+	tmp = addr1[start / BITS_PER_LONG];
+	if (addr2)
+		tmp &= addr2[start / BITS_PER_LONG];
+	tmp ^= invert;
+
+	/* Handle 1st word. */
+	tmp &= ext2_swab(BITMAP_FIRST_WORD_MASK(start));
+	start = round_down(start, BITS_PER_LONG);
+
+	while (!tmp) {
+		start += BITS_PER_LONG;
+		if (start >= nbits)
+			return nbits;
+
+		tmp = addr1[start / BITS_PER_LONG];
+		if (addr2)
+			tmp &= addr2[start / BITS_PER_LONG];
+		tmp ^= invert;
+	}
+
+	return min(start + __ffs(ext2_swab(tmp)), nbits);
+}
+
+unsigned long find_next_zero_bit_le(const void *addr, unsigned
+		long size, unsigned long offset)
+{
+	return _find_next_bit_le(addr, NULL, size, offset, ~0UL);
+}
+
+
+unsigned long find_next_bit_le(const void *addr, unsigned
+		long size, unsigned long offset)
+{
+	return _find_next_bit_le(addr, NULL, size, offset, 0UL);
+}
+
+#else
+
+static inline unsigned long find_next_zero_bit_le(const void *addr,
+                unsigned long size, unsigned long offset)
+{
+        return find_next_zero_bit(addr, size, offset);
+}
+
+static inline unsigned long find_next_bit_le(const void *addr,
+                unsigned long size, unsigned long offset)
+{
+        return find_next_bit(addr, size, offset);
+}
+
+static inline unsigned long find_first_zero_bit_le(const void *addr,
+                unsigned long size)
+{
+        return find_first_zero_bit(addr, size);
+}
+
+#endif
 
 #endif
-- 
2.7.4


  parent reply	other threads:[~2018-10-01 14:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 14:46 [PATCH 00/10] Freespace tree repair support v2 Nikolay Borisov
2018-10-01 14:46 ` [PATCH 01/10] btrfs-progs: Add support for freespace tree in btrfs_read_fs_root Nikolay Borisov
2018-10-02 19:20   ` Omar Sandoval
2018-10-04  1:05   ` Su Yue
2018-10-01 14:46 ` [PATCH 02/10] btrfs-progs: Add extent buffer bitmap manipulation infrastructure Nikolay Borisov
2018-10-02 19:24   ` Omar Sandoval
2018-10-04  1:31   ` Su Yue
2018-10-01 14:46 ` [PATCH 03/10] btrfs-progs: Replace homegrown bitops related functions with kernel counterparts Nikolay Borisov
2018-10-02 23:32   ` Omar Sandoval
2018-10-01 14:46 ` Nikolay Borisov [this message]
2018-10-04 18:08   ` [PATCH 04/10] btrfs-progs: Implement find_*_bit_le operations Omar Sandoval
2018-10-04 18:09     ` Nikolay Borisov
2018-10-01 14:46 ` [PATCH 05/10] btrfs-progs: Pull free space tree related code from kernel Nikolay Borisov
2018-10-04 18:26   ` Omar Sandoval
2018-10-04 18:34     ` Nikolay Borisov
2018-10-04 19:01       ` Omar Sandoval
2018-10-23 14:05     ` David Sterba
2018-10-01 14:46 ` [PATCH 06/10] btrfs-progs: Hook FST code in extent (de)alloc Nikolay Borisov
2018-10-01 14:46 ` [PATCH 07/10] btrfs-progs: Add freespace tree as compat_ro supported feature Nikolay Borisov
2018-10-04 18:30   ` Omar Sandoval
2018-10-04 18:36     ` Nikolay Borisov
2018-10-01 14:46 ` [PATCH 08/10] btrfs-progs: check: Add support for freespace tree fixing Nikolay Borisov
2018-10-04 19:16   ` Omar Sandoval
2018-10-01 14:46 ` [PATCH 09/10] btrfs-progs: tests: Test for FST corruption detection/repair Nikolay Borisov
2018-10-01 14:46 ` [PATCH 10/10] btrfs-progs: check: Fix wrong error message in case of corrupted bitmap Nikolay Borisov
2018-10-04 19:18   ` Omar Sandoval
2018-10-23 15:00 ` [PATCH 00/10] Freespace tree repair support v2 David Sterba

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=1538405181-25231-5-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).