mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-23 07:31:31 +00:00
Use __builtin for various mem* and b* (e.g. bzero) routines.
Some of the routines were using artificially limited builtin already, drop the explicit limit. The use of builtins allows quite often allows the compiler to elide the call or most zeroing to begin with. For instance, if the target object is 32 bytes in size and gets zeroed + has 16 bytes initialized, the compiler can just add code to zero out the rest. Note not all the primites have asm variants and some of the existing ones are not optimized. Maintaines are strongly encourage to take a look (regardless of this change).
This commit is contained in:
parent
97e8984893
commit
ba96f37758
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334534
@ -73,7 +73,6 @@
|
||||
# include <machine/cpufunc.h>
|
||||
# include <sys/libkern.h>
|
||||
# include <sys/systm.h>
|
||||
# define memset(a,b,c) bzero (a,c)
|
||||
# define port_t int
|
||||
|
||||
#ifndef _SYS_CDEFS_H_
|
||||
|
@ -44,7 +44,7 @@ typedef const unsigned long *culp;
|
||||
* bcmp -- vax cmpc3 instruction
|
||||
*/
|
||||
int
|
||||
bcmp(const void *b1, const void *b2, size_t length)
|
||||
(bcmp)(const void *b1, const void *b2, size_t length)
|
||||
{
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
/*
|
||||
|
@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
|
||||
* Compare memory regions.
|
||||
*/
|
||||
int
|
||||
memcmp(const void *s1, const void *s2, size_t n)
|
||||
(memcmp)(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
if (n != 0) {
|
||||
const unsigned char *p1 = s1, *p2 = s2;
|
||||
|
@ -33,7 +33,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/libkern.h>
|
||||
|
||||
void *
|
||||
memset(void *b, int c, size_t len)
|
||||
(memset)(void *b, int c, size_t len)
|
||||
{
|
||||
char *bb;
|
||||
|
||||
|
@ -128,7 +128,6 @@ struct malloc_type;
|
||||
uint32_t arc4random(void);
|
||||
void arc4random_buf(void *, size_t);
|
||||
void arc4rand(void *, u_int, int);
|
||||
int bcmp(const void *, const void *, size_t);
|
||||
int timingsafe_bcmp(const void *, const void *, size_t);
|
||||
void *bsearch(const void *, const void *, size_t,
|
||||
size_t, int (*)(const void *, const void *));
|
||||
@ -160,7 +159,6 @@ int fnmatch(const char *, const char *, int);
|
||||
int locc(int, char *, u_int);
|
||||
void *memchr(const void *s, int c, size_t n);
|
||||
void *memcchr(const void *s, int c, size_t n);
|
||||
int memcmp(const void *b1, const void *b2, size_t len);
|
||||
void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
|
||||
void qsort(void *base, size_t nmemb, size_t size,
|
||||
int (*compar)(const void *, const void *));
|
||||
|
@ -259,25 +259,21 @@ void hexdump(const void *ptr, int length, const char *hdr, int flags);
|
||||
|
||||
#define ovbcopy(f, t, l) bcopy((f), (t), (l))
|
||||
void bcopy(const void * _Nonnull from, void * _Nonnull to, size_t len);
|
||||
#define bcopy(from, to, len) ({ \
|
||||
if (__builtin_constant_p(len) && (len) <= 64) \
|
||||
__builtin_memmove((to), (from), (len)); \
|
||||
else \
|
||||
bcopy((from), (to), (len)); \
|
||||
})
|
||||
#define bcopy(from, to, len) __builtin_memmove((to), (from), (len))
|
||||
void bzero(void * _Nonnull buf, size_t len);
|
||||
#define bzero(buf, len) ({ \
|
||||
if (__builtin_constant_p(len) && (len) <= 64) \
|
||||
__builtin_memset((buf), 0, (len)); \
|
||||
else \
|
||||
bzero((buf), (len)); \
|
||||
})
|
||||
#define bzero(buf, len) __builtin_memset((buf), 0, (len))
|
||||
void explicit_bzero(void * _Nonnull, size_t);
|
||||
int bcmp(const void *b1, const void *b2, size_t len);
|
||||
#define bcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
|
||||
|
||||
void *memset(void * _Nonnull buf, int c, size_t len);
|
||||
#define memset(buf, c, len) __builtin_memset((buf), (c), (len))
|
||||
void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);
|
||||
#define memcpy(to, from, len) __builtin_memcpy(to, from, len)
|
||||
#define memcpy(to, from, len) __builtin_memcpy((to), (from), (len))
|
||||
void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
|
||||
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n))
|
||||
int memcmp(const void *b1, const void *b2, size_t len);
|
||||
#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
|
||||
|
||||
int copystr(const void * _Nonnull __restrict kfaddr,
|
||||
void * _Nonnull __restrict kdaddr, size_t len,
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
# define HAVE_MEMCPY
|
||||
# define memset(d, v, n) bzero((d), (n))
|
||||
# define memcmp bcmp
|
||||
|
||||
#else
|
||||
#if defined(__KERNEL__)
|
||||
|
Loading…
Reference in New Issue
Block a user