Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Nov 2018 13:03:11 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r340759 - stable/12/sys/sparc64/sparc64
Message-ID:  <201811221303.wAMD3BPr071746@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Thu Nov 22 13:03:11 2018
New Revision: 340759
URL: https://svnweb.freebsd.org/changeset/base/340759

Log:
  MFC: r340656
  
  Given that the idea of D15374 was to "make memmove a first class citizen",
  provide a _MEMMOVE extension of _MEMCPY that deals with overlap based on
  the previous bcopy(9) implementation and use the former for bcopy(9) and
  memmove(9). This addresses my D15374 review comment, avoiding extra MOVs
  in case of memmove(9) and trashing the stack pointer.

Modified:
  stable/12/sys/sparc64/sparc64/support.S
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/sparc64/sparc64/support.S
==============================================================================
--- stable/12/sys/sparc64/sparc64/support.S	Thu Nov 22 09:47:51 2018	(r340758)
+++ stable/12/sys/sparc64/sparc64/support.S	Thu Nov 22 13:03:11 2018	(r340759)
@@ -207,6 +207,30 @@ __FBSDID("$FreeBSD$");
 6:
 
 /*
+ * Extension of _MEMCPY dealing with overlap, but unaware of ASIs.
+ * Used for bcopy() and memmove().
+ */
+#define	_MEMMOVE(dst, src, len) \
+	/* Check for overlap, and copy backwards if so. */ \
+	sub	dst, src, %g1 ; \
+	cmp	%g1, len ; \
+	bgeu,a,pt %xcc, 2f ; \
+	 nop ; \
+	/* Copy backwards. */ \
+	add	src, len, src ; \
+	add	dst, len, dst ; \
+1:	deccc	1, len ; \
+	bl,pn	%xcc, 3f ; \
+	 dec	1, src ; \
+	ldub	[src], %g1 ; \
+	dec	1, dst ; \
+	ba	%xcc, 1b ; \
+	 stb	%g1, [dst] ; \
+2:	/* Do the fast version. */ \
+	_MEMCPY(dst, src, len, EMPTY, EMPTY, EMPTY, EMPTY) ; \
+3:
+
+/*
  * void ascopy(u_long asi, vm_offset_t src, vm_offset_t dst, size_t len)
  */
 ENTRY(ascopy)
@@ -265,49 +289,14 @@ ENTRY(bcmp)
 END(bcmp)
 
 /*
- * void *memmove(void *dst, const void *src, size_t len)
  * void bcopy(const void *src, void *dst, size_t len)
  */
-ENTRY(memmove)
-	/*
-	 * Swap src/dst for memmove/bcopy differences
-	 */
-	mov	%o0, %o6
-	mov	%o1, %o0
-	mov	%o6, %o1
-ALTENTRY(bcopy)
-	/*
-	 * Check for overlap, and copy backwards if so.
-	 */
-	sub	%o1, %o0, %g1
-	cmp	%g1, %o2
-	bgeu,a,pt %xcc, 3f
+ENTRY(bcopy)
+	_MEMMOVE(%o1, %o0, %o2)
+	retl
 	 nop
+END(bcopy)
 
-	/*
-	 * Copy backwards.
-	 */
-	add	%o0, %o2, %o0
-	add	%o1, %o2, %o1
-1:	deccc	1, %o2
-	bl,a,pn	%xcc, 2f
-	 nop
-	dec	1, %o0
-	ldub	[%o0], %g1
-	dec	1, %o1
-	ba	%xcc, 1b
-	 stb	%g1, [%o1]
-2:	retl
-	 mov	%o6, %o0
-
-	/*
-	 * Do the fast version.
-	 */
-3:	_MEMCPY(%o1, %o0, %o2, EMPTY, EMPTY, EMPTY, EMPTY)
-	retl
-	 mov	%o6, %o0
-END(memmove)
-
 /*
  * void bzero(void *b, size_t len)
  */
@@ -335,6 +324,16 @@ ENTRY(memcpy)
 	retl
 	 nop
 END(memcpy)
+
+/*
+ * void *memmove(void *dst, const void *src, size_t len)
+ */
+ENTRY(memmove)
+	mov	%o0, %o3
+	_MEMMOVE(%o3, %o1, %o2)
+	retl
+	 nop
+END(memmove)
 
 /*
  * void *memset(void *b, int c, size_t len)



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