2014-12-04 10:28, Qiu, Michael: > On 12/4/2014 5:01 PM, Thomas Monjalon wrote: > > 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? > > I assume that if gcc can handler why we need include that file?
Separating include on top is easier to read, and I'm not sure it won't be needed for __BYTE_ORDER__ with some toolchains. > Also it seems that only old version could have this issue, newer > versions has build in this marcos. > > So that's why I prefer "__BYTE_ORDER__" for high priority. I have no problem with reversing this priority. > > Why giving high priority to __BYTE_ORDER__? Any other comment? May I apply with above change? -- Thomas