1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 2/* byteswap.h - Byte swapping 3 Copyright (C) 2005 Free Software Foundation, Inc. 4 Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 20#ifndef _BYTESWAP_H 21 22#include <sys/endian.h> 23#if _BYTE_ORDER == _LITTLE_ENDIAN 24/* Given an unsigned 16-bit argument X, return the value corresponding to 25 X with reversed byte order. */ 26#define bswap_16(x) ((((x) & 0x00FF) << 8) | \ 27 (((x) & 0xFF00) >> 8)) 28 29/* Given an unsigned 32-bit argument X, return the value corresponding to 30 X with reversed byte order. */ 31#define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ 32 (((x) & 0x0000FF00) << 8) | \ 33 (((x) & 0x00FF0000) << 8) | \ 34 (((x) & 0xFF000000) >> 24)) 35 36/* Given an unsigned 64-bit argument X, return the value corresponding to 37 X with reversed byte order. */ 38#define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ 39 (((x) & 0x000000000000FF00ULL) << 40) | \ 40 (((x) & 0x0000000000FF0000ULL) << 24) | \ 41 (((x) & 0x00000000FF000000ULL) << 8) | \ 42 (((x) & 0x000000FF00000000ULL) >> 8) | \ 43 (((x) & 0x0000FF0000000000ULL) >> 24) | \ 44 (((x) & 0x00FF000000000000ULL) >> 40) | \ 45 (((x) & 0xFF00000000000000ULL) >> 56)) 46#else 47#define bswap_16(x) (x) 48#define bswap_32(x) (x) 49#define bswap_64(x) (x) 50#endif 51 52#endif 53