bcopy.S revision 105149
11849Swollman/*- 21849Swollman * Copyright (c) 1990 The Regents of the University of California. 31849Swollman * All rights reserved. 41849Swollman * 525043Sbde * This code is derived from locore.s. 61849Swollman * 71849Swollman * Redistribution and use in source and binary forms, with or without 81849Swollman * modification, are permitted provided that the following conditions 91849Swollman * are met: 101849Swollman * 1. Redistributions of source code must retain the above copyright 111849Swollman * notice, this list of conditions and the following disclaimer. 121849Swollman * 2. Redistributions in binary form must reproduce the above copyright 131849Swollman * notice, this list of conditions and the following disclaimer in the 141849Swollman * documentation and/or other materials provided with the distribution. 151849Swollman * 3. All advertising materials mentioning features or use of this software 161849Swollman * must display the following acknowledgement: 171849Swollman * This product includes software developed by the University of 181849Swollman * California, Berkeley and its contributors. 191849Swollman * 4. Neither the name of the University nor the names of its contributors 201849Swollman * may be used to endorse or promote products derived from this software 211849Swollman * without specific prior written permission. 221849Swollman * 231849Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241849Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251849Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261849Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271849Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281849Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291849Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301849Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311849Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321849Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331849Swollman * SUCH DAMAGE. 341849Swollman */ 351849Swollman 3625043Sbde#include <machine/asm.h> 3793000Sobrien__FBSDID("$FreeBSD: head/lib/libc/i386/string/bcopy.S 105149 2002-10-15 09:50:07Z sobomax $"); 381849Swollman 3993000Sobrien#if 0 4025043Sbde RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $") 4193000Sobrien#endif 421849Swollman 431849Swollman /* 441849Swollman * (ov)bcopy (src,dst,cnt) 451849Swollman * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 461849Swollman */ 471849Swollman 4825043Sbde#ifdef MEMCOPY 4925043SbdeENTRY(memcpy) 5025043Sbde#else 5125043Sbde#ifdef MEMMOVE 5225043SbdeENTRY(memmove) 5325043Sbde#else 541849SwollmanENTRY(bcopy) 5525043Sbde#endif 5625043Sbde#endif 571849Swollman pushl %esi 581849Swollman pushl %edi 5925043Sbde#if defined(MEMCOPY) || defined(MEMMOVE) 6025043Sbde movl 12(%esp),%edi 6125043Sbde movl 16(%esp),%esi 62105149Ssobomax movl %edi,%eax 6325043Sbde#else 641849Swollman movl 12(%esp),%esi 651849Swollman movl 16(%esp),%edi 6625043Sbde#endif 671849Swollman movl 20(%esp),%ecx 68105149Ssobomax movl %edi,%edx 69105149Ssobomax subl %esi,%edx 70105149Ssobomax cmpl %ecx,%edx /* overlapping? */ 7113064Sdg jb 1f 721849Swollman cld /* nope, copy forwards. */ 73105149Ssobomax movl %ecx,%edx 741849Swollman shrl $2,%ecx /* copy by words */ 751849Swollman rep 761849Swollman movsl 77105149Ssobomax movl %edx,%ecx 781849Swollman andl $3,%ecx /* any bytes left? */ 791849Swollman rep 801849Swollman movsb 811849Swollman popl %edi 821849Swollman popl %esi 831849Swollman ret 841849Swollman1: 851849Swollman addl %ecx,%edi /* copy backwards. */ 861849Swollman addl %ecx,%esi 8725043Sbde std 88105149Ssobomax movl %ecx,%edx 8925043Sbde andl $3,%ecx /* any fractional bytes? */ 901849Swollman decl %edi 911849Swollman decl %esi 921849Swollman rep 931849Swollman movsb 94105149Ssobomax movl %edx,%ecx /* copy remainder by words */ 951849Swollman shrl $2,%ecx 961849Swollman subl $3,%esi 971849Swollman subl $3,%edi 981849Swollman rep 991849Swollman movsl 1001849Swollman popl %edi 1011849Swollman popl %esi 1021849Swollman cld 1031849Swollman ret 104