2014-12-04 02:28, Qiu, Michael: > On 12/4/2014 5:26 AM, Thomas Monjalon wrote: > > There is no standard to check endianness. > > So we need to try different checks. > > Previous trials were done in testpmd (see commits > > 51f694dd40f56 and 64741f237cf29) without full success. > > This one is not guaranteed to work everywhere so it could > > evolve when exceptions are found. [...] > > #include <stdint.h> > > +#ifdef RTE_EXEC_ENV_BSDAPP > > +#include <sys/endian.h> > > +#else > > +#include <endian.h> > > +#endif > > + > > +/* > > + * Compile-time endianness detection > > + */ > > +#define RTE_BIG_ENDIAN 1 > > +#define RTE_LITTLE_ENDIAN 2 > > +#if defined __BYTE_ORDER > > +#if __BYTE_ORDER == __BIG_ENDIAN > > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > > +#elif __BYTE_ORDER == __LITTLE_ENDIAN > > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > > +#endif /* __BYTE_ORDER */ > > +#elif defined __BYTE_ORDER__ > > +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > > +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > > +#endif /* __BYTE_ORDER__ */ > > +#elif defined __BIG_ENDIAN__ > > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > > +#elif defined __LITTLE_ENDIAN__ > > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > > +#endif > > What do you think about : > > +/* > + * Compile-time endianness detection > + */ > +#define RTE_BIG_ENDIAN 1 > +#define RTE_LITTLE_ENDIAN 2 > +if defined __BYTE_ORDER__ /* Prefer gcc build-in macros */ > +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > +#endif /* __BYTE_ORDER__ */ > +#else > +#if defined RTE_EXEC_ENV_BSDAPP > +#include <sys/endian.h> > +#else > +#include <endian.h> > +#endif > +#if defined __BYTE_ORDER > +#if __BYTE_ORDER == __BIG_ENDIAN > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > +#elif __BYTE_ORDER == __LITTLE_ENDIAN > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > +#endif /* __BYTE_ORDER */ > +#elif defined __BIG_ENDIAN__ > +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN > +#elif defined __LITTLE_ENDIAN__ > +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN > +#endif > +#endif
Please, could you give more explanations about your proposal? Why not always try to include endian.h? Why giving high priority to __BYTE_ORDER__? -- Thomas