Page MenuHomeFreeBSD

amd64: make bcmp in libc just call memcmp
ClosedPublic

Authored by mjg on Feb 21 2021, 9:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 12:45 PM
Unknown Object (File)
Wed, Nov 6, 10:31 AM
Unknown Object (File)
Wed, Oct 16, 4:49 AM
Unknown Object (File)
Tue, Oct 15, 12:28 PM
Unknown Object (File)
Sun, Oct 13, 2:17 PM
Unknown Object (File)
Fri, Oct 11, 10:54 AM
Unknown Object (File)
Thu, Oct 10, 4:32 AM
Unknown Object (File)
Oct 9 2024, 12:42 PM
Subscribers

Details

Summary

Preferably bcmp would just alias memcmp but there is magic which makes
this problematic.

A note should be made that bcmp which finds a difference has less work
to do but it's not worth implementing it just for this case.

This has a side effect of syncing assembly missed on memcmp rewrite.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mjg requested review of this revision.Feb 21 2021, 9:48 PM
mjg created this revision.
mjg edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Feb 25 2021, 7:19 PM
lib/libc/amd64/string/bcmp.c
3

The comment should be updated, same as for strlen().

This revision was automatically updated to reflect the committed changes.

FYI as of LLVM 9, clang will optimize memcmp calls that only check for equality to bcmp.

The optimizer will now convert calls to memcmp into a calls to bcmp in some circumstances. Users who are building freestanding code (not depending on the platform’s libc) without specifying -ffreestanding may need to either pass -fno-builtin-bcmp, or provide a bcmp function.

Huh, that changes things. In this case I may end up implementing a dedicated bcmp for both the kernel and libc.