From 470db781151d240e12c3a7f1000b54b0b2c8fcde Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Tue, 4 Sep 2018 22:43:30 +0000 Subject: [PATCH] [sanitizer] optimize internal_memset for the most performance critical case (16-byte-aligned) llvm-svn: 341420 --- compiler-rt/lib/sanitizer_common/sanitizer_libc.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cc b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cc index 4b462bf..4032cb1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cc @@ -73,6 +73,18 @@ void *internal_memmove(void *dest, const void *src, uptr n) { } void *internal_memset(void* s, int c, uptr n) { + // Optimize for the most performance-critical case: + if ((reinterpret_cast(s) % 16) == 0 && (n % 16) == 0) { + u64 *p = reinterpret_cast(s); + u64 *e = p + n / 8; + u64 v = c; + v |= v << 8; + v |= v << 16; + v |= v << 32; + for (; p < e; p += 2) + p[0] = p[1] = v; + return s; + } // The next line prevents Clang from making a call to memset() instead of the // loop below. // FIXME: building the runtime with -ffreestanding is a better idea. However -- 2.7.4