@@ -28,7 +28,7 @@
OVS_PACKED(struct offset_ovs_u128
{
uint32_t a;
- ovs_u128 b;
+ ovs_u128 b[16];
});
static void
@@ -66,9 +66,9 @@ set_bit128_unaligned(struct offset_ovs_u128 *values, int bit, int n_bits)
memset(values, 0, n_bits/8 + sizeof(values->a));
if (b < 64) {
- values->b.u64.lo = UINT64_C(1) << (b % 64);
+ values->b[bit / 128].u64.lo = UINT64_C(1) << (b % 64);
} else {
- values->b.u64.hi = UINT64_C(1) << (b % 64);
+ values->b[bit / 128].u64.hi = UINT64_C(1) << (b % 64);
}
}
@@ -175,10 +175,10 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
uint32_t *in0p;
ovs_u128 in1;
- in0p = &in0.b.u32[0];
+ in0p = &in0.b[0].u32[0];
set_bit128_unaligned(&in0, i, n_bits);
set_bit128(&in1, i, n_bits);
- assert(ovs_u128_equals(in0.b, in1));
+ assert(ovs_u128_equals(in0.b[0], in1));
hash(in0p, sizeof(ovs_u128), 0, &out0);
hash(&in1, sizeof(ovs_u128), 0, &out1);
if (!ovs_u128_equals(out0, out1)) {
@@ -221,17 +221,14 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
int i, j;
for (i = 0; i < n_bits; i++) {
- OVS_PACKED(struct offset_ovs_u128 {
- uint32_t a;
- ovs_u128 b[16];
- }) in0_data;
- ovs_u128 *in0, in1[16];
+ struct offset_ovs_u128 in0;
+ ovs_u128 in1[16];
ovs_u128 out0, out1;
- in0 = in0_data.b;
- set_bit128(in0, i, n_bits);
- set_bit128(in1, i, n_bits);
- hash(in0, sizeof(ovs_u128) * 16, 0, &out0);
+ set_bit128_unaligned(&in0, i, n_bits);
+ set_bit128(&in1[0], i, n_bits);
+ assert(ovs_u128_equals(in0.b[i / 128], in1[i / 128]));
+ hash(&in0.b, sizeof(ovs_u128) * 16, 0, &out0);
hash(in1, sizeof(ovs_u128) * 16, 0, &out1);
if (!ovs_u128_equals(out0, out1)) {
printf("%s hash not the same for non-64 aligned data "
The prior patch introduced a definition for the 32-bit offset u128, and introduced a function for setting bits in this structure so refactor the 256B hash test to reuse this code. Signed-off-by: Joe Stringer <joe@ovn.org> --- tests/test-hash.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)