[ofw] Re: [ofa-general] [RFC] 3/5: IB ACM: libibacm

Ira Weiny weiny2 at llnl.gov
Fri Sep 18 15:28:48 PDT 2009


On Fri, 18 Sep 2009 15:23:40 -0700
"Sean Hefty" <sean.hefty at intel.com> wrote:

> >Rough hack.  Does windows have stdint.h, byteswap.h, and endian.h?
> 
> If not, adding the headers with the needed definitions is trivial.
> 
> >+/* 16bit */
> >+#if __BYTE_ORDER == __LITTLE_ENDIAN
> >+#define CL_NTOH16( x )		(uint16_t)(		\
> >+			(((uint16_t)(x) & 0x00FF) << 8) |		\
> >+			(((uint16_t)(x) & 0xFF00) >> 8) )
> >+#else
> >+#define CL_NTOH16( x )	(x)
> >+#endif
> >+#define CL_HTON16				CL_NTOH16
> >+
> >+/* 32bit */
> >+#if __BYTE_ORDER == __LITTLE_ENDIAN
> >+#define CL_NTOH32( x )		(uint32_t)(			\
> >+			(((uint32_t)(x) & 0x000000FF) << 24) |	\
> >+			(((uint32_t)(x) & 0x0000FF00) << 8) |	\
> >+			(((uint32_t)(x) & 0x00FF0000) >> 8) |	\
> >+			(((uint32_t)(x) & 0xFF000000) >> 24) )
> >+#else
> >+#define CL_NTOH32( x )		(x)
> >+#endif
> >+#define CL_HTON32	CL_NTOH32
> >+
> >+/* 64bit */
> >+#if __BYTE_ORDER == __LITTLE_ENDIAN
> >+#define CL_NTOH64( x )		(uint64_t)(
> \
> >+			(((uint64_t)(x) & 0x00000000000000FFULL) << 56) |
> \
> >+			(((uint64_t)(x) & 0x000000000000FF00ULL) << 40) |
> \
> >+			(((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) |
> \
> >+			(((uint64_t)(x) & 0x00000000FF000000ULL) << 8 ) |
> \
> >+			(((uint64_t)(x) & 0x000000FF00000000ULL) >> 8 ) |
> \
> >+			(((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) |
> \
> >+			(((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) |
> \
> >+			(((uint64_t)(x) & 0xFF00000000000000ULL) >> 56) )
> >+#else
> >+#define CL_NTOH64( x )		(x)
> >+#endif
> >+#define CL_HTON64				CL_NTOH64
> >+
> >+#if __BYTE_ORDER == __LITTLE_ENDIAN
> >+#define cl_ntoh16(x)	bswap_16(x)
> >+#define cl_hton16(x)	bswap_16(x)
> >+#define cl_ntoh32(x)	bswap_32(x)
> >+#define cl_hton32(x)	bswap_32(x)
> >+#define cl_ntoh64(x)	(uint64_t)bswap_64(x)
> >+#define cl_hton64(x)	(uint64_t)bswap_64(x)
> >+#else				/* Big Endian */
> >+#define cl_ntoh16(x)	(x)
> >+#define cl_hton16(x)	(x)
> >+#define cl_ntoh32(x)	(x)
> >+#define cl_hton32(x)	(x)
> >+#define cl_ntoh64(x)	(x)
> >+#define cl_hton64(x)	(x)
> >+#endif
> 
> Why the different defines for cl_noth and CL_NTOH?

One is for static defines CL_NTOH and the other is for variables at run time.  I found this code in Linux.

__bswap_constant_16
__bswap_constant_32
__bswap_constant_64

Which does the same thing, but I am not sure if they are universal or not as they are in <bits/byteswap.h> rather than byteswap.h

Ira

-- 
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2 at llnl.gov



More information about the general mailing list