aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/machine/arc64/memset.S
blob: 88c8e09fc89ab14a4fe8b32f91074ca522061b8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
   Copyright (c) 2024, Synopsys, Inc. All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:

   1) Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

   2) Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

   3) Neither the name of the Synopsys, Inc., nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   POSSIBILITY OF SUCH DAMAGE.
*/

#include <sys/asm.h>

; This file contains variants of the same function with different
; instructions.  The generic one, the implementation that comes the
; last after the #else macro, is the most commented.

; Using 128-bit memory operations
#if defined (__ARC64_M128__)

ENTRY (memset)
	;; Assemble 128b token
	bmsk_s	r1, r1, 7
	lsl8	r3, r1
	or_s	r1, r1, r3
	lsl16	r3, r1
	or	r6, r1, r3
	addhl	r6, r6, r6
	movl	r7, r6

	lsrl.f	r5, r2, 6
	beq.d	@.L_write_63_bytes
	movl	r4, r0
.L_write_64_bytes:
	stdl.ab	r6r7, [r4, +16]
	stdl.ab	r6r7, [r4, +16]
	stdl.ab	r6r7, [r4, +16]
	dbnz.d	r5, @.L_write_64_bytes
	stdl.ab	r6r7, [r4, +16]
	bmsk_s	r2, r2, 5

.L_write_63_bytes:
	bbit0.d	r2, 3, @1f
	lsr	r3, r2, 4
	stl.ab	r6, [r4, 8]
1:
	bbit0.d	r2, 2, @1f
	xor	r3, r3, 3
	st.ab	r6, [r4, 4]
1:
	bbit0	r2, 1, @1f
	sth.ab	r6, [r4, 2]
1:
	bbit0	r2, 0, @1f
	stb.ab	r6, [r4, 1]
1:
	bi	[r3]
	stdl.ab	r6r7,[r4, 16]
	stdl.ab	r6r7,[r4, 16]
	stdl.ab	r6r7,[r4, 16]

	j_s	[blink]

.L_write_1_bytes:
	breq	r2, 0, @.L_return
	dbnz.d	r2, @.
	stb.ab	r1, [r4, +1]
.L_return:
	j_s	[blink]
ENDFUNC (memset)

; The generic 64-bit implementation without any frills.
#elif defined (__ARC64_ARCH64__) || defined (__ARC64_LL64__)

#if defined (__ARC64_ARCH32__)
# define MOVH  mov	r7,r6
#elif defined (__ARC64_ARCH64__)
# define MOVH  addhl	r6,r6,r6
#else
# error Please use either 32-bit or 64-bit version of arc64 compiler
#endif

; R0: dest
; R1: ch
; R2: count
; ret (R0): dest
ENTRY (memset)
	;; Assemble the bytes to 64bit words
	bmsk_s	r1, r1, 7		; treat it like unsigned char
	lsl8	r3, r1
	or_s	r1, r1, r3
	lsl16	r3, r1
	or	r6, r1, r3
	MOVH

	LSRP.f	r5, r2, 5		; counter for 32-byte chunks
	beq.d	@.L_write_31_bytes
	MOVP	r4, r0			; work on a copy of "r0"
.L_write_32_bytes:
	ST64.ab	r6, [r4, +8]
	ST64.ab	r6, [r4, +8]
	ST64.ab	r6, [r4, +8]
	dbnz.d	r5, @.L_write_32_bytes
	ST64.ab	r6, [r4, +8]
	bmsk_s	r2, r2, 4

.L_write_31_bytes:
	bbit0.d	r2, 2, @1f
	lsr	r3, r2, 3
	st.ab	r6, [r4, 4]
1:
	bbit0.d	r2, 1, @1f
	xor	r3, r3, 3
	sth.ab	r6, [r4, 2]
1:
	bbit0	r2, 0, @1f
	stb.ab	r6, [r4, 1]
1:
	bi	[r3]
	ST64.ab	r6,[r4, 8]
	ST64.ab	r6,[r4, 8]
	ST64.ab	r6,[r4, 8]

	j_s	[blink]
ENDFUNC (memset)

#elif defined (__ARC64_ARCH32__)
ENTRY (memset)
	;; Assemble the bytes to 32bit words
	bmsk_s	r1, r1, 7		; treat it like unsigned char
	lsl8	r3, r1
	or_s	r1, r1, r3
	lsl16	r3, r1
	or	r6, r1, r3

	lsr.f	r5, r2, 4		; counter for 16-byte chunks
	beq.d	@.L_write_15_bytes
	mov	r4, r0			; work on a copy of "r0"
.L_write_16_bytes:
	st.ab	r6, [r4, 4]
	st.ab	r6, [r4, 4]
	st.ab	r6, [r4, 4]
	dbnz.d	r5, @.L_write_16_bytes
	st.ab	r6, [r4, 4]
	bmsk_s	r2, r2, 3

.L_write_15_bytes:
	bbit0.d	r2, 1, @1f
	lsr	r3, r2, 2
	sth.ab	r6, [r4, 2]
1:
	bbit0.d	r2, 0, @1f
	xor	r3, r3, 3
	stb.ab	r6, [r4, 1]
1:
	bi	[r3]
	st.ab	r6,[r4, 4]
	st.ab	r6,[r4, 4]
	st.ab	r6,[r4, 4]

	j_s	[blink]
ENDFUNC (memset)
#else
# error Unknown configuration
#endif