memdisk/dskprobe: Show the status of the last command when debugging
[profile/ivi/syslinux.git] / memdisk / memcpy.S
index 82ec870..6b986a0 100644 (file)
@@ -1,28 +1,86 @@
-#
-# memcpy.S
-#
-# Simple memcpy() implementation
-#
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   Permission is hereby granted, free of charge, to any person
+ *   obtaining a copy of this software and associated documentation
+ *   files (the "Software"), to deal in the Software without
+ *   restriction, including without limitation the rights to use,
+ *   copy, modify, merge, publish, distribute, sublicense, and/or
+ *   sell copies of the Software, and to permit persons to whom
+ *   the Software is furnished to do so, subject to the following
+ *   conditions:
+ *
+ *   The above copyright notice and this permission notice shall
+ *   be included in all copies or substantial portions of the Software.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *   OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * memcpy.S
+ *
+ * Reasonably efficient memcpy, using aligned transfers at least
+ * for the destination operand.
+ */
 
        .text
-       .globl memcpy
-       .type memcpy, @function
+       .globl  memcpy
+       .type   memcpy, @function
 memcpy:
-       cld
-       pushl %edi
-       pushl %esi
-       movl 12(%esp),%edi
-       movl 16(%esp),%esi
-       movl 20(%esp),%eax
-       movl %eax,%ecx
-       shrl $2,%ecx
-       rep ; movsl
-       movl %eax,%ecx
-       andl $3,%ecx
-       rep ; movsb
-       movl 12(%esp),%eax
-       popl %esi
-       popl %edi
+       jecxz   1f
+
+       pushl   %esi
+       pushl   %edi
+       pushl   %eax            /* Return value */
+
+       movl    %eax,%edi
+       movl    %edx,%esi
+
+       /* Initial alignment */
+       movl    %edi,%edx
+       shrl    $1,%edx
+       jnc     11f
+       movsb
+       decl    %ecx
+11:
+       movb    %cl,%al
+       cmpl    $2,%ecx
+       jb      13f
+
+       shrl    $1,%edx
+       jnc     12f
+       movsw
+       subl    $2,%ecx
+12:
+       /* Bulk transfer */
+       movb    %cl,%al
+       shrl    $2,%ecx
+       rep; movsl
+
+       /* Final alignment */
+       testb   $2,%al
+       jz      14f
+       movsw
+13:
+14:
+       testb   $1,%al
+       jz      15f
+       movsb
+15:
+
+       popl    %eax            /* Return value */
+       popl    %edi
+       popl    %esi
+1:
        ret
 
-       .size memcpy,.-memcpy
+       .size   memcpy, .-memcpy