-
Notifications
You must be signed in to change notification settings - Fork 2
/
memset.S
46 lines (38 loc) · 801 Bytes
/
memset.S
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
;;;
;;; memset
;;;
.text
.global memset
memset:
;; r0 ... target memory area
;; r1 ... fill value
;; r2 ... number of bytes
;; do not bother with words unless you can be sure that the
;; loop gets executed at least once even if r0 is unaligned
blo r2, 8, .L_set_bytes
bmask r3, r0, 2
beq r3, 0, .L_set_words
;; store bytes until r0 is word-aligned
sub r2, 4
add r2, r3
.L_align_loop:
stb r1, (r0++)
addcmpbne r3, 1, 4, .L_align_loop
.L_set_words:
;; repeat fill value in all bytes of r1
bmask r1, 8
shl r3, r1, 8
or r3, r1
shl r1, r3, 16
or r1, r3
;; store words
.L_words_loop:
st r1, (r0++)
addcmpbhs r2, -4, 4, .L_words_loop
.L_set_bytes:
beq r2, 0, .L_done
.L_bytes_loop:
stb r1, (r0++)
addcmpbne r2, -1, 0, .L_bytes_loop
.L_done:
rts