From patchwork Wed Feb 17 14:36:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 62112 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp3782lbl; Wed, 17 Feb 2016 05:39:33 -0800 (PST) X-Received: by 10.140.22.139 with SMTP id 11mr1936108qgn.34.1455716373130; Wed, 17 Feb 2016 05:39:33 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b7si46150287qgb.59.2016.02.17.05.39.32; Wed, 17 Feb 2016 05:39:33 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B817161790; Wed, 17 Feb 2016 13:39:32 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=fkZ61P3G; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id D8BE0617B0; Wed, 17 Feb 2016 13:37:49 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C6309610BC; Wed, 17 Feb 2016 13:37:36 +0000 (UTC) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by lists.linaro.org (Postfix) with ESMTPS id D1AE3610BC for ; Wed, 17 Feb 2016 13:37:32 +0000 (UTC) Received: by mail-lb0-f170.google.com with SMTP id of3so9534505lbc.1 for ; Wed, 17 Feb 2016 05:37:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qYsu62Mc2UjaIKYnENx2LNyux53qimlceJ/5m99+AFw=; b=fkZ61P3GPbZbVCLmXky5A2i3nEgYXudThHLz8rWnfquMBKf5hiX79LYEWQKDo/KugW wDCSCUEVkdVWS1mPuJIR35gJlFmhEHU6CgaWrSpSQ29UDYcUQS6Wnq95sntQMgycL4Xk dDixQ/rF4R1f4cfcUTR5yyWhS5+svo88KB84A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qYsu62Mc2UjaIKYnENx2LNyux53qimlceJ/5m99+AFw=; b=f0O3M9O9SKOz+b59Qy4PnSTgDrDYWs+eSLh3gnpjmprPws4wJfa4Hyt6MkmeNrVXeG Q6HOMRBzbQO0JTi8RFRkpWj30czCW2O5ixD18gWuiZ3TMU2TwD9wlgipFYzNrbXDIDDF NcbDtHgy2DEefFxjPhyACG/U9uTafECsu4OQIjk1qySvOfsh9lJrbyqI1URJI42MTBoj xnlK6lMWqWXNXqX34rwhxHGZjOBLARh/1oNMBH8OVxVZikiiXAwnM6Bysurvozw6Bxio cHs4R3RjRei1JNIDt/n9pcWA5oMJ/7o4aYeaL0cnjtA0YANg82i+rtTFiWB5Cm8aLleE eheA== X-Gm-Message-State: AG10YOQWvUIDgaDO1f+q4JJb9AaeUnu5nqgWf4YWLeTBNpo+QphH+BTxD0SVNKXOCAMmw6phvlU= X-Received: by 10.112.190.4 with SMTP id gm4mr785876lbc.74.1455716251821; Wed, 17 Feb 2016 05:37:31 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id wj2sm215102lbb.5.2016.02.17.05.37.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 05:37:31 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org Date: Wed, 17 Feb 2016 15:36:16 +0100 Message-Id: <1455719777-15879-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455719777-15879-1-git-send-email-christophe.milard@linaro.org> References: <1455719777-15879-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT PATCH 2/3] linux-generic: byte-order: split common part X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The files defining byte order and related functions are split so that a common part can be re-used for other odp interfaces. Signed-off-by: Christophe Milard --- platform/linux-generic/Makefile.am | 8 ++ platform/linux-generic/include/odp/api/byteorder.h | 76 ++---------- .../include/odp/api/plat/byteorder_types.h | 55 +++------ platform/linux-generic/include/odp/com/byteorder.h | 132 +++++++++++++++++++++ .../include/odp/com/plat/byteorder_types.h | 71 +++++++++++ 5 files changed, 238 insertions(+), 104 deletions(-) create mode 100644 platform/linux-generic/include/odp/com/byteorder.h create mode 100644 platform/linux-generic/include/odp/com/plat/byteorder_types.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 734e2a4..df3f0b9 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -92,6 +92,14 @@ odpdrvincludedir= $(includedir)/odp/drv odpdrvinclude_HEADERS = \ $(srcdir)/include/odp/drv/compiler.h +odpcomincludedir= $(includedir)/odp/com +odpcominclude_HEADERS = \ + $(srcdir)/include/odp/api/byteorder.h + +odpcomplatincludedir= $(includedir)/odp/com/plat +odpcomplatinclude_HEADERS = \ + $(srcdir)/include/odp/com/plat/byteorder_types.h + noinst_HEADERS = \ ${srcdir}/include/odp_align_internal.h \ ${srcdir}/include/odp_atomic_internal.h \ diff --git a/platform/linux-generic/include/odp/api/byteorder.h b/platform/linux-generic/include/odp/api/byteorder.h index c347be0..8cdc5df 100644 --- a/platform/linux-generic/include/odp/api/byteorder.h +++ b/platform/linux-generic/include/odp/api/byteorder.h @@ -20,6 +20,7 @@ extern "C" { #include #include #include +#include /** @ingroup odp_compiler_optim * @{ @@ -27,113 +28,62 @@ extern "C" { static inline uint16_t odp_be_to_cpu_16(odp_u16be_t be16) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return __odp_builtin_bswap16((__odp_force uint16_t)be16); -#else - return (__odp_force uint16_t)be16; -#endif + return _odp_be_to_cpu_16((_odp_u16be_t)be16); } static inline uint32_t odp_be_to_cpu_32(odp_u32be_t be32) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return __builtin_bswap32((__odp_force uint32_t)be32); -#else - return (__odp_force uint32_t)be32; -#endif + return _odp_be_to_cpu_32((_odp_u32be_t)be32); } static inline uint64_t odp_be_to_cpu_64(odp_u64be_t be64) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return __builtin_bswap64((__odp_force uint64_t)be64); -#else - return (__odp_force uint64_t)be64; -#endif + return _odp_be_to_cpu_64((_odp_u64be_t)be64); } - static inline odp_u16be_t odp_cpu_to_be_16(uint16_t cpu16) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u16be_t)__odp_builtin_bswap16(cpu16); -#else - return (__odp_force odp_u16be_t)cpu16; -#endif + return (odp_u16be_t)_odp_cpu_to_be_16(cpu16); } static inline odp_u32be_t odp_cpu_to_be_32(uint32_t cpu32) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u32be_t)__builtin_bswap32(cpu32); -#else - return (__odp_force odp_u32be_t)cpu32; -#endif + return (odp_u32be_t)_odp_cpu_to_be_32(cpu32); } static inline odp_u64be_t odp_cpu_to_be_64(uint64_t cpu64) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u64be_t)__builtin_bswap64(cpu64); -#else - return (__odp_force odp_u64be_t)cpu64; -#endif + return (odp_u64be_t)_odp_cpu_to_be_64(cpu64); } - static inline uint16_t odp_le_to_cpu_16(odp_u16le_t le16) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint16_t)le16; -#else - return __odp_builtin_bswap16((__odp_force uint16_t)le16); -#endif + return _odp_le_to_cpu_16((_odp_u16le_t)le16); } static inline uint32_t odp_le_to_cpu_32(odp_u32le_t le32) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint32_t)le32; -#else - return __builtin_bswap32((__odp_force uint32_t)le32); -#endif + return _odp_le_to_cpu_32((_odp_u32le_t)le32); } static inline uint64_t odp_le_to_cpu_64(odp_u64le_t le64) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint64_t)le64; -#else - return __builtin_bswap64((__odp_force uint64_t)le64); -#endif + return _odp_le_to_cpu_64((_odp_u64le_t)le64); } - static inline odp_u16le_t odp_cpu_to_le_16(uint16_t cpu16) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u16le_t)cpu16; -#else - return (__odp_force odp_u16le_t)__odp_builtin_bswap16(cpu16); -#endif + return (odp_u16le_t)_odp_cpu_to_le_16(cpu16); } static inline odp_u32le_t odp_cpu_to_le_32(uint32_t cpu32) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u32le_t)cpu32; -#else - return (__odp_force odp_u32le_t)__builtin_bswap32(cpu32); -#endif + return (odp_u32le_t)_odp_cpu_to_le_32(cpu32); } static inline odp_u64le_t odp_cpu_to_le_64(uint64_t cpu64) { -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force odp_u64le_t)cpu64; -#else - return (__odp_force odp_u64le_t)__builtin_bswap64(cpu64); -#endif + return (odp_u64le_t)_odp_cpu_to_le_64(cpu64); } /** diff --git a/platform/linux-generic/include/odp/api/plat/byteorder_types.h b/platform/linux-generic/include/odp/api/plat/byteorder_types.h index 0a8e409..d5dead7 100644 --- a/platform/linux-generic/include/odp/api/plat/byteorder_types.h +++ b/platform/linux-generic/include/odp/api/plat/byteorder_types.h @@ -14,44 +14,19 @@ #ifndef ODP_BYTEORDER_TYPES_H_ #define ODP_BYTEORDER_TYPES_H_ +#include "odp/com/plat/byteorder_types.h" + #ifdef __cplusplus extern "C" { #endif -#ifndef __BYTE_ORDER -#error __BYTE_ORDER not defined! -#endif - -#ifndef __BIG_ENDIAN -#error __BIG_ENDIAN not defined! -#endif - -#ifndef __LITTLE_ENDIAN -#error __LITTLE_ENDIAN not defined! -#endif - - -/* for use with type checkers such as sparse */ -#ifdef __CHECKER__ -/** @internal bitwise attribute */ -#define __odp_bitwise __attribute__((bitwise)) -/** @internal force attribute */ -#define __odp_force __attribute__((force)) -#else -/** @internal bitwise attribute */ -#define __odp_bitwise -/** @internal force attribute */ -#define __odp_force -#endif - - /** @addtogroup odp_compiler_optim * @{ */ -#define ODP_BIG_ENDIAN __BIG_ENDIAN +#define ODP_BIG_ENDIAN _ODP_BIG_ENDIAN -#define ODP_LITTLE_ENDIAN __LITTLE_ENDIAN +#define ODP_LITTLE_ENDIAN _ODP_LITTLE_ENDIAN #ifdef __BIG_ENDIAN_BITFIELD #define ODP_BIG_ENDIAN_BITFIELD @@ -61,23 +36,21 @@ extern "C" { #define ODP_LITTLE_ENDIAN_BITFIELD #endif -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define ODP_BYTE_ORDER ODP_LITTLE_ENDIAN -#elif __BYTE_ORDER == __BIG_ENDIAN -#define ODP_BYTE_ORDER ODP_BIG_ENDIAN +#ifdef _ODP_BYTE_ORDER +#define ODP_BYTE_ORDER _ODP_BYTE_ORDER #endif -typedef uint16_t __odp_bitwise odp_u16le_t; -typedef uint16_t __odp_bitwise odp_u16be_t; +typedef _odp_u16le_t odp_u16le_t; +typedef _odp_u16be_t odp_u16be_t; -typedef uint32_t __odp_bitwise odp_u32le_t; -typedef uint32_t __odp_bitwise odp_u32be_t; +typedef _odp_u32le_t odp_u32le_t; +typedef _odp_u32be_t odp_u32be_t; -typedef uint64_t __odp_bitwise odp_u64le_t; -typedef uint64_t __odp_bitwise odp_u64be_t; +typedef _odp_u64le_t odp_u64le_t; +typedef _odp_u64be_t odp_u64be_t; -typedef uint16_t __odp_bitwise odp_u16sum_t; -typedef uint32_t __odp_bitwise odp_u32sum_t; +typedef _odp_u16sum_t odp_u16sum_t; +typedef _odp_u32sum_t odp_u32sum_t; /** * @} diff --git a/platform/linux-generic/include/odp/com/byteorder.h b/platform/linux-generic/include/odp/com/byteorder.h new file mode 100644 index 0000000..7bd838f --- /dev/null +++ b/platform/linux-generic/include/odp/com/byteorder.h @@ -0,0 +1,132 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP byteorder, things common to API and DRV interfaces + */ + +#ifndef ODPCOM_PLAT_BYTEORDER_H_ +#define ODPCOM_PLAT_BYTEORDER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline uint16_t _odp_be_to_cpu_16(_odp_u16be_t be16) +{ +#if _ODP_BYTE_ORDER == _ODP_LITTLE_ENDIAN + return __odp_builtin_bswap16((__odp_force uint16_t)be16); +#else + return (__odp_force uint16_t)be16; +#endif +} + +static inline uint32_t _odp_be_to_cpu_32(_odp_u32be_t be32) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return __builtin_bswap32((__odp_force uint32_t)be32); +#else + return (__odp_force uint32_t)be32; +#endif +} + +static inline uint64_t _odp_be_to_cpu_64(_odp_u64be_t be64) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return __builtin_bswap64((__odp_force uint64_t)be64); +#else + return (__odp_force uint64_t)be64; +#endif +} + +static inline _odp_u16be_t _odp_cpu_to_be_16(uint16_t cpu16) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force _odp_u16be_t)__odp_builtin_bswap16(cpu16); +#else + return (__odp_force _odp_u16be_t)cpu16; +#endif +} + +static inline _odp_u32be_t _odp_cpu_to_be_32(uint32_t cpu32) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force _odp_u32be_t)__builtin_bswap32(cpu32); +#else + return (__odp_force _odp_u32be_t)cpu32; +#endif +} + +static inline odp_u64be_t _odp_cpu_to_be_64(uint64_t cpu64) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force _odp_u64be_t)__builtin_bswap64(cpu64); +#else + return (__odp_force _odp_u64be_t)cpu64; +#endif +} + +static inline uint16_t _odp_le_to_cpu_16(_odp_u16le_t le16) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force uint16_t)le16; +#else + return __odp_builtin_bswap16((__odp_force uint16_t)le16); +#endif +} + +static inline uint32_t _odp_le_to_cpu_32(_odp_u32le_t le32) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force uint32_t)le32; +#else + return __builtin_bswap32((__odp_force uint32_t)le32); +#endif +} + +static inline uint64_t _odp_le_to_cpu_64(_odp_u64le_t le64) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force uint64_t)le64; +#else + return __builtin_bswap64((__odp_force uint64_t)le64); +#endif +} + +static inline _odp_u16le_t _odp_cpu_to_le_16(uint16_t cpu16) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force odp_u16le_t)cpu16; +#else + return (__odp_force odp_u16le_t)__odp_builtin_bswap16(cpu16); +#endif +} + +static inline _odp_u32le_t _odp_cpu_to_le_32(uint32_t cpu32) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force odp_u32le_t)cpu32; +#else + return (__odp_force odp_u32le_t)__builtin_bswap32(cpu32); +#endif +} + +static inline _odp_u64le_t _odp_cpu_to_le_64(uint64_t cpu64) +{ +#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN + return (__odp_force odp_u64le_t)cpu64; +#else + return (__odp_force odp_u64le_t)__builtin_bswap64(cpu64); +#endif +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/com/plat/byteorder_types.h b/platform/linux-generic/include/odp/com/plat/byteorder_types.h new file mode 100644 index 0000000..6828d28 --- /dev/null +++ b/platform/linux-generic/include/odp/com/plat/byteorder_types.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP byteorder, things common to API and DRV interfaces + */ + +#ifndef ODPCOM_BYTEORDER_TYPES_H_ +#define ODPCOM_BYTEORDER_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __BYTE_ORDER +#error __BYTE_ORDER not defined! +#endif + +#ifndef __BIG_ENDIAN +#error __BIG_ENDIAN not defined! +#endif + +#ifndef __LITTLE_ENDIAN +#error __LITTLE_ENDIAN not defined! +#endif + +/* for use with type checkers such as sparse */ +#ifdef __CHECKER__ +/** @internal bitwise attribute */ +#define __odp_bitwise __attribute__((bitwise)) +/** @internal force attribute */ +#define __odp_force __attribute__((force)) +#else +/** @internal bitwise attribute */ +#define __odp_bitwise +/** @internal force attribute */ +#define __odp_force +#endif + +#define _ODP_BIG_ENDIAN __BIG_ENDIAN + +#define _ODP_LITTLE_ENDIAN __LITTLE_ENDIAN + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define _ODP_BYTE_ORDER _ODP_LITTLE_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN +#define _ODP_BYTE_ORDER _ODP_BIG_ENDIAN +#endif + +typedef uint16_t __odp_bitwise _odp_u16le_t; +typedef uint16_t __odp_bitwise _odp_u16be_t; + +typedef uint32_t __odp_bitwise _odp_u32le_t; +typedef uint32_t __odp_bitwise _odp_u32be_t; + +typedef uint64_t __odp_bitwise _odp_u64le_t; +typedef uint64_t __odp_bitwise _odp_u64be_t; + +typedef uint16_t __odp_bitwise _odp_u16sum_t; +typedef uint32_t __odp_bitwise _odp_u32sum_t; + +#ifdef __cplusplus +} +#endif + +#endif