xref: /netbsd-src/lib/libc/arch/hppa/string/bzero.S (revision 2af01421ec58ee0b13f04872508d2ab824742d69)
1*2af01421Sskrll/*	$NetBSD: bzero.S,v 1.4 2020/05/05 06:20:55 skrll Exp $	*/
202ac1ae2Sfredette
302ac1ae2Sfredette/*	$OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $	*/
402ac1ae2Sfredette
502ac1ae2Sfredette/*
602ac1ae2Sfredette *  (c) Copyright 1988 HEWLETT-PACKARD COMPANY
702ac1ae2Sfredette *
802ac1ae2Sfredette *  To anyone who acknowledges that this file is provided "AS IS"
902ac1ae2Sfredette *  without any express or implied warranty:
1002ac1ae2Sfredette *      permission to use, copy, modify, and distribute this file
1102ac1ae2Sfredette *  for any purpose is hereby granted without fee, provided that
1202ac1ae2Sfredette *  the above copyright notice and this notice appears in all
1302ac1ae2Sfredette *  copies, and that the name of Hewlett-Packard Company not be
1402ac1ae2Sfredette *  used in advertising or publicity pertaining to distribution
1502ac1ae2Sfredette *  of the software without specific, written prior permission.
1602ac1ae2Sfredette *  Hewlett-Packard Company makes no representations about the
1702ac1ae2Sfredette *  suitability of this software for any purpose.
1802ac1ae2Sfredette */
1902ac1ae2Sfredette/*
2002ac1ae2Sfredette * Copyright (c) 1990,1994 The University of Utah and
2102ac1ae2Sfredette * the Computer Systems Laboratory (CSL).  All rights reserved.
2202ac1ae2Sfredette *
2302ac1ae2Sfredette * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS"
2402ac1ae2Sfredette * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
2502ac1ae2Sfredette * WHATSOEVER RESULTING FROM ITS USE.
2602ac1ae2Sfredette *
2702ac1ae2Sfredette * CSL requests users of this software to return to csl-dist@cs.utah.edu any
2802ac1ae2Sfredette * improvements that they make and grant CSL redistribution rights.
2902ac1ae2Sfredette *
3002ac1ae2Sfredette * 	Utah $Hdr: bzero.s 1.9 94/12/14$
3102ac1ae2Sfredette *	Author: Bob Wheeler, University of Utah CSL
3202ac1ae2Sfredette */
3302ac1ae2Sfredette
3402ac1ae2Sfredette#include <machine/asm.h>
3502ac1ae2Sfredette
3602ac1ae2Sfredette#ifdef SYSLIBC_SCCS
3702ac1ae2Sfredette	.text
3802ac1ae2Sfredette	.asciz "$OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $"
3902ac1ae2Sfredette	.align	4
4002ac1ae2Sfredette#endif
4102ac1ae2Sfredette
4202ac1ae2Sfredette/*
4302ac1ae2Sfredette * void
4402ac1ae2Sfredette * bzero(dst, count)
45ed9d4336Smatt *	void *dst;
46ed9d4336Smatt *	size_t count;
4702ac1ae2Sfredette */
4802ac1ae2SfredetteLEAF_ENTRY(bzero)
49ed9d4336Smatt        comb,>=,n %r0,%arg1,$bzero_exit
5002ac1ae2Sfredette
5102ac1ae2Sfredette	/*
5202ac1ae2Sfredette	 * If we need to clear less than a word do it a byte at a time
5302ac1ae2Sfredette	 */
5402ac1ae2Sfredette
55ed9d4336Smatt	comib,>>,n 4,%arg1,$bzero_bytes
5602ac1ae2Sfredette
5702ac1ae2Sfredette	/*
5802ac1ae2Sfredette	 * Since we are only clearing memory the alignment restrictions
5902ac1ae2Sfredette	 * are simplified. Figure out how many "extra" bytes we need to
6002ac1ae2Sfredette	 * store with stbys.
6102ac1ae2Sfredette	 */
6202ac1ae2Sfredette
63ed9d4336Smatt        extru   %arg0,31,2,%t1
64ed9d4336Smatt        add     %arg1,%t1,%arg1
6502ac1ae2Sfredette
6602ac1ae2Sfredette	/*
6702ac1ae2Sfredette	 * We will zero the destination in blocks of 16 bytes as long as we
6802ac1ae2Sfredette	 * can and then we'll go to the 4 byte moves.
6902ac1ae2Sfredette	 */
7002ac1ae2Sfredette
7102ac1ae2Sfredette	comib,>>=	15, %arg1, $bzero_word
7202ac1ae2Sfredette	addi		-16, %arg1, %arg1
7302ac1ae2Sfredette
74ed9d4336Smatt$bzero_loop_16:
75ed9d4336Smatt        stbys,b,m %r0,4(%arg0)
76ed9d4336Smatt        stwm    %r0,4(%arg0)
77ed9d4336Smatt        stwm    %r0,4(%arg0)
78ed9d4336Smatt        stwm    %r0,4(%arg0)
7902ac1ae2Sfredette	comib,<<	15, %arg1, $bzero_loop_16
8002ac1ae2Sfredette	 addi		-16, %arg1, %arg1
8102ac1ae2Sfredette
8202ac1ae2Sfredette	/*
8302ac1ae2Sfredette	 * see if there is anything left that needs to be zeroed in a word
8402ac1ae2Sfredette	 * move. Since the count was decremented by 16, add 12 to test if
8502ac1ae2Sfredette	 * there are any full word moves left to do.
8602ac1ae2Sfredette	 */
8702ac1ae2Sfredette
88ed9d4336Smatt$bzero_word:
89ed9d4336Smatt        addib,<,n 12,%arg1,$bzero_cleanup
9002ac1ae2Sfredette
91ed9d4336Smatt$bzero_loop_4:
92ed9d4336Smatt        addib,>= -4,%arg1,$bzero_loop_4
93ed9d4336Smatt         stbys,b,m %r0,4(%arg0)
9402ac1ae2Sfredette
9502ac1ae2Sfredette	/*
9602ac1ae2Sfredette	 * zero the last bytes that may be unaligned on a word boundary
9702ac1ae2Sfredette	 */
9802ac1ae2Sfredette
99ed9d4336Smatt$bzero_cleanup:
100ed9d4336Smatt        addib,=,n 4,%arg1,$bzero_exit
101ed9d4336Smatt        add	%arg0,%arg1,%arg0
10202ac1ae2Sfredette        b       $bzero_exit
103ed9d4336Smatt         stbys,e %r0,0(%arg0)
10402ac1ae2Sfredette	b,n	$bzero_exit
10502ac1ae2Sfredette
10602ac1ae2Sfredette
10702ac1ae2Sfredette	/*
10802ac1ae2Sfredette	 * zero by bytes
10902ac1ae2Sfredette	 */
11002ac1ae2Sfredette
111ed9d4336Smatt$bzero_bytes:
112ed9d4336Smatt        addib,> -1,%arg1,$bzero_bytes
113ed9d4336Smatt         stbs,ma %r0,1(%arg0)
11402ac1ae2Sfredette
115ed9d4336Smatt$bzero_exit:
11602ac1ae2Sfredette	bv,n	%r0(%rp)
11702ac1ae2SfredetteEXIT(bzero)
11802ac1ae2Sfredette
11902ac1ae2Sfredette	.end
120