1/* $NetBSD: memcpy.S,v 1.3 2011/01/15 07:31:12 matt Exp $ */ 2 3/* stropt/memcpy_440.S, pl_string_common, pl_linux 10/11/04 11:45:36 4 * ========================================================================== 5 * Optimized memcpy implementation for IBM PowerPC 440. 6 * 7 * Copyright (c) 2003, IBM Corporation 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * * Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * * Redistributions in binary form must reproduce the above 18 * copyright notice, this list of conditions and the following 19 * disclaimer in the documentation and/or other materials 20 * provided with the distribution. 21 * * Neither the name of IBM nor the names of its contributors 22 * may be used to endorse or promote products derived from this 23 * software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 31 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 34 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 36 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * 38 * ========================================================================== 39 * 40 * Function: Copy n bytes of the source to the destination. Behavior is 41 * undefined for objects that overlap. 42 * 43 * 44 * void *memcpy(void * dest, const void * src, int n) 45 * 46 * Input: r3 - destination address 47 * r4 - source address 48 * r5 - byte count 49 * Output: r3 - destination address 50 * 51 * ========================================================================== 52 */ 53 54#include <machine/asm.h> 55 56 .text 57 .align 4 58/* LINTSTUB: Func: void *memcpy(void *, const void *, size_t) */ 59ENTRY(memcpy) 60 /* 61 * Check count passed in R5. If zero, return; otherwise continue. 62 */ 63 cmpwi %r5,0 64 beqlr- 65 66 mr %r8, %r3 /* Copy dst (return value) */ 67 68 addi %r4, %r4, -4 /* Prepare for main loop's auto */ 69 addi %r8, %r8, -4 /* update */ 70 71 srwi. %r9,%r5,2 /* Word count -> r9 */ 72 beq- last1 /* Partial copy if <4 bytes */ 73 74 mtctr %r9 /* Word cnt in CTR for loop */ 75 lwzu %r7, 4(%r4) /* Preload for main loop */ 76 77 b g1 78 79g0: /* Main loop */ 80 81 lwzu %r7, 4(%r4) /* Load a new word */ 82 stwu %r6, 4(%r8) /* Store previous word */ 83 84g1: 85 86 bdz- last /* Dec ctr and exit loop if no */ 87 /* more words */ 88 lwzu %r6, 4(%r4) /* Load another word */ 89 stwu %r7, 4(%r8) /* Store previous word */ 90 bdnz+ g0 /* Dec ctr and continue loop if */ 91 /* more words */ 92 93 mr %r7, %r6 94 95last: 96 97 stwu %r7, 4(%r8) /* Store last word */ 98 99last1: /* Byte-by-byte copy */ 100 101 clrlwi. %r5,%r5,30 102 beqlr 103 104 mtctr %r5 105 106 lbzu %r6, 4(%r4) /* 1st byte: update by word */ 107 stbu %r6, 4(%r8) 108 bdzlr- 109 110last2: 111 112 lbzu %r6, 1(%r4) /* Handle the rest */ 113 stbu %r6, 1(%r8) 114 bdnz+ last2 115 116 blr 117END(memcpy) 118