Path: blob/master/ALFA-W1F1/RTL8814AU/include/byteorder/swabb.h
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#ifndef _LINUX_BYTEORDER_SWABB_H15#define _LINUX_BYTEORDER_SWABB_H1617/*18* linux/byteorder/swabb.h19* SWAp Bytes Bizarrely20* swaHHXX[ps]?(foo)21*22* Support for obNUXIous pdp-endian and other bizarre architectures.23* Will Linux ever run on such ancient beasts? if not, this file24* will be but a programming pearl. Still, it's a reminder that we25* shouldn't be making too many assumptions when trying to be portable.26*27*/2829/*30* Meaning of the names I chose (vaxlinux people feel free to correct them):31* swahw32 swap 16-bit half-words in a 32-bit word32* swahb32 swap 8-bit halves of each 16-bit half-word in a 32-bit word33*34* No 64-bit support yet. I don't know NUXI conventions for long longs.35* I guarantee it will be a mess when it's there, though :->36* It will be even worse if there are conflicting 64-bit conventions.37* Hopefully, no one ever used 64-bit objects on NUXI machines.38*39*/4041#define ___swahw32(x) \42({ \43__u32 __x = (x); \44((__u32)(\45(((__u32)(__x) & (__u32)0x0000ffffUL) << 16) | \46(((__u32)(__x) & (__u32)0xffff0000UL) >> 16))); \47})48#define ___swahb32(x) \49({ \50__u32 __x = (x); \51((__u32)(\52(((__u32)(__x) & (__u32)0x00ff00ffUL) << 8) | \53(((__u32)(__x) & (__u32)0xff00ff00UL) >> 8))); \54})5556#define ___constant_swahw32(x) \57((__u32)(\58(((__u32)(x) & (__u32)0x0000ffffUL) << 16) | \59(((__u32)(x) & (__u32)0xffff0000UL) >> 16)))60#define ___constant_swahb32(x) \61((__u32)(\62(((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | \63(((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))6465/*66* provide defaults when no architecture-specific optimization is detected67*/68#ifndef __arch__swahw3269#define __arch__swahw32(x) ___swahw32(x)70#endif71#ifndef __arch__swahb3272#define __arch__swahb32(x) ___swahb32(x)73#endif7475#ifndef __arch__swahw32p76#define __arch__swahw32p(x) __swahw32(*(x))77#endif78#ifndef __arch__swahb32p79#define __arch__swahb32p(x) __swahb32(*(x))80#endif8182#ifndef __arch__swahw32s83#define __arch__swahw32s(x) do { *(x) = __swahw32p((x)); } while (0)84#endif85#ifndef __arch__swahb32s86#define __arch__swahb32s(x) do { *(x) = __swahb32p((x)); } while (0)87#endif888990/*91* Allow constant folding92*/93#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)94# define __swahw32(x) \95(__builtin_constant_p((__u32)(x)) ? \96___swahw32((x)) : \97__fswahw32((x)))98# define __swahb32(x) \99(__builtin_constant_p((__u32)(x)) ? \100___swahb32((x)) : \101__fswahb32((x)))102#else103# define __swahw32(x) __fswahw32(x)104# define __swahb32(x) __fswahb32(x)105#endif /* OPTIMIZE */106107108__inline static__ __const__ __u32 __fswahw32(__u32 x)109{110return __arch__swahw32(x);111}112__inline static__ __u32 __swahw32p(__u32 *x)113{114return __arch__swahw32p(x);115}116__inline static__ void __swahw32s(__u32 *addr)117{118__arch__swahw32s(addr);119}120121122__inline static__ __const__ __u32 __fswahb32(__u32 x)123{124return __arch__swahb32(x);125}126__inline static__ __u32 __swahb32p(__u32 *x)127{128return __arch__swahb32p(x);129}130__inline static__ void __swahb32s(__u32 *addr)131{132__arch__swahb32s(addr);133}134135#ifdef __BYTEORDER_HAS_U64__136/*137* Not supported yet138*/139#endif /* __BYTEORDER_HAS_U64__ */140141#if defined(PLATFORM_LINUX)142#define swahw32 __swahw32143#define swahb32 __swahb32144#define swahw32p __swahw32p145#define swahb32p __swahb32p146#define swahw32s __swahw32s147#define swahb32s __swahb32s148#endif149150#endif /* _LINUX_BYTEORDER_SWABB_H */151152153