Christoph: This is great stuff, but would be even better if we just globally replaced thinks like "cpu_to_wr64" with "cpu_to_be64" and removed the cc_byteorder.h file altogether?
What do you think? > -----Original Message----- > From: Christoph Hellwig [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 11, 2005 10:03 AM > To: Tom Tucker > Cc: [email protected] > Subject: [PATCH] amso1100: use standard byteorder macros > > Signed-off-by: Christoph Hellwig <[EMAIL PROTECTED]> > > Index: cc_byteorder.h > =================================================================== > --- cc_byteorder.h (revision 3058) > +++ cc_byteorder.h (working copy) > @@ -1,113 +1,30 @@ > #ifndef _CC_BYTEORDER_H_ > #define _CC_BYTEORDER_H_ > > +#include <asm/byteorder.h> > #include "cc_types.h" > > -static inline const u64 cc_arch_swap64(u64 x) -{ > - union { > - struct { u32 a,b; } s; > - u64 u; > - } v; > - > - v.u = x; > - > - asm("bswap %0\n\t" > - "bswap %1\n\t" > - "xchgl %0,%1\n" > - : "=r" (v.s.a), "=r" (v.s.b) > - : "0" (v.s.a), "1" (v.s.b)); > - > - return v.u; > -} > - > -static inline const u32 cc_arch_swap32(u32 x) -{ > - asm("bswap %0" : "=r" (x) : "0" (x)); > - return x; > -} > - > -#define cc_swap16(x) \ > -({ \ > - u16 __x = (x); \ > - ((u16)( \ > - (((u16)(__x) & (u16)0x00ffU) << 8) | \ > - (((u16)(__x) & (u16)0xff00U) >> 8) )); \ > -}) > - > -#define cc_swap32(x) \ > -({ \ > - u32 __x = (x); \ > - ((u32)( \ > - (((u32)(__x) & (u32)0x000000ffUL) << 24) | \ > - (((u32)(__x) & (u32)0x0000ff00UL) << 8) | \ > - (((u32)(__x) & (u32)0x00ff0000UL) >> 8) | \ > - (((u32)(__x) & (u32)0xff000000UL) >> 24) )); \ > -}) > - > -#define cc_swap64(x) \ > -({ \ > - u64 __x = (x); \ > - ((u64)( \ > - (u64)(((u64)(__x) & (u64)0x00000000000000ffULL) > << 56) | \ > - (u64)(((u64)(__x) & (u64)0x000000000000ff00ULL) > << 40) | \ > - (u64)(((u64)(__x) & (u64)0x0000000000ff0000ULL) > << 24) | \ > - (u64)(((u64)(__x) & (u64)0x00000000ff000000ULL) > << 8) | \ > - (u64)(((u64)(__x) & (u64)0x000000ff00000000ULL) > >> 8) | \ > - (u64)(((u64)(__x) & (u64)0x0000ff0000000000ULL) > >> 24) | \ > - (u64)(((u64)(__x) & (u64)0x00ff000000000000ULL) > >> 40) | \ > - (u64)(((u64)(__x) & (u64)0xff00000000000000ULL) > >> 56) )); \ > -}) > - > -/* This section defines what it means to swap a word into the byte > - order of the current CPU. For example, x86-32 and x86-64 are > - little-endian platforms, so swapping a big-endian number to the > - cpu means the bytes need to be rearranged. However, swapping a > - little-endian number to the cpu means that nothing should be done. > -*/ > - > -#define X86_32 > -#if defined(X86_32) || defined (X86_64) > - > -#define cc_be64_to_cpu(x) (__builtin_constant_p((u64)(x)) ? > cc_swap64(x) : cc_arch_swap64(x)) -#define cc_be32_to_cpu(x) > (__builtin_constant_p((u32)(x)) ? cc_swap32(x) : > cc_arch_swap32(x)) -#define cc_be16_to_cpu(x) cc_swap16(x) > -#define cc_cpu_to_be64(x) cc_be64_to_cpu(x) -#define > cc_cpu_to_be32(x) cc_be32_to_cpu(x) -#define > cc_cpu_to_be16(x) cc_be16_to_cpu(x) > - > -#define cc_le64_to_cpu(x) ((u64)(x)) > -#define cc_le32_to_cpu(x) ((u32)(x)) > -#define cc_le16_to_cpu(x) ((u16)(x)) > -#define cc_cpu_to_le64(x) ((u64)(x)) > -#define cc_cpu_to_le32(x) ((u32)(x)) > -#define cc_cpu_to_le16(x) ((u16)(x)) > - > -#else > -#error Byte swapping functions not defined for this platform -#endif > - > /* Here we define the adapter-to-cpu and cpu-to-adapter byte > order functions > based on whether the adapter is big-endian or little-endian. > */ > > #if defined(WR_BYTE_ORDER_BIG_ENDIAN) > > -#define wr64_to_cpu cc_be64_to_cpu > -#define wr32_to_cpu cc_be32_to_cpu > -#define wr16_to_cpu cc_be16_to_cpu > -#define cpu_to_wr64 cc_cpu_to_be64 > -#define cpu_to_wr32 cc_cpu_to_be32 > -#define cpu_to_wr16 cc_cpu_to_be16 > +#define wr64_to_cpu be64_to_cpu > +#define wr32_to_cpu be32_to_cpu > +#define wr16_to_cpu be16_to_cpu > +#define cpu_to_wr64 cpu_to_be64 > +#define cpu_to_wr32 cpu_to_be32 > +#define cpu_to_wr16 cpu_to_be16 > > #elif defined (WR_BYTE_ORDER_LITTLE_ENDIAN) > > -#define wr64_to_cpu cc_le64_to_cpu > -#define wr32_to_cpu cc_le32_to_cpu > -#define wr16_to_cpu cc_le16_to_cpu > -#define cpu_to_wr64 cc_cpu_to_le64 > -#define cpu_to_wr32 cc_cpu_to_le32 > -#define cpu_to_wr16 cc_cpu_to_le16 > +#define wr64_to_cpu le64_to_cpu > +#define wr32_to_cpu le32_to_cpu > +#define wr16_to_cpu le16_to_cpu > +#define cpu_to_wr64 cpu_to_le64 > +#define cpu_to_wr32 cpu_to_le32 > +#define cpu_to_wr16 cpu_to_le16 > > #else > #error Work request (WR) byte order is not defined. > _______________________________________________ openib-general mailing list [email protected] http://openib.org/mailman/listinfo/openib-general To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
