arch/riscv/include/asm/bitops.h
Source file repositories/reference/linux-study-clean/arch/riscv/include/asm/bitops.h
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/include/asm/bitops.h- Extension
.h- Size
- 9926 bytes
- Lines
- 363
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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/compiler.hasm/barrier.hasm/bitsperlong.hasm-generic/bitops/__ffs.hasm-generic/bitops/__fls.hasm-generic/bitops/ffs.hasm-generic/bitops/fls.hasm/alternative-macros.hasm/hwcap.hasm-generic/bitops/ffz.hasm-generic/bitops/fls64.hasm-generic/bitops/sched.hasm/arch_hweight.hasm-generic/bitops/const_hweight.hasm-generic/bitops/instrumented-atomic.hasm-generic/bitops/instrumented-lock.hasm-generic/bitops/non-atomic.hasm-generic/bitops/le.hasm-generic/bitops/ext2-atomic.h
Detected Declarations
function Copyrightfunction variable__ffsfunction variable__flsfunction ffsfunction arch_test_and_set_bitfunction arch_test_and_clear_bitfunction arch_test_and_change_bitfunction arch_set_bitfunction arch_clear_bitfunction arch_change_bitfunction arch_test_and_set_bit_lockfunction arch_clear_bit_unlockfunction releasedfunction arch_xor_unlock_is_negative_byte
Annotated Snippet
#ifndef _ASM_RISCV_BITOPS_H
#define _ASM_RISCV_BITOPS_H
#ifndef _LINUX_BITOPS_H
#error "Only <linux/bitops.h> can be included directly"
#endif /* _LINUX_BITOPS_H */
#include <linux/compiler.h>
#include <asm/barrier.h>
#include <asm/bitsperlong.h>
#if !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)) || defined(NO_ALTERNATIVE)
#include <asm-generic/bitops/__ffs.h>
#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/ffs.h>
#include <asm-generic/bitops/fls.h>
#else
#define __HAVE_ARCH___FFS
#define __HAVE_ARCH___FLS
#define __HAVE_ARCH_FFS
#define __HAVE_ARCH_FLS
#include <asm-generic/bitops/__ffs.h>
#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/ffs.h>
#include <asm-generic/bitops/fls.h>
#include <asm/alternative-macros.h>
#include <asm/hwcap.h>
#if (BITS_PER_LONG == 64)
#define CTZW "ctzw "
#define CLZW "clzw "
#elif (BITS_PER_LONG == 32)
#define CTZW "ctz "
#define CLZW "clz "
#else
#error "Unexpected BITS_PER_LONG"
#endif
static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word)
{
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
return generic___ffs(word);
asm volatile (".option push\n"
".option arch,+zbb\n"
"ctz %0, %1\n"
".option pop\n"
: "=r" (word) : "r" (word) :);
return word;
}
/**
* __ffs - find first set bit in a long word
* @word: The word to search
*
* Undefined if no set bit exists, so code should check against 0 first.
*/
#define __ffs(word) \
(__builtin_constant_p(word) ? \
(unsigned long)__builtin_ctzl(word) : \
variable__ffs(word))
static __always_inline __attribute_const__ unsigned long variable__fls(unsigned long word)
{
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
return generic___fls(word);
asm volatile (".option push\n"
".option arch,+zbb\n"
"clz %0, %1\n"
".option pop\n"
: "=r" (word) : "r" (word) :);
return BITS_PER_LONG - 1 - word;
}
/**
* __fls - find last set bit in a long word
* @word: the word to search
*
* Undefined if no set bit exists, so code should check against 0 first.
*/
#define __fls(word) \
(__builtin_constant_p(word) ? \
(unsigned long)(BITS_PER_LONG - 1 - __builtin_clzl(word)) : \
variable__fls(word))
Annotation
- Immediate include surface: `linux/compiler.h`, `asm/barrier.h`, `asm/bitsperlong.h`, `asm-generic/bitops/__ffs.h`, `asm-generic/bitops/__fls.h`, `asm-generic/bitops/ffs.h`, `asm-generic/bitops/fls.h`, `asm/alternative-macros.h`.
- Detected declarations: `function Copyright`, `function variable__ffs`, `function variable__fls`, `function ffs`, `function arch_test_and_set_bit`, `function arch_test_and_clear_bit`, `function arch_test_and_change_bit`, `function arch_set_bit`, `function arch_clear_bit`, `function arch_change_bit`.
- Atlas domain: Architecture Layer / arch/riscv.
- 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.