Aligning memcpy/memmove/mempcpy/memset for libcom32
[syslinux.git] / com32 / lib / mempcpy.S
blobf6961f6681454dc1155dc5e6fd479e544e73450e
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2008 H. Peter Anvin - All Rights Reserved
4  *
5  *   Permission is hereby granted, free of charge, to any person
6  *   obtaining a copy of this software and associated documentation
7  *   files (the "Software"), to deal in the Software without
8  *   restriction, including without limitation the rights to use,
9  *   copy, modify, merge, publish, distribute, sublicense, and/or
10  *   sell copies of the Software, and to permit persons to whom
11  *   the Software is furnished to do so, subject to the following
12  *   conditions:
13  *
14  *   The above copyright notice and this permission notice shall
15  *   be included in all copies or substantial portions of the Software.
16  *
17  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19  *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21  *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  *   OTHER DEALINGS IN THE SOFTWARE.
25  *
26  * ----------------------------------------------------------------------- */
29  * mempcpy.S
30  *
31  * Reasonably efficient mempcpy, using aligned transfers at least
32  * for the destination operand.
33  */
35         .text
36         .globl  mempcpy
37         .type   mempcpy, @function
38 mempcpy:
39         jecxz   1f
41         pushl   %esi
42         pushl   %edi
44         movl    %eax,%edi
45         movl    %edx,%esi
47         /* Initial alignment */
48         movl    %edi,%edx
49         shrl    $1,%edx
50         jnc     11f
51         movsb
52         decl    %ecx
53 11:
54         movb    %cl,%al
55         cmpl    $2,%ecx
56         jb      13f
58         shrl    $1,%edx
59         jnc     12f
60         movsw
61         subl    $2,%ecx
62 12:
63         /* Bulk transfer */
64         movb    %cl,%al
65         shrl    $2,%ecx
66         rep; movsl
68         /* Final alignment */
69         testb   $2,%al
70         jz      14f
71         movsw
72 13:
73 14:
74         testb   $1,%al
75         jz      15f
76         movsb
77 15:
79         movl    %edi,%eax       /* Return value */
80         popl    %edi
81         popl    %esi
82 1:      
83         ret
85         .size   mempcpy, .-mempcpy