diff mbox series

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

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

Commit Message

Github ODP bot July 20, 2017, 8 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 82 (Bill-Fischofer-Linaro:pktrefs)
 ** https://github.com/Linaro/odp/pull/82
 ** Patch: https://github.com/Linaro/odp/pull/82.patch
 ** Base sha: 3eeb249a4774f12d2d16ca349a591654eae620ae
 ** Merge commit sha: f6e0d4b8b10f1803fb4513254c404df31e3f9f3f
 **/
 .../include/odp/api/plat/packet_flag_inlines.h     |  7 +++-
 .../include/odp/api/plat/packet_inlines.h          | 44 +++++++++-------------
 2 files changed, 23 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..738fced3 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
@@ -16,14 +16,17 @@ 
 #include <odp/api/plat/packet_types.h>
 #include <odp/api/hints.h>
 
+/** @internal Packet field accessor */
+#define _odp_pkt_get(pkt, cast, field) \
+	(*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field))
+
 /** @internal Inline function offsets */
 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..14cc86c8 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -18,6 +18,10 @@ 
 #include <odp/api/packet_io.h>
 #include <odp/api/hints.h>
 
+/** @internal Packet field accessor */
+#define _odp_pkt_get(pkt, cast, field) \
+	(*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field))
+
 /** @internal Inline function offsets */
 extern const _odp_packet_inline_offset_t _odp_packet_inline;
 
@@ -38,91 +42,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 +126,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 */