Home | History | Annotate | Line # | Download | only in string
      1 /*	$NetBSD: bzero.S,v 1.1 2016/08/05 15:06:02 scole Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 Doug Rabson
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  * __FBSDID("$FreeBSD: releng/10.1/lib/libc/ia64/string/bzero.S 125669 2004-02-10 20:45:28Z cperciva $");
     29  */
     30 
     31 #include <machine/asm.h>
     32 
     33 /*
     34  * void
     35  * bzero(void *b, size_t len);
     36  */
     37 ENTRY(bzero, 2)
     38 
     39 	cmp.le	p6,p0=in1,r0			// bail if len <= 0
     40 (p6)	br.ret.spnt.few rp
     41 	;;
     42 	mov	r14=ar.lc			// save ar.lc
     43 
     44 	cmp.ltu	p6,p0=17,in1			// check for small
     45 (p6)	br.dptk.few 3f
     46 
     47 1:	add	r15=-1,in1 ;;
     48 	mov	ar.lc=r15 ;;
     49 2:	st1	[in0]=r0,1			// zero one byte
     50 	br.cloop.sptk.few 2b			// loop
     51 
     52 	;;
     53 	mov	ar.lc=r14			// done
     54 	br.ret.sptk.few rp
     55 
     56 	// Zero up to 8byte alignment
     57 
     58 3:	tbit.nz	p6,p0=in0,0 ;;
     59 (p6)	st1	[in0]=r0,1
     60 (p6)	add	in1=-1,in1 ;;
     61 
     62 	tbit.nz	p6,p0=in0,1 ;;
     63 (p6)	st2	[in0]=r0,2
     64 (p6)	add	in1=-2,in1 ;;
     65 
     66 	tbit.nz	p6,p0=in0,2 ;;
     67 (p6)	st4	[in0]=r0,4
     68 (p6)	add	in1=-4,in1
     69 
     70 	;;
     71 	shr.u	r15=in1,3			// word count
     72 	extr.u	in1=in1,0,3 ;;			// trailing bytes
     73 	cmp.eq	p6,p0=r15,r0			// check for zero
     74 	cmp.ne	p7,p0=in1,r0
     75 (p6)	br.dpnt.few 1b				// zero last bytes
     76 
     77 	add	r15=-1,r15 ;;
     78 	mov	ar.lc=r15 ;;
     79 4:	st8	[in0]=r0,8
     80 	br.cloop.sptk.few 4b
     81 
     82 (p7)	br.dpnt.few 1b				// zero last bytes
     83 
     84 	;;
     85 	mov	ar.lc=r14			// done
     86 	br.ret.sptk.few rp
     87 
     88 END(bzero)
     89