[ovs-dev] [PATCH 1/3] unaligned: Introduce helpers for 32-bit aligned 128-bit integers.

Ben Pfaff blp at ovn.org
Wed Jun 14 16:24:55 UTC 2017


These are analogous to the existing helpers for 32-bit aligned 64-bit
integers, and will have users in upcoming commits.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 include/openvswitch/types.h | 12 ++++++++++++
 lib/unaligned.h             | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/openvswitch/types.h b/include/openvswitch/types.h
index 5ae0972dac99..111e30bca98b 100644
--- a/include/openvswitch/types.h
+++ b/include/openvswitch/types.h
@@ -82,6 +82,18 @@ typedef struct {
 #endif
 } ovs_32aligned_u64;
 
+/* A 128-bit value, in host byte order, that is only aligned on a 32-bit
+ * boundary.  */
+typedef struct {
+    uint32_t u32[4];
+} ovs_32aligned_u128;
+
+/* A 128-bit value, in network byte order, that is only aligned on a 32-bit
+ * boundary.  */
+typedef struct {
+    ovs_be32 be32[4];
+} ovs_32aligned_be128;
+
 typedef union {
     uint32_t u32[4];
     struct {
diff --git a/lib/unaligned.h b/lib/unaligned.h
index 130f3379040c..a150d7d22e94 100644
--- a/lib/unaligned.h
+++ b/lib/unaligned.h
@@ -216,6 +216,24 @@ put_32aligned_u64(ovs_32aligned_u64 *x, uint64_t value)
     x->lo = value;
 }
 
+/* Returns the value in 'x'. */
+static inline ovs_u128
+get_32aligned_u128(const ovs_32aligned_u128 *x)
+{
+    ovs_u128 u = { .u32 = { x->u32[0], x->u32[1], x->u32[2], x->u32[3] } };
+    return u;
+}
+
+/* Stores 'value' in 'x'. */
+static inline void
+put_32aligned_u128(ovs_32aligned_u128 *x, ovs_u128 value)
+{
+    x->u32[0] = value.u32[0];
+    x->u32[1] = value.u32[1];
+    x->u32[2] = value.u32[2];
+    x->u32[3] = value.u32[3];
+}
+
 #ifndef __CHECKER__
 /* Returns the value of 'x'. */
 static inline ovs_be32
@@ -264,6 +282,25 @@ put_32aligned_be64(ovs_32aligned_be64 *x, ovs_be64 value)
     x->lo = value >> 32;
 #endif
 }
+
+/* Returns the value of 'x'. */
+static inline ovs_be128
+get_32aligned_be128(const ovs_32aligned_be128 *x)
+{
+    ovs_be128 u = { .be32 = { x->be32[0], x->be32[1],
+                              x->be32[2], x->be32[3] } };
+    return u;
+}
+
+/* Stores network byte order 'value' into 'x'. */
+static inline void
+put_32aligned_be128(ovs_32aligned_be128 *x, ovs_be128 value)
+{
+    x->be32[0] = value.be32[0];
+    x->be32[1] = value.be32[1];
+    x->be32[2] = value.be32[2];
+    x->be32[3] = value.be32[3];
+}
 #else  /* __CHECKER__ */
 /* Making sparse happy with these functions also makes them unreadable, so
  * don't bother to show it their implementations. */
@@ -271,6 +308,8 @@ ovs_be32 get_16aligned_be32(const ovs_16aligned_be32 *);
 void put_16aligned_be32(ovs_16aligned_be32 *, ovs_be32);
 ovs_be64 get_32aligned_be64(const ovs_32aligned_be64 *);
 void put_32aligned_be64(ovs_32aligned_be64 *, ovs_be64);
+ovs_be128 get_32aligned_be128(const ovs_32aligned_be128 *);
+void put_32aligned_be128(ovs_32aligned_be128 *, ovs_be128);
 #endif
 
 #endif /* unaligned.h */
-- 
2.10.2



More information about the dev mailing list