函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:lib\bitmap.c Create Date:2022-07-27 07:17:30
首页 Copyright©Brick

823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/**
 * bitmap_bitremap - Apply map defined by a pair of bitmaps to a single bit
 *  @oldbit: bit position to be mapped
 *  @old: defines domain of map
 *  @new: defines range of map
 *  @bits: number of bits in each of these bitmaps
 *
 * Let @old and @new define a mapping of bit positions, such that
 * whatever position is held by the n-th set bit in @old is mapped
 * to the n-th set bit in @new.  In the more general case, allowing
 * for the possibility that the weight 'w' of @new is less than the
 * weight of @old, map the position of the n-th set bit in @old to
 * the position of the m-th set bit in @new, where m == n % w.
 *
 * The positions of unset bits in @old are mapped to themselves
 * (the identify map).
 *
 * Apply the above specified mapping to bit position @oldbit, returning
 * the new bit position.
 *
 * For example, lets say that @old has bits 4 through 7 set, and
 * @new has bits 12 through 15 set.  This defines the mapping of bit
 * position 4 to 12, 5 to 13, 6 to 14 and 7 to 15, and of all other
 * bit positions unchanged.  So if say @oldbit is 5, then this routine
 * returns 13.
 */
int bitmap_bitremap(int oldbit, const unsigned long *old,
                const unsigned long *new, int bits)
{
    int w = bitmap_weight(new, bits);
    int n = bitmap_pos_to_ord(old, oldbit, bits);
    if (n < 0 || w == 0)
        return oldbit;
    else
        return bitmap_ord_to_pos(new, n % w, bits);
}