From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shreyansh Jain Subject: [PATCH 01/38] eal: add support for 24 40 and 48 bit operations Date: Fri, 16 Jun 2017 11:10:31 +0530 Message-ID: <1497591668-3320-2-git-send-email-shreyansh.jain@nxp.com> References: <1497591668-3320-1-git-send-email-shreyansh.jain@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Cc: , To: Return-path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0082.outbound.protection.outlook.com [104.47.40.82]) by dpdk.org (Postfix) with ESMTP id 731E02BB9 for ; Fri, 16 Jun 2017 07:32:30 +0200 (CEST) In-Reply-To: <1497591668-3320-1-git-send-email-shreyansh.jain@nxp.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Hemant Agrawal Bit Swap and LE<=>BE conversions for 23, 40 and 48 bit width Signed-off-by: Hemant Agrawal --- .../common/include/generic/rte_byteorder.h | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/lib/librte_eal/common/include/generic/rte_byteorder.h b/lib/librte_eal/common/include/generic/rte_byteorder.h index e00bccb..8903ff6 100644 --- a/lib/librte_eal/common/include/generic/rte_byteorder.h +++ b/lib/librte_eal/common/include/generic/rte_byteorder.h @@ -122,6 +122,84 @@ rte_constant_bswap64(uint64_t x) ((x & 0xff00000000000000ULL) >> 56); } +/* + * An internal function to swap bytes of a 48-bit value. + */ +static inline uint64_t +rte_constant_bswap48(uint64_t x) +{ + return ((x & 0x0000000000ffULL) << 40) | + ((x & 0x00000000ff00ULL) << 24) | + ((x & 0x000000ff0000ULL) << 8) | + ((x & 0x0000ff000000ULL) >> 8) | + ((x & 0x00ff00000000ULL) >> 24) | + ((x & 0xff0000000000ULL) >> 40); +} + +/* + * An internal function to swap bytes of a 40-bit value. + */ +static inline uint64_t +rte_constant_bswap40(uint64_t x) +{ + return ((x & 0x00000000ffULL) << 32) | + ((x & 0x000000ff00ULL) << 16) | + ((x & 0x0000ff0000ULL)) | + ((x & 0x00ff000000ULL) >> 16) | + ((x & 0xff00000000ULL) >> 32); +} + +/* + * An internal function to swap bytes of a 24-bit value. + */ +static inline uint32_t +rte_constant_bswap24(uint32_t x) +{ + return ((x & 0x0000ffULL) << 16) | + ((x & 0x00ff00ULL)) | + ((x & 0xff0000ULL) >> 16); +} + +#define rte_bswap24 rte_constant_bswap24 +#define rte_bswap40 rte_constant_bswap40 +#define rte_bswap48 rte_constant_bswap48 + +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN + +#define rte_cpu_to_le_24(x) (x) +#define rte_cpu_to_le_40(x) (x) +#define rte_cpu_to_le_48(x) (x) + +#define rte_cpu_to_be_24(x) rte_bswap24(x) +#define rte_cpu_to_be_40(x) rte_bswap40(x) +#define rte_cpu_to_be_48(x) rte_bswap48(x) + +#define rte_le_to_cpu_24(x) (x) +#define rte_le_to_cpu_40(x) (x) +#define rte_le_to_cpu_48(x) (x) + +#define rte_be_to_cpu_24(x) rte_bswap24(x) +#define rte_be_to_cpu_40(x) rte_bswap40(x) +#define rte_be_to_cpu_48(x) rte_bswap48(x) + +#else /* RTE_BIG_ENDIAN */ + +#define rte_cpu_to_le_24(x) rte_bswap24(x) +#define rte_cpu_to_le_40(x) rte_bswap40(x) +#define rte_cpu_to_le_48(x) rte_bswap48(x) + +#define rte_cpu_to_be_24(x) (x) +#define rte_cpu_to_be_40(x) (x) +#define rte_cpu_to_be_48(x) (x) + +#define rte_le_to_cpu_24(x) rte_bswap24(x) +#define rte_le_to_cpu_40(x) rte_bswap40(x) +#define rte_le_to_cpu_48(x) rte_bswap48(x) + +#define rte_be_to_cpu_24(x) (x) +#define rte_be_to_cpu_40(x) (x) +#define rte_be_to_cpu_48(x) (x) +#endif #ifdef __DOXYGEN__ -- 2.7.4