diff mbox series

[v3,1/10] linux-generic: packet: restructure inline routines to use macros

Message ID 1501599610-28388-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v3,1/10] linux-generic: packet: restructure inline routines to use macros | expand

Commit Message

Github ODP bot Aug. 1, 2017, 3 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>


Use an internal macro for accessing inline fields in preparation for
introducing packet reference support.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
/** Email created from pull request 90 (Bill-Fischofer-Linaro:pktrefs)
 ** https://github.com/Linaro/odp/pull/90
 ** Patch: https://github.com/Linaro/odp/pull/90.patch
 ** Base sha: bb0ca193f8c28036fdf8b3d6c8aa5d4f11980e6c
 ** Merge commit sha: dfef320840f96825686124135a6e509db80b7b82
 **/
 .../include/odp/api/plat/packet_flag_inlines.h     |  3 +-
 .../include/odp/api/plat/packet_inlines.h          | 40 ++++++++--------------
 .../include/odp/api/plat/packet_types.h            |  4 +++
 3 files changed, 19 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h
index 2de04c81..42003e31 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h
@@ -22,8 +22,7 @@  extern const _odp_packet_inline_offset_t _odp_packet_inline;
 /** @internal Inline function @param pkt @return */
 static inline uint64_t _odp_packet_input_flags(odp_packet_t pkt)
 {
-	return *(uint64_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.input_flags);
+	return _odp_pkt_get(pkt, uint64_t, input_flags);
 }
 
 /** @internal Inline function @param pkt @return */
diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
index 3dd643fe..d0cf1390 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -38,91 +38,79 @@  static inline odp_packet_seg_t _odp_packet_seg_from_ndx(uint32_t ndx)
 /** @internal Inline function @param pkt @return */
 static inline void *_odp_packet_data(odp_packet_t pkt)
 {
-	return *(void **)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.data);
+	return _odp_pkt_get(pkt, void *, data);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_seg_len(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.seg_len);
+	return _odp_pkt_get(pkt, uint32_t, seg_len);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_len(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.frame_len);
+	return _odp_pkt_get(pkt, uint32_t, frame_len);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_headroom(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.headroom);
+	return _odp_pkt_get(pkt, uint32_t, headroom);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_tailroom(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.tailroom);
+	return _odp_pkt_get(pkt, uint32_t, tailroom);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline odp_pool_t _odp_packet_pool(odp_packet_t pkt)
 {
-	return *(odp_pool_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.pool);
+	return _odp_pkt_get(pkt, odp_pool_t, pool);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline odp_pktio_t _odp_packet_input(odp_packet_t pkt)
 {
-	return *(odp_pktio_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.input);
+	return _odp_pkt_get(pkt, odp_pktio_t, input);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline int _odp_packet_num_segs(odp_packet_t pkt)
 {
-	return *(uint8_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.segcount);
+	return _odp_pkt_get(pkt, uint8_t, segcount);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline void *_odp_packet_user_ptr(odp_packet_t pkt)
 {
-	return *(void **)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.user_ptr);
+	return _odp_pkt_get(pkt, void *, user_ptr);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline void *_odp_packet_user_area(odp_packet_t pkt)
 {
-	return *(void **)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.user_area);
+	return _odp_pkt_get(pkt, void *, user_area);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_user_area_size(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.user_area_size);
+	return _odp_pkt_get(pkt, uint32_t, user_area_size);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_flow_hash(odp_packet_t pkt)
 {
-	return *(uint32_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.flow_hash);
+	return _odp_pkt_get(pkt, uint32_t, flow_hash);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline odp_time_t _odp_packet_ts(odp_packet_t pkt)
 {
-	return *(odp_time_t *)(uintptr_t)((uint8_t *)pkt +
-	       _odp_packet_inline.timestamp);
+	return _odp_pkt_get(pkt, odp_time_t, timestamp);
 }
 
 /** @internal Inline function @param pkt @return */
@@ -134,7 +122,7 @@  static inline void *_odp_packet_head(odp_packet_t pkt)
 /** @internal Inline function @param pkt @return */
 static inline int _odp_packet_is_segmented(odp_packet_t pkt)
 {
-	return _odp_packet_num_segs(pkt) > 1;
+	return _odp_pkt_get(pkt, uint8_t, segcount) > 1;
 }
 
 /** @internal Inline function @param pkt @return */
diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h
index a209c759..41468bec 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_types.h
@@ -67,6 +67,10 @@  typedef enum {
 
 #endif
 
+/** @internal Packet field accessor */
+#define _odp_pkt_get(pkt, cast, field) \
+	(*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field))
+
 /** @internal Packet header field offsets for inline functions */
 typedef struct _odp_packet_inline_offset_t {
 	/** @internal field offset */