mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH 1/4] wmemmove: implement via memmove()
@ 2025-03-30 12:17 Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 2/4] wmemcpy: implement via memcpy() Christian Göttsche
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christian Göttsche @ 2025-03-30 12:17 UTC (permalink / raw)
  To: musl; +Cc: Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

Implement via memmove() to inherit its optimizations.
---
 src/string/wmemmove.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/string/wmemmove.c b/src/string/wmemmove.c
index 964c9032..380d11f0 100644
--- a/src/string/wmemmove.c
+++ b/src/string/wmemmove.c
@@ -1,13 +1,8 @@
 #include <wchar.h>
 #include <stdint.h>
+#include <string.h>
 
 wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n)
 {
-	wchar_t *d0 = d;
-	if (d == s) return d;
-	if ((uintptr_t)d-(uintptr_t)s < n * sizeof *d)
-		while (n--) d[n] = s[n];
-	else
-		while (n--) *d++ = *s++;
-	return d0;
+	return memmove(d, s, n * sizeof(wchar_t));
 }
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [musl] [PATCH 2/4] wmemcpy: implement via memcpy()
  2025-03-30 12:17 [musl] [PATCH 1/4] wmemmove: implement via memmove() Christian Göttsche
@ 2025-03-30 12:17 ` Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 3/4] memmove: avoid dropping const qualifier Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 4/4] memcpy: " Christian Göttsche
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Göttsche @ 2025-03-30 12:17 UTC (permalink / raw)
  To: musl; +Cc: Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

Implement via memcpy() to inherit its optimizations.
---
 src/string/wmemcpy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/string/wmemcpy.c b/src/string/wmemcpy.c
index 52e6e6e0..e68fdf49 100644
--- a/src/string/wmemcpy.c
+++ b/src/string/wmemcpy.c
@@ -1,8 +1,7 @@
 #include <wchar.h>
+#include <string.h>
 
 wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n)
 {
-	wchar_t *a = d;
-	while (n--) *d++ = *s++;
-	return a;
+	return memcpy(d, s, n * sizeof(wchar_t));
 }
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [musl] [PATCH 3/4] memmove: avoid dropping const qualifier
  2025-03-30 12:17 [musl] [PATCH 1/4] wmemmove: implement via memmove() Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 2/4] wmemcpy: implement via memcpy() Christian Göttsche
@ 2025-03-30 12:17 ` Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 4/4] memcpy: " Christian Göttsche
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Göttsche @ 2025-03-30 12:17 UTC (permalink / raw)
  To: musl; +Cc: Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

For const correctness retain the const qualifier for pointer casts of
the source parameter.
---
 src/string/memmove.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/string/memmove.c b/src/string/memmove.c
index 5dc9cdb9..87806ab1 100644
--- a/src/string/memmove.c
+++ b/src/string/memmove.c
@@ -21,7 +21,7 @@ void *memmove(void *dest, const void *src, size_t n)
 				if (!n--) return dest;
 				*d++ = *s++;
 			}
-			for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s;
+			for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(const WT *)s;
 		}
 #endif
 		for (; n; n--) *d++ = *s++;
@@ -32,7 +32,7 @@ void *memmove(void *dest, const void *src, size_t n)
 				if (!n--) return dest;
 				d[n] = s[n];
 			}
-			while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n);
+			while (n>=WS) n-=WS, *(WT *)(d+n) = *(const WT *)(s+n);
 		}
 #endif
 		while (n) n--, d[n] = s[n];
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [musl] [PATCH 4/4] memcpy: avoid dropping const qualifier
  2025-03-30 12:17 [musl] [PATCH 1/4] wmemmove: implement via memmove() Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 2/4] wmemcpy: implement via memcpy() Christian Göttsche
  2025-03-30 12:17 ` [musl] [PATCH 3/4] memmove: avoid dropping const qualifier Christian Göttsche
@ 2025-03-30 12:17 ` Christian Göttsche
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Göttsche @ 2025-03-30 12:17 UTC (permalink / raw)
  To: musl; +Cc: Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

For const correctness retain the const qualifier for pointer casts of
the source parameter.
---
 src/string/memcpy.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/string/memcpy.c b/src/string/memcpy.c
