LCOV - code coverage report
Current view: top level - fs/xfs/libxfs - xfs_bit.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-achx @ Mon Jul 31 20:08:12 PDT 2023 Lines: 49 49 100.0 %
Date: 2023-07-31 20:08:12 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : #include "xfs.h"
       7             : #include "xfs_log_format.h"
       8             : #include "xfs_bit.h"
       9             : 
      10             : /*
      11             :  * XFS bit manipulation routines, used in non-realtime code.
      12             :  */
      13             : 
      14             : /*
      15             :  * Return whether bitmap is empty.
      16             :  * Size is number of words in the bitmap, which is padded to word boundary
      17             :  * Returns 1 for empty, 0 for non-empty.
      18             :  */
      19             : int
      20  4084915433 : xfs_bitmap_empty(uint *map, uint size)
      21             : {
      22  4084915433 :         uint i;
      23             : 
      24  4188926033 :         for (i = 0; i < size; i++) {
      25  4116254572 :                 if (map[i] != 0)
      26             :                         return 0;
      27             :         }
      28             : 
      29             :         return 1;
      30             : }
      31             : 
      32             : /*
      33             :  * Count the number of contiguous bits set in the bitmap starting with bit
      34             :  * start_bit.  Size is the size of the bitmap in words.
      35             :  */
      36             : int
      37 10860893282 : xfs_contig_bits(uint *map, uint size, uint start_bit)
      38             : {
      39 10860893282 :         uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
      40 10860893282 :         uint result = 0;
      41 10860893282 :         uint tmp;
      42             : 
      43 10860893282 :         size <<= BIT_TO_WORD_SHIFT;
      44             : 
      45 10860893282 :         ASSERT(start_bit < size);
      46 10860893282 :         size -= start_bit & ~(NBWORD - 1);
      47 10860893282 :         start_bit &= (NBWORD - 1);
      48 10860893282 :         if (start_bit) {
      49  4216500902 :                 tmp = *p++;
      50             :                 /* set to one first offset bits prior to start */
      51  4216500902 :                 tmp |= (~0U >> (NBWORD-start_bit));
      52  4216500902 :                 if (tmp != ~0U)
      53  3841502120 :                         goto found;
      54   374998782 :                 result += NBWORD;
      55   374998782 :                 size -= NBWORD;
      56             :         }
      57  8917822602 :         while (size) {
      58  6666457810 :                 if ((tmp = *p++) != ~0U)
      59  4768026370 :                         goto found;
      60  1898431440 :                 result += NBWORD;
      61  1898431440 :                 size -= NBWORD;
      62             :         }
      63  2251364792 :         return result - start_bit;
      64  8609528490 : found:
      65  8609528490 :         return result + ffz(tmp) - start_bit;
      66             : }
      67             : 
      68             : /*
      69             :  * This takes the bit number to start looking from and
      70             :  * returns the next set bit from there.  It returns -1
      71             :  * if there are no more bits set or the start bit is
      72             :  * beyond the end of the bitmap.
      73             :  *
      74             :  * Size is the number of words, not bytes, in the bitmap.
      75             :  */
      76 >11014*10^7 : int xfs_next_bit(uint *map, uint size, uint start_bit)
      77             : {
      78 >11014*10^7 :         uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
      79 >11014*10^7 :         uint result = start_bit & ~(NBWORD - 1);
      80 >11014*10^7 :         uint tmp;
      81             : 
      82 >11014*10^7 :         size <<= BIT_TO_WORD_SHIFT;
      83             : 
      84 >11014*10^7 :         if (start_bit >= size)
      85             :                 return -1;
      86 >10769*10^7 :         size -= result;
      87 >10769*10^7 :         start_bit &= (NBWORD - 1);
      88 >10769*10^7 :         if (start_bit) {
      89 90726613750 :                 tmp = *p++;
      90             :                 /* set to zero first offset bits prior to start */
      91 90726613750 :                 tmp &= (~0U << start_bit);
      92 90726613750 :                 if (tmp != 0U)
      93 75815057012 :                         goto found;
      94 14911556738 :                 result += NBWORD;
      95 14911556738 :                 size -= NBWORD;
      96             :         }
      97 32035765195 :         while (size) {
      98 17367215172 :                 if ((tmp = *p++) != 0U)
      99 17215158076 :                         goto found;
     100   152057096 :                 result += NBWORD;
     101   152057096 :                 size -= NBWORD;
     102             :         }
     103             :         return -1;
     104 93030215088 : found:
     105 93030215088 :         return result + ffs(tmp) - 1;
     106             : }

Generated by: LCOV version 1.14