arch/mips/include/asm/bitops.h
Source file repositories/reference/linux-study-clean/arch/mips/include/asm/bitops.h
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/include/asm/bitops.h- Extension
.h- Size
- 11532 bytes
- Lines
- 484
- Domain
- Architecture Layer
- Bucket
- arch/mips
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
linux/bits.hlinux/compiler.hlinux/types.hasm/asm.hasm/barrier.hasm/byteorder.hasm/compiler.hasm/cpu-features.hasm/sgidefs.hasm-generic/bitops/non-atomic.hasm-generic/bitops/fls64.hasm-generic/bitops/ffz.hasm-generic/bitops/sched.hasm/arch_hweight.hasm-generic/bitops/const_hweight.hasm-generic/bitops/le.hasm-generic/bitops/ext2-atomic.h
Detected Declarations
function set_bitfunction clear_bitfunction clear_bitfunction change_bitfunction test_and_set_bit_lockfunction test_and_set_bitfunction test_and_clear_bitfunction test_and_change_bitfunction xor_unlock_is_negative_bytefunction __clear_bitfunction positionfunction __ffsfunction flsfunction ffz
Annotated Snippet
__builtin_constant_p(cpu_has_clo_clz) && cpu_has_clo_clz) {
__asm__(
" .set push \n"
" .set "MIPS_ISA_LEVEL" \n"
" clz %0, %1 \n"
" .set pop \n"
: "=r" (num)
: "r" (word));
return 31 - num;
}
if (BITS_PER_LONG == 64 && !__builtin_constant_p(word) &&
__builtin_constant_p(cpu_has_mips64) && cpu_has_mips64) {
__asm__(
" .set push \n"
" .set "MIPS_ISA_LEVEL" \n"
" dclz %0, %1 \n"
" .set pop \n"
: "=r" (num)
: "r" (word));
return 63 - num;
}
num = BITS_PER_LONG - 1;
#if BITS_PER_LONG == 64
if (!(word & (~0ul << 32))) {
num -= 32;
word <<= 32;
}
#endif
if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
num -= 16;
word <<= 16;
}
if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
num -= 8;
word <<= 8;
}
if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
num -= 4;
word <<= 4;
}
if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
num -= 2;
word <<= 2;
}
if (!(word & (~0ul << (BITS_PER_LONG-1))))
num -= 1;
return num;
}
/*
* __ffs - find first bit in word.
* @word: The word to search
*
* Returns 0..SZLONG-1
* Undefined if no bit exists, so code should check against 0 first.
*/
static __always_inline __attribute_const__ unsigned long __ffs(unsigned long word)
{
return __fls(word & -word);
}
/*
* fls - find last bit set.
* @word: The word to search
*
* This is defined the same way as ffs.
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
*/
static inline __attribute_const__ int fls(unsigned int x)
{
int r;
if (!__builtin_constant_p(x) &&
__builtin_constant_p(cpu_has_clo_clz) && cpu_has_clo_clz) {
__asm__(
" .set push \n"
" .set "MIPS_ISA_LEVEL" \n"
" clz %0, %1 \n"
" .set pop \n"
: "=r" (x)
: "r" (x));
return 32 - x;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/compiler.h`, `linux/types.h`, `asm/asm.h`, `asm/barrier.h`, `asm/byteorder.h`, `asm/compiler.h`, `asm/cpu-features.h`.
- Detected declarations: `function set_bit`, `function clear_bit`, `function clear_bit`, `function change_bit`, `function test_and_set_bit_lock`, `function test_and_set_bit`, `function test_and_clear_bit`, `function test_and_change_bit`, `function xor_unlock_is_negative_byte`, `function __clear_bit`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.