Ignore:
Timestamp:
Jan 1, 2021, 5:31:48 AM (5 years ago)
Author:
Paul Smedley
Message:

Add source for uniaud32 based on code from linux kernel 5.4.86

Location:
GPL/branches/uniaud32-next
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/include/linux/bitops.h

    r441 r615  
    11#ifndef _I386_BITOPS_H
    22#define _I386_BITOPS_H
     3
     4#include <linux/types.h>
    35
    46/*
    57 * Copyright 1992, Linus Torvalds.
    68 */
     9
    710
    811/*
     
    1922#include <asm\bitops.h>
    2023#define smp_mb__after_clear_bit()       
     24unsigned int hweight32(unsigned int w);
     25/**
     26 * find_first_bit - find the first set bit in a memory region
     27 * @addr: The address to start the search at
     28 * @size: The maximum number of bits to search
     29 *
     30 * Returns the bit number of the first set bit.
     31 * If no bits are set, returns @size.
     32 */
     33extern unsigned long find_first_bit(const unsigned long *addr,
     34                                    unsigned long size);
     35
     36
     37/**
     38 * __ffs - find first bit in word.
     39 * @word: The word to search
     40 *
     41 * Undefined if no bit exists, so code should check against 0 first.
     42 */
     43static unsigned long __ffs(unsigned long word)
     44{
     45        int num = 0;
     46
     47#if BITS_PER_LONG == 64
     48        if ((word & 0xffffffff) == 0) {
     49                num += 32;
     50                word >>= 32;
     51        }
     52#endif
     53        if ((word & 0xffff) == 0) {
     54                num += 16;
     55                word >>= 16;
     56        }
     57        if ((word & 0xff) == 0) {
     58                num += 8;
     59                word >>= 8;
     60        }
     61        if ((word & 0xf) == 0) {
     62                num += 4;
     63                word >>= 4;
     64        }
     65        if ((word & 0x3) == 0) {
     66                num += 2;
     67                word >>= 2;
     68        }
     69        if ((word & 0x1) == 0)
     70                num += 1;
     71        return num;
     72}
     73
     74/**
     75 * __fls - find last (most-significant) set bit in a long word
     76 * @word: the word to search
     77 *
     78 * Undefined if no set bit exists, so code should check against 0 first.
     79 */
     80static unsigned long __fls(unsigned long word)
     81{
     82        int num = BITS_PER_LONG - 1;
     83
     84#if BITS_PER_LONG == 64
     85        if (!(word & (~0ul << 32))) {
     86                num -= 32;
     87                word <<= 32;
     88        }
     89#endif
     90        if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
     91                num -= 16;
     92                word <<= 16;
     93        }
     94        if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
     95                num -= 8;
     96                word <<= 8;
     97        }
     98        if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
     99                num -= 4;
     100                word <<= 4;
     101        }
     102        if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
     103                num -= 2;
     104                word <<= 2;
     105        }
     106        if (!(word & (~0ul << (BITS_PER_LONG-1))))
     107                num -= 1;
     108        return num;
     109}
     110
     111/* same as for_each_set_bit() but use bit as value to start with */
     112#define for_each_set_bit_from(bit, addr, size) \
     113        for ((bit) = find_next_bit((addr), (size), (bit));      \
     114             (bit) < (size);                                    \
     115             (bit) = find_next_bit((addr), (size), (bit) + 1))
     116
     117/**
     118 * fls - find last (most-significant) bit set
     119 * @x: the word to search
     120 *
     121 * This is defined the same way as ffs.
     122 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
     123 */
     124
     125static inline int fls(int x)
     126{
     127        int r = 32;
     128
     129        if (!x)
     130                return 0;
     131        if (!(x & 0xffff0000u)) {
     132                x <<= 16;
     133                r -= 16;
     134        }
     135        if (!(x & 0xff000000u)) {
     136                x <<= 8;
     137                r -= 8;
     138        }
     139        if (!(x & 0xf0000000u)) {
     140                x <<= 4;
     141                r -= 4;
     142        }
     143        if (!(x & 0xc0000000u)) {
     144                x <<= 2;
     145                r -= 2;
     146        }
     147        if (!(x & 0x80000000u)) {
     148                x <<= 1;
     149                r -= 1;
     150        }
     151        return r;
     152}
     153
     154#define BIT(nr)                 (1UL << (nr))
     155#define BIT_MASK(nr)            (1UL << ((nr) % BITS_PER_LONG))
     156#define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
     157#define BITS_PER_BYTE           8
     158#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
     159
     160/*
     161 * Create a contiguous bitmask starting at bit position @l and ending at
     162 * position @h. For example
     163 * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
     164 */
     165#define GENMASK(h, l) \
     166        (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
     167
     168#define GENMASK_ULL(h, l) \
     169        (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
     170
     171#define for_each_set_bit(bit, addr, size) \
     172        for ((bit) = find_first_bit((addr), (size)); \
     173             (bit) < (size); \
     174             (bit) = find_next_bit((addr), (size), (bit) + 1))
     175
     176static inline int get_bitmask_order(unsigned int count)
     177{
     178        int order;
     179
     180        order = fls(count);
     181        return order;   /* We could be slightly more clever with -1 here... */
     182}
     183
     184static inline int get_count_order(unsigned int count)
     185{
     186        int order;
     187
     188        order = fls(count) - 1;
     189        if (count & (count - 1))
     190                order++;
     191        return order;
     192}
     193
    21194#endif /* _I386_BITOPS_H */
Note: See TracChangeset for help on using the changeset viewer.