1/*
2 *  (c) Copyright 1986 HEWLETT-PACKARD COMPANY
3 *
4 *  To anyone who acknowledges that this file is provided "AS IS"
5 *  without any express or implied warranty:
6 *      permission to use, copy, modify, and distribute this file
7 *  for any purpose is hereby granted without fee, provided that
8 *  the above copyright notice and this notice appears in all
9 *  copies, and that the name of Hewlett-Packard Company not be
10 *  used in advertising or publicity pertaining to distribution
11 *  of the software without specific, written prior permission.
12 *  Hewlett-Packard Company makes no representations about the
13 *  suitability of this software for any purpose.
14 */
15
16/* SPECTRUM_ID: @(#)memset.s	37.4     86/08/25 */
17/*
18 * memset(s, c, n)
19 *
20 * Sets first n chars in memory area s to value of character c.
21 * Returns s.
22 */
23#include <picolibc.h>
24
25#ifndef _NAMESPACE_CLEAN
26#define NOSECDEF   /* prevent _memset from being defined as entry */
27#endif
28
29#include "DEFS.h"
30
31#define TO	arg0
32#define FILLCHAR arg1
33#define COUNT	arg2
34#define TMP	r31
35
36ENTRY(memset)
37	comb,<=	COUNT,r0,msexit /* return if count not positive */
38	copy	TO,ret0 	/* return value is start of copy */
39	comibf,<,n	5,COUNT,msbyteloop /* be straightforward */
40
41	dep	FILLCHAR,23,8,FILLCHAR	/* dup low byte  */
42	dep	FILLCHAR,15,16,FILLCHAR /* into high bytes */
43
44	add		TO,COUNT,TMP	/* TMP points just past fill area */
45	stbys,m		FILLCHAR,0(TO)	/* fill out first word */
46	/*
47	 * If we're pointing to high-order byte, no fill will happen,
48	 * but permissions will be checked.  We don't want this (we
49	 * might be pointing at the beginning of a protected region),
50	 * so we branch around stbys if neither low bits are set.
51	 */
52	bb,<,n		TMP,31,filend	/* if low bit is set, stbys */
53	bb,>=,n		TMP,30,endfil	/* if next lowest bit isn't set */
54					/*  (and lowest isn't, either) */
55					/*  do not stbys */
56filend:
57	stbys,m,e	FILLCHAR,0(TMP)	/* fill out the last */
58endfil:
59	addi		4, TO, TO
60	sub		TMP,TO,COUNT	/* will now divide by 4 */
61	comb,=,n	COUNT,r0,msexit /* If count is zero ret. */
62
63	extru,<>	COUNT,31,4,r1
64	b		msquadloop
65	depi		0,31,4,COUNT	/* will now divide by 16 */
66
67
68mswordloop:
69	addib,<>	-4,r1,mswordloop
70	stws,ma 	FILLCHAR,4(TO)
71
72	comb,=,n	COUNT,r0,msexit /* If count is zero ret. */
73
74msquadloop:
75	stws,ma 	FILLCHAR,4(TO)
76	stws,ma 	FILLCHAR,4(TO)
77	stws,ma 	FILLCHAR,4(TO)
78	addib,<>	-16,COUNT,msquadloop
79	stws,ma 	FILLCHAR,4(TO)
80	b,n		msexit
81
82msbyteloop:
83	addib,<>	-1,COUNT,msbyteloop
84	stbs,ma		FILLCHAR,1(TO)
85
86msexit:
87EXIT(memset)
88