From patchwork Mon Apr 28 11:41:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 29216 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5A70220553 for ; Mon, 28 Apr 2014 11:42:25 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id hz1sf12474697pad.4 for ; Mon, 28 Apr 2014 04:42:24 -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:cc: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=3pKj0qB+yKhJIMpbEOYDVAqOubaDP6wvUbvn07ODWxQ=; b=E4p5vp79+A9pdCpIakVxoSxGN1j6zoPlgKYrzXVt1jNoR4NKZ57z5jrnmo3QeGoreA PAsDHMVTCNBC8eMH/huHmaGCB+6Xmwuu9GbBQujhCLNV2pKdi0V/5lGD8ReD9IyWpz+o fm0AlK4uulpVEGtvmlwvP5GkPlnvczKuGJ7x1oSxgy/u5hpL+eA9gXHae5i2qW37FldR 31cBYZrSOZmHXa577/2l3w3I5AXN3XZYbOWg3QePqRWCKxT6v1VXUnpQ/syBSIMSPEQ/ T9rQy6FJIijPevKzd7YnCvNl6Tj8V73Ijn9zjogVQDLIAI9/r0+UXHhfwaczGG9gIhde ng2A== X-Gm-Message-State: ALoCoQm80tMtOkfL9OykAb+wghYTO87zRcIuIqmslEmB9BuVkTQ1uwX/LmtMj3wSt0HHdQPFYcqH X-Received: by 10.66.232.38 with SMTP id tl6mr11916268pac.33.1398685344590; Mon, 28 Apr 2014 04:42:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.78 with SMTP id z72ls2087212qge.37.gmail; Mon, 28 Apr 2014 04:42:24 -0700 (PDT) X-Received: by 10.52.6.162 with SMTP id c2mr20058957vda.6.1398685344411; Mon, 28 Apr 2014 04:42:24 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id sw4si3545928vdc.120.2014.04.28.04.42.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 04:42:24 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lg15so7896240vcb.16 for ; Mon, 28 Apr 2014 04:42:24 -0700 (PDT) X-Received: by 10.58.90.99 with SMTP id bv3mr168292veb.34.1398685344327; Mon, 28 Apr 2014 04:42:24 -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.220.221.72 with SMTP id ib8csp110818vcb; Mon, 28 Apr 2014 04:42:21 -0700 (PDT) X-Received: by 10.140.104.78 with SMTP id z72mr11478564qge.60.1398685340953; Mon, 28 Apr 2014 04:42:20 -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 t1si7670813qga.122.2014.04.28.04.42.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 28 Apr 2014 04:42:20 -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 1WejwW-0002pK-5S; Mon, 28 Apr 2014 11:41:52 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wejvw-0002lr-L8 for lng-odp@lists.linaro.org; Mon, 28 Apr 2014 11:41:16 +0000 Received: by mail-lb0-f177.google.com with SMTP id z11so4795969lbi.8 for ; Mon, 28 Apr 2014 04:41:38 -0700 (PDT) X-Received: by 10.112.61.199 with SMTP id s7mr18077092lbr.25.1398685298782; Mon, 28 Apr 2014 04:41:38 -0700 (PDT) Received: from uglx0153363.itg.ti.com ([195.238.92.128]) by mx.google.com with ESMTPSA id x10sm9873857lad.1.2014.04.28.04.41.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 04:41:37 -0700 (PDT) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Mon, 28 Apr 2014 14:41:06 +0300 Message-Id: <1398685276-4610-8-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398685276-4610-1-git-send-email-taras.kondratiuk@linaro.org> References: <1398685276-4610-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Cc: linaro-networking@linaro.org Subject: [lng-odp] [RFC PATCH 07/17] 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 --- include/odp_byteorder.h | 110 ++--------- .../linux-generic/include/plat/odp_byteorder.h | 207 ++++++++++++++++++++ 2 files changed, 220 insertions(+), 97 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 c573bb6..5eab24d 100644 --- a/include/odp_byteorder.h +++ b/include/odp_byteorder.h @@ -20,7 +20,6 @@ extern "C" { #include #include -#include #ifndef BYTE_ORDER #error BYTE_ORDER not defined! @@ -63,6 +62,7 @@ typedef uint32_t __odp_bitwise uint32be_t; /**< unsigned 32bit big endian */ typedef uint64_t __odp_bitwise uint64le_t; /**< unsigned 64bit little endian */ typedef uint64_t __odp_bitwise uint64be_t; /**< unsigned 64bit big endian */ +#include /* * Big Endian -> CPU byte order: @@ -73,42 +73,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); /* @@ -120,42 +99,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); /* @@ -167,42 +125,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); /* @@ -214,42 +151,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..8f35193 --- /dev/null +++ b/platform/linux-generic/include/plat/odp_byteorder.h @@ -0,0 +1,207 @@ +/* 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 + +/* + * 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(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 +} + +/** + * 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 +} + +/** + * 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 +} + + +/* + * 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 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 +} + +/** + * 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 +} + +/** + * 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 +} + + +/* + * 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(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 +} + +/** + * 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 +} + +/** + * 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 +} + + +/* + * 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 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 +} + +/** + * 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 +} + +/** + * 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 +} + +#endif