]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
amd64: handle small memset buffers with overlapping stores
authorMateusz Guzik <mjg@FreeBSD.org>
Fri, 16 Nov 2018 00:44:22 +0000 (00:44 +0000)
committerMateusz Guzik <mjg@FreeBSD.org>
Fri, 16 Nov 2018 00:44:22 +0000 (00:44 +0000)
commit088ac3ef4b7c315e5669a38197fd04f76a20b8f1
tree631314e3c81dc57819f09373c4ac34cd355e9839
parent47c64f9e3eae5665ebaee0ec874d82b352fc26b1
amd64: handle small memset buffers with overlapping stores

Instead of jumping to locations which store the exact number of bytes,
use displacement to move the destination.

In particular the following clears an area between 8-16 (inclusive)
branch-free:

movq    %r10,(%rdi)
movq    %r10,-8(%rdi,%rcx)

For instance for rcx of 10 the second line is rdi + 10 - 8 = rdi + 2.
Writing 8 bytes starting at that offset overlaps with 6 bytes written
previously and writes 2 new, giving 10 in total.

Provides a nice win for smaller stores. Other ones are erratic depending
on the microarchitecture.

General idea taken from NetBSD (restricted use of the trick) and bionic
string functions (use for various ranges like in this patch).

Reviewed by: kib (previous version)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17660
lib/libc/amd64/string/memset.S
sys/amd64/amd64/support.S