arch/riscv/include/asm/swab.h
Source file repositories/reference/linux-study-clean/arch/riscv/include/asm/swab.h
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/include/asm/swab.h- Extension
.h- Size
- 2626 bytes
- Lines
- 88
- 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/types.hlinux/compiler.hasm/cpufeature-macros.hasm/hwcap.hasm-generic/swab.h
Detected Declarations
function __arch_swab16function __arch_swab32function __arch_swab64function __arch_swab64
Annotated Snippet
#ifndef _ASM_RISCV_SWAB_H
#define _ASM_RISCV_SWAB_H
#include <linux/types.h>
#include <linux/compiler.h>
#include <asm/cpufeature-macros.h>
#include <asm/hwcap.h>
#include <asm-generic/swab.h>
#if defined(CONFIG_TOOLCHAIN_HAS_ZBB) && defined(CONFIG_RISCV_ISA_ZBB) && !defined(NO_ALTERNATIVE)
// Duplicated from include/uapi/linux/swab.h
#define ___constant_swab16(x) ((__u16)( \
(((__u16)(x) & (__u16)0x00ffU) << 8) | \
(((__u16)(x) & (__u16)0xff00U) >> 8)))
#define ___constant_swab32(x) ((__u32)( \
(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
#define ___constant_swab64(x) ((__u64)( \
(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
(((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
(((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
#define ARCH_SWAB(size, value) \
({ \
unsigned long x = value; \
\
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)) { \
asm volatile (".option push\n" \
".option arch,+zbb\n" \
"rev8 %0, %1\n" \
".option pop\n" \
: "=r" (x) : "r" (x)); \
x = x >> (BITS_PER_LONG - size); \
} else { \
x = ___constant_swab##size(value); \
} \
x; \
})
static __always_inline __u16 __arch_swab16(__u16 value)
{
return ARCH_SWAB(16, value);
}
static __always_inline __u32 __arch_swab32(__u32 value)
{
return ARCH_SWAB(32, value);
}
#ifdef CONFIG_64BIT
static __always_inline __u64 __arch_swab64(__u64 value)
{
return ARCH_SWAB(64, value);
}
#else
static __always_inline __u64 __arch_swab64(__u64 value)
{
__u32 h = value >> 32;
__u32 l = value & ((1ULL << 32) - 1);
return ((__u64)(__arch_swab32(l)) << 32) | ((__u64)(__arch_swab32(h)));
}
#endif
#define __arch_swab64 __arch_swab64
#define __arch_swab32 __arch_swab32
#define __arch_swab16 __arch_swab16
#undef ___constant_swab16
#undef ___constant_swab32
#undef ___constant_swab64
#undef ARCH_SWAB
#endif /* defined(CONFIG_TOOLCHAIN_HAS_ZBB) && defined(CONFIG_RISCV_ISA_ZBB) && !defined(NO_ALTERNATIVE) */
#endif /* _ASM_RISCV_SWAB_H */
Annotation
- Immediate include surface: `linux/types.h`, `linux/compiler.h`, `asm/cpufeature-macros.h`, `asm/hwcap.h`, `asm-generic/swab.h`.
- Detected declarations: `function __arch_swab16`, `function __arch_swab32`, `function __arch_swab64`, `function __arch_swab64`.
- 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.