libstdf_bswap.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Copyright (C) 2004-2006 Mike Frysinger <vapier@gmail.com>
00007  * Released under the BSD license.  For more information,
00008  * please see: http://opensource.org/licenses/bsd-license.php
00009  *
00010  * $Header: /cvsroot/freestdf/libstdf/include/libstdf_bswap.h,v 1.6 2005/05/31 23:08:32 vapier Exp $
00011  */
00012 
00013 #ifndef _LIBSTDF_BSWAP_H
00014 #define _LIBSTDF_BSWAP_H
00015 
00016 #if defined(bswap_16)
00017 # define stdf_bswap_16(x) x = bswap_16(x)
00018 # define stdf_bswap_32(x) x = bswap_32(x)
00019 # define stdf_bswap_64(x) x = bswap_64(x)
00020 #endif
00021 #if defined(bswap16)
00022 # define stdf_bswap_16(x) x = bswap16(x)
00023 # define stdf_bswap_32(x) x = bswap32(x)
00024 # define stdf_bswap_64(x) x = bswap64(x)
00025 #endif
00026 
00030 #ifndef stdf_bswap_16
00031 # define stdf_bswap_16(x) \
00032     x = ((((x) & 0xff00) >> 8) | \
00033          (((x) & 0x00ff) << 8))
00034 #endif
00035 
00039 #ifndef stdf_bswap_32
00040 # define stdf_bswap_32(x) \
00041     x = ((((x) & 0xff000000) >> 24) | \
00042          (((x) & 0x00ff0000) >>  8) | \
00043          (((x) & 0x0000ff00) <<  8) | \
00044          (((x) & 0x000000ff) << 24))
00045 #endif
00046 
00050 #ifndef stdf_bswap_64
00051 #if defined(__GNUC__)
00052 /* gcc sometimes stupidly types these wrong */
00053 # define stdf_bswap_64(x) \
00054     x = ((((x) & 0xff00000000000000ull) >> 56) | \
00055          (((x) & 0x00ff000000000000ull) >> 40) | \
00056          (((x) & 0x0000ff0000000000ull) >> 24) | \
00057          (((x) & 0x000000ff00000000ull) >>  8) | \
00058          (((x) & 0x00000000ff000000ull) <<  8) | \
00059          (((x) & 0x0000000000ff0000ull) << 24) | \
00060          (((x) & 0x000000000000ff00ull) << 40) | \
00061          (((x) & 0x00000000000000ffull) << 56))
00062 #else
00063 # define stdf_bswap_64(x) \
00064     x = ((((x) & 0xff00000000000000) >> 56) | \
00065          (((x) & 0x00ff000000000000) >> 40) | \
00066          (((x) & 0x0000ff0000000000) >> 24) | \
00067          (((x) & 0x000000ff00000000) >>  8) | \
00068          (((x) & 0x00000000ff000000) <<  8) | \
00069          (((x) & 0x0000000000ff0000) << 24) | \
00070          (((x) & 0x000000000000ff00) << 40) | \
00071          (((x) & 0x00000000000000ff) << 56))
00072 #endif /* __GNUC__ */
00073 #endif
00074 
00075 #endif /* _LIBSTDF_BSWAP_H */

Generated on Thu Jun 8 14:05:35 2006 for libstdf by  doxygen 1.4.6