xref: /kernel/linux/linux-6.6/arch/ia64/lib/memset.S (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Optimized version of the standard memset() function.
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci   Copyright (c) 2002 Hewlett-Packard Co/CERN
562306a36Sopenharmony_ci	Sverre Jarp <Sverre.Jarp@cern.ch>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci   Return: dest
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci   Inputs:
1062306a36Sopenharmony_ci        in0:    dest
1162306a36Sopenharmony_ci        in1:    value
1262306a36Sopenharmony_ci        in2:    count
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci   The algorithm is fairly straightforward: set byte by byte until we
1562306a36Sopenharmony_ci   we get to a 16B-aligned address, then loop on 128 B chunks using an
1662306a36Sopenharmony_ci   early store as prefetching, then loop on 32B chucks, then clear remaining
1762306a36Sopenharmony_ci   words, finally clear remaining bytes.
1862306a36Sopenharmony_ci   Since a stf.spill f0 can store 16B in one go, we use this instruction
1962306a36Sopenharmony_ci   to get peak speed when value = 0.  */
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#include <linux/export.h>
2262306a36Sopenharmony_ci#include <asm/asmmacro.h>
2362306a36Sopenharmony_ci#undef ret
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define dest		in0
2662306a36Sopenharmony_ci#define value		in1
2762306a36Sopenharmony_ci#define	cnt		in2
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define tmp		r31
3062306a36Sopenharmony_ci#define save_lc		r30
3162306a36Sopenharmony_ci#define ptr0		r29
3262306a36Sopenharmony_ci#define ptr1		r28
3362306a36Sopenharmony_ci#define ptr2		r27
3462306a36Sopenharmony_ci#define ptr3		r26
3562306a36Sopenharmony_ci#define ptr9 		r24
3662306a36Sopenharmony_ci#define	loopcnt		r23
3762306a36Sopenharmony_ci#define linecnt		r22
3862306a36Sopenharmony_ci#define bytecnt		r21
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define fvalue		f6
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci// This routine uses only scratch predicate registers (p6 - p15)
4362306a36Sopenharmony_ci#define p_scr		p6			// default register for same-cycle branches
4462306a36Sopenharmony_ci#define p_nz		p7
4562306a36Sopenharmony_ci#define p_zr		p8
4662306a36Sopenharmony_ci#define p_unalgn	p9
4762306a36Sopenharmony_ci#define p_y		p11
4862306a36Sopenharmony_ci#define p_n		p12
4962306a36Sopenharmony_ci#define p_yy		p13
5062306a36Sopenharmony_ci#define p_nn		p14
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define MIN1		15
5362306a36Sopenharmony_ci#define MIN1P1HALF	8
5462306a36Sopenharmony_ci#define LINE_SIZE	128
5562306a36Sopenharmony_ci#define LSIZE_SH        7			// shift amount
5662306a36Sopenharmony_ci#define PREF_AHEAD	8
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciGLOBAL_ENTRY(memset)
5962306a36Sopenharmony_ci{ .mmi
6062306a36Sopenharmony_ci	.prologue
6162306a36Sopenharmony_ci	alloc	tmp = ar.pfs, 3, 0, 0, 0
6262306a36Sopenharmony_ci	lfetch.nt1 [dest]			//
6362306a36Sopenharmony_ci	.save   ar.lc, save_lc
6462306a36Sopenharmony_ci	mov.i	save_lc = ar.lc
6562306a36Sopenharmony_ci	.body
6662306a36Sopenharmony_ci} { .mmi
6762306a36Sopenharmony_ci	mov	ret0 = dest			// return value
6862306a36Sopenharmony_ci	cmp.ne	p_nz, p_zr = value, r0		// use stf.spill if value is zero
6962306a36Sopenharmony_ci	cmp.eq	p_scr, p0 = cnt, r0
7062306a36Sopenharmony_ci;; }
7162306a36Sopenharmony_ci{ .mmi
7262306a36Sopenharmony_ci	and	ptr2 = -(MIN1+1), dest		// aligned address
7362306a36Sopenharmony_ci	and	tmp = MIN1, dest		// prepare to check for correct alignment
7462306a36Sopenharmony_ci	tbit.nz p_y, p_n = dest, 0		// Do we have an odd address? (M_B_U)
7562306a36Sopenharmony_ci} { .mib
7662306a36Sopenharmony_ci	mov	ptr1 = dest
7762306a36Sopenharmony_ci	mux1	value = value, @brcst		// create 8 identical bytes in word
7862306a36Sopenharmony_ci(p_scr)	br.ret.dpnt.many rp			// return immediately if count = 0
7962306a36Sopenharmony_ci;; }
8062306a36Sopenharmony_ci{ .mib
8162306a36Sopenharmony_ci	cmp.ne	p_unalgn, p0 = tmp, r0		//
8262306a36Sopenharmony_ci} { .mib
8362306a36Sopenharmony_ci	sub	bytecnt = (MIN1+1), tmp		// NB: # of bytes to move is 1 higher than loopcnt
8462306a36Sopenharmony_ci	cmp.gt	p_scr, p0 = 16, cnt		// is it a minimalistic task?
8562306a36Sopenharmony_ci(p_scr)	br.cond.dptk.many .move_bytes_unaligned	// go move just a few (M_B_U)
8662306a36Sopenharmony_ci;; }
8762306a36Sopenharmony_ci{ .mmi
8862306a36Sopenharmony_ci(p_unalgn) add	ptr1 = (MIN1+1), ptr2		// after alignment
8962306a36Sopenharmony_ci(p_unalgn) add	ptr2 = MIN1P1HALF, ptr2		// after alignment
9062306a36Sopenharmony_ci(p_unalgn) tbit.nz.unc p_y, p_n = bytecnt, 3	// should we do a st8 ?
9162306a36Sopenharmony_ci;; }
9262306a36Sopenharmony_ci{ .mib
9362306a36Sopenharmony_ci(p_y)	add	cnt = -8, cnt			//
9462306a36Sopenharmony_ci(p_unalgn) tbit.nz.unc p_yy, p_nn = bytecnt, 2	// should we do a st4 ?
9562306a36Sopenharmony_ci} { .mib
9662306a36Sopenharmony_ci(p_y)	st8	[ptr2] = value,-4		//
9762306a36Sopenharmony_ci(p_n)	add	ptr2 = 4, ptr2			//
9862306a36Sopenharmony_ci;; }
9962306a36Sopenharmony_ci{ .mib
10062306a36Sopenharmony_ci(p_yy)	add	cnt = -4, cnt			//
10162306a36Sopenharmony_ci(p_unalgn) tbit.nz.unc p_y, p_n = bytecnt, 1	// should we do a st2 ?
10262306a36Sopenharmony_ci} { .mib
10362306a36Sopenharmony_ci(p_yy)	st4	[ptr2] = value,-2		//
10462306a36Sopenharmony_ci(p_nn)	add	ptr2 = 2, ptr2			//
10562306a36Sopenharmony_ci;; }
10662306a36Sopenharmony_ci{ .mmi
10762306a36Sopenharmony_ci	mov	tmp = LINE_SIZE+1		// for compare
10862306a36Sopenharmony_ci(p_y)	add	cnt = -2, cnt			//
10962306a36Sopenharmony_ci(p_unalgn) tbit.nz.unc p_yy, p_nn = bytecnt, 0	// should we do a st1 ?
11062306a36Sopenharmony_ci} { .mmi
11162306a36Sopenharmony_ci	setf.sig fvalue=value			// transfer value to FLP side
11262306a36Sopenharmony_ci(p_y)	st2	[ptr2] = value,-1		//
11362306a36Sopenharmony_ci(p_n)	add	ptr2 = 1, ptr2			//
11462306a36Sopenharmony_ci;; }
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci{ .mmi
11762306a36Sopenharmony_ci(p_yy)	st1	[ptr2] = value 			//
11862306a36Sopenharmony_ci  	cmp.gt	p_scr, p0 = tmp, cnt		// is it a minimalistic task?
11962306a36Sopenharmony_ci} { .mbb
12062306a36Sopenharmony_ci(p_yy)	add	cnt = -1, cnt			//
12162306a36Sopenharmony_ci(p_scr)	br.cond.dpnt.many .fraction_of_line	// go move just a few
12262306a36Sopenharmony_ci;; }
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci{ .mib
12562306a36Sopenharmony_ci	nop.m 0
12662306a36Sopenharmony_ci	shr.u	linecnt = cnt, LSIZE_SH
12762306a36Sopenharmony_ci(p_zr)	br.cond.dptk.many .l1b			// Jump to use stf.spill
12862306a36Sopenharmony_ci;; }
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	TEXT_ALIGN(32) // --------------------- //  L1A: store ahead into cache lines; fill later
13162306a36Sopenharmony_ci{ .mmi
13262306a36Sopenharmony_ci	and	tmp = -(LINE_SIZE), cnt		// compute end of range
13362306a36Sopenharmony_ci	mov	ptr9 = ptr1			// used for prefetching
13462306a36Sopenharmony_ci	and	cnt = (LINE_SIZE-1), cnt	// remainder
13562306a36Sopenharmony_ci} { .mmi
13662306a36Sopenharmony_ci	mov	loopcnt = PREF_AHEAD-1		// default prefetch loop
13762306a36Sopenharmony_ci	cmp.gt	p_scr, p0 = PREF_AHEAD, linecnt	// check against actual value
13862306a36Sopenharmony_ci;; }
13962306a36Sopenharmony_ci{ .mmi
14062306a36Sopenharmony_ci(p_scr)	add	loopcnt = -1, linecnt		//
14162306a36Sopenharmony_ci	add	ptr2 = 8, ptr1			// start of stores (beyond prefetch stores)
14262306a36Sopenharmony_ci	add	ptr1 = tmp, ptr1		// first address beyond total range
14362306a36Sopenharmony_ci;; }
14462306a36Sopenharmony_ci{ .mmi
14562306a36Sopenharmony_ci	add	tmp = -1, linecnt		// next loop count
14662306a36Sopenharmony_ci	mov.i	ar.lc = loopcnt			//
14762306a36Sopenharmony_ci;; }
14862306a36Sopenharmony_ci.pref_l1a:
14962306a36Sopenharmony_ci{ .mib
15062306a36Sopenharmony_ci	stf8 [ptr9] = fvalue, 128		// Do stores one cache line apart
15162306a36Sopenharmony_ci	nop.i	0
15262306a36Sopenharmony_ci	br.cloop.dptk.few .pref_l1a
15362306a36Sopenharmony_ci;; }
15462306a36Sopenharmony_ci{ .mmi
15562306a36Sopenharmony_ci	add	ptr0 = 16, ptr2			// Two stores in parallel
15662306a36Sopenharmony_ci	mov.i	ar.lc = tmp			//
15762306a36Sopenharmony_ci;; }
15862306a36Sopenharmony_ci.l1ax:
15962306a36Sopenharmony_ci { .mmi
16062306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
16162306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
16262306a36Sopenharmony_ci ;; }
16362306a36Sopenharmony_ci { .mmi
16462306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
16562306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
16662306a36Sopenharmony_ci ;; }
16762306a36Sopenharmony_ci { .mmi
16862306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
16962306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
17062306a36Sopenharmony_ci ;; }
17162306a36Sopenharmony_ci { .mmi
17262306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
17362306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
17462306a36Sopenharmony_ci ;; }
17562306a36Sopenharmony_ci { .mmi
17662306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
17762306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
17862306a36Sopenharmony_ci ;; }
17962306a36Sopenharmony_ci { .mmi
18062306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
18162306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
18262306a36Sopenharmony_ci ;; }
18362306a36Sopenharmony_ci { .mmi
18462306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
18562306a36Sopenharmony_ci	stf8 [ptr0] = fvalue, 32
18662306a36Sopenharmony_ci 	cmp.lt	p_scr, p0 = ptr9, ptr1		// do we need more prefetching?
18762306a36Sopenharmony_ci ;; }
18862306a36Sopenharmony_ci{ .mmb
18962306a36Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
19062306a36Sopenharmony_ci(p_scr)	stf8 [ptr9] = fvalue, 128
19162306a36Sopenharmony_ci	br.cloop.dptk.few .l1ax
19262306a36Sopenharmony_ci;; }
19362306a36Sopenharmony_ci{ .mbb
19462306a36Sopenharmony_ci	cmp.le  p_scr, p0 = 8, cnt		// just a few bytes left ?
19562306a36Sopenharmony_ci(p_scr) br.cond.dpnt.many  .fraction_of_line	// Branch no. 2
19662306a36Sopenharmony_ci	br.cond.dpnt.many  .move_bytes_from_alignment	// Branch no. 3
19762306a36Sopenharmony_ci;; }
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci	TEXT_ALIGN(32)
20062306a36Sopenharmony_ci.l1b:	// ------------------------------------ //  L1B: store ahead into cache lines; fill later
20162306a36Sopenharmony_ci{ .mmi
20262306a36Sopenharmony_ci	and	tmp = -(LINE_SIZE), cnt		// compute end of range
20362306a36Sopenharmony_ci	mov	ptr9 = ptr1			// used for prefetching
20462306a36Sopenharmony_ci	and	cnt = (LINE_SIZE-1), cnt	// remainder
20562306a36Sopenharmony_ci} { .mmi
20662306a36Sopenharmony_ci	mov	loopcnt = PREF_AHEAD-1		// default prefetch loop
20762306a36Sopenharmony_ci	cmp.gt	p_scr, p0 = PREF_AHEAD, linecnt	// check against actual value
20862306a36Sopenharmony_ci;; }
20962306a36Sopenharmony_ci{ .mmi
21062306a36Sopenharmony_ci(p_scr)	add	loopcnt = -1, linecnt
21162306a36Sopenharmony_ci	add	ptr2 = 16, ptr1			// start of stores (beyond prefetch stores)
21262306a36Sopenharmony_ci	add	ptr1 = tmp, ptr1		// first address beyond total range
21362306a36Sopenharmony_ci;; }
21462306a36Sopenharmony_ci{ .mmi
21562306a36Sopenharmony_ci	add	tmp = -1, linecnt		// next loop count
21662306a36Sopenharmony_ci	mov.i	ar.lc = loopcnt
21762306a36Sopenharmony_ci;; }
21862306a36Sopenharmony_ci.pref_l1b:
21962306a36Sopenharmony_ci{ .mib
22062306a36Sopenharmony_ci	stf.spill [ptr9] = f0, 128		// Do stores one cache line apart
22162306a36Sopenharmony_ci	nop.i   0
22262306a36Sopenharmony_ci	br.cloop.dptk.few .pref_l1b
22362306a36Sopenharmony_ci;; }
22462306a36Sopenharmony_ci{ .mmi
22562306a36Sopenharmony_ci	add	ptr0 = 16, ptr2			// Two stores in parallel
22662306a36Sopenharmony_ci	mov.i	ar.lc = tmp
22762306a36Sopenharmony_ci;; }
22862306a36Sopenharmony_ci.l1bx:
22962306a36Sopenharmony_ci { .mmi
23062306a36Sopenharmony_ci	stf.spill [ptr2] = f0, 32
23162306a36Sopenharmony_ci	stf.spill [ptr0] = f0, 32
23262306a36Sopenharmony_ci ;; }
23362306a36Sopenharmony_ci { .mmi
23462306a36Sopenharmony_ci	stf.spill [ptr2] = f0, 32
23562306a36Sopenharmony_ci	stf.spill [ptr0] = f0, 32
23662306a36Sopenharmony_ci ;; }
23762306a36Sopenharmony_ci { .mmi
23862306a36Sopenharmony_ci	stf.spill [ptr2] = f0, 32
23962306a36Sopenharmony_ci	stf.spill [ptr0] = f0, 64
24062306a36Sopenharmony_ci 	cmp.lt	p_scr, p0 = ptr9, ptr1		// do we need more prefetching?
24162306a36Sopenharmony_ci ;; }
24262306a36Sopenharmony_ci{ .mmb
24362306a36Sopenharmony_ci	stf.spill [ptr2] = f0, 32
24462306a36Sopenharmony_ci(p_scr)	stf.spill [ptr9] = f0, 128
24562306a36Sopenharmony_ci	br.cloop.dptk.few .l1bx
24662306a36Sopenharmony_ci;; }
24762306a36Sopenharmony_ci{ .mib
24862306a36Sopenharmony_ci	cmp.gt  p_scr, p0 = 8, cnt		// just a few bytes left ?
24962306a36Sopenharmony_ci(p_scr)	br.cond.dpnt.many  .move_bytes_from_alignment	//
25062306a36Sopenharmony_ci;; }
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci.fraction_of_line:
25362306a36Sopenharmony_ci{ .mib
25462306a36Sopenharmony_ci	add	ptr2 = 16, ptr1
25562306a36Sopenharmony_ci	shr.u	loopcnt = cnt, 5   		// loopcnt = cnt / 32
25662306a36Sopenharmony_ci;; }
25762306a36Sopenharmony_ci{ .mib
25862306a36Sopenharmony_ci	cmp.eq	p_scr, p0 = loopcnt, r0
25962306a36Sopenharmony_ci	add	loopcnt = -1, loopcnt
26062306a36Sopenharmony_ci(p_scr)	br.cond.dpnt.many .store_words
26162306a36Sopenharmony_ci;; }
26262306a36Sopenharmony_ci{ .mib
26362306a36Sopenharmony_ci	and	cnt = 0x1f, cnt			// compute the remaining cnt
26462306a36Sopenharmony_ci	mov.i   ar.lc = loopcnt
26562306a36Sopenharmony_ci;; }
26662306a36Sopenharmony_ci	TEXT_ALIGN(32)
26762306a36Sopenharmony_ci.l2:	// ------------------------------------ //  L2A:  store 32B in 2 cycles
26862306a36Sopenharmony_ci{ .mmb
26962306a36Sopenharmony_ci	stf8	[ptr1] = fvalue, 8
27062306a36Sopenharmony_ci	stf8	[ptr2] = fvalue, 8
27162306a36Sopenharmony_ci;; } { .mmb
27262306a36Sopenharmony_ci	stf8	[ptr1] = fvalue, 24
27362306a36Sopenharmony_ci	stf8	[ptr2] = fvalue, 24
27462306a36Sopenharmony_ci	br.cloop.dptk.many .l2
27562306a36Sopenharmony_ci;; }
27662306a36Sopenharmony_ci.store_words:
27762306a36Sopenharmony_ci{ .mib
27862306a36Sopenharmony_ci	cmp.gt	p_scr, p0 = 8, cnt		// just a few bytes left ?
27962306a36Sopenharmony_ci(p_scr)	br.cond.dpnt.many .move_bytes_from_alignment	// Branch
28062306a36Sopenharmony_ci;; }
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci{ .mmi
28362306a36Sopenharmony_ci	stf8	[ptr1] = fvalue, 8		// store
28462306a36Sopenharmony_ci	cmp.le	p_y, p_n = 16, cnt
28562306a36Sopenharmony_ci	add	cnt = -8, cnt			// subtract
28662306a36Sopenharmony_ci;; }
28762306a36Sopenharmony_ci{ .mmi
28862306a36Sopenharmony_ci(p_y)	stf8	[ptr1] = fvalue, 8		// store
28962306a36Sopenharmony_ci(p_y)	cmp.le.unc p_yy, p_nn = 16, cnt
29062306a36Sopenharmony_ci(p_y)	add	cnt = -8, cnt			// subtract
29162306a36Sopenharmony_ci;; }
29262306a36Sopenharmony_ci{ .mmi						// store
29362306a36Sopenharmony_ci(p_yy)	stf8	[ptr1] = fvalue, 8
29462306a36Sopenharmony_ci(p_yy)	add	cnt = -8, cnt			// subtract
29562306a36Sopenharmony_ci;; }
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_ci.move_bytes_from_alignment:
29862306a36Sopenharmony_ci{ .mib
29962306a36Sopenharmony_ci	cmp.eq	p_scr, p0 = cnt, r0
30062306a36Sopenharmony_ci	tbit.nz.unc p_y, p0 = cnt, 2		// should we terminate with a st4 ?
30162306a36Sopenharmony_ci(p_scr)	br.cond.dpnt.few .restore_and_exit
30262306a36Sopenharmony_ci;; }
30362306a36Sopenharmony_ci{ .mib
30462306a36Sopenharmony_ci(p_y)	st4	[ptr1] = value,4
30562306a36Sopenharmony_ci	tbit.nz.unc p_yy, p0 = cnt, 1		// should we terminate with a st2 ?
30662306a36Sopenharmony_ci;; }
30762306a36Sopenharmony_ci{ .mib
30862306a36Sopenharmony_ci(p_yy)	st2	[ptr1] = value,2
30962306a36Sopenharmony_ci	tbit.nz.unc p_y, p0 = cnt, 0		// should we terminate with a st1 ?
31062306a36Sopenharmony_ci;; }
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci{ .mib
31362306a36Sopenharmony_ci(p_y)	st1	[ptr1] = value
31462306a36Sopenharmony_ci;; }
31562306a36Sopenharmony_ci.restore_and_exit:
31662306a36Sopenharmony_ci{ .mib
31762306a36Sopenharmony_ci	nop.m	0
31862306a36Sopenharmony_ci	mov.i	ar.lc = save_lc
31962306a36Sopenharmony_ci	br.ret.sptk.many rp
32062306a36Sopenharmony_ci;; }
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci.move_bytes_unaligned:
32362306a36Sopenharmony_ci{ .mmi
32462306a36Sopenharmony_ci       .pred.rel "mutex",p_y, p_n
32562306a36Sopenharmony_ci       .pred.rel "mutex",p_yy, p_nn
32662306a36Sopenharmony_ci(p_n)	cmp.le  p_yy, p_nn = 4, cnt
32762306a36Sopenharmony_ci(p_y)	cmp.le  p_yy, p_nn = 5, cnt
32862306a36Sopenharmony_ci(p_n)	add	ptr2 = 2, ptr1
32962306a36Sopenharmony_ci} { .mmi
33062306a36Sopenharmony_ci(p_y)	add	ptr2 = 3, ptr1
33162306a36Sopenharmony_ci(p_y)	st1	[ptr1] = value, 1		// fill 1 (odd-aligned) byte [15, 14 (or less) left]
33262306a36Sopenharmony_ci(p_y)	add	cnt = -1, cnt
33362306a36Sopenharmony_ci;; }
33462306a36Sopenharmony_ci{ .mmi
33562306a36Sopenharmony_ci(p_yy)	cmp.le.unc p_y, p0 = 8, cnt
33662306a36Sopenharmony_ci	add	ptr3 = ptr1, cnt		// prepare last store
33762306a36Sopenharmony_ci	mov.i	ar.lc = save_lc
33862306a36Sopenharmony_ci} { .mmi
33962306a36Sopenharmony_ci(p_yy)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
34062306a36Sopenharmony_ci(p_yy)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [11, 10 (o less) left]
34162306a36Sopenharmony_ci(p_yy)	add	cnt = -4, cnt
34262306a36Sopenharmony_ci;; }
34362306a36Sopenharmony_ci{ .mmi
34462306a36Sopenharmony_ci(p_y)	cmp.le.unc p_yy, p0 = 8, cnt
34562306a36Sopenharmony_ci	add	ptr3 = -1, ptr3			// last store
34662306a36Sopenharmony_ci	tbit.nz p_scr, p0 = cnt, 1		// will there be a st2 at the end ?
34762306a36Sopenharmony_ci} { .mmi
34862306a36Sopenharmony_ci(p_y)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
34962306a36Sopenharmony_ci(p_y)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [7, 6 (or less) left]
35062306a36Sopenharmony_ci(p_y)	add	cnt = -4, cnt
35162306a36Sopenharmony_ci;; }
35262306a36Sopenharmony_ci{ .mmi
35362306a36Sopenharmony_ci(p_yy)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
35462306a36Sopenharmony_ci(p_yy)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [3, 2 (or less) left]
35562306a36Sopenharmony_ci	tbit.nz p_y, p0 = cnt, 0		// will there be a st1 at the end ?
35662306a36Sopenharmony_ci} { .mmi
35762306a36Sopenharmony_ci(p_yy)	add	cnt = -4, cnt
35862306a36Sopenharmony_ci;; }
35962306a36Sopenharmony_ci{ .mmb
36062306a36Sopenharmony_ci(p_scr)	st2	[ptr1] = value			// fill 2 (aligned) bytes
36162306a36Sopenharmony_ci(p_y)	st1	[ptr3] = value			// fill last byte (using ptr3)
36262306a36Sopenharmony_ci	br.ret.sptk.many rp
36362306a36Sopenharmony_ci}
36462306a36Sopenharmony_ciEND(memset)
36562306a36Sopenharmony_ciEXPORT_SYMBOL(memset)
366