aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/string.h')
-rw-r--r--src/vppinfra/string.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/vppinfra/string.h b/src/vppinfra/string.h
index 5c1d8267742..b00c0cfbcc2 100644
--- a/src/vppinfra/string.h
+++ b/src/vppinfra/string.h
@@ -78,10 +78,10 @@ void clib_memswap (void *_a, void *_b, uword bytes);
#elif __SSSE3__
#include <vppinfra/memcpy_sse3.h>
#else
-#define _clib_memcpy(a,b,c) memcpy(a,b,c)
+#define clib_memcpy_fast(a,b,c) memcpy(a,b,c)
#endif
#else /* __COVERITY__ */
-#define _clib_memcpy(a,b,c) memcpy(a,b,c)
+#define clib_memcpy_fast(a,b,c) memcpy(a,b,c)
#endif
/* c-11 string manipulation variants */
@@ -108,6 +108,16 @@ memcpy_s_inline (void *__restrict__ dest, rsize_t dmax,
u8 bad;
/*
+ * Optimize constant-number-of-bytes calls without asking
+ * "too many questions for someone from New Jersey"
+ */
+ if (__builtin_constant_p (n))
+ {
+ clib_memcpy_fast (dest, src, n);
+ return EOK;
+ }
+
+ /*
* call bogus if: src or dst NULL, trying to copy
* more data than we have space in dst, or src == dst.
* n == 0 isn't really "bad", so check first in the
@@ -140,7 +150,7 @@ memcpy_s_inline (void *__restrict__ dest, rsize_t dmax,
return EINVAL;
}
- _clib_memcpy (dest, src, n);
+ clib_memcpy_fast (dest, src, n);
return EOK;
}
@@ -247,10 +257,10 @@ clib_memcpy64_x4 (void *d0, void *d1, void *d2, void *d3, void *s)
_mm_storeu_si128 ((__m128i *) (d3 + 3 * 16), r3);
#else
- clib_memcpy (d0, s, 64);
- clib_memcpy (d1, s, 64);
- clib_memcpy (d2, s, 64);
- clib_memcpy (d3, s, 64);
+ clib_memcpy_fast (d0, s, 64);
+ clib_memcpy_fast (d1, s, 64);
+ clib_memcpy_fast (d2, s, 64);
+ clib_memcpy_fast (d3, s, 64);
#endif
}