Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Nov 2018 16:27:31 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-releng@freebsd.org
Subject:   svn commit: r340768 - releng/12.0/sys/sparc64/sparc64
Message-ID:  <201811221627.wAMGRV3G074338@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Thu Nov 22 16:27:30 2018
New Revision: 340768
URL: https://svnweb.freebsd.org/changeset/base/340768

Log:
  MFC: r340656, MF12: r340759
  
  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.
  
  Approved by:	re (kib)

Modified:
  releng/12.0/sys/sparc64/sparc64/support.S
Directory Properties:
  releng/12.0/   (props changed)

Modified: releng/12.0/sys/sparc64/sparc64/support.S
==============================================================================
--- releng/12.0/sys/sparc64/sparc64/support.S	Thu Nov 22 16:15:24 2018	(r340767)
+++ releng/12.0/sys/sparc64/sparc64/support.S	Thu Nov 22 16:27:30 2018	(r340768)
@@ -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?201811221627.wAMGRV3G074338>