The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/bswap.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: bswap.h,v 1.12 2006/05/22 16:28:27 drochner Exp $      */
    2 
    3 /* Written by Manuel Bouyer. Public domain */
    4 
    5 #ifndef _SYS_BSWAP_H_
    6 #define _SYS_BSWAP_H_
    7 
    8 #ifndef _LOCORE
    9 #include <sys/cdefs.h>
   10 #include <sys/types.h>
   11 
   12 #include <machine/bswap.h>
   13 
   14 __BEGIN_DECLS
   15 /* Always declare the functions in case their address is taken (etc) */
   16 #if defined(_KERNEL) || defined(_STANDALONE) || !defined(__BSWAP_RENAME)
   17 uint16_t bswap16(uint16_t) __attribute__((__const__));
   18 uint32_t bswap32(uint32_t) __attribute__((__const__));
   19 #else
   20 uint16_t bswap16(uint16_t) __RENAME(__bswap16) __attribute__((__const__));
   21 uint32_t bswap32(uint32_t) __RENAME(__bswap32) __attribute__((__const__));
   22 #endif
   23 uint64_t bswap64(uint64_t) __attribute__((__const__));
   24 __END_DECLS
   25 
   26 #if defined(__GNUC__) && defined(__OPTIMIZE__)
   27 
   28 /* machine/byte_swap.h might have defined inline versions */
   29 #ifndef __BYTE_SWAP_U64_VARIABLE
   30 #define __BYTE_SWAP_U64_VARIABLE bswap64
   31 #endif
   32 
   33 #ifndef __BYTE_SWAP_U32_VARIABLE
   34 #define __BYTE_SWAP_U32_VARIABLE bswap32
   35 #endif
   36 
   37 #ifndef __BYTE_SWAP_U16_VARIABLE
   38 #define __BYTE_SWAP_U16_VARIABLE bswap16
   39 #endif
   40 
   41 #define __byte_swap_u64_constant(x) \
   42         ((uint64_t) \
   43          ((((x) & 0xff00000000000000ull) >> 56) | \
   44           (((x) & 0x00ff000000000000ull) >> 40) | \
   45           (((x) & 0x0000ff0000000000ull) >> 24) | \
   46           (((x) & 0x000000ff00000000ull) >>  8) | \
   47           (((x) & 0x00000000ff000000ull) <<  8) | \
   48           (((x) & 0x0000000000ff0000ull) << 24) | \
   49           (((x) & 0x000000000000ff00ull) << 40) | \
   50           (((x) & 0x00000000000000ffull) << 56)))
   51 
   52 #define __byte_swap_u32_constant(x) \
   53         ((((x) & 0xff000000) >> 24) | \
   54          (((x) & 0x00ff0000) >>  8) | \
   55          (((x) & 0x0000ff00) <<  8) | \
   56          (((x) & 0x000000ff) << 24))
   57 
   58 #define __byte_swap_u16_constant(x) \
   59         ((((x) & 0xff00) >> 8) | \
   60          (((x) & 0x00ff) << 8))
   61 
   62 #define bswap64(x) \
   63         (__builtin_constant_p((x)) ? \
   64          __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x))
   65 
   66 #define bswap32(x) \
   67         (__builtin_constant_p((x)) ? \
   68          __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x))
   69 
   70 #define bswap16(x) \
   71         (__builtin_constant_p((x)) ? \
   72          __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x))
   73 
   74 #endif /* __GNUC__ && __OPTIMIZE__ */
   75 #endif /* !_LOCORE */
   76 
   77 #endif /* !_SYS_BSWAP_H_ */

Cache object: 37af9947eea992e80a5e9a2e0291f75f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.