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#ifndef _NAMESPACE_CLEAN
24#define NOSECDEF   /* prevent _memset from being defined as entry */
25#endif
26
27#include "DEFS.h"
28
29#define TO	arg0
30#define FILLCHAR arg1
31#define COUNT	arg2
32#define TMP	r31
33
34ENTRY(memset)
35	comb,<=	COUNT,r0,msexit /* return if count not positive */
36	copy	TO,ret0 	/* return value is start of copy */
37	comibf,<,n	5,COUNT,msbyteloop /* be straightforward */
38
39	dep	FILLCHAR,23,8,FILLCHAR	/* dup low byte  */
40	dep	FILLCHAR,15,16,FILLCHAR /* into high bytes */
41
42	add		TO,COUNT,TMP	/* TMP points just past fill area */
43	stbys,m		FILLCHAR,0(TO)	/* fill out first word */
44	/*
45	 * If we're pointing to high-order byte, no fill will happen,
46	 * but permissions will be checked.  We don't want this (we
47	 * might be pointing at the beginning of a protected region),
48	 * so we branch around stbys if neither low bits are set.
49	 */
50	bb,<,n		TMP,31,filend	/* if low bit is set, stbys */
51	bb,>=,n		TMP,30,endfil	/* if next lowest bit isn't set */
52					/*  (and lowest isn't, either) */
53					/*  do not stbys */
54filend:
55	stbys,m,e	FILLCHAR,0(TMP)	/* fill out the last */
56endfil:
57	addi		4, TO, TO
58	sub		TMP,TO,COUNT	/* will now divide by 4 */
59	comb,=,n	COUNT,r0,msexit /* If count is zero ret. */
60
61	extru,<>	COUNT,31,4,r1
62	b		msquadloop
63	depi		0,31,4,COUNT	/* will now divide by 16 */
64
65
66mswordloop:
67	addib,<>	-4,r1,mswordloop
68	stws,ma 	FILLCHAR,4(TO)
69
70	comb,=,n	COUNT,r0,msexit /* If count is zero ret. */
71
72msquadloop:
73	stws,ma 	FILLCHAR,4(TO)
74	stws,ma 	FILLCHAR,4(TO)
75	stws,ma 	FILLCHAR,4(TO)
76	addib,<>	-16,COUNT,msquadloop
77	stws,ma 	FILLCHAR,4(TO)
78	b,n		msexit
79
80msbyteloop:
81	addib,<>	-1,COUNT,msbyteloop
82	stbs,ma		FILLCHAR,1(TO)
83
84msexit:
85EXIT(memset)
86