1 1.1 scole /* $NetBSD: bcopy.S,v 1.1 2016/08/05 15:06:02 scole Exp $ */ 2 1.1 scole 3 1.1 scole /*- 4 1.1 scole * Copyright (c) 2000 Doug Rabson 5 1.1 scole * All rights reserved. 6 1.1 scole * 7 1.1 scole * Redistribution and use in source and binary forms, with or without 8 1.1 scole * modification, are permitted provided that the following conditions 9 1.1 scole * are met: 10 1.1 scole * 1. Redistributions of source code must retain the above copyright 11 1.1 scole * notice, this list of conditions and the following disclaimer. 12 1.1 scole * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 scole * notice, this list of conditions and the following disclaimer in the 14 1.1 scole * documentation and/or other materials provided with the distribution. 15 1.1 scole * 16 1.1 scole * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 1.1 scole * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.1 scole * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.1 scole * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 1.1 scole * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.1 scole * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.1 scole * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.1 scole * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.1 scole * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.1 scole * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.1 scole * SUCH DAMAGE. 27 1.1 scole * 28 1.1 scole * __FBSDID("$FreeBSD: releng/10.1/lib/libc/ia64/string/bcopy.S 125669 2004-02-10 20:45:28Z cperciva $"); 29 1.1 scole */ 30 1.1 scole 31 1.1 scole #include <machine/asm.h> 32 1.1 scole 33 1.1 scole /* 34 1.1 scole * void 35 1.1 scole * bcopy(const void *src, void *dst, size_t len); 36 1.1 scole */ 37 1.1 scole 38 1.1 scole /* 39 1.1 scole * Not the fastest bcopy in the world. 40 1.1 scole */ 41 1.1 scole ENTRY(bcopy, 3) 42 1.1 scole 43 1.1 scole cmp.le p6,p0=in2,r0 // bail if len <= 0 44 1.1 scole (p6) br.ret.spnt.few rp 45 1.1 scole 46 1.1 scole sub r14=in1,in0 ;; // check for overlap 47 1.1 scole cmp.ltu p6,p0=r14,in2 // dst-src < len 48 1.1 scole (p6) br.cond.spnt.few 5f 49 1.1 scole 50 1.1 scole extr.u r14=in0,0,3 // src & 7 51 1.1 scole extr.u r15=in1,0,3 ;; // dst & 7 52 1.1 scole cmp.eq p6,p0=r14,r15 // different alignment? 53 1.1 scole (p6) br.cond.spnt.few 2f // branch if same alignment 54 1.1 scole 55 1.1 scole 1: ld1 r14=[in0],1 ;; // copy bytewise 56 1.1 scole st1 [in1]=r14,1 57 1.1 scole add in2=-1,in2 ;; // len-- 58 1.1 scole cmp.ne p6,p0=r0,in2 59 1.1 scole (p6) br.cond.dptk.few 1b // loop 60 1.1 scole br.ret.sptk.few rp // done 61 1.1 scole 62 1.1 scole 2: cmp.eq p6,p0=r14,r0 // aligned? 63 1.1 scole (p6) br.cond.sptk.few 4f 64 1.1 scole 65 1.1 scole 3: ld1 r14=[in0],1 ;; // copy bytewise 66 1.1 scole st1 [in1]=r14,1 67 1.1 scole extr.u r15=in0,0,3 // src & 7 68 1.1 scole add in2=-1,in2 ;; // len-- 69 1.1 scole cmp.eq p6,p0=r0,in2 // done? 70 1.1 scole cmp.eq p7,p0=r0,r15 ;; // aligned now? 71 1.1 scole (p6) br.ret.spnt.few rp // return if done 72 1.1 scole (p7) br.cond.spnt.few 4f // go to main copy 73 1.1 scole br.cond.sptk.few 3b // more bytes to copy 74 1.1 scole 75 1.1 scole // At this point, in2 is non-zero 76 1.1 scole 77 1.1 scole 4: mov r14=8 ;; 78 1.1 scole cmp.ltu p6,p0=in2,r14 ;; // len < 8? 79 1.1 scole (p6) br.cond.spnt.few 1b // byte copy the end 80 1.1 scole ld8 r15=[in0],8 ;; // copy word 81 1.1 scole st8 [in1]=r15,8 82 1.1 scole add in2=-8,in2 ;; // len -= 8 83 1.1 scole cmp.ne p6,p0=r0,in2 // done? 84 1.1 scole (p6) br.cond.spnt.few 4b // again 85 1.1 scole 86 1.1 scole br.ret.sptk.few rp // return 87 1.1 scole 88 1.1 scole // Don't bother optimising overlap case 89 1.1 scole 90 1.1 scole 5: add in0=in0,in2 91 1.1 scole add in1=in1,in2 ;; 92 1.1 scole add in0=-1,in0 93 1.1 scole add in1=-1,in1 ;; 94 1.1 scole 95 1.1 scole 6: ld1 r14=[in0],-1 ;; 96 1.1 scole st1 [in1]=r14,-1 97 1.1 scole add in2=-1,in2 ;; 98 1.1 scole cmp.ne p6,p0=r0,in2 99 1.1 scole (p6) br.cond.spnt.few 6b 100 1.1 scole 101 1.1 scole br.ret.sptk.few rp 102 1.1 scole END(bcopy) 103