Home | History | Annotate | Download | only in lib
      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  * ----------------------------------------------------------------------- */
     27 
     28 /*
     29  * mempcpy.S
     30  *
     31  * Reasonably efficient mempcpy, using aligned transfers at least
     32  * for the destination operand.
     33  */
     34 
     35 	.text
     36 	.globl	mempcpy
     37 	.type	mempcpy, @function
     38 mempcpy:
     39 	movl	0xc(%esp),%ecx
     40 	movl	0x8(%esp),%edx
     41 	movl	0x4(%esp),%eax
     42 
     43 	jecxz	1f
     44 
     45 	pushl	%esi
     46 	pushl	%edi
     47 
     48 	movl	%eax,%edi
     49 	movl	%edx,%esi
     50 
     51 	/* Initial alignment */
     52 	movl	%edi,%edx
     53 	shrl	$1,%edx
     54 	jnc	11f
     55 	movsb
     56 	decl	%ecx
     57 11:
     58 	movb	%cl,%al
     59 	cmpl	$2,%ecx
     60 	jb	13f
     61 
     62 	shrl	$1,%edx
     63 	jnc	12f
     64 	movsw
     65 	subl	$2,%ecx
     66 12:
     67 	/* Bulk transfer */
     68 	movb	%cl,%al
     69 	shrl	$2,%ecx
     70 	rep; movsl
     71 
     72 	/* Final alignment */
     73 	testb	$2,%al
     74 	jz	14f
     75 	movsw
     76 13:
     77 14:
     78 	testb	$1,%al
     79 	jz	15f
     80 	movsb
     81 15:
     82 
     83 	movl	%edi,%eax	/* Return value */
     84 	popl	%edi
     85 	popl	%esi
     86 1:
     87 	ret
     88 
     89 	.size	mempcpy, .-mempcpy
     90