15b859c19Sderaadt/*- 25b859c19Sderaadt * Copyright (c) 1990 The Regents of the University of California. 35b859c19Sderaadt * All rights reserved. 45b859c19Sderaadt * 55b859c19Sderaadt * This code is derived from locore.s. 65b859c19Sderaadt * 75b859c19Sderaadt * Redistribution and use in source and binary forms, with or without 85b859c19Sderaadt * modification, are permitted provided that the following conditions 95b859c19Sderaadt * are met: 105b859c19Sderaadt * 1. Redistributions of source code must retain the above copyright 115b859c19Sderaadt * notice, this list of conditions and the following disclaimer. 125b859c19Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 135b859c19Sderaadt * notice, this list of conditions and the following disclaimer in the 145b859c19Sderaadt * documentation and/or other materials provided with the distribution. 155b859c19Sderaadt * 3. All advertising materials mentioning features or use of this software 165b859c19Sderaadt * must display the following acknowledgement: 175b859c19Sderaadt * This product includes software developed by the University of 185b859c19Sderaadt * California, Berkeley and its contributors. 195b859c19Sderaadt * 4. Neither the name of the University nor the names of its contributors 205b859c19Sderaadt * may be used to endorse or promote products derived from this software 215b859c19Sderaadt * without specific prior written permission. 225b859c19Sderaadt * 235b859c19Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 245b859c19Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 255b859c19Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 265b859c19Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 275b859c19Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 285b859c19Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 295b859c19Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 305b859c19Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 315b859c19Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 325b859c19Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 335b859c19Sderaadt * SUCH DAMAGE. 345b859c19Sderaadt */ 355b859c19Sderaadt 36b4551fdeSguenther#include "DEFS.h" 375b859c19Sderaadt 385b859c19Sderaadt /* 395b859c19Sderaadt * memmove (dst,src,cnt) 405b859c19Sderaadt * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 415b859c19Sderaadt */ 425b859c19Sderaadt 43ec0f1ad6SguentherENTRY_NB(bcopy) 445b859c19Sderaadt xchgq %rdi,%rsi 455b859c19Sderaadt /* fall into memmove */ 465b859c19Sderaadt 472f731f58SguentherNENTRY(memmove) 48*eb1d3726Sguenther endbr64 49631951aaSmortimer RETGUARD_SETUP(memmove, r10) 505b859c19Sderaadt movq %rdi,%r11 /* save dest */ 515b859c19Sderaadt movq %rdx,%rcx 525b859c19Sderaadt movq %rdi,%rax 535b859c19Sderaadt subq %rsi,%rax 545b859c19Sderaadt cmpq %rcx,%rax /* overlapping? */ 555b859c19Sderaadt jb 1f 56ea6088e7Sguenther#ifdef memcpy_in_asm 575b859c19Sderaadt jmp 2f /* nope */ 585b859c19Sderaadt 59ec0f1ad6SguentherENTRY_NB(memcpy) 60631951aaSmortimer RETGUARD_SETUP(memmove, r10) 615b859c19Sderaadt movq %rdi,%r11 /* save dest */ 625b859c19Sderaadt movq %rdx,%rcx 635b859c19Sderaadt2: 64ea6088e7Sguenther#endif 655b859c19Sderaadt cld /* copy forwards. */ 665b859c19Sderaadt shrq $3,%rcx /* copy by words */ 675b859c19Sderaadt rep 685b859c19Sderaadt movsq 695b859c19Sderaadt movq %rdx,%rcx 705b859c19Sderaadt andq $7,%rcx /* any bytes left? */ 715b859c19Sderaadt rep 725b859c19Sderaadt movsb 735b859c19Sderaadt movq %r11,%rax 74631951aaSmortimer jmp 3f 755b859c19Sderaadt1: 765b859c19Sderaadt addq %rcx,%rdi /* copy backwards. */ 775b859c19Sderaadt addq %rcx,%rsi 785b859c19Sderaadt std 795b859c19Sderaadt andq $7,%rcx /* any fractional bytes? */ 805b859c19Sderaadt decq %rdi 815b859c19Sderaadt decq %rsi 825b859c19Sderaadt rep 835b859c19Sderaadt movsb 845b859c19Sderaadt movq %rdx,%rcx /* copy remainder by words */ 855b859c19Sderaadt shrq $3,%rcx 865b859c19Sderaadt subq $7,%rsi 875b859c19Sderaadt subq $7,%rdi 885b859c19Sderaadt rep 895b859c19Sderaadt movsq 905b859c19Sderaadt movq %r11,%rax 915b859c19Sderaadt cld 92631951aaSmortimer3: RETGUARD_CHECK(memmove, r10) 935b859c19Sderaadt ret 94ea6088e7Sguenther#ifdef memcpy_in_asm 95ea6088e7SguentherEND_BUILTIN(memcpy) 96ea6088e7Sguenther#endif 97ea6088e7SguentherEND_BUILTIN(memmove) 989b9d2a55SguentherEND_WEAK(bcopy) 99