blob: 05bef6b505984465699627db5aeec012714893f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/alpha/lib/ev6-clear_user.S
3 * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com>
4 *
5 * Zero user space, handling exceptions as we go.
6 *
7 * We have to make sure that $0 is always up-to-date and contains the
8 * right "bytes left to zero" value (and that it is updated only _after_
9 * a successful copy). There is also some rather minor exception setup
10 * stuff.
11 *
12 * NOTE! This is not directly C-callable, because the calling semantics
13 * are different:
14 *
15 * Inputs:
16 * length in $0
17 * destination address in $6
18 * exception pointer in $7
19 * return address in $28 (exceptions expect it there)
20 *
21 * Outputs:
22 * bytes left to copy in $0
23 *
24 * Clobbers:
25 * $1,$2,$3,$4,$5,$6
26 *
27 * Much of the information about 21264 scheduling/coding comes from:
28 * Compiler Writer's Guide for the Alpha 21264
29 * abbreviated as 'CWG' in other comments here
30 * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
31 * Scheduling notation:
32 * E - either cluster
33 * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
34 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
35 * Try not to change the actual algorithm if possible for consistency.
36 * Determining actual stalls (other than slotting) doesn't appear to be easy to do.
37 * From perusing the source code context where this routine is called, it is
38 * a fair assumption that significant fractions of entire pages are zeroed, so
39 * it's going to be worth the effort to hand-unroll a big loop, and use wh64.
40 * ASSUMPTION:
41 * The believed purpose of only updating $0 after a store is that a signal
42 * may come along during the execution of this chunk of code, and we don't
43 * want to leave a hole (and we also want to avoid repeating lots of work)
44 */
45
Al Viro00fc0e02016-01-11 09:51:29 -050046#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* Allow an exception for an insn; exit if we get one. */
48#define EX(x,y...) \
49 99: x,##y; \
50 .section __ex_table,"a"; \
51 .long 99b - .; \
52 lda $31, $exception-99b($31); \
53 .previous
54
55 .set noat
56 .set noreorder
57 .align 4
58
59 .globl __do_clear_user
60 .ent __do_clear_user
61 .frame $30, 0, $28
62 .prologue 0
63
64 # Pipeline info : Slotting & Comments
65__do_clear_user:
66 and $6, 7, $4 # .. E .. .. : find dest head misalignment
67 beq $0, $zerolength # U .. .. .. : U L U L
68
69 addq $0, $4, $1 # .. .. .. E : bias counter
70 and $1, 7, $2 # .. .. E .. : number of misaligned bytes in tail
71# Note - we never actually use $2, so this is a moot computation
72# and we can rewrite this later...
73 srl $1, 3, $1 # .. E .. .. : number of quadwords to clear
74 beq $4, $headalign # U .. .. .. : U L U L
75
76/*
77 * Head is not aligned. Write (8 - $4) bytes to head of destination
78 * This means $6 is known to be misaligned
79 */
80 EX( ldq_u $5, 0($6) ) # .. .. .. L : load dst word to mask back in
81 beq $1, $onebyte # .. .. U .. : sub-word store?
82 mskql $5, $6, $5 # .. U .. .. : take care of misaligned head
83 addq $6, 8, $6 # E .. .. .. : L U U L
84
85 EX( stq_u $5, -8($6) ) # .. .. .. L :
86 subq $1, 1, $1 # .. .. E .. :
87 addq $0, $4, $0 # .. E .. .. : bytes left -= 8 - misalignment
88 subq $0, 8, $0 # E .. .. .. : U L U L
89
90 .align 4
91/*
92 * (The .align directive ought to be a moot point)
93 * values upon initial entry to the loop
94 * $1 is number of quadwords to clear (zero is a valid value)
95 * $2 is number of trailing bytes (0..7) ($2 never used...)
96 * $6 is known to be aligned 0mod8
97 */
98$headalign:
99 subq $1, 16, $4 # .. .. .. E : If < 16, we can not use the huge loop
100 and $6, 0x3f, $2 # .. .. E .. : Forward work for huge loop
101 subq $2, 0x40, $3 # .. E .. .. : bias counter (huge loop)
102 blt $4, $trailquad # U .. .. .. : U L U L
103
104/*
105 * We know that we're going to do at least 16 quads, which means we are
106 * going to be able to use the large block clear loop at least once.
107 * Figure out how many quads we need to clear before we are 0mod64 aligned
108 * so we can use the wh64 instruction.
109 */
110
111 nop # .. .. .. E
112 nop # .. .. E ..
113 nop # .. E .. ..
114 beq $3, $bigalign # U .. .. .. : U L U L : Aligned 0mod64
115
116$alignmod64:
117 EX( stq_u $31, 0($6) ) # .. .. .. L
118 addq $3, 8, $3 # .. .. E ..
119 subq $0, 8, $0 # .. E .. ..
120 nop # E .. .. .. : U L U L
121
122 nop # .. .. .. E
123 subq $1, 1, $1 # .. .. E ..
124 addq $6, 8, $6 # .. E .. ..
125 blt $3, $alignmod64 # U .. .. .. : U L U L
126
127$bigalign:
128/*
129 * $0 is the number of bytes left
130 * $1 is the number of quads left
131 * $6 is aligned 0mod64
132 * we know that we'll be taking a minimum of one trip through
133 * CWG Section 3.7.6: do not expect a sustained store rate of > 1/cycle
134 * We are _not_ going to update $0 after every single store. That
135 * would be silly, because there will be cross-cluster dependencies
136 * no matter how the code is scheduled. By doing it in slightly
137 * staggered fashion, we can still do this loop in 5 fetches
138 * The worse case will be doing two extra quads in some future execution,
139 * in the event of an interrupted clear.
140 * Assumes the wh64 needs to be for 2 trips through the loop in the future
141 * The wh64 is issued on for the starting destination address for trip +2
142 * through the loop, and if there are less than two trips left, the target
143 * address will be for the current trip.
144 */
145 nop # E :
146 nop # E :
147 nop # E :
148 bis $6,$6,$3 # E : U L U L : Initial wh64 address is dest
149 /* This might actually help for the current trip... */
150
151$do_wh64:
152 wh64 ($3) # .. .. .. L1 : memory subsystem hint
153 subq $1, 16, $4 # .. .. E .. : Forward calculation - repeat the loop?
154 EX( stq_u $31, 0($6) ) # .. L .. ..
155 subq $0, 8, $0 # E .. .. .. : U L U L
156
157 addq $6, 128, $3 # E : Target address of wh64
158 EX( stq_u $31, 8($6) ) # L :
159 EX( stq_u $31, 16($6) ) # L :
160 subq $0, 16, $0 # E : U L L U
161
162 nop # E :
163 EX( stq_u $31, 24($6) ) # L :
164 EX( stq_u $31, 32($6) ) # L :
165 subq $0, 168, $5 # E : U L L U : two trips through the loop left?
166 /* 168 = 192 - 24, since we've already completed some stores */
167
168 subq $0, 16, $0 # E :
169 EX( stq_u $31, 40($6) ) # L :
170 EX( stq_u $31, 48($6) ) # L :
171 cmovlt $5, $6, $3 # E : U L L U : Latency 2, extra mapping cycle
172
173 subq $1, 8, $1 # E :
174 subq $0, 16, $0 # E :
175 EX( stq_u $31, 56($6) ) # L :
176 nop # E : U L U L
177
178 nop # E :
179 subq $0, 8, $0 # E :
180 addq $6, 64, $6 # E :
181 bge $4, $do_wh64 # U : U L U L
182
183$trailquad:
184 # zero to 16 quadwords left to store, plus any trailing bytes
185 # $1 is the number of quadwords left to go.
186 #
187 nop # .. .. .. E
188 nop # .. .. E ..
189 nop # .. E .. ..
190 beq $1, $trailbytes # U .. .. .. : U L U L : Only 0..7 bytes to go
191
192$onequad:
193 EX( stq_u $31, 0($6) ) # .. .. .. L
194 subq $1, 1, $1 # .. .. E ..
195 subq $0, 8, $0 # .. E .. ..
196 nop # E .. .. .. : U L U L
197
198 nop # .. .. .. E
199 nop # .. .. E ..
200 addq $6, 8, $6 # .. E .. ..
201 bgt $1, $onequad # U .. .. .. : U L U L
202
203 # We have an unknown number of bytes left to go.
204$trailbytes:
205 nop # .. .. .. E
206 nop # .. .. E ..
207 nop # .. E .. ..
208 beq $0, $zerolength # U .. .. .. : U L U L
209
210 # $0 contains the number of bytes left to copy (0..31)
211 # so we will use $0 as the loop counter
212 # We know for a fact that $0 > 0 zero due to previous context
213$onebyte:
214 EX( stb $31, 0($6) ) # .. .. .. L
215 subq $0, 1, $0 # .. .. E .. :
216 addq $6, 1, $6 # .. E .. .. :
217 bgt $0, $onebyte # U .. .. .. : U L U L
218
219$zerolength:
220$exception: # Destination for exception recovery(?)
221 nop # .. .. .. E :
222 nop # .. .. E .. :
223 nop # .. E .. .. :
224 ret $31, ($28), 1 # L0 .. .. .. : L U L U
225 .end __do_clear_user
Al Viro00fc0e02016-01-11 09:51:29 -0500226 EXPORT_SYMBOL(__do_clear_user)