"Das U-Boot" Source Tree

include: Add generic bitops headers

Use the generic bitops header files from the kernel.

Imported from kernel 4.2.3.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

authored by

Fabio Estevam and committed by
Tom Rini
77c8554e f598e7a9

+163
+43
include/asm-generic/bitops/__ffs.h
··· 1 + #ifndef _ASM_GENERIC_BITOPS___FFS_H_ 2 + #define _ASM_GENERIC_BITOPS___FFS_H_ 3 + 4 + #include <asm/types.h> 5 + 6 + /** 7 + * __ffs - find first bit in word. 8 + * @word: The word to search 9 + * 10 + * Undefined if no bit exists, so code should check against 0 first. 11 + */ 12 + static __always_inline unsigned long __ffs(unsigned long word) 13 + { 14 + int num = 0; 15 + 16 + #if BITS_PER_LONG == 64 17 + if ((word & 0xffffffff) == 0) { 18 + num += 32; 19 + word >>= 32; 20 + } 21 + #endif 22 + if ((word & 0xffff) == 0) { 23 + num += 16; 24 + word >>= 16; 25 + } 26 + if ((word & 0xff) == 0) { 27 + num += 8; 28 + word >>= 8; 29 + } 30 + if ((word & 0xf) == 0) { 31 + num += 4; 32 + word >>= 4; 33 + } 34 + if ((word & 0x3) == 0) { 35 + num += 2; 36 + word >>= 2; 37 + } 38 + if ((word & 0x1) == 0) 39 + num += 1; 40 + return num; 41 + } 42 + 43 + #endif /* _ASM_GENERIC_BITOPS___FFS_H_ */
+43
include/asm-generic/bitops/__fls.h
··· 1 + #ifndef _ASM_GENERIC_BITOPS___FLS_H_ 2 + #define _ASM_GENERIC_BITOPS___FLS_H_ 3 + 4 + #include <asm/types.h> 5 + 6 + /** 7 + * __fls - find last (most-significant) set bit in a long word 8 + * @word: the word to search 9 + * 10 + * Undefined if no set bit exists, so code should check against 0 first. 11 + */ 12 + static __always_inline unsigned long __fls(unsigned long word) 13 + { 14 + int num = BITS_PER_LONG - 1; 15 + 16 + #if BITS_PER_LONG == 64 17 + if (!(word & (~0ul << 32))) { 18 + num -= 32; 19 + word <<= 32; 20 + } 21 + #endif 22 + if (!(word & (~0ul << (BITS_PER_LONG-16)))) { 23 + num -= 16; 24 + word <<= 16; 25 + } 26 + if (!(word & (~0ul << (BITS_PER_LONG-8)))) { 27 + num -= 8; 28 + word <<= 8; 29 + } 30 + if (!(word & (~0ul << (BITS_PER_LONG-4)))) { 31 + num -= 4; 32 + word <<= 4; 33 + } 34 + if (!(word & (~0ul << (BITS_PER_LONG-2)))) { 35 + num -= 2; 36 + word <<= 2; 37 + } 38 + if (!(word & (~0ul << (BITS_PER_LONG-1)))) 39 + num -= 1; 40 + return num; 41 + } 42 + 43 + #endif /* _ASM_GENERIC_BITOPS___FLS_H_ */
+41
include/asm-generic/bitops/fls.h
··· 1 + #ifndef _ASM_GENERIC_BITOPS_FLS_H_ 2 + #define _ASM_GENERIC_BITOPS_FLS_H_ 3 + 4 + /** 5 + * fls - find last (most-significant) bit set 6 + * @x: the word to search 7 + * 8 + * This is defined the same way as ffs. 9 + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 10 + */ 11 + 12 + static __always_inline int fls(int x) 13 + { 14 + int r = 32; 15 + 16 + if (!x) 17 + return 0; 18 + if (!(x & 0xffff0000u)) { 19 + x <<= 16; 20 + r -= 16; 21 + } 22 + if (!(x & 0xff000000u)) { 23 + x <<= 8; 24 + r -= 8; 25 + } 26 + if (!(x & 0xf0000000u)) { 27 + x <<= 4; 28 + r -= 4; 29 + } 30 + if (!(x & 0xc0000000u)) { 31 + x <<= 2; 32 + r -= 2; 33 + } 34 + if (!(x & 0x80000000u)) { 35 + x <<= 1; 36 + r -= 1; 37 + } 38 + return r; 39 + } 40 + 41 + #endif /* _ASM_GENERIC_BITOPS_FLS_H_ */
+36
include/asm-generic/bitops/fls64.h
··· 1 + #ifndef _ASM_GENERIC_BITOPS_FLS64_H_ 2 + #define _ASM_GENERIC_BITOPS_FLS64_H_ 3 + 4 + #include <asm/types.h> 5 + 6 + /** 7 + * fls64 - find last set bit in a 64-bit word 8 + * @x: the word to search 9 + * 10 + * This is defined in a similar way as the libc and compiler builtin 11 + * ffsll, but returns the position of the most significant set bit. 12 + * 13 + * fls64(value) returns 0 if value is 0 or the position of the last 14 + * set bit if value is nonzero. The last (most significant) bit is 15 + * at position 64. 16 + */ 17 + #if BITS_PER_LONG == 32 18 + static __always_inline int fls64(__u64 x) 19 + { 20 + __u32 h = x >> 32; 21 + if (h) 22 + return fls(h) + 32; 23 + return fls(x); 24 + } 25 + #elif BITS_PER_LONG == 64 26 + static __always_inline int fls64(__u64 x) 27 + { 28 + if (x == 0) 29 + return 0; 30 + return __fls(x) + 1; 31 + } 32 + #else 33 + #error BITS_PER_LONG not 32 or 64 34 + #endif 35 + 36 + #endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */