]> git.proxmox.com Git - mirror_ovs.git/commitdiff
unaligned: Introduce helpers for 32-bit aligned 128-bit integers.
authorBen Pfaff <blp@ovn.org>
Wed, 14 Jun 2017 15:46:32 +0000 (08:46 -0700)
committerBen Pfaff <blp@ovn.org>
Wed, 14 Jun 2017 19:34:23 +0000 (12:34 -0700)
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@ovn.org>
Acked-by: Lance Richardson <lrichard@redhat.com>
include/openvswitch/types.h
lib/unaligned.h

index 5ae0972dac99f889f44d5af9d65eaa070826bc02..111e30bca98b814b24dc50636236d5543bcd9687 100644 (file)
@@ -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 {
index 130f3379040cfad3b9c9b2fc44013f56193daf8a..a150d7d22e948c5bc8dac1587c434872c8418d61 100644 (file)
@@ -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 */