Text file
src/runtime/memclr_riscv64.s
Documentation: runtime
1// Copyright 2016 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5#include "textflag.h"
6
7// See memclrNoHeapPointers Go doc for important implementation constraints.
8
9// void runtime·memclrNoHeapPointers(void*, uintptr)
10TEXT runtime·memclrNoHeapPointers<ABIInternal>(SB),NOSPLIT,$0-16
11 // X10 = ptr
12 // X11 = n
13
14 // If less than 8 bytes, do single byte zeroing.
15 MOV $8, X9
16 BLT X11, X9, check4
17
18 // Check alignment
19 AND $7, X10, X5
20 BEQZ X5, aligned
21
22 // Zero one byte at a time until we reach 8 byte alignment.
23 SUB X5, X9, X5
24 SUB X5, X11, X11
25align:
26 SUB $1, X5
27 MOVB ZERO, 0(X10)
28 ADD $1, X10
29 BNEZ X5, align
30
31aligned:
32 // X9 already contains $8
33 BLT X11, X9, check4
34 MOV $16, X9
35 BLT X11, X9, zero8
36 MOV $32, X9
37 BLT X11, X9, zero16
38 MOV $64, X9
39 BLT X11, X9, zero32
40loop64:
41 MOV ZERO, 0(X10)
42 MOV ZERO, 8(X10)
43 MOV ZERO, 16(X10)
44 MOV ZERO, 24(X10)
45 MOV ZERO, 32(X10)
46 MOV ZERO, 40(X10)
47 MOV ZERO, 48(X10)
48 MOV ZERO, 56(X10)
49 ADD $64, X10
50 SUB $64, X11
51 BGE X11, X9, loop64
52 BEQZ X11, done
53
54check32:
55 MOV $32, X9
56 BLT X11, X9, check16
57zero32:
58 MOV ZERO, 0(X10)
59 MOV ZERO, 8(X10)
60 MOV ZERO, 16(X10)
61 MOV ZERO, 24(X10)
62 ADD $32, X10
63 SUB $32, X11
64 BEQZ X11, done
65
66check16:
67 MOV $16, X9
68 BLT X11, X9, check8
69zero16:
70 MOV ZERO, 0(X10)
71 MOV ZERO, 8(X10)
72 ADD $16, X10
73 SUB $16, X11
74 BEQZ X11, done
75
76check8:
77 MOV $8, X9
78 BLT X11, X9, check4
79zero8:
80 MOV ZERO, 0(X10)
81 ADD $8, X10
82 SUB $8, X11
83 BEQZ X11, done
84
85check4:
86 MOV $4, X9
87 BLT X11, X9, loop1
88zero4:
89 MOVB ZERO, 0(X10)
90 MOVB ZERO, 1(X10)
91 MOVB ZERO, 2(X10)
92 MOVB ZERO, 3(X10)
93 ADD $4, X10
94 SUB $4, X11
95
96loop1:
97 BEQZ X11, done
98 MOVB ZERO, 0(X10)
99 ADD $1, X10
100 SUB $1, X11
101 JMP loop1
102
103done:
104 RET
View as plain text