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/lib/libkern/bswap64.c

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: bswap64.c,v 1.5 2003/12/04 13:57:31 keihan Exp $    */
    2 
    3 /*
    4  * Written by Manuel Bouyer <bouyer@NetBSD.org>.
    5  * Public domain.
    6  */
    7 
    8 #include <sys/cdefs.h>
    9 #if defined(LIBC_SCCS) && !defined(lint)
   10 __RCSID("$NetBSD: bswap64.c,v 1.5 2003/12/04 13:57:31 keihan Exp $");
   11 #endif /* LIBC_SCCS and not lint */
   12 
   13 #include <sys/types.h>
   14 #include <machine/bswap.h>
   15 
   16 #undef bswap64
   17 
   18 u_int64_t
   19 bswap64(x)
   20         u_int64_t x;
   21 {
   22 #ifdef _LP64
   23         /*
   24          * Assume we have wide enough registers to do it without touching
   25          * memory.
   26          */
   27         return  ( (x << 56) & 0xff00000000000000UL ) |
   28                 ( (x << 40) & 0x00ff000000000000UL ) |
   29                 ( (x << 24) & 0x0000ff0000000000UL ) |
   30                 ( (x <<  8) & 0x000000ff00000000UL ) |
   31                 ( (x >>  8) & 0x00000000ff000000UL ) |
   32                 ( (x >> 24) & 0x0000000000ff0000UL ) |
   33                 ( (x >> 40) & 0x000000000000ff00UL ) |
   34                 ( (x >> 56) & 0x00000000000000ffUL );
   35 #else
   36         /*
   37          * Split the operation in two 32bit steps.
   38          */
   39         u_int32_t tl, th;
   40 
   41         th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
   42         tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
   43         return ((u_int64_t)th << 32) | tl;
   44 #endif
   45 }

Cache object: e37622fae448942470f5ca3fcb1dd7c5


[ 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.