index 06e88742..51d9669e 100644
--- a/src/string/memcpy.c
+++ b/src/string/memcpy.c
@@ -24,18 +24,18 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n)
 
 	if ((uintptr_t)d % 4 == 0) {
 		for (; n>=16; s+=16, d+=16, n-=16) {
-			*(u32 *)(d+0) = *(u32 *)(s+0);
-			*(u32 *)(d+4) = *(u32 *)(s+4);
-			*(u32 *)(d+8) = *(u32 *)(s+8);
-			*(u32 *)(d+12) = *(u32 *)(s+12);
+			*(u32 *)(d+0) = *(const u32 *)(s+0);
+			*(u32 *)(d+4) = *(const u32 *)(s+4);
+			*(u32 *)(d+8) = *(const u32 *)(s+8);
+			*(u32 *)(d+12) = *(const u32 *)(s+12);
 		}
 		if (n&8) {
-			*(u32 *)(d+0) = *(u32 *)(s+0);
-			*(u32 *)(d+4) = *(u32 *)(s+4);
+			*(u32 *)(d+0) = *(const u32 *)(s+0);
+			*(u32 *)(d+4) = *(const u32 *)(s+4);
 			d += 8; s += 8;
 		}
 		if (n&4) {
-			*(u32 *)(d+0) = *(u32 *)(s+0);
+			*(u32 *)(d+0) = *(const u32 *)(s+0);
 			d += 4; s += 4;
 		}
 		if (n&2) {
@@ -49,50 +49,50 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n)
 
 	if (n >= 32) switch ((uintptr_t)d % 4) {
 	case 1:
-		w = *(u32 *)s;
+		w = *(const u32 *)s;
 		*d++ = *s++;
 		*d++ = *s++;
 		*d++ = *s++;
 		n -= 3;
 		for (; n>=17; s+=16, d+=16, n-=16) {
-			x = *(u32 *)(s+1);
+			x = *(const u32 *)(s+1);
 			*(u32 *)(d+0) = (w LS 24) | (x RS 8);
-			w = *(u32 *)(s+5);
+			w = *(const u32 *)(s+5);
 			*(u32 *)(d+4) = (x LS 24) | (w RS 8);
-			x = *(u32 *)(s+9);
+			x = *(const u32 *)(s+9);
 			*(u32 *)(d+8) = (w LS 24) | (x RS 8);
-			w = *(u32 *)(s+13);
+			w = *(const u32 *)(s+13);
 			*(u32 *)(d+12) = (x LS 24) | (w RS 8);
 		}
 		break;
 	case 2:
-		w = *(u32 *)s;
+		w = *(const u32 *)s;
 		*d++ = *s++;
 		*d++ = *s++;
 		n -= 2;
 		for (; n>=18; s+=16, d+=16, n-=16) {
-			x = *(u32 *)(s+2);
+			x = *(const u32 *)(s+2);
 			*(u32 *)(d+0) = (w LS 16) | (x RS 16);
-			w = *(u32 *)(s+6);
+			w = *(const u32 *)(s+6);
 			*(u32 *)(d+4) = (x LS 16) | (w RS 16);
-			x = *(u32 *)(s+10);
+			x = *(const u32 *)(s+10);
 			*(u32 *)(d+8) = (w LS 16) | (x RS 16);
-			w = *(u32 *)(s+14);
+			w = *(const u32 *)(s+14);
 			*(u32 *)(d+12) = (x LS 16) | (w RS 16);
 		}
 		break;
 	case 3:
-		w = *(u32 *)s;
+		w = *(const u32 *)s;
 		*d++ = *s++;
 		n -= 1;
 		for (; n>=19; s+=16, d+=16, n-=16) {
-			x = *(u32 *)(s+3);
+			x = *(const u32 *)(s+3);
 			*(u32 *)(d+0) = (w LS 8) | (x RS 24);
-			w = *(u32 *)(s+7);
+			w = *(const u32 *)(s+7);
 			*(u32 *)(d+4) = (x LS 8) | (w RS 24);
-			x = *(u32 *)(s+11);
+			x = *(const u32 *)(s+11);
 			*(u32 *)(d+8) = (w LS 8) | (x RS 24);
-			w = *(u32 *)(s+15);
+			w = *(const u32 *)(s+15);
 			*(u32 *)(d+12) = (x LS 8) | (w RS 24);
 		}
 		break;
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-30 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-30 12:17 [musl] [PATCH 1/4] wmemmove: implement via memmove() Christian Göttsche
2025-03-30 12:17 ` [musl] [PATCH 2/4] wmemcpy: implement via memcpy() Christian Göttsche
2025-03-30 12:17 ` [musl] [PATCH 3/4] memmove: avoid dropping const qualifier Christian Göttsche
2025-03-30 12:17 ` [musl] [PATCH 4/4] memcpy: " Christian Göttsche

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).