Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Apr 2021 00:47:02 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: ab147542b7c0 - main - libc/string/memset.c: Use unsigned long for stores
Message-ID:  <202104200047.13K0l22f036904@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=ab147542b7c0bbc41f7f0499b16933bd8f3f31d7

commit ab147542b7c0bbc41f7f0499b16933bd8f3f31d7
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-04-19 23:19:20 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-04-20 00:46:43 +0000

    libc/string/memset.c: Use unsigned long for stores
    
    While most 64-bit architectures have an assembly implementation of this
    file, RISC-V does not. As we now store 8 bytes instead of 4 it should speed
    up RISC-V.
    
    Reviewed By:    kib
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D29536
---
 lib/libc/string/memset.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/libc/string/memset.c b/lib/libc/string/memset.c
index 7d9909a76083..e2d4027eea0c 100644
--- a/lib/libc/string/memset.c
+++ b/lib/libc/string/memset.c
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
 
 #include <limits.h>
 
-#define	wsize	sizeof(u_int)
+#define	wsize	sizeof(u_long)
 #define	wmask	(wsize - 1)
 
 #ifdef BZERO
@@ -67,7 +67,7 @@ memset(void *dst0, int c0, size_t length)
 {
 	size_t t;
 #ifndef BZERO
-	u_int c;
+	u_long c;
 #endif
 	u_char *dst;
 
@@ -84,6 +84,9 @@ memset(void *dst0, int c0, size_t length)
 	 *
 	 * but we use a minimum of 3 here since the overhead of the code
 	 * to do word writes is substantial.
+	 *
+	 * TODO: This threshold might not be sensible for 64-bit u_long.
+	 * We should benchmark and revisit this decision.
 	 */
 	if (length < 3 * wsize) {
 		while (length != 0) {
@@ -95,12 +98,12 @@ memset(void *dst0, int c0, size_t length)
 
 #ifndef BZERO
 	if ((c = (u_char)c0) != 0) {	/* Fill the word. */
-		c = (c << 8) | c;	/* u_int is 16 bits. */
-#if UINT_MAX > 0xffff
-		c = (c << 16) | c;	/* u_int is 32 bits. */
+		c = (c << 8) | c;	/* u_long is 16 bits. */
+#if ULONG_MAX > 0xffff
+		c = (c << 16) | c;	/* u_long is 32 bits. */
 #endif
-#if UINT_MAX > 0xffffffff
-		c = (c << 32) | c;	/* u_int is 64 bits. */
+#if ULONG_MAX > 0xffffffff
+		c = (c << 32) | c;	/* u_long is 64 bits. */
 #endif
 	}
 #endif
@@ -116,7 +119,7 @@ memset(void *dst0, int c0, size_t length)
 	/* Fill words.  Length was >= 2*words so we know t >= 1 here. */
 	t = length / wsize;
 	do {
-		*(u_int *)dst = WIDEVAL;
+		*(u_long *)(void *)dst = WIDEVAL;
 		dst += wsize;
 	} while (--t != 0);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104200047.13K0l22f036904>