]> git.droids-corp.org - dpdk.git/commitdiff
eal: detect endianness
authorThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 3 Dec 2014 20:01:19 +0000 (21:01 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 5 Dec 2014 15:55:00 +0000 (16:55 +0100)
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.

If endianness is not detected, there is a fallback on x86
to little endian. It could be forced before doing detection
but it would add some arch-dependent code in the generic header.

The option CONFIG_RTE_ARCH_BIG_ENDIAN introduced for IBM Power only
(commit a982ec81d84d53) can be removed. A compile-time check is better.

Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>
Acked-by: Michael Qiu <michael.qiu@intel.com>
config/defconfig_ppc_64-power8-linuxapp-gcc
lib/librte_eal/common/include/arch/ppc_64/rte_byteorder.h
lib/librte_eal/common/include/arch/x86/rte_byteorder.h
lib/librte_eal/common/include/generic/rte_byteorder.h

index 48018c331caaf97b9a2fbbe6e8d21e412db4e8c8..d97a8854439de99b66829eb36bc647aed86980a1 100644 (file)
@@ -34,7 +34,6 @@ CONFIG_RTE_MACHINE="power8"
 
 CONFIG_RTE_ARCH="ppc_64"
 CONFIG_RTE_ARCH_PPC_64=y
-CONFIG_RTE_ARCH_BIG_ENDIAN=y
 CONFIG_RTE_ARCH_64=y
 
 CONFIG_RTE_TOOLCHAIN="gcc"
index 1a89051029462088aa69a038a7550724504b6877..80436f246041aa636df7d5c76a2ce1670b7b50c7 100644 (file)
@@ -105,7 +105,7 @@ static inline uint64_t rte_arch_bswap64(uint64_t _x)
 /* Power 8 have both little endian and big endian mode
  * Power 7 only support big endian
  */
-#ifndef RTE_ARCH_BIG_ENDIAN
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
 
 #define rte_cpu_to_le_16(x) (x)
 #define rte_cpu_to_le_32(x) (x)
@@ -123,7 +123,7 @@ static inline uint64_t rte_arch_bswap64(uint64_t _x)
 #define rte_be_to_cpu_32(x) rte_bswap32(x)
 #define rte_be_to_cpu_64(x) rte_bswap64(x)
 
-#else
+#else /* RTE_BIG_ENDIAN */
 
 #define rte_cpu_to_le_16(x) rte_bswap16(x)
 #define rte_cpu_to_le_32(x) rte_bswap32(x)
index 1aa6985f7c64053cb23784a799b1356ce83cf621..ffdb6ef5488e41b65a5f0815c80bed63c36257df 100644 (file)
@@ -40,6 +40,10 @@ extern "C" {
 
 #include "generic/rte_byteorder.h"
 
+#ifndef RTE_BYTE_ORDER
+#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
+#endif
+
 /*
  * An architecture-optimized byte swap for a 16-bit value.
  *
index 9358136ac0c4f088fff90948684cd779a6d305c0..c46fdcf20dee22e273a1d049f5bcd0ae31cb9c60 100644 (file)
  */
 
 #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__ == __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 __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
 
 /*
  * An internal function to swap bytes in a 16-bit value.