File: bitops.c

package info (click to toggle)
erofs-utils 1.9-1
  • links: PTS
  • area: main
  • in suites:
  • size: 1,392 kB
  • sloc: ansic: 28,406; makefile: 202; sh: 33
file content (30 lines) | stat: -rw-r--r-- 638 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0
/*
 * erofs-utils/lib/bitops.c
 *
 * Copyright (C) 2025, Alibaba Cloud
 */
#include <erofs/bitops.h>

unsigned long erofs_find_next_bit(const unsigned long *addr,
				  unsigned long nbits, unsigned long start)
{
	unsigned long tmp;

	if (__erofs_unlikely(start >= nbits))
		return nbits;

	tmp = addr[start / BITS_PER_LONG];

	tmp &= ~0UL << ((start) & (BITS_PER_LONG - 1));
	start = round_down(start, BITS_PER_LONG);

	while (!tmp) {
		start += BITS_PER_LONG;
		if (start >= nbits)
			return nbits;

		tmp = addr[start / BITS_PER_LONG];
	}
	return min(start + ffs_long(tmp), nbits);
}