Page MenuHomeFreeBSD

amd64: reimplement libc memcmp and bcmp with kernel memcmp
ClosedPublic

Authored by mjg on Sep 27 2018, 11:32 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 12:57 PM
Unknown Object (File)
Tue, Dec 10, 3:16 PM
Unknown Object (File)
Nov 26 2024, 3:02 PM
Unknown Object (File)
Nov 25 2024, 4:30 PM
Unknown Object (File)
Nov 19 2024, 9:22 PM
Unknown Object (File)
Nov 15 2024, 3:49 AM
Unknown Object (File)
Oct 18 2024, 12:09 PM
Unknown Object (File)
Oct 17 2024, 3:33 AM
Subscribers

Details

Summary

Both are significantly slower than hand-coded loops. See rXXXX for kernel commit.

bcmp differs from memcmp by always returning 1 when a difference is found, as opposed to going for a value bigger or lower than 0 depending on what it is. This means it can do less work. For now the code is duplicated and modified. This will get deduplicated after another round of optimization when memcmp will get a longer-term form.

Both tested with the glibc suite. While the suite does not have a test for bcmp, I created a wrapper routine which verified that values match (0 vs 0, 1 vs non-zero).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lib/libc/amd64/string/bcmp.S
2 ↗(On Diff #48504)

Why ?

71 ↗(On Diff #48504)

So the difference between two is only this line ? Am I missed some more ?
If I am right, or close to be right, I propose to macro-ify the body and use one macro to generate two implementations.

mjg marked 2 inline comments as done.Sep 27 2018, 12:22 PM
mjg added inline comments.
lib/libc/amd64/string/bcmp.S
2 ↗(On Diff #48504)

The work is sponsored by FF. I was under the impression the copyright goes to them in such a case.

71 ↗(On Diff #48504)

I noted the func does not have to compute the diff, just only note there is one. non-byte comparisons in memcmp jump to byte comparisons once a difference is determined to find what it is (basically *src - *dst). So bcmp jumps here if a difference is found, while memcmp jumps to 1b.

There are clever ways of computing such a diff without having to redo part of the work which I'll be looking at later. With them in place bcopy and memcpy will do differ roughly by this.

Thus for simplicity I just kept a separate routine, to be removed later after memcmp gets further reworked. I can change it if really needed.

lib/libc/amd64/string/bcmp.S
2 ↗(On Diff #48504)

You should have the contract which says exactly what wording to use. There is usually an informational block like

* This software was developed by Konstantin Belousov <kib@FreeBSD.org>
* under sponsorship from the FreeBSD Foundation.

(too lazy to type in your name).

71 ↗(On Diff #48504)

ok.

  • update copyright to include my name
This revision is now accepted and ready to land.Sep 27 2018, 4:21 PM
This revision was automatically updated to reflect the committed changes.