blob: 6225a7604a3c0fc0ed75bb524dfdedab512e6c99 [file] [log] [blame]
Elliott Hughes180edef2023-11-02 00:08:05 +00001/*
2 * This file is auto-generated. Modifications will be lost.
3 *
4 * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
5 * for more information.
6 */
Ben Cheng655a7c02013-10-16 16:09:24 -07007#ifndef _UAPI_LINUX_SWAB_H
8#define _UAPI_LINUX_SWAB_H
9#include <linux/types.h>
Christopher Ferris8b7fdc92023-02-21 13:36:32 -080010#include <linux/stddef.h>
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -070011#include <asm/bitsperlong.h>
Ben Cheng655a7c02013-10-16 16:09:24 -070012#include <asm/swab.h>
Tao Baod7db5942015-01-28 10:07:51 -080013#define ___constant_swab16(x) ((__u16) ((((__u16) (x) & (__u16) 0x00ffU) << 8) | (((__u16) (x) & (__u16) 0xff00U) >> 8)))
14#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)))
15#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)))
Tao Baod7db5942015-01-28 10:07:51 -080016#define ___constant_swahw32(x) ((__u32) ((((__u32) (x) & (__u32) 0x0000ffffUL) << 16) | (((__u32) (x) & (__u32) 0xffff0000UL) >> 16)))
17#define ___constant_swahb32(x) ((__u32) ((((__u32) (x) & (__u32) 0x00ff00ffUL) << 8) | (((__u32) (x) & (__u32) 0xff00ff00UL) >> 8)))
Christopher Ferris106b3a82016-08-24 12:15:38 -070018#ifdef __arch_swab16
19#else
Christopher Ferris106b3a82016-08-24 12:15:38 -070020#endif
21#ifdef __arch_swab32
Ben Cheng655a7c02013-10-16 16:09:24 -070022#else
23#endif
Christopher Ferris106b3a82016-08-24 12:15:38 -070024#ifdef __arch_swab64
Ben Cheng655a7c02013-10-16 16:09:24 -070025#elif defined(__SWAB_64_THRU_32__)
26#else
27#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070028static inline __attribute__((__const__)) __u32 __fswahw32(__u32 val) {
Christopher Ferris106b3a82016-08-24 12:15:38 -070029#ifdef __arch_swahw32
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070030 return __arch_swahw32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070031#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070032 return ___constant_swahw32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070033#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070034}
35static inline __attribute__((__const__)) __u32 __fswahb32(__u32 val) {
Ben Cheng655a7c02013-10-16 16:09:24 -070036#ifdef __arch_swahb32
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070037 return __arch_swahb32(val);
Christopher Ferris106b3a82016-08-24 12:15:38 -070038#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070039 return ___constant_swahb32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070040#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070041}
Christopher Ferris106b3a82016-08-24 12:15:38 -070042#define __swab16(x) (__u16) __builtin_bswap16((__u16) (x))
Christopher Ferris106b3a82016-08-24 12:15:38 -070043#define __swab32(x) (__u32) __builtin_bswap32((__u32) (x))
Christopher Ferris106b3a82016-08-24 12:15:38 -070044#define __swab64(x) (__u64) __builtin_bswap64((__u64) (x))
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -070045#if __BITS_PER_LONG == 64
46#else
47#endif
Tao Baod7db5942015-01-28 10:07:51 -080048#define __swahw32(x) (__builtin_constant_p((__u32) (x)) ? ___constant_swahw32(x) : __fswahw32(x))
49#define __swahb32(x) (__builtin_constant_p((__u32) (x)) ? ___constant_swahb32(x) : __fswahb32(x))
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070050static __always_inline __u16 __swab16p(const __u16 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070051#ifdef __arch_swab16p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070052 return __arch_swab16p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070053#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070054 return __swab16(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070055#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070056}
57static __always_inline __u32 __swab32p(const __u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070058#ifdef __arch_swab32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070059 return __arch_swab32p(p);
60#else
61 return __swab32(* p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070062#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070063}
64static __always_inline __u64 __swab64p(const __u64 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070065#ifdef __arch_swab64p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070066 return __arch_swab64p(p);
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070067#else
68 return __swab64(* p);
69#endif
70}
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070071static inline __u32 __swahw32p(const __u32 * p) {
Christopher Ferris106b3a82016-08-24 12:15:38 -070072#ifdef __arch_swahw32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070073 return __arch_swahw32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -070074#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070075 return __swahw32(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070076#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070077}
78static inline __u32 __swahb32p(const __u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070079#ifdef __arch_swahb32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070080 return __arch_swahb32p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070081#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070082 return __swahb32(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070083#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070084}
85static inline void __swab16s(__u16 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070086#ifdef __arch_swab16s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070087 __arch_swab16s(p);
88#else
89 * p = __swab16p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070090#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070091}
92static __always_inline void __swab32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070093#ifdef __arch_swab32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070094 __arch_swab32s(p);
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070095#else
96 * p = __swab32p(p);
97#endif
98}
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070099static __always_inline void __swab64s(__u64 * p) {
Christopher Ferris106b3a82016-08-24 12:15:38 -0700100#ifdef __arch_swab64s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700101 __arch_swab64s(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700102#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700103 * p = __swab64p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700104#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700105}
106static inline void __swahw32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -0700107#ifdef __arch_swahw32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700108 __arch_swahw32s(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -0700109#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700110 * p = __swahw32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700111#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700112}
113static inline void __swahb32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -0700114#ifdef __arch_swahb32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700115 __arch_swahb32s(p);
116#else
117 * p = __swahb32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700118#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700119}
Christopher Ferris106b3a82016-08-24 12:15:38 -0700120#endif