]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
lib/libc/amd64/string/strcmp.S: add baseline implementation
authorRobert Clausecker <fuz@FreeBSD.org>
Sat, 16 Sep 2023 05:29:39 +0000 (01:29 -0400)
committerRobert Clausecker <fuz@FreeBSD.org>
Mon, 25 Dec 2023 13:54:33 +0000 (14:54 +0100)
commitbca25680b91b3bea7faef615765806a04634eb23
treefe9381ee045831139e481300f17874966ae3dd79
parent13037eaabede7fb7fbc25f4e84b549c73f9acb3c
lib/libc/amd64/string/strcmp.S: add baseline implementation

This is the most complicated one so far.  The basic idea is to process
the bulk of the string in aligned blocks of 16 bytes such that one
string runs ahead and the other runs behind.  The string that runs ahead
is checked for NUL bytes, the one that runs behind is compared with the
corresponding chunk of the string that runs ahead.  This trades an extra
load per iteration for the very complicated block-reassembly needed in
the other implementations (bionic, glibc).  On the flip side, we need
two code paths depending on the relative alignment of the two buffers.

The initial part of the string is compared directly if it is known not
to cross a page boundary.  Otherwise, a complex slow path to avoid
crossing into unmapped memory commences.

Performance-wise we beat bionic for misaligned strings (i.e. the strings
do not share an alignment offset) and reach comparable performance for
aligned strings.  glibc is a bit better as it has a special kernel for
AVX-512, where this stuff is a bit easier to do.

Sponsored by: The FreeBSD Foundation
Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D41971
lib/libc/amd64/string/strcmp.S