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

Jason Gunthorpe jgunthorpe at obsidianresearch.com
Fri Sep 18 16:23:36 PDT 2009


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..

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

Jason



More information about the general mailing list