[syslinux:pathbased] memmove: don't reverse copy if there is no overlap

syslinux-bot for H. Peter Anvin hpa at zytor.com
Mon Feb 15 16:30:07 PST 2010


Commit-ID:  48cb36465251f4b44797ef3bdfe446ef58e728cb
Gitweb:     http://syslinux.zytor.com/commit/48cb36465251f4b44797ef3bdfe446ef58e728cb
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 15 Feb 2010 16:28:23 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 15 Feb 2010 16:28:23 -0800

memmove: don't reverse copy if there is no overlap

Don't do reverse copies if there is no overlap.  Current x86 CPUs
optimize forward copies, but some of them don't optimize reverse
copies.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 com32/lib/memmove.S |   31 +++++++++++++++++++------------
 core/bcopyxx.inc    |    9 ++++++---
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/com32/lib/memmove.S b/com32/lib/memmove.S
index b7ac676..e97299f 100644
--- a/com32/lib/memmove.S
+++ b/com32/lib/memmove.S
@@ -1,6 +1,7 @@
 /* ----------------------------------------------------------------------- *
  *
  *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
  *
  *   Permission is hereby granted, free of charge, to any person
  *   obtaining a copy of this software and associated documentation
@@ -36,7 +37,7 @@
 	.type	memmove, at function
 	.text
 memmove:
-	jecxz	3f
+	jecxz	4f
 
 	pushl	%esi
 	pushl	%edi
@@ -46,11 +47,12 @@ memmove:
 	movl	%edx,%esi
 
 	cmpl	%edi,%esi
-	jb	1f
+	jb	2f
 
 	/* source >= dest, forwards move */
 
 	/* Initial alignment */
+1:
 	movl	%edi,%edx
 	shrl	$1,%edx
 	jnc	11f
@@ -81,14 +83,24 @@ memmove:
 	jz	15f
 	movsb
 15:
-	jmp	2f
+	/* Common exit stub */
+3:
+	popl	%eax		/* Return value */
+	popl	%edi
+	popl	%esi
+4:
+	ret
 
 
-1:
-	/* source < dest, backwards move */
+2:
+	/* source < dest, backwards move if overlap */
+	leal	-1(%ecx,%esi),%eax
+	cmpl	%eax,%edi
+	ja	1b			/* No overlap, after all... */
+
 	std
-	leal	-1(%ecx,%esi),%esi
 	leal	-1(%ecx,%edi),%edi
+	movl	%eax,%esi
 
 	/* Initial alignment */
 	movl	%edi,%edx
@@ -129,11 +141,6 @@ memmove:
 	movsb
 25:
 	cld
-2:
-	popl	%eax		/* Return value */
-	popl	%edi
-	popl	%esi
-3:
-	ret
+	jmp	3b
 
 	.size	memmove, .-memmove
diff --git a/core/bcopyxx.inc b/core/bcopyxx.inc
index 823662b..abaafa7 100644
--- a/core/bcopyxx.inc
+++ b/core/bcopyxx.inc
@@ -1,7 +1,7 @@
 ;; -----------------------------------------------------------------------
 ;;
 ;;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
-;;   Copyright 2009 Intel Corporation; author: H. Peter Anvin
+;;   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
 ;;
 ;;   This program is free software; you can redistribute it and/or modify
 ;;   it under the terms of the GNU General Public License as published by
@@ -95,10 +95,13 @@ pm_bcopy:
 		ret
 
 .reverse:
-		std			; Reverse copy
+		lea eax,[esi+ecx-1]	; Point to final byte
+		cmp edi,eax
+		ja .forward		; No overlap, do forward copy
 
-		lea esi,[esi+ecx-1]	; Point to final byte
+		std			; Reverse copy
 		lea edi,[edi+ecx-1]
+		mov esi,eax
 
 		; Initial alignment
 		mov edx,edi



More information about the Syslinux-commits mailing list