diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index 505adcbf134c..b6e25687d748 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -41,25 +41,24 @@ .text /* - * bcopy family - * void bzero(void *buf, u_int len) + * void *memset(void *dest, int c, size_t len) */ - -/* done */ -ENTRY(bzero) +ENTRY(memset) PUSH_FRAME_POINTER - movq %rsi,%rcx - xorl %eax,%eax + movq %rdi,%r9 + movq %rdx,%rcx + movq %rsi,%rax shrq $3,%rcx rep stosq - movq %rsi,%rcx + movq %rdx,%rcx andq $7,%rcx rep stosb + movq %r9,%rax POP_FRAME_POINTER ret -END(bzero) +END(memset) /* Address: %rdi */ ENTRY(pagezero) @@ -116,13 +115,14 @@ ENTRY(bcmp) END(bcmp) /* - * bcopy(src, dst, cnt) + * memmove(dst, src, cnt) * rdi, rsi, rdx + * Original by: * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 */ -ENTRY(bcopy) +ENTRY(memmove) PUSH_FRAME_POINTER - xchgq %rsi,%rdi + movq %rdi,%r9 movq %rdx,%rcx movq %rdi,%rax @@ -137,6 +137,7 @@ ENTRY(bcopy) andq $7,%rcx /* any bytes left? */ rep movsb + movq %r9,%rax POP_FRAME_POINTER ret @@ -157,9 +158,10 @@ ENTRY(bcopy) rep movsq cld + movq %r9,%rax POP_FRAME_POINTER ret -END(bcopy) +END(memmove) /* * Note: memcpy does not support overlapping copies diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h index 86f7e08d9725..e28b542c0e0d 100644 --- a/sys/amd64/include/param.h +++ b/sys/amd64/include/param.h @@ -158,4 +158,7 @@ #define SC_TABLESIZE 1024 /* Must be power of 2. */ #endif +#define ARCH_WANT_BUIILTIN_BCOPY +#define ARCH_WANT_BUIILTIN_BZERO + #endif /* !_AMD64_INCLUDE_PARAM_H_ */ diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 68191238ff97..97a1ecef924e 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -620,8 +620,6 @@ isa/vga_isa.c optional vga kern/kern_clocksource.c standard kern/link_elf_obj.c standard libkern/x86/crc32_sse42.c standard -libkern/memmove.c standard -libkern/memset.c standard # # IA32 binary support # diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h index 3ec1ca76855e..e43dabaeb232 100644 --- a/sys/sys/libkern.h +++ b/sys/sys/libkern.h @@ -232,9 +232,11 @@ memset(void *b, int c, size_t len) { char *bb; +#ifndef ARCH_WANT_BUIILTIN_BZERO if (c == 0) bzero(b, len); else +#endif for (bb = (char *)b; len--; ) *bb++ = c; return (b); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 995e06774d64..c8834449a88a 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -41,6 +41,7 @@ #define _SYS_SYSTM_H_ #include +#include #include #include #include @@ -258,13 +259,14 @@ void hexdump(const void *ptr, int length, const char *hdr, int flags); #define HD_OMIT_CHARS (1 << 18) #define ovbcopy(f, t, l) bcopy((f), (t), (l)) +#ifdef ARCH_WANT_BUIILTIN_BCOPY +#define bcopy(from, to, len) __builtin_memmove(to, from, len) +#else 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)); \ -}) +#endif +#ifdef ARCH_WANT_BUIILTIN_BZERO +#define bzero(buf, len) __builtin_memset((buf), 0, (len)) +#else void bzero(void * _Nonnull buf, size_t len); #define bzero(buf, len) ({ \ if (__builtin_constant_p(len) && (len) <= 64) \ @@ -272,6 +274,7 @@ void bzero(void * _Nonnull buf, size_t len); else \ bzero((buf), (len)); \ }) +#endif void explicit_bzero(void * _Nonnull, size_t); void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);