diff mbox series

[PATCHv2,03/11] linux-generic: packet: restructure inline routines to use macros

Message ID 20170312123045.3852-4-bill.fischofer@linaro.org
State New
Headers show
Series Optimized Packet References | expand

Commit Message

Bill Fischofer March 12, 2017, 12:30 p.m. UTC
Use an internal macro for accessing inline fields in preparation for
introducing packet reference support.

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

---
 .../include/odp/api/plat/packet_flag_inlines.h     |  7 +++-
 .../include/odp/api/plat/packet_inlines.h          | 44 +++++++++-------------
 2 files changed, 23 insertions(+), 28 deletions(-)

-- 
2.12.0.rc1
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 eb36aa96..02295b08 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -18,97 +18,89 @@ 
 #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;
 
 /** @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 */
@@ -120,7 +112,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 */