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

Ira Weiny weiny2 at llnl.gov
Fri Sep 18 17:05:39 PDT 2009


On Fri, 18 Sep 2009 17:23:36 -0600
Jason Gunthorpe <jgunthorpe at obsidianresearch.com> wrote:

> On Fri, Sep 18, 2009 at 03:28:48PM -0700, Ira Weiny wrote:
> 
> > One is for static defines CL_NTOH and the other is for variables at
> > run time.  I found this code in Linux.
> 
> Thats gross, and is exactly why you don't do this yourself...
> 
> bswap64/32/16 do this all automatically. ntohl also do it and are more
> portable.
> 
> from glibc:
> 
> #   define ntohl(x)     __bswap_32 (x)
> #define bswap_32(x) __bswap_32 (x)
> #  define __bswap_32(x) \
>      (__extension__                                                           \
>       ({ register unsigned int __v, __x = (x);                                \
>          if (__builtin_constant_p (__x))                                      \
>            __v = __bswap_constant_32 (__x);                                   \
>          else                                                                 \
>            __asm__ ("bswap %0" : "=r" (__v) : "0" (__x));                     \
>          __v; }))
> 
> 
> I'd say just use the ntohl, ntohs, and bswap64 macros directly and
> Window can provide headers with whatever it needs instead. They are
> already doing this..

I agree but ntohl etc do not seem to work for the macros which are defined.

osm_sa_mad_ctrl.c: In function 'sa_mad_ctrl_process':
osm_sa_mad_ctrl.c:140: error: case label does not reduce to an integer constant
...
	switch (p_sa_mad->attr_id) {
	case IB_MAD_ATTR_CLASS_PORT_INFO:
...

>From ib_types.h

#define IB_MAD_ATTR_CLASS_PORT_INFO			(CL_HTON16(0x0001))

Thus the 

#define __bswap_constant_16(x) \
     ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))

in bits/byteswap.h

Ira

> 
> Ditto for stdint.h and stdbool.h. Those are C99 headers, just use them.
> 
> Jason


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



More information about the ofw mailing list