/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _UAPI_LINUX_SWAB_H
#define _UAPI_LINUX_SWAB_H
#include <linux/types.h>
#include <linux/stddef.h>
#include <asm /bitsperlong.h>
#include <asm /swab.h>
/*
* casts are necessary for constants , because we never know how for sure
* how U / UL / ULL map to _ _ u16 , _ _ u32 , _ _ u64 . At least not in a portable way .
*/
#define ___constant_swab16(x) ((__u16)( \
(((__u16)(x) & (__u16)0 x00ffU) << 8 ) | \
(((__u16)(x) & (__u16)0 xff00U) >> 8 )))
#define ___constant_swab32(x) ((__u32)( \
(((__u32)(x) & (__u32)0 x000000ffUL) << 24 ) | \
(((__u32)(x) & (__u32)0 x0000ff00UL) << 8 ) | \
(((__u32)(x) & (__u32)0 x00ff0000UL) >> 8 ) | \
(((__u32)(x) & (__u32)0 xff000000UL) >> 24 )))
#define ___constant_swab64(x) ((__u64)( \
(((__u64)(x) & (__u64)0 x00000000000000ffULL) << 56 ) | \
(((__u64)(x) & (__u64)0 x000000000000ff00ULL) << 40 ) | \
(((__u64)(x) & (__u64)0 x0000000000ff0000ULL) << 24 ) | \
(((__u64)(x) & (__u64)0 x00000000ff000000ULL) << 8 ) | \
(((__u64)(x) & (__u64)0 x000000ff00000000ULL) >> 8 ) | \
(((__u64)(x) & (__u64)0 x0000ff0000000000ULL) >> 24 ) | \
(((__u64)(x) & (__u64)0 x00ff000000000000ULL) >> 40 ) | \
(((__u64)(x) & (__u64)0 xff00000000000000ULL) >> 56 )))
#define ___constant_swahw32(x) ((__u32)( \
(((__u32)(x) & (__u32)0 x0000ffffUL) << 16 ) | \
(((__u32)(x) & (__u32)0 xffff0000UL) >> 16 )))
#define ___constant_swahb32(x) ((__u32)( \
(((__u32)(x) & (__u32)0 x00ff00ffUL) << 8 ) | \
(((__u32)(x) & (__u32)0 xff00ff00UL) >> 8 )))
/*
* Implement the following as inlines , but define the interface using
* macros to allow constant folding when possible :
* _ _ _ swab16 , _ _ _ swab32 , _ _ _ swab64 , _ _ _ swahw32 , _ _ _ swahb32
*/
static inline __attribute_const__ __u16 __fswab16(__u16 val)
{
#if defined (__arch_swab16)
return __arch_swab16(val);
#else
return ___constant_swab16(val);
#endif
}
static inline __attribute_const__ __u32 __fswab32(__u32 val)
{
#if defined (__arch_swab32)
return __arch_swab32(val);
#else
return ___constant_swab32(val);
#endif
}
static inline __attribute_const__ __u64 __fswab64(__u64 val)
{
#if defined (__arch_swab64)
return __arch_swab64(val);
#elif defined (__SWAB_64_THRU_32__)
__u32 h = val >> 32 ;
__u32 l = val & ((1 ULL << 32 ) - 1 );
return (((__u64)__fswab32(l)) << 32 ) | ((__u64)(__fswab32(h)));
#else
return ___constant_swab64(val);
#endif
}
static inline __attribute_const__ __u32 __fswahw32(__u32 val)
{
#ifdef __arch_swahw32
return __arch_swahw32(val);
#else
return ___constant_swahw32(val);
#endif
}
static inline __attribute_const__ __u32 __fswahb32(__u32 val)
{
#ifdef __arch_swahb32
return __arch_swahb32(val);
#else
return ___constant_swahb32(val);
#endif
}
/**
* _ _ swab16 - return a byteswapped 16 - bit value
* @ x : value to byteswap
*/
#ifdef __HAVE_BUILTIN_BSWAP16__
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
#else
#define __swab16(x) \
(__u16)(__builtin_constant_p(x) ? \
___constant_swab16(x) : \
__fswab16(x))
#endif
/**
* _ _ swab32 - return a byteswapped 32 - bit value
* @ x : value to byteswap
*/
#ifdef __HAVE_BUILTIN_BSWAP32__
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
#else
#define __swab32(x) \
(__u32)(__builtin_constant_p(x) ? \
___constant_swab32(x) : \
__fswab32(x))
#endif
/**
* _ _ swab64 - return a byteswapped 64 - bit value
* @ x : value to byteswap
*/
#ifdef __HAVE_BUILTIN_BSWAP64__
#define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
#else
#define __swab64(x) \
(__u64)(__builtin_constant_p(x) ? \
___constant_swab64(x) : \
__fswab64(x))
#endif
static __always_inline unsigned long __swab(const unsigned long y)
{
#if __BITS_PER_LONG == 64
return __swab64(y);
#else /* __BITS_PER_LONG == 32 */
return __swab32(y);
#endif
}
/**
* _ _ swahw32 - return a word - swapped 32 - bit value
* @ x : value to wordswap
*
* _ _ swahw32 ( 0 x12340000 ) is 0 x00001234
*/
#define __swahw32(x) \
(__builtin_constant_p((__u32)(x)) ? \
___constant_swahw32(x) : \
__fswahw32(x))
/**
* _ _ swahb32 - return a high and low byte - swapped 32 - bit value
* @ x : value to byteswap
*
* _ _ swahb32 ( 0 x12345678 ) is 0 x34127856
*/
#define __swahb32(x) \
(__builtin_constant_p((__u32)(x)) ? \
___constant_swahb32(x) : \
__fswahb32(x))
/**
* _ _ swab16p - return a byteswapped 16 - bit value from a pointer
* @ p : pointer to a naturally - aligned 16 - bit value
*/
static __always_inline __u16 __swab16p(const __u16 *p)
{
#ifdef __arch_swab16p
return __arch_swab16p(p);
#else
return __swab16(*p);
#endif
}
/**
* _ _ swab32p - return a byteswapped 32 - bit value from a pointer
* @ p : pointer to a naturally - aligned 32 - bit value
*/
static __always_inline __u32 __swab32p(const __u32 *p)
{
#ifdef __arch_swab32p
return __arch_swab32p(p);
#else
return __swab32(*p);
#endif
}
/**
* _ _ swab64p - return a byteswapped 64 - bit value from a pointer
* @ p : pointer to a naturally - aligned 64 - bit value
*/
static __always_inline __u64 __swab64p(const __u64 *p)
{
#ifdef __arch_swab64p
return __arch_swab64p(p);
#else
return __swab64(*p);
#endif
}
/**
* _ _ swahw32p - return a wordswapped 32 - bit value from a pointer
* @ p : pointer to a naturally - aligned 32 - bit value
*
* See _ _ swahw32 ( ) for details of wordswapping .
*/
static inline __u32 __swahw32p(const __u32 *p)
{
#ifdef __arch_swahw32p
return __arch_swahw32p(p);
#else
return __swahw32(*p);
#endif
}
/**
* _ _ swahb32p - return a high and low byteswapped 32 - bit value from a pointer
* @ p : pointer to a naturally - aligned 32 - bit value
*
* See _ _ swahb32 ( ) for details of high / low byteswapping .
*/
static inline __u32 __swahb32p(const __u32 *p)
{
#ifdef __arch_swahb32p
return __arch_swahb32p(p);
#else
return __swahb32(*p);
#endif
}
/**
* _ _ swab16s - byteswap a 16 - bit value in - place
* @ p : pointer to a naturally - aligned 16 - bit value
*/
static inline void __swab16s(__u16 *p)
{
#ifdef __arch_swab16s
__arch_swab16s(p);
#else
*p = __swab16p(p);
#endif
}
/**
* _ _ swab32s - byteswap a 32 - bit value in - place
* @ p : pointer to a naturally - aligned 32 - bit value
*/
static __always_inline void __swab32s(__u32 *p)
{
#ifdef __arch_swab32s
__arch_swab32s(p);
#else
*p = __swab32p(p);
#endif
}
/**
* _ _ swab64s - byteswap a 64 - bit value in - place
* @ p : pointer to a naturally - aligned 64 - bit value
*/
static __always_inline void __swab64s(__u64 *p)
{
#ifdef __arch_swab64s
__arch_swab64s(p);
#else
*p = __swab64p(p);
#endif
}
/**
* _ _ swahw32s - wordswap a 32 - bit value in - place
* @ p : pointer to a naturally - aligned 32 - bit value
*
* See _ _ swahw32 ( ) for details of wordswapping
*/
static inline void __swahw32s(__u32 *p)
{
#ifdef __arch_swahw32s
__arch_swahw32s(p);
#else
*p = __swahw32p(p);
#endif
}
/**
* _ _ swahb32s - high and low byteswap a 32 - bit value in - place
* @ p : pointer to a naturally - aligned 32 - bit value
*
* See _ _ swahb32 ( ) for details of high and low byte swapping
*/
static inline void __swahb32s(__u32 *p)
{
#ifdef __arch_swahb32s
__arch_swahb32s(p);
#else
*p = __swahb32p(p);
#endif
}
#endif /* _UAPI_LINUX_SWAB_H */
Messung V0.5 in Prozent C=94 H=95 G=94
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-09-30)
¤
*© Formatika GbR, Deutschland