diff mbox

[API-NEXT,PATCHv3,05/18] linux-generic: drv: adding byteorder.h

Message ID 1469102786-65530-6-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard July 21, 2016, 12:06 p.m. UTC
Based on API interface files.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 include/odp_drv.h                                  |   1 +
 platform/linux-generic/Makefile.am                 |   5 +
 platform/linux-generic/include/odp/drv/byteorder.h | 146 +++++++++++++++++++++
 .../include/odp/drv/plat/byteorder_types.h         |  80 +++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 platform/linux-generic/include/odp/drv/byteorder.h
 create mode 100644 platform/linux-generic/include/odp/drv/plat/byteorder_types.h

-- 
2.7.4
diff mbox

Patch

diff --git a/include/odp_drv.h b/include/odp_drv.h
index a6d3a44..1956e8c 100644
--- a/include/odp_drv.h
+++ b/include/odp_drv.h
@@ -18,6 +18,7 @@ 
 extern C {
 #endif
 
+#include <odp/drv/byteorder.h>
 #include <odp/drv/compiler.h>
 #include <odp/drv/std_types.h>
 
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 991ccd2..5b70fb4 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -93,8 +93,13 @@  odpapiplatinclude_HEADERS = \
 
 odpdrvincludedir = $(includedir)/odp/drv
 odpdrvinclude_HEADERS = \
+		  $(srcdir)/include/odp/drv/byteorder.h \
 		  $(srcdir)/include/odp/drv/compiler.h
 
+odpdrvplatincludedir = $(includedir)/odp/drv/plat
+odpdrvplatinclude_HEADERS = \
+		  $(srcdir)/include/odp/drv/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/drv/byteorder.h b/platform/linux-generic/include/odp/drv/byteorder.h
new file mode 100644
index 0000000..709a520
--- /dev/null
+++ b/platform/linux-generic/include/odp/drv/byteorder.h
@@ -0,0 +1,146 @@ 
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODPDRV byteorder
+ */
+
+#ifndef ODPDRVP_PLAT_BYTEORDER_H_
+#define ODPDRVP_PLAT_BYTEORDER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/drv/plat/byteorder_types.h>
+#include <odp/drv/std_types.h>
+#include <odp/drv/compiler.h>
+
+/** @ingroup odpdrv_compiler_optim
+ *  @{
+ */
+
+static inline uint16_t odpdrv_be_to_cpu_16(odpdrv_u16be_t be16)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return __odpdrv_builtin_bswap16((__odpdrv_force uint16_t)be16);
+#else
+	return (__odpdrv_force uint16_t)be16;
+#endif
+}
+
+static inline uint32_t odpdrv_be_to_cpu_32(odpdrv_u32be_t be32)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return __builtin_bswap32((__odpdrv_force uint32_t)be32);
+#else
+	return (__odpdrv_force uint32_t)be32;
+#endif
+}
+
+static inline uint64_t odpdrv_be_to_cpu_64(odpdrv_u64be_t be64)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return __builtin_bswap64((__odpdrv_force uint64_t)be64);
+#else
+	return (__odpdrv_force uint64_t)be64;
+#endif
+}
+
+static inline odpdrv_u16be_t odpdrv_cpu_to_be_16(uint16_t cpu16)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u16be_t)__odpdrv_builtin_bswap16(cpu16);
+#else
+	return (__odpdrv_force odpdrv_u16be_t)cpu16;
+#endif
+}
+
+static inline odpdrv_u32be_t odpdrv_cpu_to_be_32(uint32_t cpu32)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u32be_t)__builtin_bswap32(cpu32);
+#else
+	return (__odpdrv_force odpdrv_u32be_t)cpu32;
+#endif
+}
+
+static inline odpdrv_u64be_t odpdrv_cpu_to_be_64(uint64_t cpu64)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u64be_t)__builtin_bswap64(cpu64);
+#else
+	return (__odpdrv_force odpdrv_u64be_t)cpu64;
+#endif
+}
+
+static inline uint16_t odpdrv_le_to_cpu_16(odpdrv_u16le_t le16)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force uint16_t)le16;
+#else
+	return __odpdrv_builtin_bswap16((__odpdrv_force uint16_t)le16);
+#endif
+}
+
+static inline uint32_t odpdrv_le_to_cpu_32(odpdrv_u32le_t le32)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force uint32_t)le32;
+#else
+	return __builtin_bswap32((__odpdrv_force uint32_t)le32);
+#endif
+}
+
+static inline uint64_t odpdrv_le_to_cpu_64(odpdrv_u64le_t le64)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force uint64_t)le64;
+#else
+	return __builtin_bswap64((__odpdrv_force uint64_t)le64);
+#endif
+}
+
+static inline odpdrv_u16le_t odpdrv_cpu_to_le_16(uint16_t cpu16)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u16le_t)cpu16;
+#else
+	return (__odpdrv_force odpdrv_u16le_t)__odpdrv_builtin_bswap16(cpu16);
+#endif
+}
+
+static inline odpdrv_u32le_t odpdrv_cpu_to_le_32(uint32_t cpu32)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u32le_t)cpu32;
+#else
+	return (__odpdrv_force odpdrv_u32le_t)__builtin_bswap32(cpu32);
+#endif
+}
+
+static inline odpdrv_u64le_t odpdrv_cpu_to_le_64(uint64_t cpu64)
+{
+#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN
+	return (__odpdrv_force odpdrv_u64le_t)cpu64;
+#else
+	return (__odpdrv_force odpdrv_u64le_t)__builtin_bswap64(cpu64);
+#endif
+}
+
+/**
+ * @}
+ */
+
+#include <odp/drv/spec/byteorder.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/include/odp/drv/plat/byteorder_types.h b/platform/linux-generic/include/odp/drv/plat/byteorder_types.h
new file mode 100644
index 0000000..bf461e5
--- /dev/null
+++ b/platform/linux-generic/include/odp/drv/plat/byteorder_types.h
@@ -0,0 +1,80 @@ 
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODPDRV byteorder
+ */
+
+#ifndef ODPDRV_BYTEORDER_TYPES_H_
+#define ODPDRV_BYTEORDER_TYPES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __BYTE_ORDER__
+#error __BYTE_ORDER not defined!
+#endif
+
+#ifndef __ORDER_BIG_ENDIAN__
+#error __BIG_ENDIAN not defined!
+#endif
+
+#ifndef __ORDER_LITTLE_ENDIAN__
+#error __LITTLE_ENDIAN not defined!
+#endif
+
+/* for use with type checkers such as sparse */
+#ifdef __CHECKER__
+/** @internal bitwise attribute */
+#define __odpdrv_bitwise	__attribute__((bitwise))
+/** @internal force attribute */
+#define __odpdrv_force     __attribute__((force))
+#else
+/** @internal bitwise attribute */
+#define __odpdrv_bitwise
+/** @internal force attribute */
+#define __odpdrv_force
+#endif
+
+/** @addtogroup odpdrv_compiler_optim
+ *  @{
+ */
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+	#define ODPDRV_LITTLE_ENDIAN           1
+	#define ODPDRV_BIG_ENDIAN              0
+	#define ODPDRV_BYTE_ORDER              ODP_LITTLE_ENDIAN
+	#define ODPDRV_LITTLE_ENDIAN_BITFIELD
+#else
+	#define ODPDRV_LITTLE_ENDIAN           0
+	#define ODPDRV_BIG_ENDIAN              1
+	#define	ODPDRV_BYTE_ORDER              ODP_BIG_ENDIAN
+	#define ODPDRV_BIG_ENDIAN_BITFIELD
+#endif
+
+typedef uint16_t __odpdrv_bitwise	odpdrv_u16le_t;
+typedef uint16_t __odpdrv_bitwise	odpdrv_u16be_t;
+
+typedef uint32_t __odpdrv_bitwise	odpdrv_u32le_t;
+typedef uint32_t __odpdrv_bitwise	odpdrv_u32be_t;
+
+typedef uint64_t __odpdrv_bitwise	odpdrv_u64le_t;
+typedef uint64_t __odpdrv_bitwise	odpdrv_u64be_t;
+
+typedef uint16_t __odpdrv_bitwise	odpdrv_u16sum_t;
+typedef uint32_t __odpdrv_bitwise	odpdrv_u32sum_t;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif