Home | History | Annotate | Line # | Download | only in string
bzero.S revision 1.3
      1 /*	$NetBSD: bzero.S,v 1.3 2006/07/07 06:53:42 ross Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Ross Harvey.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include	<machine/asm.h>
     40 
     41 	.file	"bzero.c"
     42 ENTRY(bzero)
     43 	mr	5, 4		# translate to memcpy signature
     44 	li	4, 0		# add missing memcpy param
     45 ENTRY(memset)
     46 	cmpldi	7, 5, 7		# only optimize if len >= 8
     47 	mr	9, 3
     48 	ble	7, 2f
     49 	rldicl.	0, 3, 0, 61	# only optimize if aligned
     50 	beq	0, 4f
     51 2:
     52 	cmpdi	7, 5, 0
     53 	beqlr	7
     54 3:
     55 	mtctr	5
     56 	rldicl	0, 4, 0, 56
     57 	.p2align 4,, 15
     58 2:
     59 	stb	0, 0(9)		# byte-at-a-time loop
     60 	addi	9, 9, 1
     61 	bdnz	2b
     62 	blr			# done
     63 4:
     64 	rldicl	4, 4, 0, 56	# construct parallel store
     65 	cmpldi	7, 5, 31
     66 	mr	10, 3
     67 	sldi	0, 4, 8
     68 	or	0, 0, 4
     69 	sldi	9, 0, 16
     70 	or	0, 0, 9
     71 	sldi	11, 0, 32
     72 	or	0, 0, 11
     73 	ble	7, 5f
     74 	addi	9, 5, -32
     75 	srdi	9, 9, 5
     76 	addi	9, 9, 1
     77 	mtctr	9
     78 	.p2align 4,, 15
     79 2:
     80 	std	0, 0(10)	# 8-way + unrolled store loop
     81 	std	0, 8(10)
     82 	addi	5, 5, -32	# schedule count decrement
     83 	std	0, 16(10)
     84 	std	0, 24(10)
     85 	addi	10, 10, 32
     86 	bdnz	2b
     87 	cmpldi	7, 5, 7
     88 	ble	7, 8f
     89 5:
     90 	addi	9, 5, -8
     91 	srdi	9, 9, 3
     92 	addi	9, 9, 1
     93 	mtctr	9
     94 	.p2align 4,, 15
     95 14:
     96 	std	0, 0(10)	# 8-way not-unrolled loop
     97 	addi	5, 5, -8
     98 	addi	10, 10, 8
     99 	bdnz	14b
    100 8:
    101 	cmpdi	7, 5, 0
    102 	mr	9, 10
    103 	bne	7, 3b
    104 	blr
    105 	.long	0
    106 	.byte	0, 0, 0, 0, 0, 0, 0, 0
    107 	.size	.memset, .-.memset
    108