1 /* $Id: VIScsum.S,v 1.5 1999/07/30 09:35:36 davem Exp $
2 * VIScsum.S: High bandwidth IP checksumming utilizing the UltraSparc
3 * Visual Instruction Set.
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Based on older sparc32/sparc64 checksum.S, which is:
9 * Copyright(C) 1995 Linus Torvalds
10 * Copyright(C) 1995 Miguel de Icaza
11 * Copyright(C) 1996,1997 David S. Miller
13 * Linux/Alpha checksum c-code
14 * Linux/ix86 inline checksum assembly
15 * RFC1071 Computing the Internet Checksum (esp. Jacobsons m68k code)
16 * David Mosberger-Tang for optimized reference c-code
17 * BSD4.4 portable checksum routine
29 #include <asm/visasm.h>
30 #include <asm/asm_offsets.h>
32 #define ASI_BLK_P 0xf0
36 /* Dobrou noc, SunSoft engineers. Spete sladce.
37 * This has a couple of tricks in and those
38 * tricks are UltraLinux trade secrets :))
41 #define START_THE_TRICK(fz,f0,f2,f4,f6,f8,f10) \
42 fcmpgt32 %fz, %f0, %g1 /* FPM Group */; \
43 fcmpgt32 %fz, %f2, %g2 /* FPM Group */; \
44 fcmpgt32 %fz, %f4, %g3 /* FPM Group */; \
45 fcmpgt32 %fz, %f6, %g5 /* FPM Group */; \
47 fcmpgt32 %fz, %f8, %g7 /* FPM Group */; \
48 srl %g1, 1, %g1 /* IEU0 */; \
50 fcmpgt32 %fz, %f10, %o3 /* FPM Group */; \
51 srl %g2, 1, %g2 /* IEU0 */; \
52 add %o2, %g1, %o2 /* IEU1 */; \
53 add %g3, 1, %g3 /* IEU0 Group */; \
54 srl %g3, 1, %g3 /* IEU0 Group */; \
55 add %o2, %g2, %o2 /* IEU1 */; \
56 inc %g5 /* IEU0 Group */; \
57 add %o2, %g3, %o2 /* IEU1 */;
59 #define DO_THE_TRICK(O12,O14,f0,f2,f4,f6,f8,f10,f12,f14,F0,F2,F4,F6,F8,F10,F12,F14) \
60 fcmpgt32 %O12, %f12, %o4 /* FPM Group */; \
61 srl %g5, 1, %g5 /* IEU0 */; \
63 fpadd32 %F0, %f0, %F0 /* FPA */; \
64 fcmpgt32 %O14, %f14, %o5 /* FPM Group */; \
65 srl %g7, 1, %g7 /* IEU0 */; \
66 add %o2, %g5, %o2 /* IEU1 */; \
67 fpadd32 %F2, %f2, %F2 /* FPA */; \
68 inc %o3 /* IEU0 Group */; \
69 add %o2, %g7, %o2 /* IEU1 */; \
70 fcmpgt32 %f0, %F0, %g1 /* FPM Group */; \
71 srl %o3, 1, %o3 /* IEU0 */; \
73 fpadd32 %F4, %f4, %F4 /* FPA */; \
74 fcmpgt32 %f2, %F2, %g2 /* FPM Group */; \
75 srl %o4, 1, %o4 /* IEU0 */; \
76 add %o2, %o3, %o2 /* IEU1 */; \
77 fpadd32 %F6, %f6, %F6 /* FPA */; \
78 inc %o5 /* IEU0 Group */; \
79 add %o2, %o4, %o2 /* IEU1 */; \
80 fcmpgt32 %f4, %F4, %g3 /* FPM Group */; \
81 srl %o5, 1, %o5 /* IEU0 */; \
83 fpadd32 %F8, %f8, %F8 /* FPA */; \
84 fcmpgt32 %f6, %F6, %g5 /* FPM Group */; \
85 srl %g1, 1, %g1 /* IEU0 */; \
86 add %o2, %o5, %o2 /* IEU1 */; \
87 fpadd32 %F10, %f10, %F10 /* FPA */; \
88 inc %g2 /* IEU0 Group */; \
89 add %o2, %g1, %o2 /* IEU1 */; \
90 fcmpgt32 %f8, %F8, %g7 /* FPM Group */; \
91 srl %g2, 1, %g2 /* IEU0 */; \
93 fpadd32 %F12, %f12, %F12 /* FPA */; \
94 fcmpgt32 %f10, %F10, %o3 /* FPM Group */; \
95 srl %g3, 1, %g3 /* IEU0 */; \
96 add %o2, %g2, %o2 /* IEU1 */; \
97 fpadd32 %F14, %f14, %F14 /* FPA */; \
98 inc %g5 /* IEU0 Group */; \
99 add %o2, %g3, %o2 /* IEU1 */;
101 #define END_THE_TRICK(O12,O14,f0,f2,f4,f6,f8,f10,f12,f14,S0,S1,S2,S3,T0,T1,U0,fz) \
102 fcmpgt32 %O12, %f12, %o4 /* FPM Group */; \
103 srl %g5, 1, %g5 /* IEU0 */; \
104 inc %g7 /* IEU1 */; \
105 fpadd32 %f2, %f0, %S0 /* FPA */; \
106 fcmpgt32 %O14, %f14, %o5 /* FPM Group */; \
107 srl %g7, 1, %g7 /* IEU0 */; \
108 add %o2, %g5, %o2 /* IEU1 */; \
109 fpadd32 %f6, %f4, %S1 /* FPA */; \
110 inc %o3 /* IEU0 Group */; \
111 add %o2, %g7, %o2 /* IEU1 */; \
112 fcmpgt32 %f0, %S0, %g1 /* FPM Group */; \
113 srl %o3, 1, %o3 /* IEU0 */; \
114 inc %o4 /* IEU1 */; \
115 fpadd32 %f10, %f8, %S2 /* FPA */; \
116 fcmpgt32 %f4, %S1, %g2 /* FPM Group */; \
117 srl %o4, 1, %o4 /* IEU0 */; \
118 add %o2, %o3, %o2 /* IEU1 */; \
119 fpadd32 %f14, %f12, %S3 /* FPA */; \
120 inc %o5 /* IEU0 Group */; \
121 add %o2, %o4, %o2 /* IEU1 */; \
122 fzero %fz /* FPA */; \
123 fcmpgt32 %f8, %S2, %g3 /* FPM Group */; \
124 srl %o5, 1, %o5 /* IEU0 */; \
125 inc %g1 /* IEU1 */; \
126 fpadd32 %S0, %S1, %T0 /* FPA */; \
127 fcmpgt32 %f12, %S3, %g5 /* FPM Group */; \
128 srl %g1, 1, %g1 /* IEU0 */; \
129 add %o2, %o5, %o2 /* IEU1 */; \
130 fpadd32 %S2, %S3, %T1 /* FPA */; \
131 inc %g2 /* IEU0 Group */; \
132 add %o2, %g1, %o2 /* IEU1 */; \
133 fcmpgt32 %S0, %T0, %g7 /* FPM Group */; \
134 srl %g2, 1, %g2 /* IEU0 */; \
135 inc %g3 /* IEU1 */; \
136 fcmpgt32 %S2, %T1, %o3 /* FPM Group */; \
137 srl %g3, 1, %g3 /* IEU0 */; \
138 add %o2, %g2, %o2 /* IEU1 */; \
139 inc %g5 /* IEU0 Group */; \
140 add %o2, %g3, %o2 /* IEU1 */; \
141 fcmpgt32 %fz, %f2, %o4 /* FPM Group */; \
142 srl %g5, 1, %g5 /* IEU0 */; \
143 inc %g7 /* IEU1 */; \
144 fpadd32 %T0, %T1, %U0 /* FPA */; \
145 fcmpgt32 %fz, %f6, %o5 /* FPM Group */; \
146 srl %g7, 1, %g7 /* IEU0 */; \
147 add %o2, %g5, %o2 /* IEU1 */; \
148 inc %o3 /* IEU0 Group */; \
149 add %o2, %g7, %o2 /* IEU1 */; \
150 fcmpgt32 %fz, %f10, %g1 /* FPM Group */; \
151 srl %o3, 1, %o3 /* IEU0 */; \
152 inc %o4 /* IEU1 */; \
153 fcmpgt32 %fz, %f14, %g2 /* FPM Group */; \
154 srl %o4, 1, %o4 /* IEU0 */; \
155 add %o2, %o3, %o2 /* IEU1 */; \
156 std %U0, [%sp + STACKOFF] /* Store Group */; \
157 inc %o5 /* IEU0 */; \
158 sub %o2, %o4, %o2 /* IEU1 */; \
159 fcmpgt32 %fz, %S1, %g3 /* FPM Group */; \
160 srl %o5, 1, %o5 /* IEU0 */; \
161 inc %g1 /* IEU1 */; \
162 fcmpgt32 %fz, %S3, %g5 /* FPM Group */; \
163 srl %g1, 1, %g1 /* IEU0 */; \
164 sub %o2, %o5, %o2 /* IEU1 */; \
165 ldx [%sp + STACKOFF], %o5 /* Load Group */; \
166 inc %g2 /* IEU0 */; \
167 sub %o2, %g1, %o2 /* IEU1 */; \
168 fcmpgt32 %fz, %T1, %g7 /* FPM Group */; \
169 srl %g2, 1, %g2 /* IEU0 */; \
170 inc %g3 /* IEU1 */; \
171 fcmpgt32 %T0, %U0, %o3 /* FPM Group */; \
172 srl %g3, 1, %g3 /* IEU0 */; \
173 sub %o2, %g2, %o2 /* IEU1 */; \
174 inc %g5 /* IEU0 Group */; \
175 sub %o2, %g3, %o2 /* IEU1 */; \
176 fcmpgt32 %fz, %U0, %o4 /* FPM Group */; \
177 srl %g5, 1, %g5 /* IEU0 */; \
178 inc %g7 /* IEU1 */; \
179 srl %g7, 1, %g7 /* IEU0 Group */; \
180 sub %o2, %g5, %o2 /* IEU1 */; \
181 inc %o3 /* IEU0 Group */; \
182 sub %o2, %g7, %o2 /* IEU1 */; \
183 srl %o3, 1, %o3 /* IEU0 Group */; \
184 inc %o4 /* IEU1 */; \
185 srl %o4, 1, %o4 /* IEU0 Group */; \
186 add %o2, %o3, %o2 /* IEU1 */; \
187 sub %o2, %o4, %o2 /* IEU0 Group */; \
188 addcc %o2, %o5, %o2 /* IEU1 Group */; \
189 bcs,a,pn %xcc, 33f /* CTI */; \
190 add %o2, 1, %o2 /* IEU0 */; \
193 #define CSUM_LASTCHUNK(offset) \
194 ldx [%o0 - offset - 0x10], %g2; \
195 ldx [%o0 - offset - 0x08], %g3; \
196 addcc %g2, %o2, %o2; \
197 bcs,a,pn %xcc, 31f; \
199 31: addcc %g3, %o2, %o2; \
200 bcs,a,pn %xcc, 32f; \
208 andcc %o0, 7, %g0 /* IEU1 Group */
209 be,pt %icc, 4f /* CTI */
210 andcc %o0, 0x38, %g3 /* IEU1 */
211 mov 1, %g5 /* IEU0 Group */
212 cmp %o1, 6 /* IEU1 */
213 bl,pn %icc, 21f /* CTI */
214 andcc %o0, 2, %g0 /* IEU1 Group */
215 be,pt %icc, 1f /* CTI */
216 and %o0, 4, %g7 /* IEU0 */
217 lduh [%o0], %g2 /* Load */
218 sub %o1, 2, %o1 /* IEU0 Group */
219 add %o0, 2, %o0 /* IEU1 */
220 andcc %o0, 4, %g7 /* IEU1 Group */
221 sll %g5, 16, %g5 /* IEU0 */
222 sll %g2, 16, %g2 /* IEU0 Group */
223 addcc %g2, %o2, %o2 /* IEU1 Group (regdep) */
224 bcs,a,pn %icc, 1f /* CTI */
225 add %o2, %g5, %o2 /* IEU0 */
226 1: ld [%o0], %g2 /* Load */
227 brz,a,pn %g7, 4f /* CTI+IEU1 Group */
228 and %o0, 0x38, %g3 /* IEU0 */
229 add %o0, 4, %o0 /* IEU0 Group */
230 sub %o1, 4, %o1 /* IEU1 */
231 addcc %g2, %o2, %o2 /* IEU1 Group */
232 bcs,a,pn %icc, 1f /* CTI */
233 add %o2, 1, %o2 /* IEU0 */
234 1: and %o0, 0x38, %g3 /* IEU1 Group */
235 4: srl %o2, 0, %o2 /* IEU0 Group */
236 mov 0x40, %g1 /* IEU1 */
237 brz,pn %g3, 3f /* CTI+IEU1 Group */
238 sub %g1, %g3, %g1 /* IEU0 */
239 cmp %o1, 56 /* IEU1 Group */
240 blu,pn %icc, 20f /* CTI */
241 andcc %o0, 8, %g0 /* IEU1 Group */
242 be,pn %icc, 1f /* CTI */
243 ldx [%o0], %g2 /* Load */
244 add %o0, 8, %o0 /* IEU0 Group */
245 sub %o1, 8, %o1 /* IEU1 */
246 addcc %g2, %o2, %o2 /* IEU1 Group */
247 bcs,a,pn %xcc, 1f /* CTI */
248 add %o2, 1, %o2 /* IEU0 */
249 1: andcc %g1, 0x10, %g0 /* IEU1 Group */
250 be,pn %icc, 2f /* CTI */
251 and %g1, 0x20, %g1 /* IEU0 */
252 ldx [%o0], %g2 /* Load */
253 ldx [%o0+8], %g3 /* Load Group */
254 add %o0, 16, %o0 /* IEU0 */
255 sub %o1, 16, %o1 /* IEU1 */
256 addcc %g2, %o2, %o2 /* IEU1 Group */
257 bcs,a,pn %xcc, 1f /* CTI */
258 add %o2, 1, %o2 /* IEU0 */
259 1: addcc %g3, %o2, %o2 /* IEU1 Group */
260 bcs,a,pn %xcc, 2f /* CTI */
261 add %o2, 1, %o2 /* IEU0 */
262 2: brz,pn %g1, 3f /* CTI+IEU1 Group */
263 ldx [%o0], %g2 /* Load */
264 ldx [%o0+8], %g3 /* Load Group */
265 ldx [%o0+16], %g5 /* Load Group */
266 ldx [%o0+24], %g7 /* Load Group */
267 add %o0, 32, %o0 /* IEU0 */
268 sub %o1, 32, %o1 /* IEU1 */
269 addcc %g2, %o2, %o2 /* IEU1 Group */
270 bcs,a,pn %xcc, 1f /* CTI */
271 add %o2, 1, %o2 /* IEU0 */
272 1: addcc %g3, %o2, %o2 /* IEU1 Group */
273 bcs,a,pn %xcc, 1f /* CTI */
274 add %o2, 1, %o2 /* IEU0 */
275 1: addcc %g5, %o2, %o2 /* IEU1 Group */
276 bcs,a,pn %xcc, 1f /* CTI */
277 add %o2, 1, %o2 /* IEU0 */
278 1: addcc %g7, %o2, %o2 /* IEU1 Group */
279 bcs,a,pn %xcc, 3f /* CTI */
280 add %o2, 1, %o2 /* IEU0 */
281 3: cmp %o1, 0xc0 /* IEU1 Group */
282 blu,pn %icc, 20f /* CTI */
283 sllx %o2, 32, %g5 /* IEU0 */
287 addcc %o2, %g5, %o2 /* IEU1 Group */
288 sub %o1, 0xc0, %o1 /* IEU0 */
289 wr %g0, ASI_BLK_P, %asi /* LSU Group */
290 membar #StoreLoad /* LSU Group */
291 srlx %o2, 32, %o2 /* IEU0 Group */
292 bcs,a,pn %xcc, 1f /* CTI */
293 add %o2, 1, %o2 /* IEU1 */
294 1: andcc %o1, 0x80, %g0 /* IEU1 Group */
295 bne,pn %icc, 7f /* CTI */
296 andcc %o1, 0x40, %g0 /* IEU1 Group */
297 be,pn %icc, 6f /* CTI */
299 fzero %f14 /* FPA Group */
300 ldda [%o0 + 0x000] %asi, %f16
301 ldda [%o0 + 0x040] %asi, %f32
302 ldda [%o0 + 0x080] %asi, %f48
303 START_THE_TRICK(f12,f16,f18,f20,f22,f24,f26)
305 6: sub %o0, 0x40, %o0 /* IEU0 Group */
307 fzero %f30 /* FPA Group */
308 ldda [%o0 + 0x040] %asi, %f32
309 ldda [%o0 + 0x080] %asi, %f48
310 ldda [%o0 + 0x0c0] %asi, %f0
311 START_THE_TRICK(f28,f32,f34,f36,f38,f40,f42)
313 7: bne,pt %icc, 8f /* CTI */
315 add %o0, 0x40, %o0 /* IEU0 Group */
317 fzero %f62 /* FPA Group */
318 ldda [%o0 - 0x040] %asi, %f0
319 ldda [%o0 + 0x000] %asi, %f16
320 ldda [%o0 + 0x040] %asi, %f32
321 START_THE_TRICK(f60,f0,f2,f4,f6,f8,f10)
323 8: add %o0, 0x80, %o0 /* IEU0 Group */
325 ldda [%o0 - 0x080] %asi, %f48
326 ldda [%o0 - 0x040] %asi, %f0
327 ldda [%o0 + 0x000] %asi, %f16
328 START_THE_TRICK(f44,f48,f50,f52,f54,f56,f58)
329 1: DO_THE_TRICK(f44,f46,f48,f50,f52,f54,f56,f58,f60,f62,f0,f2,f4,f6,f8,f10,f12,f14)
330 ldda [%o0 + 0x040] %asi, %f32
331 2: DO_THE_TRICK(f60,f62,f0,f2,f4,f6,f8,f10,f12,f14,f16,f18,f20,f22,f24,f26,f28,f30)
332 ldda [%o0 + 0x080] %asi, %f48
333 3: DO_THE_TRICK(f12,f14,f16,f18,f20,f22,f24,f26,f28,f30,f32,f34,f36,f38,f40,f42,f44,f46)
334 ldda [%o0 + 0x0c0] %asi, %f0
335 4: DO_THE_TRICK(f28,f30,f32,f34,f36,f38,f40,f42,f44,f46,f48,f50,f52,f54,f56,f58,f60,f62)
336 add %o0, 0x100, %o0 /* IEU0 Group */
337 subcc %o1, 0x100, %o1 /* IEU1 */
338 bgeu,a,pt %icc, 1b /* CTI */
339 ldda [%o0 + 0x000] %asi, %f16
340 membar #Sync /* LSU Group */
341 DO_THE_TRICK(f44,f46,f48,f50,f52,f54,f56,f58,f60,f62,f0,f2,f4,f6,f8,f10,f12,f14)
342 END_THE_TRICK(f60,f62,f0,f2,f4,f6,f8,f10,f12,f14,f16,f18,f20,f22,f24,f26,f28,f30)
344 ldub [%g6 + AOFF_task_thread + AOFF_thread_current_ds], %g7
346 and %o1, 0x3f, %o1 /* IEU0 Group */
351 20: andcc %o1, 0xf0, %g1 /* IEU1 Group */
352 be,pn %icc, 23f /* CTI */
353 and %o1, 0xf, %o3 /* IEU0 */
355 22: sll %g1, 1, %o4 /* IEU0 Group */
356 sethi %hi(23f), %g7 /* IEU1 */
357 sub %g7, %o4, %g7 /* IEU0 Group */
358 jmpl %g7 + %lo(23f), %g0 /* CTI Group brk forced */
359 add %o0, %g1, %o0 /* IEU0 */
361 22: rd %pc, %g7 /* LSU Group+4bubbles */
362 sll %g1, 1, %o4 /* IEU0 Group */
363 sub %g7, %o4, %g7 /* IEU0 Group (regdep) */
364 jmpl %g7 + (23f - 22b), %g0 /* CTI Group brk forced */
365 add %o0, %g1, %o0 /* IEU0 */
382 23: brnz,pn %o3, 26f /* CTI+IEU1 Group */
383 24: sllx %o2, 32, %g1 /* IEU0 */
384 25: addcc %o2, %g1, %o0 /* IEU1 Group */
385 srlx %o0, 32, %o0 /* IEU0 Group (regdep) */
386 bcs,a,pn %xcc, 1f /* CTI */
387 add %o0, 1, %o0 /* IEU1 */
388 1: retl /* CTI Group brk forced */
389 srl %o0, 0, %o0 /* IEU0 */
390 26: andcc %o1, 8, %g0 /* IEU1 Group */
391 be,pn %icc, 1f /* CTI */
392 ldx [%o0], %g3 /* Load */
393 add %o0, 8, %o0 /* IEU0 Group */
394 addcc %g3, %o2, %o2 /* IEU1 Group */
395 bcs,a,pn %xcc, 1f /* CTI */
396 add %o2, 1, %o2 /* IEU0 */
397 1: andcc %o1, 4, %g0 /* IEU1 Group */
398 be,a,pn %icc, 1f /* CTI */
400 ld [%o0], %g2 /* Load */
401 add %o0, 4, %o0 /* IEU0 Group */
402 sllx %g2, 32, %g2 /* IEU0 Group */
403 1: andcc %o1, 2, %g0 /* IEU1 */
404 be,a,pn %icc, 1f /* CTI */
405 clr %o4 /* IEU0 Group */
406 lduh [%o0], %o4 /* Load */
407 add %o0, 2, %o0 /* IEU1 */
408 sll %o4, 16, %o4 /* IEU0 Group */
409 1: andcc %o1, 1, %g0 /* IEU1 */
410 be,a,pn %icc, 1f /* CTI */
411 clr %o5 /* IEU0 Group */
412 ldub [%o0], %o5 /* Load */
413 sll %o5, 8, %o5 /* IEU0 Group */
414 1: or %g2, %o4, %o4 /* IEU1 */
415 or %o5, %o4, %o4 /* IEU0 Group (regdep) */
416 addcc %o4, %o2, %o2 /* IEU1 Group (regdep) */
417 bcs,a,pn %xcc, 1f /* CTI */
418 add %o2, 1, %o2 /* IEU0 */
419 1: ba,pt %xcc, 25b /* CTI Group */
420 sllx %o2, 32, %g1 /* IEU0 */
421 21: srl %o2, 0, %o2 /* IEU0 Group */
422 cmp %o1, 0 /* IEU1 */
423 be,pn %icc, 24b /* CTI */
424 andcc %o1, 4, %g0 /* IEU1 Group */
425 be,a,pn %icc, 1f /* CTI */
427 lduh [%o0], %g3 /* Load */
428 lduh [%o0+2], %g2 /* Load Group */
429 add %o0, 4, %o0 /* IEU0 Group */
430 sllx %g3, 48, %g3 /* IEU0 Group */
431 sllx %g2, 32, %g2 /* IEU0 Group */
432 or %g3, %g2, %g2 /* IEU0 Group */
433 1: andcc %o1, 2, %g0 /* IEU1 */
434 be,a,pn %icc, 1f /* CTI */
435 clr %o4 /* IEU0 Group */
436 lduh [%o0], %o4 /* Load */
437 add %o0, 2, %o0 /* IEU1 */
438 sll %o4, 16, %o4 /* IEU0 Group */
439 1: andcc %o1, 1, %g0 /* IEU1 */
440 be,a,pn %icc, 1f /* CTI */
441 clr %o5 /* IEU0 Group */
442 ldub [%o0], %o5 /* Load */
443 sll %o5, 8, %o5 /* IEU0 Group */
444 1: or %g2, %o4, %o4 /* IEU1 */
445 or %o5, %o4, %o4 /* IEU0 Group (regdep) */
446 addcc %o4, %o2, %o2 /* IEU1 Group (regdep) */
447 bcs,a,pn %xcc, 1f /* CTI */
448 add %o2, 1, %o2 /* IEU0 */
449 1: ba,pt %xcc, 25b /* CTI Group */
450 sllx %o2, 32, %g1 /* IEU0 */