From patchwork Tue Jun 17 17:55:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 32093 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B653E20C81 for ; Tue, 17 Jun 2014 17:56:19 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id t59sf33291928yho.6 for ; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=87cJj5nsqgkyyIWBvgcrOAhTXRnld4hpJJN/aFUtb40=; b=kdGcA5fgIDOVv/gs7Jpvc5KysfnQJbELEBldYslOgxIH+PjA4E15SfZDj1/j4yylrg 0C1u3/vKuEGJFh+wefX4CIkYIgo2HoFdMH67xFFJWu20ciR3pUBRpe1xQQDuIscDulm/ izYinwZ/O3tl5qfrRDkUTVmW38y75vv/ldykZeptjZwSUSPdMJagbHZbs0r78eEfys84 h9mflTO4WpyMYH7QcLD2n6zshZnD3+cYTeQcwjjcvEM4bUYVJhlgtWThwhdKT+7u4U55 BQ8D+IBuPFJfWSHE/C6TzQ58R7JyusimYvF6Qy+O9tFldHemIcRNdZ8YMMM5crD+GZnd NWmw== X-Gm-Message-State: ALoCoQk6u0H21tvS6n1h9118onX2qCq7pCoitKmfssI6VSYfVzvDPh4I9AhEvcqpCZXhkAtMjuIU X-Received: by 10.52.186.132 with SMTP id fk4mr422220vdc.1.1403027779541; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.42 with SMTP id 39ls4745593qgq.26.gmail; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-Received: by 10.58.85.3 with SMTP id d3mr2940182vez.34.1403027779459; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id ij19si5768488vec.99.2014.06.17.10.56.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Jun 2014 10:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so6077668veb.13 for ; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-Received: by 10.58.198.46 with SMTP id iz14mr1652987vec.53.1403027779373; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp227569vcb; Tue, 17 Jun 2014 10:56:19 -0700 (PDT) X-Received: by 10.224.123.202 with SMTP id q10mr1855444qar.79.1403027778891; Tue, 17 Jun 2014 10:56:18 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id y8si17210257qcq.19.2014.06.17.10.56.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 17 Jun 2014 10:56:18 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wwxac-0004sA-Lz; Tue, 17 Jun 2014 17:54:34 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wwxa2-0004n1-UA for lng-odp@lists.linaro.org; Tue, 17 Jun 2014 17:53:59 +0000 Received: by mail-la0-f48.google.com with SMTP id gl10so4081781lab.7 for ; Tue, 17 Jun 2014 10:55:35 -0700 (PDT) X-Received: by 10.112.198.102 with SMTP id jb6mr18199167lbc.18.1403027735917; Tue, 17 Jun 2014 10:55:35 -0700 (PDT) Received: from localhost.localdomain (176-241-155-136-dynamic.retail.datagroup.ua. [176.241.155.136]) by mx.google.com with ESMTPSA id d3sm11646351lbw.2.2014.06.17.10.55.34 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Jun 2014 10:55:35 -0700 (PDT) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 17 Jun 2014 20:55:10 +0300 Message-Id: <1403027720-9738-9-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403027720-9738-1-git-send-email-taras.kondratiuk@linaro.org> References: <1403027720-9738-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v2 08/18] Split out platform-specific part of odp_byteorder.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Taras Kondratiuk --- include/odp_byteorder.h | 147 ++---------- .../linux-generic/include/plat/odp_byteorder.h | 244 ++++++++++++++++++++ 2 files changed, 266 insertions(+), 125 deletions(-) create mode 100644 platform/linux-generic/include/plat/odp_byteorder.h diff --git a/include/odp_byteorder.h b/include/odp_byteorder.h index 22e5a64..a9a5526 100644 --- a/include/odp_byteorder.h +++ b/include/odp_byteorder.h @@ -18,45 +18,26 @@ extern "C" { #endif -#include #include -#include - -#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 +#include /** Big endian byte order */ -#define ODP_BIG_ENDIAN __BIG_ENDIAN +#define ODP_BIG_ENDIAN PLAT_ODP_BIG_ENDIAN /** Little endian byte order */ -#define ODP_LITTLE_ENDIAN __LITTLE_ENDIAN +#define ODP_LITTLE_ENDIAN PLAT_ODP_LITTLE_ENDIAN /** Selected byte order */ -#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 uint16le_t; /**< unsigned 16bit little endian */ -typedef uint16_t __odp_bitwise uint16be_t; /**< unsigned 16bit big endian */ +#define ODP_BYTE_ORDER PLAT_ODP_BYTE_ORDER -typedef uint32_t __odp_bitwise uint32le_t; /**< unsigned 32bit little endian */ -typedef uint32_t __odp_bitwise uint32be_t; /**< unsigned 32bit big endian */ +typedef plat_uint16le_t uint16le_t; /**< unsigned 16bit little endian */ +typedef plat_uint16be_t uint16be_t; /**< unsigned 16bit big endian */ -typedef uint64_t __odp_bitwise uint64le_t; /**< unsigned 64bit little endian */ -typedef uint64_t __odp_bitwise uint64be_t; /**< unsigned 64bit big endian */ +typedef plat_uint32le_t uint32le_t; /**< unsigned 32bit little endian */ +typedef plat_uint32be_t uint32be_t; /**< unsigned 32bit big endian */ +typedef plat_uint64le_t uint64le_t; /**< unsigned 64bit little endian */ +typedef plat_uint64be_t uint64be_t; /**< unsigned 64bit big endian */ /* * Big Endian -> CPU byte order: @@ -67,42 +48,21 @@ typedef uint64_t __odp_bitwise uint64be_t; /**< unsigned 64bit big endian */ * @param be16 big endian 16bit * @return cpu native uint16_t */ -static inline uint16_t odp_be_to_cpu_16(uint16be_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 -} +uint16_t odp_be_to_cpu_16(uint16be_t be16); /** * Convert 32bit big endian to cpu native uint32_t * @param be32 big endian 32bit * @return cpu native uint32_t */ -static inline uint32_t odp_be_to_cpu_32(uint32be_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 -} +uint32_t odp_be_to_cpu_32(uint32be_t be32); /** * Convert 64bit big endian to cpu native uint64_t * @param be64 big endian 64bit * @return cpu native uint64_t */ -static inline uint64_t odp_be_to_cpu_64(uint64be_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 -} +uint64_t odp_be_to_cpu_64(uint64be_t be64); /* @@ -114,42 +74,21 @@ static inline uint64_t odp_be_to_cpu_64(uint64be_t be64) * @param cpu16 uint16_t in cpu native format * @return big endian 16bit */ -static inline uint16be_t odp_cpu_to_be_16(uint16_t cpu16) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint16be_t)__odp_builtin_bswap16(cpu16); -#else - return (__odp_force uint16be_t)cpu16; -#endif -} +uint16be_t odp_cpu_to_be_16(uint16_t cpu16); /** * Convert cpu native uint32_t to 32bit big endian * @param cpu32 uint32_t in cpu native format * @return big endian 32bit */ -static inline uint32be_t odp_cpu_to_be_32(uint32_t cpu32) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint32be_t)__builtin_bswap32(cpu32); -#else - return (__odp_force uint32be_t)cpu32; -#endif -} +uint32be_t odp_cpu_to_be_32(uint32_t cpu32); /** * Convert cpu native uint64_t to 64bit big endian * @param cpu64 uint64_t in cpu native format * @return big endian 64bit */ -static inline uint64be_t odp_cpu_to_be_64(uint64_t cpu64) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint64be_t)__builtin_bswap64(cpu64); -#else - return (__odp_force uint64be_t)cpu64; -#endif -} +uint64be_t odp_cpu_to_be_64(uint64_t cpu64); /* @@ -161,42 +100,21 @@ static inline uint64be_t odp_cpu_to_be_64(uint64_t cpu64) * @param le16 little endian 16bit * @return cpu native uint16_t */ -static inline uint16_t odp_le_to_cpu_16(uint16le_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 -} +uint16_t odp_le_to_cpu_16(uint16le_t le16); /** * Convert 32bit little endian to cpu native uint32_t * @param le32 little endian 32bit * @return cpu native uint32_t */ -static inline uint32_t odp_le_to_cpu_32(uint32le_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 -} +uint32_t odp_le_to_cpu_32(uint32le_t le32); /** * Convert 64bit little endian to cpu native uint64_t * @param le64 little endian 64bit * @return cpu native uint64_t */ -static inline uint64_t odp_le_to_cpu_64(uint64le_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 -} +uint64_t odp_le_to_cpu_64(uint64le_t le64); /* @@ -208,42 +126,21 @@ static inline uint64_t odp_le_to_cpu_64(uint64le_t le64) * @param cpu16 uint16_t in cpu native format * @return little endian 16bit */ -static inline uint16le_t odp_cpu_to_le_16(uint16_t cpu16) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint16le_t)cpu16; -#else - return (__odp_force uint16le_t)__odp_builtin_bswap16(cpu16); -#endif -} +uint16le_t odp_cpu_to_le_16(uint16_t cpu16); /** * Convert cpu native uint32_t to 32bit little endian * @param cpu32 uint32_t in cpu native format * @return little endian 32bit */ -static inline uint32le_t odp_cpu_to_le_32(uint32_t cpu32) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint32le_t)cpu32; -#else - return (__odp_force uint32le_t)__builtin_bswap32(cpu32); -#endif -} +uint32le_t odp_cpu_to_le_32(uint32_t cpu32); /** * Convert cpu native uint64_t to 64bit little endian * @param cpu64 uint64_t in cpu native format * @return little endian 64bit */ -static inline uint64le_t odp_cpu_to_le_64(uint64_t cpu64) -{ -#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN - return (__odp_force uint64le_t)cpu64; -#else - return (__odp_force uint64le_t)__builtin_bswap64(cpu64); -#endif -} +uint64le_t odp_cpu_to_le_64(uint64_t cpu64); #ifdef __cplusplus diff --git a/platform/linux-generic/include/plat/odp_byteorder.h b/platform/linux-generic/include/plat/odp_byteorder.h new file mode 100644 index 0000000..9838cc7 --- /dev/null +++ b/platform/linux-generic/include/plat/odp_byteorder.h @@ -0,0 +1,244 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP byteorder + */ + +#ifndef ODP_BYTEORDER_H_ +#error This file should be included only into corresponding top level header +#else + +#include + +#include +#include + +#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 + +/** Big endian byte order */ +#define PLAT_ODP_BIG_ENDIAN __BIG_ENDIAN + +/** Little endian byte order */ +#define PLAT_ODP_LITTLE_ENDIAN __LITTLE_ENDIAN + +/** Selected byte order */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define PLAT_ODP_BYTE_ORDER PLAT_ODP_LITTLE_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN +#define PLAT_ODP_BYTE_ORDER PLAT_ODP_BIG_ENDIAN +#endif + + +typedef uint16_t __odp_bitwise plat_uint16le_t; /**< unsigned 16bit little endian */ +typedef uint16_t __odp_bitwise plat_uint16be_t; /**< unsigned 16bit big endian */ + +typedef uint32_t __odp_bitwise plat_uint32le_t; /**< unsigned 32bit little endian */ +typedef uint32_t __odp_bitwise plat_uint32be_t; /**< unsigned 32bit big endian */ + +typedef uint64_t __odp_bitwise plat_uint64le_t; /**< unsigned 64bit little endian */ +typedef uint64_t __odp_bitwise plat_uint64be_t; /**< unsigned 64bit big endian */ +/* + * Big Endian -> CPU byte order: + */ + +/** + * Convert 16bit big endian to cpu native uint16_t + * @param be16 big endian 16bit + * @return cpu native uint16_t + */ +static inline uint16_t odp_be_to_cpu_16(plat_uint16be_t be16) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return __odp_builtin_bswap16((__odp_force uint16_t)be16); +#else + return (__odp_force uint16_t)be16; +#endif +} + +/** + * Convert 32bit big endian to cpu native uint32_t + * @param be32 big endian 32bit + * @return cpu native uint32_t + */ +static inline uint32_t odp_be_to_cpu_32(plat_uint32be_t be32) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return __builtin_bswap32((__odp_force uint32_t)be32); +#else + return (__odp_force uint32_t)be32; +#endif +} + +/** + * Convert 64bit big endian to cpu native uint64_t + * @param be64 big endian 64bit + * @return cpu native uint64_t + */ +static inline uint64_t odp_be_to_cpu_64(plat_uint64be_t be64) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return __builtin_bswap64((__odp_force uint64_t)be64); +#else + return (__odp_force uint64_t)be64; +#endif +} + + +/* + * CPU byte order -> Big Endian: + */ + +/** + * Convert cpu native uint16_t to 16bit big endian + * @param cpu16 uint16_t in cpu native format + * @return big endian 16bit + */ +static inline plat_uint16be_t odp_cpu_to_be_16(uint16_t cpu16) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint16be_t)__odp_builtin_bswap16(cpu16); +#else + return (__odp_force plat_uint16be_t)cpu16; +#endif +} + +/** + * Convert cpu native uint32_t to 32bit big endian + * @param cpu32 uint32_t in cpu native format + * @return big endian 32bit + */ +static inline plat_uint32be_t odp_cpu_to_be_32(uint32_t cpu32) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint32be_t)__builtin_bswap32(cpu32); +#else + return (__odp_force plat_uint32be_t)cpu32; +#endif +} + +/** + * Convert cpu native uint64_t to 64bit big endian + * @param cpu64 uint64_t in cpu native format + * @return big endian 64bit + */ +static inline plat_uint64be_t odp_cpu_to_be_64(uint64_t cpu64) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint64be_t)__builtin_bswap64(cpu64); +#else + return (__odp_force plat_uint64be_t)cpu64; +#endif +} + + +/* + * Little Endian -> CPU byte order: + */ + +/** + * Convert 16bit little endian to cpu native uint16_t + * @param le16 little endian 16bit + * @return cpu native uint16_t + */ +static inline uint16_t odp_le_to_cpu_16(plat_uint16le_t le16) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force uint16_t)le16; +#else + return __odp_builtin_bswap16((__odp_force uint16_t)le16); +#endif +} + +/** + * Convert 32bit little endian to cpu native uint32_t + * @param le32 little endian 32bit + * @return cpu native uint32_t + */ +static inline uint32_t odp_le_to_cpu_32(plat_uint32le_t le32) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force uint32_t)le32; +#else + return __builtin_bswap32((__odp_force uint32_t)le32); +#endif +} + +/** + * Convert 64bit little endian to cpu native uint64_t + * @param le64 little endian 64bit + * @return cpu native uint64_t + */ +static inline uint64_t odp_le_to_cpu_64(plat_uint64le_t le64) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force uint64_t)le64; +#else + return __builtin_bswap64((__odp_force uint64_t)le64); +#endif +} + + +/* + * CPU byte order -> Little Endian: + */ + +/** + * Convert cpu native uint16_t to 16bit little endian + * @param cpu16 uint16_t in cpu native format + * @return little endian 16bit + */ +static inline plat_uint16le_t odp_cpu_to_le_16(uint16_t cpu16) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint16le_t)cpu16; +#else + return (__odp_force plat_uint16le_t)__odp_builtin_bswap16(cpu16); +#endif +} + +/** + * Convert cpu native uint32_t to 32bit little endian + * @param cpu32 uint32_t in cpu native format + * @return little endian 32bit + */ +static inline plat_uint32le_t odp_cpu_to_le_32(uint32_t cpu32) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint32le_t)cpu32; +#else + return (__odp_force plat_uint32le_t)__builtin_bswap32(cpu32); +#endif +} + +/** + * Convert cpu native uint64_t to 64bit little endian + * @param cpu64 uint64_t in cpu native format + * @return little endian 64bit + */ +static inline plat_uint64le_t odp_cpu_to_le_64(uint64_t cpu64) +{ +#if PLAT_ODP_BYTE_ORDER == PLAT_ODP_LITTLE_ENDIAN + return (__odp_force plat_uint64le_t)cpu64; +#else + return (__odp_force plat_uint64le_t)__builtin_bswap64(cpu64); +#endif +} + +#endif