memcpy.s revision 8cd45542f2a452ca0dab13d8b2d5cfa876ccbebc
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
1067N/A
1185N/A/*
1185N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
850N/A .ident "%Z%%M% %I% %E% SMI"
850N/A
1384N/A .file "%M%"
0N/A
0N/A#include <sys/asm_linkage.h>
0N/A
0N/A ANSI_PRAGMA_WEAK(memmove,function)
0N/A ANSI_PRAGMA_WEAK(memcpy,function)
850N/A
0N/A#include "SYS.h"
0N/A
850N/A ENTRY(memcpy)
1185N/A movl %edi,%edx / save register variables
1185N/A pushl %esi
1185N/A movl 8(%esp),%edi / %edi = dest address
0N/A movl 12(%esp),%esi / %esi = source address
1020N/A movl 16(%esp),%ecx / %ecx = length of string
1384N/A movl %edi,%eax / return value from the call
1281N/A
1281N/A shrl $2,%ecx / %ecx = number of words to move
1281N/A rep ; smovl / move the words
1020N/A
974N/A movl 16(%esp),%ecx / %ecx = number of bytes to move
974N/A andl $0x3,%ecx / %ecx = number of bytes left to move
974N/A rep ; smovb / move the bytes
0N/A
1020N/A popl %esi / restore register variables
1020N/A movl %edx,%edi
1020N/A ret
1020N/A SET_SIZE(memcpy)
1020N/A
1020N/A
1185N/A ENTRY(memmove)
1185N/A pushl %edi / save off %edi, %esi and move destination
1185N/A movl 4+12(%esp),%ecx / get number of bytes to move
1281N/A pushl %esi
1281N/A testl %ecx,%ecx / if (n == 0)
1281N/A je .CleanupReturn / return(s);
1281N/A movl 8+ 4(%esp),%edi / destination buffer address
1185N/A movl 8+ 8(%esp),%esi / source buffer address
1185N/A.Common:
1281N/A movl $3,%eax / heavily used constant
1281N/A cmpl %esi,%edi / if (source addr > dest addr)
1281N/A leal -1(%esi,%ecx),%edx
1281N/A jle .CopyRight /
1185N/A cmpl %edx,%edi
1185N/A jle .CopyLeft
1281N/A.CopyRight:
1281N/A cmpl $8,%ecx / if (size < 8 bytes)
1281N/A jbe .OneByteCopy / goto fast short copy loop
1281N/A.FourByteCopy:
1185N/A movl %ecx,%edx / save count
1185N/A movl %esi,%ecx / get source buffer 4 byte aligned
1281N/A andl %eax,%ecx
1281N/A jz .SkipAlignRight
1185N/A subl %ecx,%edx
1185N/A rep; smovb / do the byte part of copy
1281N/A.SkipAlignRight:
1281N/A movl %edx,%ecx
1281N/A shrl $2,%ecx
1281N/A rep; smovl / do the long word part
1185N/A movl %edx,%ecx / compute bytes left to move
1185N/A andl %eax,%ecx / complete copy of remaining bytes
1185N/A jz .CleanupReturn
1281N/A.OneByteCopy:
1281N/A rep; smovb / do the byte part of copy
1281N/A.CleanupReturn:
1281N/A popl %esi / }
1185N/A popl %edi / restore registers
1185N/A movl 4(%esp),%eax / set up return value
1185N/A.Return:
1185N/A ret / return(dba);
1281N/A
1281N/A.CopyLeft:
1281N/A std / reverse direction bit (RtoL)
1281N/A cmpl $12,%ecx / if (size < 12)
1281N/A ja .BigCopyLeft / {
1281N/A movl %edx,%esi / src = src + size - 1
1281N/A leal -1(%ecx,%edi),%edi / dst = dst + size - 1
1281N/A rep; smovb / do the byte copy
1281N/A cld / reset direction flag to LtoR
1185N/A popl %esi / }
0N/A popl %edi / restore registers
0N/A movl 4(%esp),%eax / set up return value
1185N/A ret / return(dba);
1281N/A.BigCopyLeft: / } else {
1281N/A xchgl %edx,%ecx
1281N/A movl %ecx,%esi / align source w/byte copy
1281N/A leal -1(%edx,%edi),%edi
1281N/A andl %eax,%ecx
1281N/A jz .SkipAlignLeft
1281N/A addl $1, %ecx / we need to insure that future
1281N/A subl %ecx,%edx / copy is done on aligned boundary
1185N/A rep; smovb
1185N/A.SkipAlignLeft:
936N/A movl %edx,%ecx
1020N/A subl %eax,%esi
0N/A shrl $2,%ecx / do 4 byte copy RtoL
0N/A subl %eax,%edi
0N/A rep; smovl
0N/A andl %eax,%edx / do 1 byte copy whats left
0N/A jz .CleanupReturnLeft
0N/A movl %edx,%ecx
0N/A addl %eax,%esi / rep; smovl instruction will decrement
0N/A addl %eax,%edi / %edi, %esi by four after each copy
1390N/A / adding 3 will restore pointers to byte
1185N/A / before last double word copied
0N/A / which is where they are expected to
0N/A / be for the single byte copy code
0N/A rep; smovb
1185N/A.CleanupReturnLeft:
0N/A cld / reset direction flag to LtoR
0N/A popl %esi
0N/A popl %edi / restore registers
1185N/A movl 4(%esp),%eax / set up return value
0N/A ret / return(dba);
0N/A SET_SIZE(memmove)
1185N/A