Lines Matching +full:bit +full:- +full:shift

1 /* SPDX-License-Identifier: GPL-2.0 */
25 * Defined here because those may be needed by architecture-specific static
29 #include <asm-generic/bitops/generic-non-atomic.h>
32 * Many architecture-specific non-atomic bitops contain inline asm code and due
33 * to that the compiler can't optimize them to compile-time expressions or
37 * equal to `unsigned long foo = BIT(BAR)`, pick the generic C alternative when
40 * The casts to `uintptr_t` are needed to mitigate `-Waddress` warnings when
41 * passing a bitmap from .bss or .data (-> `!!addr` is always true).
51 * The following macros are non-atomic versions of their non-underscored
92 return order; /* We could be slightly more clever with -1 here... */ in get_bitmask_order()
101 * rol64 - rotate a 64-bit value left
103 * @shift: bits to roll
105 static inline __u64 rol64(__u64 word, unsigned int shift) in rol64() argument
107 return (word << (shift & 63)) | (word >> ((-shift) & 63)); in rol64()
111 * ror64 - rotate a 64-bit value right
113 * @shift: bits to roll
115 static inline __u64 ror64(__u64 word, unsigned int shift) in ror64() argument
117 return (word >> (shift & 63)) | (word << ((-shift) & 63)); in ror64()
121 * rol32 - rotate a 32-bit value left
123 * @shift: bits to roll
125 static inline __u32 rol32(__u32 word, unsigned int shift) in rol32() argument
127 return (word << (shift & 31)) | (word >> ((-shift) & 31)); in rol32()
131 * ror32 - rotate a 32-bit value right
133 * @shift: bits to roll
135 static inline __u32 ror32(__u32 word, unsigned int shift) in ror32() argument
137 return (word >> (shift & 31)) | (word << ((-shift) & 31)); in ror32()
141 * rol16 - rotate a 16-bit value left
143 * @shift: bits to roll
145 static inline __u16 rol16(__u16 word, unsigned int shift) in rol16() argument
147 return (word << (shift & 15)) | (word >> ((-shift) & 15)); in rol16()
151 * ror16 - rotate a 16-bit value right
153 * @shift: bits to roll
155 static inline __u16 ror16(__u16 word, unsigned int shift) in ror16() argument
157 return (word >> (shift & 15)) | (word << ((-shift) & 15)); in ror16()
161 * rol8 - rotate an 8-bit value left
163 * @shift: bits to roll
165 static inline __u8 rol8(__u8 word, unsigned int shift) in rol8() argument
167 return (word << (shift & 7)) | (word >> ((-shift) & 7)); in rol8()
171 * ror8 - rotate an 8-bit value right
173 * @shift: bits to roll
175 static inline __u8 ror8(__u8 word, unsigned int shift) in ror8() argument
177 return (word >> (shift & 7)) | (word << ((-shift) & 7)); in ror8()
181 * sign_extend32 - sign extend a 32-bit value using specified bit as sign-bit
183 * @index: 0 based bit index (0<=index<32) to sign bit
185 * This is safe to use for 16- and 8-bit types as well.
189 __u8 shift = 31 - index; in sign_extend32() local
190 return (__s32)(value << shift) >> shift; in sign_extend32()
194 * sign_extend64 - sign extend a 64-bit value using specified bit as sign-bit
196 * @index: 0 based bit index (0<=index<64) to sign bit
200 __u8 shift = 63 - index; in sign_extend64() local
201 return (__s64)(value << shift) >> shift; in sign_extend64()
214 return -1; in get_count_order()
216 return fls(--count); in get_count_order()
220 * get_count_order_long - get order after rounding @l up to power of 2
228 return -1; in get_count_order_long()
229 return (int)fls_long(--l); in get_count_order_long()
233 * parity8 - get the parity of an u8 value
245 * return -EBADMSG;
247 * If you need to calculate a parity bit, you need to draw the conclusion from
248 * this result yourself. Example to enforce odd parity, parity bit is bit 7:
251 * val ^= BIT(7);
264 * __ffs64 - find first set bit in a 64 bit word
265 * @word: The 64 bit word
267 * On 64 bit arches this is a synonym for __ffs
269 * is non-zero before calling this.
283 * fns - find N'th set bit in a word
285 * @n: Bit to find
289 while (word && n--) in fns()
290 word &= word - 1; in fns()
296 * assign_bit - Assign value to a bit in memory
297 * @nr: the bit to set
308 * __ptr_set_bit - Set bit in a pointer's value
309 * @nr: the bit to set
314 * __ptr_set_bit(bit, &p);
323 * __ptr_clear_bit - Clear bit in a pointer's value
324 * @nr: the bit to clear
329 * __ptr_clear_bit(bit, &p);
338 * __ptr_test_bit - Test bit in a pointer's value
339 * @nr: the bit to test
344 * if (__ptr_test_bit(bit, &p)) {