diff mbox

[RFC,07/17] Split out platform-specific part of odp_byteorder.h

Message ID 1398685276-4610-8-git-send-email-taras.kondratiuk@linaro.org
State RFC
Headers show

Commit Message

Taras Kondratiuk April 28, 2014, 11:41 a.m. UTC
---
 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 mbox

Patch

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 <endian.h>
 #include <odp_std_types.h>
-#include <odp_compiler.h>
 
 #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 <plat/odp_byteorder.h>
 
 /*
  * 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 <odp_compiler.h>
+
+/*
+ * 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