From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH 1/2] eal: detect endianness Date: Thu, 04 Dec 2014 13:19:49 +0100 Message-ID: <1538241.xRI4LPKbTP@xps13> References: <283531301.lWbIahXLyM@xps13> <3580620.HEA1jLh5UM@xps13> <533710CFB86FA344BFBF2D6802E60286C9CB38@SHSMSX101.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev-VfR2kkLFssw@public.gmane.org, Chao Zhu To: "Qiu, Michael" Return-path: In-Reply-To: <533710CFB86FA344BFBF2D6802E60286C9CB38-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" 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 > >>> +#ifdef RTE_EXEC_ENV_BSDAPP > >>> +#include > >>> +#else > >>> +#include > >>> +#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 > >> +#else > >> +#include > >> +#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