bcopy.S revision 93000
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 93000 2002-03-23 02:44:19Z obrien $"); 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 6225043Sbde#else 631849Swollman movl 12(%esp),%esi 641849Swollman movl 16(%esp),%edi 6525043Sbde#endif 661849Swollman movl 20(%esp),%ecx 6713064Sdg movl %edi,%eax 6813064Sdg subl %esi,%eax 6913064Sdg cmpl %ecx,%eax /* overlapping? */ 7013064Sdg jb 1f 711849Swollman cld /* nope, copy forwards. */ 721849Swollman shrl $2,%ecx /* copy by words */ 731849Swollman rep 741849Swollman movsl 751849Swollman movl 20(%esp),%ecx 761849Swollman andl $3,%ecx /* any bytes left? */ 771849Swollman rep 781849Swollman movsb 7925043Sbde#if defined(MEMCOPY) || defined(MEMMOVE) 8025043Sbde movl 12(%esp),%eax 8125043Sbde#endif 821849Swollman popl %edi 831849Swollman popl %esi 841849Swollman ret 851849Swollman1: 861849Swollman addl %ecx,%edi /* copy backwards. */ 871849Swollman addl %ecx,%esi 8825043Sbde std 8925043Sbde andl $3,%ecx /* any fractional bytes? */ 901849Swollman decl %edi 911849Swollman decl %esi 921849Swollman rep 931849Swollman movsb 941849Swollman movl 20(%esp),%ecx /* copy remainder by words */ 951849Swollman shrl $2,%ecx 961849Swollman subl $3,%esi 971849Swollman subl $3,%edi 981849Swollman rep 991849Swollman movsl 10025043Sbde#if defined(MEMCOPY) || defined(MEMMOVE) 10125043Sbde movl 12(%esp),%eax 10225043Sbde#endif 1031849Swollman popl %edi 1041849Swollman popl %esi 1051849Swollman cld 1061849Swollman ret 107