aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-10-03 14:13:27 -0400
committerDamjan Marion <dmarion@me.com>2018-10-04 15:28:42 +0000
commit2329e090fc4c158988d4f14b1edb6a8623149679 (patch)
treeeea2c1ea22ad0be5e40307fdd11e7411460098d7
parent29d22c52061df519c22b1bb58afe461d107899e2 (diff)
clib_count_equal_*: don't read of the end of a small array and init data only if used (VPP-1429)
Change-Id: I8afa57ecca590698d3430746968aa0a5b0070469 Signed-off-by: Neale Ranns <nranns@cisco.com>
-rw-r--r--src/vppinfra/string.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/vppinfra/string.h b/src/vppinfra/string.h
index 5a47725f5c3..8f165dfa18e 100644
--- a/src/vppinfra/string.h
+++ b/src/vppinfra/string.h
@@ -324,12 +324,17 @@ clib_memset_u8 (void *p, u8 val, uword count)
static_always_inline uword
clib_count_equal_u64 (u64 * data, uword max_count)
{
- uword count = 0;
- u64 first = data[0];
+ uword count;
+ u64 first;
+ if (max_count == 1)
+ return 1;
if (data[0] != data[1])
return 1;
+ count = 0;
+ first = data[0];
+
#if defined(CLIB_HAVE_VEC256)
u64x4 splat = u64x4_splat (first);
while (1)
@@ -369,12 +374,17 @@ clib_count_equal_u64 (u64 * data, uword max_count)
static_always_inline uword
clib_count_equal_u32 (u32 * data, uword max_count)
{
- uword count = 0;
- u32 first = data[0];
+ uword count;
+ u32 first;
+ if (max_count == 1)
+ return 1;
if (data[0] != data[1])
return 1;
+ count = 0;
+ first = data[0];
+
#if defined(CLIB_HAVE_VEC256)
u32x8 splat = u32x8_splat (first);
while (1)
@@ -432,12 +442,17 @@ clib_count_equal_u32 (u32 * data, uword max_count)
static_always_inline uword
clib_count_equal_u16 (u16 * data, uword max_count)
{
- uword count = 0;
- u16 first = data[0];
+ uword count;
+ u16 first;
+ if (max_count == 1)
+ return 1;
if (data[0] != data[1])
return 1;
+ count = 0;
+ first = data[0];
+
#if defined(CLIB_HAVE_VEC256)
u16x16 splat = u16x16_splat (first);
while (1)
@@ -495,12 +510,17 @@ clib_count_equal_u16 (u16 * data, uword max_count)
static_always_inline uword
clib_count_equal_u8 (u8 * data, uword max_count)
{
- uword count = 0;
- u8 first = data[0];
+ uword count;
+ u8 first;
+ if (max_count == 1)
+ return 1;
if (data[0] != data[1])
return 1;
+ count = 0;
+ first = data[0];
+
#if defined(CLIB_HAVE_VEC256)
u8x32 splat = u8x32_splat (first);
while (1)