EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

StdLib/LibC/Main/bswap64.c

Go to the documentation of this file.
00001 /*  $NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $    */
00002 
00003 /*
00004  * Written by Manuel Bouyer <bouyer@NetBSD.org>.
00005  * Public domain.
00006  */
00007 
00008 //#include <sys/cdefs.h>
00009 //#if defined(LIBC_SCCS) && !defined(lint)
00010 //__RCSID("$NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
00011 //#endif /* LIBC_SCCS and not lint */
00012 
00013 //#include <sys/types.h>
00014 //#include <machine/bswap.h>
00015 
00016 #undef bswap64
00017 
00018 UINT64
00019 bswap64(UINT64 x)
00020 {
00021 #ifndef _LP64
00022   /*
00023    * Assume we have wide enough registers to do it without touching
00024    * memory.
00025    */
00026   return  ( (x << 56) & 0xff00000000000000UL ) |
00027     ( (x << 40) & 0x00ff000000000000UL ) |
00028     ( (x << 24) & 0x0000ff0000000000UL ) |
00029     ( (x <<  8) & 0x000000ff00000000UL ) |
00030     ( (x >>  8) & 0x00000000ff000000UL ) |
00031     ( (x >> 24) & 0x0000000000ff0000UL ) |
00032     ( (x >> 40) & 0x000000000000ff00UL ) |
00033     ( (x >> 56) & 0x00000000000000ffUL );
00034 #else
00035   /*
00036    * Split the operation in two 32bit steps.
00037    */
00038   u_int32_t tl, th;
00039 
00040   th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
00041   tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
00042   return ((u_int64_t)th << 32) | tl;
00043 #endif
00044 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines