aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-02-15 16:28:23 -0800
committerH. Peter Anvin <hpa@zytor.com>2010-02-15 16:28:23 -0800
commit48cb36465251f4b44797ef3bdfe446ef58e728cb (patch)
treebb65083e2cf7d7af6db78d0d29fa40c2c0a85459
parentdd01ec19a62c769e37416878dbe63989d2526660 (diff)
downloadsyslinux-48cb36465251f4b44797ef3bdfe446ef58e728cb.tar.gz
syslinux-48cb36465251f4b44797ef3bdfe446ef58e728cb.tar.xz
syslinux-48cb36465251f4b44797ef3bdfe446ef58e728cb.zip
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@zytor.com>
-rw-r--r--com32/lib/memmove.S31
-rw-r--r--core/bcopyxx.inc9
2 files changed, 25 insertions, 15 deletions
diff --git a/com32/lib/memmove.S b/com32/lib/memmove.S
index b7ac6767..e97299f2 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,@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 823662b4..abaafa75 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