aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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