diff options
-rw-r--r-- | src/vppinfra/vector/array_mask.h | 4 | ||||
-rw-r--r-- | src/vppinfra/vector/test/array_mask.c | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/vppinfra/vector/array_mask.h b/src/vppinfra/vector/array_mask.h index 8f2e1d7d88c..778ed3e638f 100644 --- a/src/vppinfra/vector/array_mask.h +++ b/src/vppinfra/vector/array_mask.h @@ -37,11 +37,12 @@ clib_array_mask_u32 (u32 *src, u32 mask, u32 n_elts) for (i = 0; i + 8 <= n_elts; i += 8) *((u32x8u *) (src + i)) &= mask8; n_elts -= i; + src += i; #if defined(CLIB_HAVE_VEC256_MASK_LOAD_STORE) if (n_elts) { u8 m = pow2_mask (n_elts); - u32x8_mask_store (u32x8_mask_load_zero (src + i, m) & mask8, src + i, m); + u32x8_mask_store (u32x8_mask_load_zero (src, m) & mask8, src, m); } return; #endif @@ -51,6 +52,7 @@ clib_array_mask_u32 (u32 *src, u32 mask, u32 n_elts) for (i = 0; i + 4 <= n_elts; i += 4) *((u32x4u *) (src + i)) &= mask4; n_elts -= i; + src += i; switch (n_elts) { case 3: diff --git a/src/vppinfra/vector/test/array_mask.c b/src/vppinfra/vector/test/array_mask.c index 703c70abbe9..a1f4da728d4 100644 --- a/src/vppinfra/vector/test/array_mask.c +++ b/src/vppinfra/vector/test/array_mask.c @@ -76,13 +76,15 @@ static array_mask_test_t tests[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } }, + /* mask values 0x1, output array of 1, 0, 1, 0,.. */ + { .mask = 1, .expected = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 } }, }; static clib_error_t * test_clib_array_mask_u32 (clib_error_t *err) { u32 i, j; - for (i = 0; i < ARRAY_LEN (tests); i++) + for (i = 0; i < ARRAY_LEN (tests) - 1; i++) { u32 src[256]; for (j = 0; j < ARRAY_LEN (src); j++) @@ -99,6 +101,20 @@ test_clib_array_mask_u32 (clib_error_t *err) i, j, src[j], t->expected[j]); } } + + u32 src[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + array_mask_test_t *t = tests + i; + + clib_array_mask_u32_wrapper (src, t->mask, ARRAY_LEN (src)); + for (j = 0; j < ARRAY_LEN (src); j++) + { + if (src[j] != t->expected[j]) + return clib_error_return (err, + "testcase %u failed at " + "(src[%u] = 0x%x, expected 0x%x)", + i, j, src[j], t->expected[j]); + } + return err; } |