Date: Tue, 20 Apr 2021 00:47:01 GMT From: Alex Richardson <arichardson@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 0b4ad01d91a3 - main - libc/string/bcopy.c: Use intptr_t as the copy type Message-ID: <202104200047.13K0l10T036883@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by arichardson: URL: https://cgit.FreeBSD.org/src/commit/?id=0b4ad01d91a3b24cea00d54d25beed0f487c0183 commit 0b4ad01d91a3b24cea00d54d25beed0f487c0183 Author: Alex Richardson <arichardson@FreeBSD.org> AuthorDate: 2021-04-19 23:15:57 +0000 Commit: Alex Richardson <arichardson@FreeBSD.org> CommitDate: 2021-04-20 00:46:42 +0000 libc/string/bcopy.c: Use intptr_t as the copy type While most 64-bit architectures have an assembly implementation of this file RISC-V does not. As we now copy 8 bytes instead of 4 it should speed up RISC-V. Using intptr_t instead of int also allows using this file for CHERI pure-capability code since trying to copy pointers using integer loads/stores will invalidate pointers. Reviewed By: kib Obtained from: CheriBSD (partially) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29535 --- lib/libc/string/bcopy.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/libc/string/bcopy.c b/lib/libc/string/bcopy.c index 141416d0afec..84715d0432e3 100644 --- a/lib/libc/string/bcopy.c +++ b/lib/libc/string/bcopy.c @@ -40,11 +40,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> -/* - * sizeof(word) MUST BE A POWER OF TWO - * SO THAT wmask BELOW IS ALL ONES - */ -typedef int word; /* "word" used for optimal copy speed */ +typedef intptr_t word; /* "word" used for optimal copy speed */ #define wsize sizeof(word) #define wmask (wsize - 1) @@ -105,7 +101,8 @@ bcopy(const void *src0, void *dst0, size_t length) * Copy whole words, then mop up any trailing bytes. */ t = length / wsize; - TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); + TLOOP(*(word *)(void *)dst = *(const word *)(const void *)src; + src += wsize; dst += wsize); t = length & wmask; TLOOP(*dst++ = *src++); } else { @@ -126,7 +123,8 @@ bcopy(const void *src0, void *dst0, size_t length) TLOOP1(*--dst = *--src); } t = length / wsize; - TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); + TLOOP(src -= wsize; dst -= wsize; + *(word *)(void *)dst = *(const word *)(const void *)src); t = length & wmask; TLOOP(*--dst = *--src); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104200047.13K0l10T036883>