From 099c6f6d45c0b4cd50d768428d6c1cf0ca93c624 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Mon, 22 Oct 2018 06:44:20 +0000 Subject: amd64: finish the tail in memset with an overlapping store Instead of finding the exact size to fit in we can just shift the target by -8 + tail. Doing a blind write to a previously rep stosq'ed area comes with a penalty so do it conditionally. Sample win on EPYC when zeroing a 257 sized buffer (tail = 1) aligned to 16 bytes: before: 44782846 ops/s after: 46118614 ops/s Idea stolen from NetBSD. Sponsored by: The FreeBSD Foundation --- sys/amd64/amd64/support.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index d3e5a829b67d..bbcbd54937f9 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -524,9 +524,12 @@ END(memcpy_erms) rep stosq movq %r9,%rax - movq %rdx,%rcx - andb $7,%cl - jne 1004b + andl $7,%edx + jnz 1f + POP_FRAME_POINTER + ret +1: + movq %r10,-8(%rdi,%rdx) .endif POP_FRAME_POINTER ret -- cgit v1.3