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