]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Main/bswap64.c
BaseTools: Add DevicePath support for PCD values
[mirror_edk2.git] / StdLib / LibC / Main / bswap64.c
CommitLineData
2aa62f2b 1/* $NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */\r
2\r
3/*\r
4 * Written by Manuel Bouyer <bouyer@NetBSD.org>.\r
5 * Public domain.\r
6 */\r
7\r
8//#include <sys/cdefs.h>\r
9//#if defined(LIBC_SCCS) && !defined(lint)\r
10//__RCSID("$NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $");\r
11//#endif /* LIBC_SCCS and not lint */\r
12\r
13//#include <sys/types.h>\r
14//#include <machine/bswap.h>\r
15\r
16#undef bswap64\r
17\r
18UINT64\r
19bswap64(UINT64 x)\r
20{\r
21#ifndef _LP64\r
22 /*\r
23 * Assume we have wide enough registers to do it without touching\r
24 * memory.\r
25 */\r
26 return ( (x << 56) & 0xff00000000000000UL ) |\r
27 ( (x << 40) & 0x00ff000000000000UL ) |\r
28 ( (x << 24) & 0x0000ff0000000000UL ) |\r
29 ( (x << 8) & 0x000000ff00000000UL ) |\r
30 ( (x >> 8) & 0x00000000ff000000UL ) |\r
31 ( (x >> 24) & 0x0000000000ff0000UL ) |\r
32 ( (x >> 40) & 0x000000000000ff00UL ) |\r
33 ( (x >> 56) & 0x00000000000000ffUL );\r
34#else\r
35 /*\r
36 * Split the operation in two 32bit steps.\r
37 */\r
38 u_int32_t tl, th;\r
39\r
40 th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));\r
41 tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));\r
42 return ((u_int64_t)th << 32) | tl;\r
43#endif\r
44}\r