1 /* csum_copy.S: Checksum+copy code for sparc64
3 * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
7 #define GLOBAL_SPARE %g7
9 #define GLOBAL_SPARE %g5
21 #define EX_RETVAL(x) x
25 #define LOAD(type,addr,dest) type [addr], dest
29 #define STORE(type,src,addr) type src, [addr]
33 #define FUNC_NAME csum_partial_copy_nocheck
36 .register %g2, #scratch
37 .register %g3, #scratch
42 /* We checked for zero length already, so there must be
47 EX_LD(LOAD(ldub, %o0 + 0x00, %o4))
50 EX_ST(STORE(stb, %o4, %o1 + 0x00))
52 1: andcc %o0, 0x2, %g0
57 EX_LD(LOAD(lduh, %o0 + 0x00, %o5))
60 EX_ST(STORE(sth, %o5, %o1 + 0x00))
66 FUNC_NAME: /* %o0=src, %o1=dst, %o2=len, %o3=sum */
67 LOAD(prefetch, %o0 + 0x000, #n_reads)
72 LOAD(prefetch, %o0 + 0x040, #n_reads)
77 /* We "remember" whether the lowest bit in the address
78 * was set in GLOBAL_SPARE. Because if it is, we have to swap
79 * upper and lower 8 bit fields of the sum we calculate.
82 andcc %o0, 0x1, GLOBAL_SPARE
85 LOAD(prefetch, %o0 + 0x080, #n_reads)
88 LOAD(prefetch, %o0 + 0x0c0, #n_reads)
91 LOAD(prefetch, %o0 + 0x100, #n_reads)
93 /* So that we don't need to use the non-pairing
94 * add-with-carry instructions we accumulate 32-bit
95 * values into a 64-bit register. At the end of the
96 * loop we fold it down to 32-bits and so on.
99 LOAD(prefetch, %o0 + 0x140, #n_reads)
102 1: EX_LD(LOAD(lduw, %o0 + 0x00, %o5))
103 EX_LD(LOAD(lduw, %o0 + 0x04, %g1))
104 EX_LD(LOAD(lduw, %o0 + 0x08, %g2))
106 EX_ST(STORE(stw, %o5, %o1 + 0x00))
107 EX_LD(LOAD(lduw, %o0 + 0x0c, %o5))
109 EX_ST(STORE(stw, %g1, %o1 + 0x04))
110 EX_LD(LOAD(lduw, %o0 + 0x10, %g1))
112 EX_ST(STORE(stw, %g2, %o1 + 0x08))
113 EX_LD(LOAD(lduw, %o0 + 0x14, %g2))
115 EX_ST(STORE(stw, %o5, %o1 + 0x0c))
116 EX_LD(LOAD(lduw, %o0 + 0x18, %o5))
118 EX_ST(STORE(stw, %g1, %o1 + 0x10))
119 EX_LD(LOAD(lduw, %o0 + 0x1c, %g1))
121 EX_ST(STORE(stw, %g2, %o1 + 0x14))
122 EX_LD(LOAD(lduw, %o0 + 0x20, %g2))
124 EX_ST(STORE(stw, %o5, %o1 + 0x18))
125 EX_LD(LOAD(lduw, %o0 + 0x24, %o5))
127 EX_ST(STORE(stw, %g1, %o1 + 0x1c))
128 EX_LD(LOAD(lduw, %o0 + 0x28, %g1))
130 EX_ST(STORE(stw, %g2, %o1 + 0x20))
131 EX_LD(LOAD(lduw, %o0 + 0x2c, %g2))
133 EX_ST(STORE(stw, %o5, %o1 + 0x24))
134 EX_LD(LOAD(lduw, %o0 + 0x30, %o5))
136 EX_ST(STORE(stw, %g1, %o1 + 0x28))
137 EX_LD(LOAD(lduw, %o0 + 0x34, %g1))
139 EX_ST(STORE(stw, %g2, %o1 + 0x2c))
140 EX_LD(LOAD(lduw, %o0 + 0x38, %g2))
142 EX_ST(STORE(stw, %o5, %o1 + 0x30))
143 EX_LD(LOAD(lduw, %o0 + 0x3c, %o5))
145 EX_ST(STORE(stw, %g1, %o1 + 0x34))
146 LOAD(prefetch, %o0 + 0x180, #n_reads)
148 EX_ST(STORE(stw, %g2, %o1 + 0x38))
152 EX_ST(STORE(stw, %o5, %o1 + 0x3c))
156 2: and %o2, 0x3c, %g3
159 1: EX_LD(LOAD(lduw, %o0 + 0x00, %o5))
163 EX_ST(STORE(stw, %o5, %o1 + 0x00))
177 sethi %hi(0xffff0000), %g1
186 /* %o4 has the 16-bit sum we have calculated so-far. */
190 EX_LD(LOAD(lduh, %o0 + 0x00, %o5))
194 EX_ST(STORE(sth, %o5, %o1 + 0x00))
198 EX_LD(LOAD(ldub, %o0 + 0x00, %o5))
201 EX_ST(STORE(stb, %o5, %o1 + 0x00))
207 sethi %hi(0xffff0000), %g1
215 1: brz,pt GLOBAL_SPARE, 1f
218 /* We started with an odd byte, byte-swap the result. */
224 1: addcc %o3, %o4, %o3
231 95: mov 0, GLOBAL_SPARE
237 EX_LD(LOAD(ldub, %o0, GLOBAL_SPARE))
239 EX_ST(STORE(stb, GLOBAL_SPARE, %o1))
247 EX_LD(LOAD(lduh, %o0, %o4))
251 EX_ST(STORE(stb, %g2, %o1))
252 add %o4, GLOBAL_SPARE, GLOBAL_SPARE
253 EX_ST(STORE(stb, %o4, %o1 + 1))
259 EX_LD(LOAD(lduw, %o0, %o4))
262 EX_ST(STORE(stb, %g2, %o1))
264 EX_ST(STORE(stb, %g3, %o1 + 1))
266 EX_ST(STORE(stb, %g2, %o1 + 2))
267 addcc %o4, GLOBAL_SPARE, GLOBAL_SPARE
268 EX_ST(STORE(stb, %o4, %o1 + 3))
269 addc GLOBAL_SPARE, %g0, GLOBAL_SPARE
273 EX_LD(LOAD(lduw, %o0, %o4))
274 sll GLOBAL_SPARE, 16, %g2
275 srl GLOBAL_SPARE, 16, GLOBAL_SPARE
278 add %g2, GLOBAL_SPARE, GLOBAL_SPARE
281 EX_LD(LOAD(lduh, %o0, %o4))
285 EX_ST(STORE(stb, %g2, %o1))
286 add GLOBAL_SPARE, %o4, GLOBAL_SPARE
287 EX_ST(STORE(stb, %o4, %o1 + 1))
290 sll GLOBAL_SPARE, 16, %o4
291 EX_LD(LOAD(ldub, %o0, %g2))
293 EX_ST(STORE(stb, %g2, %o1))
294 add GLOBAL_SPARE, %o4, GLOBAL_SPARE
295 sll GLOBAL_SPARE, 16, %o4
296 1: addcc %o4, GLOBAL_SPARE, GLOBAL_SPARE
297 srl GLOBAL_SPARE, 16, %o4
298 addc %g0, %o4, GLOBAL_SPARE
300 srl GLOBAL_SPARE, 8, %o4
301 and GLOBAL_SPARE, 0xff, %g2
304 or %g2, %o4, GLOBAL_SPARE
305 4: addcc %o3, GLOBAL_SPARE, %o3
309 .size FUNC_NAME, .-FUNC_NAME