On Fri, 18 Sep 2009 17:23:36 -0600
Jason Gunthorpe <jguntho...@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
wei...@llnl.gov
_______________________________________________
general mailing list
general@lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to