blob: da949db613b10b8110968c96ea0cb4bfccb0ae28 [file] [log] [blame]
Ben Cheng655a7c02013-10-16 16:09:24 -07001/****************************************************************************
2 ****************************************************************************
3 ***
4 *** This header was automatically generated from a Linux kernel header
5 *** of the same name, to make information necessary for userspace to
6 *** call into the kernel available to libc. It contains only constants,
7 *** structures, and macros generated from the original header, and thus,
8 *** contains no copyrightable information.
9 ***
10 *** To edit the content of this header, modify the corresponding
11 *** source file (e.g. under external/kernel-headers/original/) then
12 *** run bionic/libc/kernel/tools/update_all.py
13 ***
14 *** Any manual change here will be lost the next time this script will
15 *** be run. You've been warned!
16 ***
17 ****************************************************************************
18 ****************************************************************************/
19#ifndef _UAPI_LINUX_SWAB_H
20#define _UAPI_LINUX_SWAB_H
21#include <linux/types.h>
22#include <linux/compiler.h>
Ben Cheng655a7c02013-10-16 16:09:24 -070023#include <asm/swab.h>
Tao Baod7db5942015-01-28 10:07:51 -080024#define ___constant_swab16(x) ((__u16) ((((__u16) (x) & (__u16) 0x00ffU) << 8) | (((__u16) (x) & (__u16) 0xff00U) >> 8)))
25#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)))
26#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 -080027#define ___constant_swahw32(x) ((__u32) ((((__u32) (x) & (__u32) 0x0000ffffUL) << 16) | (((__u32) (x) & (__u32) 0xffff0000UL) >> 16)))
28#define ___constant_swahb32(x) ((__u32) ((((__u32) (x) & (__u32) 0x00ff00ffUL) << 8) | (((__u32) (x) & (__u32) 0xff00ff00UL) >> 8)))
Christopher Ferris106b3a82016-08-24 12:15:38 -070029#ifdef __arch_swab16
30#else
Christopher Ferris106b3a82016-08-24 12:15:38 -070031#endif
32#ifdef __arch_swab32
Ben Cheng655a7c02013-10-16 16:09:24 -070033#else
34#endif
Christopher Ferris106b3a82016-08-24 12:15:38 -070035#ifdef __arch_swab64
Ben Cheng655a7c02013-10-16 16:09:24 -070036#elif defined(__SWAB_64_THRU_32__)
37#else
38#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070039static inline __attribute__((__const__)) __u32 __fswahw32(__u32 val) {
Christopher Ferris106b3a82016-08-24 12:15:38 -070040#ifdef __arch_swahw32
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070041 return __arch_swahw32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070042#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070043 return ___constant_swahw32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070044#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070045}
46static inline __attribute__((__const__)) __u32 __fswahb32(__u32 val) {
Ben Cheng655a7c02013-10-16 16:09:24 -070047#ifdef __arch_swahb32
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070048 return __arch_swahb32(val);
Christopher Ferris106b3a82016-08-24 12:15:38 -070049#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070050 return ___constant_swahb32(val);
Ben Cheng655a7c02013-10-16 16:09:24 -070051#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070052}
Christopher Ferris106b3a82016-08-24 12:15:38 -070053#define __swab16(x) (__u16) __builtin_bswap16((__u16) (x))
Christopher Ferris106b3a82016-08-24 12:15:38 -070054#define __swab32(x) (__u32) __builtin_bswap32((__u32) (x))
Christopher Ferris106b3a82016-08-24 12:15:38 -070055#define __swab64(x) (__u64) __builtin_bswap64((__u64) (x))
Tao Baod7db5942015-01-28 10:07:51 -080056#define __swahw32(x) (__builtin_constant_p((__u32) (x)) ? ___constant_swahw32(x) : __fswahw32(x))
57#define __swahb32(x) (__builtin_constant_p((__u32) (x)) ? ___constant_swahb32(x) : __fswahb32(x))
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070058static __always_inline __u16 __swab16p(const __u16 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070059#ifdef __arch_swab16p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070060 return __arch_swab16p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070061#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070062 return __swab16(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070063#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070064}
65static __always_inline __u32 __swab32p(const __u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070066#ifdef __arch_swab32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070067 return __arch_swab32p(p);
68#else
69 return __swab32(* p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070070#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070071}
72static __always_inline __u64 __swab64p(const __u64 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070073#ifdef __arch_swab64p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070074 return __arch_swab64p(p);
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070075#else
76 return __swab64(* p);
77#endif
78}
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070079static inline __u32 __swahw32p(const __u32 * p) {
Christopher Ferris106b3a82016-08-24 12:15:38 -070080#ifdef __arch_swahw32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070081 return __arch_swahw32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -070082#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070083 return __swahw32(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070084#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070085}
86static inline __u32 __swahb32p(const __u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070087#ifdef __arch_swahb32p
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070088 return __arch_swahb32p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070089#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070090 return __swahb32(* p);
Ben Cheng655a7c02013-10-16 16:09:24 -070091#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070092}
93static inline void __swab16s(__u16 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -070094#ifdef __arch_swab16s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070095 __arch_swab16s(p);
96#else
97 * p = __swab16p(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -070098#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070099}
100static __always_inline void __swab32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -0700101#ifdef __arch_swab32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700102 __arch_swab32s(p);
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700103#else
104 * p = __swab32p(p);
105#endif
106}
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700107static __always_inline void __swab64s(__u64 * p) {
Christopher Ferris106b3a82016-08-24 12:15:38 -0700108#ifdef __arch_swab64s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700109 __arch_swab64s(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700110#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700111 * p = __swab64p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700112#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700113}
114static inline void __swahw32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -0700115#ifdef __arch_swahw32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700116 __arch_swahw32s(p);
Christopher Ferris106b3a82016-08-24 12:15:38 -0700117#else
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700118 * p = __swahw32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700119#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700120}
121static inline void __swahb32s(__u32 * p) {
Ben Cheng655a7c02013-10-16 16:09:24 -0700122#ifdef __arch_swahb32s
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700123 __arch_swahb32s(p);
124#else
125 * p = __swahb32p(p);
Ben Cheng655a7c02013-10-16 16:09:24 -0700126#endif
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700127}
Christopher Ferris106b3a82016-08-24 12:15:38 -0700128#endif