findbit.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************
  2. *
  3. * Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
  4. *
  5. * smartdns is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * smartdns is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _TOOLS_GENERIC_BITOPS_FIND_H_
  19. #define _TOOLS_GENERIC_BITOPS_FIND_H_
  20. #ifndef find_next_bit
  21. /**
  22. * find_next_bit - find the next set bit in a memory region
  23. * @addr: The address to base the search on
  24. * @offset: The bitnumber to start searching at
  25. * @size: The bitmap size in bits
  26. *
  27. * Returns the bit number for the next set bit
  28. * If no bits are set, returns @size.
  29. */
  30. extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
  31. size, unsigned long offset);
  32. #endif
  33. #ifndef find_next_and_bit
  34. /**
  35. * find_next_and_bit - find the next set bit in both memory regions
  36. * @addr1: The first address to base the search on
  37. * @addr2: The second address to base the search on
  38. * @offset: The bitnumber to start searching at
  39. * @size: The bitmap size in bits
  40. *
  41. * Returns the bit number for the next set bit
  42. * If no bits are set, returns @size.
  43. */
  44. extern unsigned long find_next_and_bit(const unsigned long *addr1,
  45. const unsigned long *addr2, unsigned long size,
  46. unsigned long offset);
  47. #endif
  48. #ifndef find_next_zero_bit
  49. /**
  50. * find_next_zero_bit - find the next cleared bit in a memory region
  51. * @addr: The address to base the search on
  52. * @offset: The bitnumber to start searching at
  53. * @size: The bitmap size in bits
  54. *
  55. * Returns the bit number of the next zero bit
  56. * If no bits are zero, returns @size.
  57. */
  58. unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
  59. unsigned long offset);
  60. #endif
  61. #ifndef find_first_bit
  62. /**
  63. * find_first_bit - find the first set bit in a memory region
  64. * @addr: The address to start the search at
  65. * @size: The maximum number of bits to search
  66. *
  67. * Returns the bit number of the first set bit.
  68. * If no bits are set, returns @size.
  69. */
  70. extern unsigned long find_first_bit(const unsigned long *addr,
  71. unsigned long size);
  72. #endif /* find_first_bit */
  73. #ifndef find_first_zero_bit
  74. /**
  75. * find_first_zero_bit - find the first cleared bit in a memory region
  76. * @addr: The address to start the search at
  77. * @size: The maximum number of bits to search
  78. *
  79. * Returns the bit number of the first cleared bit.
  80. * If no bits are zero, returns @size.
  81. */
  82. unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size);
  83. #endif
  84. #endif /*_TOOLS_GENERIC_BITOPS_FIND_H_ */