amd64: bring back asm bcmp, shared with memcmp

Turns out clang converts "memcmp(foo, bar, len) == 0" and similar to
bcmp calls.

Reviewed by:	emaste (previous version), jhb (previous version)
Differential Revision:	https://reviews.freebsd.org/D34673
This commit is contained in:
Mateusz Guzik 2022-03-25 15:04:04 +00:00
parent 8f1543785f
commit fbc002cb72
4 changed files with 32 additions and 18 deletions

View File

@ -1,6 +1,7 @@
# $FreeBSD$
MDSRCS+= \
bcmp.S \
memcmp.S \
memcpy.S \
memmove.S \

View File

@ -0,0 +1,7 @@
/*-
* Written by Mateusz Guzik <mjg@freebsd.org>
* Public domain.
*/
#define BCMP
#include "memcmp.S"

View File

@ -1,16 +0,0 @@
/*-
* Written by Mateusz Guzik <mjg@freebsd.org>
* Public domain.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <string.h>
int
bcmp(const void *b1, const void *b2, size_t len)
{
return (memcmp(b1, b2, len));
}

View File

@ -39,7 +39,11 @@ __FBSDID("$FreeBSD$");
#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */
#ifdef BCMP
ENTRY(bcmp)
#else
ENTRY(memcmp)
#endif
xorl %eax,%eax
10:
cmpq $16,%rdx
@ -143,8 +147,25 @@ ENTRY(memcmp)
/*
* Mismatch was found.
*
* Before we compute it we narrow down the range (16 -> 8 -> 4 bytes).
*/
#ifdef BCMP
ALIGN_TEXT
10320016:
10320000:
10081608:
10163224:
10163216:
10163208:
10040804:
80:
1:
leal 1(%eax),%eax
ret
END(bcmp)
#else
/*
* We need to compute the difference between strings.
* Start with narrowing the range down (16 -> 8 -> 4 bytes).
*/
ALIGN_TEXT
10320016:
@ -214,5 +235,6 @@ ENTRY(memcmp)
subl %r8d,%eax
ret
END(memcmp)
#endif
.section .note.GNU-stack,"",%progbits