18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Optimized version of the standard memset() function.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci   Copyright (c) 2002 Hewlett-Packard Co/CERN
58c2ecf20Sopenharmony_ci	Sverre Jarp <Sverre.Jarp@cern.ch>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci   Return: dest
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci   Inputs:
108c2ecf20Sopenharmony_ci        in0:    dest
118c2ecf20Sopenharmony_ci        in1:    value
128c2ecf20Sopenharmony_ci        in2:    count
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci   The algorithm is fairly straightforward: set byte by byte until we
158c2ecf20Sopenharmony_ci   we get to a 16B-aligned address, then loop on 128 B chunks using an
168c2ecf20Sopenharmony_ci   early store as prefetching, then loop on 32B chucks, then clear remaining
178c2ecf20Sopenharmony_ci   words, finally clear remaining bytes.
188c2ecf20Sopenharmony_ci   Since a stf.spill f0 can store 16B in one go, we use this instruction
198c2ecf20Sopenharmony_ci   to get peak speed when value = 0.  */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <asm/asmmacro.h>
228c2ecf20Sopenharmony_ci#include <asm/export.h>
238c2ecf20Sopenharmony_ci#undef ret
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define dest		in0
268c2ecf20Sopenharmony_ci#define value		in1
278c2ecf20Sopenharmony_ci#define	cnt		in2
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define tmp		r31
308c2ecf20Sopenharmony_ci#define save_lc		r30
318c2ecf20Sopenharmony_ci#define ptr0		r29
328c2ecf20Sopenharmony_ci#define ptr1		r28
338c2ecf20Sopenharmony_ci#define ptr2		r27
348c2ecf20Sopenharmony_ci#define ptr3		r26
358c2ecf20Sopenharmony_ci#define ptr9 		r24
368c2ecf20Sopenharmony_ci#define	loopcnt		r23
378c2ecf20Sopenharmony_ci#define linecnt		r22
388c2ecf20Sopenharmony_ci#define bytecnt		r21
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define fvalue		f6
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci// This routine uses only scratch predicate registers (p6 - p15)
438c2ecf20Sopenharmony_ci#define p_scr		p6			// default register for same-cycle branches
448c2ecf20Sopenharmony_ci#define p_nz		p7
458c2ecf20Sopenharmony_ci#define p_zr		p8
468c2ecf20Sopenharmony_ci#define p_unalgn	p9
478c2ecf20Sopenharmony_ci#define p_y		p11
488c2ecf20Sopenharmony_ci#define p_n		p12
498c2ecf20Sopenharmony_ci#define p_yy		p13
508c2ecf20Sopenharmony_ci#define p_nn		p14
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define MIN1		15
538c2ecf20Sopenharmony_ci#define MIN1P1HALF	8
548c2ecf20Sopenharmony_ci#define LINE_SIZE	128
558c2ecf20Sopenharmony_ci#define LSIZE_SH        7			// shift amount
568c2ecf20Sopenharmony_ci#define PREF_AHEAD	8
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciGLOBAL_ENTRY(memset)
598c2ecf20Sopenharmony_ci{ .mmi
608c2ecf20Sopenharmony_ci	.prologue
618c2ecf20Sopenharmony_ci	alloc	tmp = ar.pfs, 3, 0, 0, 0
628c2ecf20Sopenharmony_ci	lfetch.nt1 [dest]			//
638c2ecf20Sopenharmony_ci	.save   ar.lc, save_lc
648c2ecf20Sopenharmony_ci	mov.i	save_lc = ar.lc
658c2ecf20Sopenharmony_ci	.body
668c2ecf20Sopenharmony_ci} { .mmi
678c2ecf20Sopenharmony_ci	mov	ret0 = dest			// return value
688c2ecf20Sopenharmony_ci	cmp.ne	p_nz, p_zr = value, r0		// use stf.spill if value is zero
698c2ecf20Sopenharmony_ci	cmp.eq	p_scr, p0 = cnt, r0
708c2ecf20Sopenharmony_ci;; }
718c2ecf20Sopenharmony_ci{ .mmi
728c2ecf20Sopenharmony_ci	and	ptr2 = -(MIN1+1), dest		// aligned address
738c2ecf20Sopenharmony_ci	and	tmp = MIN1, dest		// prepare to check for correct alignment
748c2ecf20Sopenharmony_ci	tbit.nz p_y, p_n = dest, 0		// Do we have an odd address? (M_B_U)
758c2ecf20Sopenharmony_ci} { .mib
768c2ecf20Sopenharmony_ci	mov	ptr1 = dest
778c2ecf20Sopenharmony_ci	mux1	value = value, @brcst		// create 8 identical bytes in word
788c2ecf20Sopenharmony_ci(p_scr)	br.ret.dpnt.many rp			// return immediately if count = 0
798c2ecf20Sopenharmony_ci;; }
808c2ecf20Sopenharmony_ci{ .mib
818c2ecf20Sopenharmony_ci	cmp.ne	p_unalgn, p0 = tmp, r0		//
828c2ecf20Sopenharmony_ci} { .mib
838c2ecf20Sopenharmony_ci	sub	bytecnt = (MIN1+1), tmp		// NB: # of bytes to move is 1 higher than loopcnt
848c2ecf20Sopenharmony_ci	cmp.gt	p_scr, p0 = 16, cnt		// is it a minimalistic task?
858c2ecf20Sopenharmony_ci(p_scr)	br.cond.dptk.many .move_bytes_unaligned	// go move just a few (M_B_U)
868c2ecf20Sopenharmony_ci;; }
878c2ecf20Sopenharmony_ci{ .mmi
888c2ecf20Sopenharmony_ci(p_unalgn) add	ptr1 = (MIN1+1), ptr2		// after alignment
898c2ecf20Sopenharmony_ci(p_unalgn) add	ptr2 = MIN1P1HALF, ptr2		// after alignment
908c2ecf20Sopenharmony_ci(p_unalgn) tbit.nz.unc p_y, p_n = bytecnt, 3	// should we do a st8 ?
918c2ecf20Sopenharmony_ci;; }
928c2ecf20Sopenharmony_ci{ .mib
938c2ecf20Sopenharmony_ci(p_y)	add	cnt = -8, cnt			//
948c2ecf20Sopenharmony_ci(p_unalgn) tbit.nz.unc p_yy, p_nn = bytecnt, 2	// should we do a st4 ?
958c2ecf20Sopenharmony_ci} { .mib
968c2ecf20Sopenharmony_ci(p_y)	st8	[ptr2] = value,-4		//
978c2ecf20Sopenharmony_ci(p_n)	add	ptr2 = 4, ptr2			//
988c2ecf20Sopenharmony_ci;; }
998c2ecf20Sopenharmony_ci{ .mib
1008c2ecf20Sopenharmony_ci(p_yy)	add	cnt = -4, cnt			//
1018c2ecf20Sopenharmony_ci(p_unalgn) tbit.nz.unc p_y, p_n = bytecnt, 1	// should we do a st2 ?
1028c2ecf20Sopenharmony_ci} { .mib
1038c2ecf20Sopenharmony_ci(p_yy)	st4	[ptr2] = value,-2		//
1048c2ecf20Sopenharmony_ci(p_nn)	add	ptr2 = 2, ptr2			//
1058c2ecf20Sopenharmony_ci;; }
1068c2ecf20Sopenharmony_ci{ .mmi
1078c2ecf20Sopenharmony_ci	mov	tmp = LINE_SIZE+1		// for compare
1088c2ecf20Sopenharmony_ci(p_y)	add	cnt = -2, cnt			//
1098c2ecf20Sopenharmony_ci(p_unalgn) tbit.nz.unc p_yy, p_nn = bytecnt, 0	// should we do a st1 ?
1108c2ecf20Sopenharmony_ci} { .mmi
1118c2ecf20Sopenharmony_ci	setf.sig fvalue=value			// transfer value to FLP side
1128c2ecf20Sopenharmony_ci(p_y)	st2	[ptr2] = value,-1		//
1138c2ecf20Sopenharmony_ci(p_n)	add	ptr2 = 1, ptr2			//
1148c2ecf20Sopenharmony_ci;; }
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci{ .mmi
1178c2ecf20Sopenharmony_ci(p_yy)	st1	[ptr2] = value 			//
1188c2ecf20Sopenharmony_ci  	cmp.gt	p_scr, p0 = tmp, cnt		// is it a minimalistic task?
1198c2ecf20Sopenharmony_ci} { .mbb
1208c2ecf20Sopenharmony_ci(p_yy)	add	cnt = -1, cnt			//
1218c2ecf20Sopenharmony_ci(p_scr)	br.cond.dpnt.many .fraction_of_line	// go move just a few
1228c2ecf20Sopenharmony_ci;; }
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci{ .mib
1258c2ecf20Sopenharmony_ci	nop.m 0
1268c2ecf20Sopenharmony_ci	shr.u	linecnt = cnt, LSIZE_SH
1278c2ecf20Sopenharmony_ci(p_zr)	br.cond.dptk.many .l1b			// Jump to use stf.spill
1288c2ecf20Sopenharmony_ci;; }
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	TEXT_ALIGN(32) // --------------------- //  L1A: store ahead into cache lines; fill later
1318c2ecf20Sopenharmony_ci{ .mmi
1328c2ecf20Sopenharmony_ci	and	tmp = -(LINE_SIZE), cnt		// compute end of range
1338c2ecf20Sopenharmony_ci	mov	ptr9 = ptr1			// used for prefetching
1348c2ecf20Sopenharmony_ci	and	cnt = (LINE_SIZE-1), cnt	// remainder
1358c2ecf20Sopenharmony_ci} { .mmi
1368c2ecf20Sopenharmony_ci	mov	loopcnt = PREF_AHEAD-1		// default prefetch loop
1378c2ecf20Sopenharmony_ci	cmp.gt	p_scr, p0 = PREF_AHEAD, linecnt	// check against actual value
1388c2ecf20Sopenharmony_ci;; }
1398c2ecf20Sopenharmony_ci{ .mmi
1408c2ecf20Sopenharmony_ci(p_scr)	add	loopcnt = -1, linecnt		//
1418c2ecf20Sopenharmony_ci	add	ptr2 = 8, ptr1			// start of stores (beyond prefetch stores)
1428c2ecf20Sopenharmony_ci	add	ptr1 = tmp, ptr1		// first address beyond total range
1438c2ecf20Sopenharmony_ci;; }
1448c2ecf20Sopenharmony_ci{ .mmi
1458c2ecf20Sopenharmony_ci	add	tmp = -1, linecnt		// next loop count
1468c2ecf20Sopenharmony_ci	mov.i	ar.lc = loopcnt			//
1478c2ecf20Sopenharmony_ci;; }
1488c2ecf20Sopenharmony_ci.pref_l1a:
1498c2ecf20Sopenharmony_ci{ .mib
1508c2ecf20Sopenharmony_ci	stf8 [ptr9] = fvalue, 128		// Do stores one cache line apart
1518c2ecf20Sopenharmony_ci	nop.i	0
1528c2ecf20Sopenharmony_ci	br.cloop.dptk.few .pref_l1a
1538c2ecf20Sopenharmony_ci;; }
1548c2ecf20Sopenharmony_ci{ .mmi
1558c2ecf20Sopenharmony_ci	add	ptr0 = 16, ptr2			// Two stores in parallel
1568c2ecf20Sopenharmony_ci	mov.i	ar.lc = tmp			//
1578c2ecf20Sopenharmony_ci;; }
1588c2ecf20Sopenharmony_ci.l1ax:
1598c2ecf20Sopenharmony_ci { .mmi
1608c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
1618c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
1628c2ecf20Sopenharmony_ci ;; }
1638c2ecf20Sopenharmony_ci { .mmi
1648c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
1658c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
1668c2ecf20Sopenharmony_ci ;; }
1678c2ecf20Sopenharmony_ci { .mmi
1688c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
1698c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
1708c2ecf20Sopenharmony_ci ;; }
1718c2ecf20Sopenharmony_ci { .mmi
1728c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
1738c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
1748c2ecf20Sopenharmony_ci ;; }
1758c2ecf20Sopenharmony_ci { .mmi
1768c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
1778c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 8
1788c2ecf20Sopenharmony_ci ;; }
1798c2ecf20Sopenharmony_ci { .mmi
1808c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
1818c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 24
1828c2ecf20Sopenharmony_ci ;; }
1838c2ecf20Sopenharmony_ci { .mmi
1848c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 8
1858c2ecf20Sopenharmony_ci	stf8 [ptr0] = fvalue, 32
1868c2ecf20Sopenharmony_ci 	cmp.lt	p_scr, p0 = ptr9, ptr1		// do we need more prefetching?
1878c2ecf20Sopenharmony_ci ;; }
1888c2ecf20Sopenharmony_ci{ .mmb
1898c2ecf20Sopenharmony_ci	stf8 [ptr2] = fvalue, 24
1908c2ecf20Sopenharmony_ci(p_scr)	stf8 [ptr9] = fvalue, 128
1918c2ecf20Sopenharmony_ci	br.cloop.dptk.few .l1ax
1928c2ecf20Sopenharmony_ci;; }
1938c2ecf20Sopenharmony_ci{ .mbb
1948c2ecf20Sopenharmony_ci	cmp.le  p_scr, p0 = 8, cnt		// just a few bytes left ?
1958c2ecf20Sopenharmony_ci(p_scr) br.cond.dpnt.many  .fraction_of_line	// Branch no. 2
1968c2ecf20Sopenharmony_ci	br.cond.dpnt.many  .move_bytes_from_alignment	// Branch no. 3
1978c2ecf20Sopenharmony_ci;; }
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	TEXT_ALIGN(32)
2008c2ecf20Sopenharmony_ci.l1b:	// ------------------------------------ //  L1B: store ahead into cache lines; fill later
2018c2ecf20Sopenharmony_ci{ .mmi
2028c2ecf20Sopenharmony_ci	and	tmp = -(LINE_SIZE), cnt		// compute end of range
2038c2ecf20Sopenharmony_ci	mov	ptr9 = ptr1			// used for prefetching
2048c2ecf20Sopenharmony_ci	and	cnt = (LINE_SIZE-1), cnt	// remainder
2058c2ecf20Sopenharmony_ci} { .mmi
2068c2ecf20Sopenharmony_ci	mov	loopcnt = PREF_AHEAD-1		// default prefetch loop
2078c2ecf20Sopenharmony_ci	cmp.gt	p_scr, p0 = PREF_AHEAD, linecnt	// check against actual value
2088c2ecf20Sopenharmony_ci;; }
2098c2ecf20Sopenharmony_ci{ .mmi
2108c2ecf20Sopenharmony_ci(p_scr)	add	loopcnt = -1, linecnt
2118c2ecf20Sopenharmony_ci	add	ptr2 = 16, ptr1			// start of stores (beyond prefetch stores)
2128c2ecf20Sopenharmony_ci	add	ptr1 = tmp, ptr1		// first address beyond total range
2138c2ecf20Sopenharmony_ci;; }
2148c2ecf20Sopenharmony_ci{ .mmi
2158c2ecf20Sopenharmony_ci	add	tmp = -1, linecnt		// next loop count
2168c2ecf20Sopenharmony_ci	mov.i	ar.lc = loopcnt
2178c2ecf20Sopenharmony_ci;; }
2188c2ecf20Sopenharmony_ci.pref_l1b:
2198c2ecf20Sopenharmony_ci{ .mib
2208c2ecf20Sopenharmony_ci	stf.spill [ptr9] = f0, 128		// Do stores one cache line apart
2218c2ecf20Sopenharmony_ci	nop.i   0
2228c2ecf20Sopenharmony_ci	br.cloop.dptk.few .pref_l1b
2238c2ecf20Sopenharmony_ci;; }
2248c2ecf20Sopenharmony_ci{ .mmi
2258c2ecf20Sopenharmony_ci	add	ptr0 = 16, ptr2			// Two stores in parallel
2268c2ecf20Sopenharmony_ci	mov.i	ar.lc = tmp
2278c2ecf20Sopenharmony_ci;; }
2288c2ecf20Sopenharmony_ci.l1bx:
2298c2ecf20Sopenharmony_ci { .mmi
2308c2ecf20Sopenharmony_ci	stf.spill [ptr2] = f0, 32
2318c2ecf20Sopenharmony_ci	stf.spill [ptr0] = f0, 32
2328c2ecf20Sopenharmony_ci ;; }
2338c2ecf20Sopenharmony_ci { .mmi
2348c2ecf20Sopenharmony_ci	stf.spill [ptr2] = f0, 32
2358c2ecf20Sopenharmony_ci	stf.spill [ptr0] = f0, 32
2368c2ecf20Sopenharmony_ci ;; }
2378c2ecf20Sopenharmony_ci { .mmi
2388c2ecf20Sopenharmony_ci	stf.spill [ptr2] = f0, 32
2398c2ecf20Sopenharmony_ci	stf.spill [ptr0] = f0, 64
2408c2ecf20Sopenharmony_ci 	cmp.lt	p_scr, p0 = ptr9, ptr1		// do we need more prefetching?
2418c2ecf20Sopenharmony_ci ;; }
2428c2ecf20Sopenharmony_ci{ .mmb
2438c2ecf20Sopenharmony_ci	stf.spill [ptr2] = f0, 32
2448c2ecf20Sopenharmony_ci(p_scr)	stf.spill [ptr9] = f0, 128
2458c2ecf20Sopenharmony_ci	br.cloop.dptk.few .l1bx
2468c2ecf20Sopenharmony_ci;; }
2478c2ecf20Sopenharmony_ci{ .mib
2488c2ecf20Sopenharmony_ci	cmp.gt  p_scr, p0 = 8, cnt		// just a few bytes left ?
2498c2ecf20Sopenharmony_ci(p_scr)	br.cond.dpnt.many  .move_bytes_from_alignment	//
2508c2ecf20Sopenharmony_ci;; }
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci.fraction_of_line:
2538c2ecf20Sopenharmony_ci{ .mib
2548c2ecf20Sopenharmony_ci	add	ptr2 = 16, ptr1
2558c2ecf20Sopenharmony_ci	shr.u	loopcnt = cnt, 5   		// loopcnt = cnt / 32
2568c2ecf20Sopenharmony_ci;; }
2578c2ecf20Sopenharmony_ci{ .mib
2588c2ecf20Sopenharmony_ci	cmp.eq	p_scr, p0 = loopcnt, r0
2598c2ecf20Sopenharmony_ci	add	loopcnt = -1, loopcnt
2608c2ecf20Sopenharmony_ci(p_scr)	br.cond.dpnt.many .store_words
2618c2ecf20Sopenharmony_ci;; }
2628c2ecf20Sopenharmony_ci{ .mib
2638c2ecf20Sopenharmony_ci	and	cnt = 0x1f, cnt			// compute the remaining cnt
2648c2ecf20Sopenharmony_ci	mov.i   ar.lc = loopcnt
2658c2ecf20Sopenharmony_ci;; }
2668c2ecf20Sopenharmony_ci	TEXT_ALIGN(32)
2678c2ecf20Sopenharmony_ci.l2:	// ------------------------------------ //  L2A:  store 32B in 2 cycles
2688c2ecf20Sopenharmony_ci{ .mmb
2698c2ecf20Sopenharmony_ci	stf8	[ptr1] = fvalue, 8
2708c2ecf20Sopenharmony_ci	stf8	[ptr2] = fvalue, 8
2718c2ecf20Sopenharmony_ci;; } { .mmb
2728c2ecf20Sopenharmony_ci	stf8	[ptr1] = fvalue, 24
2738c2ecf20Sopenharmony_ci	stf8	[ptr2] = fvalue, 24
2748c2ecf20Sopenharmony_ci	br.cloop.dptk.many .l2
2758c2ecf20Sopenharmony_ci;; }
2768c2ecf20Sopenharmony_ci.store_words:
2778c2ecf20Sopenharmony_ci{ .mib
2788c2ecf20Sopenharmony_ci	cmp.gt	p_scr, p0 = 8, cnt		// just a few bytes left ?
2798c2ecf20Sopenharmony_ci(p_scr)	br.cond.dpnt.many .move_bytes_from_alignment	// Branch
2808c2ecf20Sopenharmony_ci;; }
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci{ .mmi
2838c2ecf20Sopenharmony_ci	stf8	[ptr1] = fvalue, 8		// store
2848c2ecf20Sopenharmony_ci	cmp.le	p_y, p_n = 16, cnt
2858c2ecf20Sopenharmony_ci	add	cnt = -8, cnt			// subtract
2868c2ecf20Sopenharmony_ci;; }
2878c2ecf20Sopenharmony_ci{ .mmi
2888c2ecf20Sopenharmony_ci(p_y)	stf8	[ptr1] = fvalue, 8		// store
2898c2ecf20Sopenharmony_ci(p_y)	cmp.le.unc p_yy, p_nn = 16, cnt
2908c2ecf20Sopenharmony_ci(p_y)	add	cnt = -8, cnt			// subtract
2918c2ecf20Sopenharmony_ci;; }
2928c2ecf20Sopenharmony_ci{ .mmi						// store
2938c2ecf20Sopenharmony_ci(p_yy)	stf8	[ptr1] = fvalue, 8
2948c2ecf20Sopenharmony_ci(p_yy)	add	cnt = -8, cnt			// subtract
2958c2ecf20Sopenharmony_ci;; }
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci.move_bytes_from_alignment:
2988c2ecf20Sopenharmony_ci{ .mib
2998c2ecf20Sopenharmony_ci	cmp.eq	p_scr, p0 = cnt, r0
3008c2ecf20Sopenharmony_ci	tbit.nz.unc p_y, p0 = cnt, 2		// should we terminate with a st4 ?
3018c2ecf20Sopenharmony_ci(p_scr)	br.cond.dpnt.few .restore_and_exit
3028c2ecf20Sopenharmony_ci;; }
3038c2ecf20Sopenharmony_ci{ .mib
3048c2ecf20Sopenharmony_ci(p_y)	st4	[ptr1] = value,4
3058c2ecf20Sopenharmony_ci	tbit.nz.unc p_yy, p0 = cnt, 1		// should we terminate with a st2 ?
3068c2ecf20Sopenharmony_ci;; }
3078c2ecf20Sopenharmony_ci{ .mib
3088c2ecf20Sopenharmony_ci(p_yy)	st2	[ptr1] = value,2
3098c2ecf20Sopenharmony_ci	tbit.nz.unc p_y, p0 = cnt, 0		// should we terminate with a st1 ?
3108c2ecf20Sopenharmony_ci;; }
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci{ .mib
3138c2ecf20Sopenharmony_ci(p_y)	st1	[ptr1] = value
3148c2ecf20Sopenharmony_ci;; }
3158c2ecf20Sopenharmony_ci.restore_and_exit:
3168c2ecf20Sopenharmony_ci{ .mib
3178c2ecf20Sopenharmony_ci	nop.m	0
3188c2ecf20Sopenharmony_ci	mov.i	ar.lc = save_lc
3198c2ecf20Sopenharmony_ci	br.ret.sptk.many rp
3208c2ecf20Sopenharmony_ci;; }
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci.move_bytes_unaligned:
3238c2ecf20Sopenharmony_ci{ .mmi
3248c2ecf20Sopenharmony_ci       .pred.rel "mutex",p_y, p_n
3258c2ecf20Sopenharmony_ci       .pred.rel "mutex",p_yy, p_nn
3268c2ecf20Sopenharmony_ci(p_n)	cmp.le  p_yy, p_nn = 4, cnt
3278c2ecf20Sopenharmony_ci(p_y)	cmp.le  p_yy, p_nn = 5, cnt
3288c2ecf20Sopenharmony_ci(p_n)	add	ptr2 = 2, ptr1
3298c2ecf20Sopenharmony_ci} { .mmi
3308c2ecf20Sopenharmony_ci(p_y)	add	ptr2 = 3, ptr1
3318c2ecf20Sopenharmony_ci(p_y)	st1	[ptr1] = value, 1		// fill 1 (odd-aligned) byte [15, 14 (or less) left]
3328c2ecf20Sopenharmony_ci(p_y)	add	cnt = -1, cnt
3338c2ecf20Sopenharmony_ci;; }
3348c2ecf20Sopenharmony_ci{ .mmi
3358c2ecf20Sopenharmony_ci(p_yy)	cmp.le.unc p_y, p0 = 8, cnt
3368c2ecf20Sopenharmony_ci	add	ptr3 = ptr1, cnt		// prepare last store
3378c2ecf20Sopenharmony_ci	mov.i	ar.lc = save_lc
3388c2ecf20Sopenharmony_ci} { .mmi
3398c2ecf20Sopenharmony_ci(p_yy)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
3408c2ecf20Sopenharmony_ci(p_yy)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [11, 10 (o less) left]
3418c2ecf20Sopenharmony_ci(p_yy)	add	cnt = -4, cnt
3428c2ecf20Sopenharmony_ci;; }
3438c2ecf20Sopenharmony_ci{ .mmi
3448c2ecf20Sopenharmony_ci(p_y)	cmp.le.unc p_yy, p0 = 8, cnt
3458c2ecf20Sopenharmony_ci	add	ptr3 = -1, ptr3			// last store
3468c2ecf20Sopenharmony_ci	tbit.nz p_scr, p0 = cnt, 1		// will there be a st2 at the end ?
3478c2ecf20Sopenharmony_ci} { .mmi
3488c2ecf20Sopenharmony_ci(p_y)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
3498c2ecf20Sopenharmony_ci(p_y)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [7, 6 (or less) left]
3508c2ecf20Sopenharmony_ci(p_y)	add	cnt = -4, cnt
3518c2ecf20Sopenharmony_ci;; }
3528c2ecf20Sopenharmony_ci{ .mmi
3538c2ecf20Sopenharmony_ci(p_yy)	st2	[ptr1] = value, 4		// fill 2 (aligned) bytes
3548c2ecf20Sopenharmony_ci(p_yy)	st2	[ptr2] = value, 4		// fill 2 (aligned) bytes [3, 2 (or less) left]
3558c2ecf20Sopenharmony_ci	tbit.nz p_y, p0 = cnt, 0		// will there be a st1 at the end ?
3568c2ecf20Sopenharmony_ci} { .mmi
3578c2ecf20Sopenharmony_ci(p_yy)	add	cnt = -4, cnt
3588c2ecf20Sopenharmony_ci;; }
3598c2ecf20Sopenharmony_ci{ .mmb
3608c2ecf20Sopenharmony_ci(p_scr)	st2	[ptr1] = value			// fill 2 (aligned) bytes
3618c2ecf20Sopenharmony_ci(p_y)	st1	[ptr3] = value			// fill last byte (using ptr3)
3628c2ecf20Sopenharmony_ci	br.ret.sptk.many rp
3638c2ecf20Sopenharmony_ci}
3648c2ecf20Sopenharmony_ciEND(memset)
3658c2ecf20Sopenharmony_ciEXPORT_SYMBOL(memset)
366