arch/x86/include/asm/bitops.h
Source file repositories/reference/linux-study-clean/arch/x86/include/asm/bitops.h
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/include/asm/bitops.h- Extension
.h- Size
- 11342 bytes
- Lines
- 433
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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/alternative.hasm/rmwcc.hasm/barrier.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-non-atomic.hasm-generic/bitops/instrumented-lock.hasm-generic/bitops/le.hasm-generic/bitops/ext2-atomic-setbit.h
Detected Declarations
function arch_set_bitfunction arch___set_bitfunction arch_clear_bitfunction arch_clear_bit_unlockfunction arch___clear_bitfunction arch_xor_unlock_is_negative_bytefunction arch___clear_bit_unlockfunction arch___change_bitfunction arch_change_bitfunction arch_test_and_set_bitfunction arch_test_and_set_bit_lockfunction arch___test_and_set_bitfunction arch_test_and_clear_bitfunction arch___test_and_clear_bitfunction arch___test_and_change_bitfunction arch_test_and_change_bitfunction constant_test_bitfunction constant_test_bit_acquirefunction variable_test_bitfunction arch_test_bitfunction arch_test_bit_acquirefunction variable__ffsfunction variable__ffsfunction variable_ffzfunction variable_ffsfunction ffsfunction fls64
Annotated Snippet
#ifndef _ASM_X86_BITOPS_H
#define _ASM_X86_BITOPS_H
/*
* Copyright 1992, Linus Torvalds.
*
* Note: inlines with more than a single statement should be marked
* __always_inline to avoid problems with older gcc's inlining heuristics.
*/
#ifndef _LINUX_BITOPS_H
#error only <linux/bitops.h> can be included directly
#endif
#include <linux/compiler.h>
#include <asm/alternative.h>
#include <asm/rmwcc.h>
#include <asm/barrier.h>
#if BITS_PER_LONG == 32
# define _BITOPS_LONG_SHIFT 5
#elif BITS_PER_LONG == 64
# define _BITOPS_LONG_SHIFT 6
#else
# error "Unexpected BITS_PER_LONG"
#endif
#define BIT_64(n) (U64_C(1) << (n))
/*
* These have to be done with inline assembly: that way the bit-setting
* is guaranteed to be atomic. All bit operations return 0 if the bit
* was cleared before the operation and != 0 if it was not.
*
* bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
*/
#define RLONG_ADDR(x) "m" (*(volatile long *) (x))
#define WBYTE_ADDR(x) "+m" (*(volatile char *) (x))
#define ADDR RLONG_ADDR(addr)
/*
* We do the locked ops that don't return the old value as
* a mask operation on a byte.
*/
#define CONST_MASK_ADDR(nr, addr) WBYTE_ADDR((void *)(addr) + ((nr)>>3))
#define CONST_MASK(nr) (1 << ((nr) & 7))
static __always_inline void
arch_set_bit(long nr, volatile unsigned long *addr)
{
if (__builtin_constant_p(nr)) {
asm_inline volatile(LOCK_PREFIX "orb %b1,%0"
: CONST_MASK_ADDR(nr, addr)
: "iq" (CONST_MASK(nr))
: "memory");
} else {
asm_inline volatile(LOCK_PREFIX __ASM_SIZE(bts) " %1,%0"
: : RLONG_ADDR(addr), "Ir" (nr) : "memory");
}
}
static __always_inline void
arch___set_bit(unsigned long nr, volatile unsigned long *addr)
{
asm volatile(__ASM_SIZE(bts) " %1,%0" : : ADDR, "Ir" (nr) : "memory");
}
static __always_inline void
arch_clear_bit(long nr, volatile unsigned long *addr)
{
if (__builtin_constant_p(nr)) {
asm_inline volatile(LOCK_PREFIX "andb %b1,%0"
: CONST_MASK_ADDR(nr, addr)
: "iq" (~CONST_MASK(nr)));
} else {
asm_inline volatile(LOCK_PREFIX __ASM_SIZE(btr) " %1,%0"
: : RLONG_ADDR(addr), "Ir" (nr) : "memory");
}
}
static __always_inline void
arch_clear_bit_unlock(long nr, volatile unsigned long *addr)
{
barrier();
arch_clear_bit(nr, addr);
}
static __always_inline void
Annotation
- Immediate include surface: `linux/compiler.h`, `asm/alternative.h`, `asm/rmwcc.h`, `asm/barrier.h`, `asm-generic/bitops/fls64.h`, `asm-generic/bitops/sched.h`, `asm/arch_hweight.h`, `asm-generic/bitops/const_hweight.h`.
- Detected declarations: `function arch_set_bit`, `function arch___set_bit`, `function arch_clear_bit`, `function arch_clear_bit_unlock`, `function arch___clear_bit`, `function arch_xor_unlock_is_negative_byte`, `function arch___clear_bit_unlock`, `function arch___change_bit`, `function arch_change_bit`, `function arch_test_and_set_bit`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.