Files
@ 5fc7f2080582
Branch filter:
Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public/vmkernel64/release/lib/vmkapi_bits.h
5fc7f2080582
5.3 KiB
text/x-chdr
ESXi-5.5-U3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /***************************************************************************
* Copyright 2007 - 2009 VMware, Inc. All rights reserved.
***************************************************************************/
/*
* @VMKAPIMOD_LICENSE@
*/
/*
***********************************************************************
* Bits */ /**
* \addtogroup Lib
* @{
* \defgroup Bits Bit Manipulation
*
* Utility interfaces for bit shifting, flipping, etc.
*
* @{
***********************************************************************
*/
#ifndef _VMKAPI_BITS_H_
#define _VMKAPI_BITS_H_
/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */
/*
***********************************************************************
* vmk_CPUToBE64 -- */ /**
*
* \brief Convert an unsigned 64 bit unsigned integer in the
* CPU native endian format into a big endian 64 bit
* unsigned integer.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_BE64ToCPU
*
***********************************************************************
*/
static inline vmk_uint64
vmk_CPUToBE64(vmk_uint64 x)
{
#if defined(__x86_64__) && defined(__GNUC__)
if (!__builtin_constant_p(x)) {
__asm__ ("bswapq %0"
: "=r" (x)
: "0" (x));
return x;
}
#endif
return ((x >> 56) & VMK_CONST64U(0x00000000000000FF)) |
((x >> 40) & VMK_CONST64U(0x000000000000FF00)) |
((x >> 24) & VMK_CONST64U(0x0000000000FF0000)) |
((x >> 8) & VMK_CONST64U(0x00000000FF000000)) |
((x << 8) & VMK_CONST64U(0x000000FF00000000)) |
((x << 24) & VMK_CONST64U(0x0000FF0000000000)) |
((x << 40) & VMK_CONST64U(0x00FF000000000000)) |
((x << 56) & VMK_CONST64U(0xFF00000000000000));
}
/*
***********************************************************************
* vmk_BE64ToCPU -- */ /**
*
* \brief Convert an unsigned 64 bit unsigned integer in the
* big endian format into a 64 bit unsigned integer in
* the native CPU endian format.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_CPUToBE64
*
***********************************************************************
*/
static inline vmk_uint64
vmk_BE64ToCPU(vmk_uint64 x)
{
return vmk_CPUToBE64(x);
}
/*
***********************************************************************
* vmk_CPUToBE32 -- */ /**
*
* \brief Convert an unsigned 32 bit unsigned integer in the
* CPU native endian format into a big endian 32 bit
* unsigned integer.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_BE32ToCPU
*
***********************************************************************
*/
static inline vmk_uint32
vmk_CPUToBE32(vmk_uint32 x)
{
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
if (!__builtin_constant_p(x)) {
__asm__ ("bswap %0"
: "=r" (x)
: "0" (x));
return x;
}
#endif
return ((x >> 24) & 0x000000ff) | ((x >> 8) & 0x0000ff00) |
((x << 8) & 0x00ff0000) | ((x << 24) & 0xff000000);
}
/*
***********************************************************************
* vmk_BE32ToCPU -- */ /**
*
* \brief Convert an unsigned 32 bit unsigned integer in the
* big endian format into a 32 bit unsigned integer in
* the native CPU endian format.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_CPUToBE32
*
***********************************************************************
*/
static inline vmk_uint32
vmk_BE32ToCPU(vmk_uint32 x)
{
return vmk_CPUToBE32(x);
}
/*
***********************************************************************
* vmk_CPUToBE16 -- */ /**
*
* \brief Convert an unsigned 16 bit unsigned integer in the
* CPU native endian format into a big endian 16 bit
* unsigned integer.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_BE16ToCPU
*
***********************************************************************
*/
static inline vmk_uint16
vmk_CPUToBE16(vmk_uint16 x)
{
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
if (!__builtin_constant_p(x)) {
int bits = 8;
__asm__ ("rolw %%cl, %0"
: "=r" (x)
: "0" (x), "c" (bits));
return x;
}
#endif
return ((x >> 8) & 0x00ff) | ((x << 8) & 0xff00);
}
/*
***********************************************************************
* vmk_BE16ToCPU -- */ /**
*
* \brief Convert an unsigned 16 bit unsigned integer in the
* big endian format into a 16 bit unsigned integer in
* the native CPU endian format.
*
* \param[in] x Value to swap
*
* \return Swapped value.
*
* \sa vmk_CPUToBE16
*
***********************************************************************
*/
static inline vmk_uint16
vmk_BE16ToCPU(vmk_uint16 x)
{
return vmk_CPUToBE16(x);
}
#endif /* _VMKAPI_BITS_H_ */
/** @} */
/** @} */
|