Skip to content

Commit

Permalink
unaligned: Introduce helpers for 32-bit aligned 128-bit integers.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Lance Richardson <[email protected]>
  • Loading branch information
blp committed Jun 14, 2017
1 parent 8568c7a commit 62a78fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/openvswitch/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions lib/unaligned.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -264,13 +282,34 @@ 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. */
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 */

0 comments on commit 62a78fe

Please sign in to comment.