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