From 83f0bc5d8487aa491782d364e1da2e0f6d5a2641 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 15 Feb 2021 07:50:38 +1000 Subject: [PATCH] util: add optimised memset64 This just adds a memset64 along the lines of the previously added memset32. Reviewed-by: Eric Anholt Part-of: --- src/util/u_memset.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/u_memset.h b/src/util/u_memset.h index df8cf80..46a43e5 100644 --- a/src/util/u_memset.h +++ b/src/util/u_memset.h @@ -45,3 +45,23 @@ util_memset32(void *s, uint32_t ui, size_t n) return s; #endif } + +static inline void * +util_memset64(void *s, uint64_t ui, size_t n) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64) + long d0, d1; + __asm__ volatile("rep\n\t" + "stosq" + : "=&c" (d0), "=&D" (d1) + : "a" (ui), "1" (s), "0" (n) + : "memory"); + return s; +#else + uint64_t *xs = (uint64_t *)s; + while (n--) + *xs++ = ui; + return s; +#endif + +} -- 2.7.4