2 * This file contains assembly-language implementations
3 * of IP-style 1's complement checksum routines.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Severely hacked about by Paul Mackerras (paulus@cs.anu.edu.au).
15 #include <linux/sys.h>
16 #include <asm/processor.h>
17 #include <asm/errno.h>
18 #include <asm/ppc_asm.h>
19 #include <asm/export.h>
22 * Computes the checksum of a memory block at buff, length len,
23 * and adds in "sum" (32-bit).
25 * __csum_partial(r3=buff, r4=len, r5=sum)
27 _GLOBAL(__csum_partial)
28 addic r0,r5,0 /* clear carry */
30 srdi. r6,r4,3 /* less than 8 bytes? */
34 * If only halfword aligned, align to a double word. Since odd
35 * aligned addresses should be rare and they would require more
36 * work to calculate the correct checksum, we ignore that case
37 * and take the potential slowdown of unaligned loads.
39 rldicl. r6,r3,64-1,64-2 /* r6 = (r3 & 0x3) >> 1 */
47 lhz r6,0(r3) /* align to doubleword */
55 * We unroll the loop such that each iteration is 64 bytes with an
56 * entry and exit limb of 64 bytes, meaning a minimum size of
60 beq .Lcsum_tail_doublewords /* len < 128 */
66 stdu r1,-STACKFRAMESIZE(r1)
67 std r14,STK_REG(R14)(r1)
68 std r15,STK_REG(R15)(r1)
69 std r16,STK_REG(R16)(r1)
78 * On POWER6 and POWER7 back to back adde instructions take 2 cycles
79 * because of the XER dependency. This means the fastest this loop can
80 * go is 16 cycles per iteration. The scheduling of the loop below has
81 * been shown to hit this on both POWER6 and POWER7.
128 ld r14,STK_REG(R14)(r1)
129 ld r15,STK_REG(R15)(r1)
130 ld r16,STK_REG(R16)(r1)
131 addi r1,r1,STACKFRAMESIZE
135 .Lcsum_tail_doublewords: /* Up to 127 bytes to go */
148 .Lcsum_tail_word: /* Up to 7 bytes to go */
150 beq .Lcsum_tail_halfword
157 .Lcsum_tail_halfword: /* Up to 3 bytes to go */
166 .Lcsum_tail_byte: /* Up to 1 byte to go */
171 sldi r9,r6,8 /* Pad the byte out to 16 bits */
175 addze r0,r0 /* add in final carry */
176 rldicl r4,r0,32,0 /* fold two 32 bit halves together */
180 EXPORT_SYMBOL(__csum_partial)
185 .section __ex_table,"a"
187 .llong 100b,.Lsrc_error_nr
193 .section __ex_table,"a"
195 .llong 150b,.Lsrc_error
201 .section __ex_table,"a"
203 .llong 200b,.Ldest_error_nr
209 .section __ex_table,"a"
211 .llong 250b,.Ldest_error
216 * Computes the checksum of a memory block at src, length len,
217 * and adds in "sum" (32-bit), while copying the block to dst.
218 * If an access exception occurs on src or dst, it stores -EFAULT
219 * to *src_err or *dst_err respectively. The caller must take any action
220 * required in this case (zeroing memory, recalculating partial checksum etc).
222 * csum_partial_copy_generic(r3=src, r4=dst, r5=len, r6=sum, r7=src_err, r8=dst_err)
224 _GLOBAL(csum_partial_copy_generic)
225 addic r0,r6,0 /* clear carry */
227 srdi. r6,r5,3 /* less than 8 bytes? */
231 * If only halfword aligned, align to a double word. Since odd
232 * aligned addresses should be rare and they would require more
233 * work to calculate the correct checksum, we ignore that case
234 * and take the potential slowdown of unaligned loads.
236 * If the source and destination are relatively unaligned we only
237 * align the source. This keeps things simple.
239 rldicl. r6,r3,64-1,64-2 /* r6 = (r3 & 0x3) >> 1 */
247 srcnr; lhz r6,0(r3) /* align to doubleword */
257 * We unroll the loop such that each iteration is 64 bytes with an
258 * entry and exit limb of 64 bytes, meaning a minimum size of
262 beq .Lcopy_tail_doublewords /* len < 128 */
268 stdu r1,-STACKFRAMESIZE(r1)
269 std r14,STK_REG(R14)(r1)
270 std r15,STK_REG(R15)(r1)
271 std r16,STK_REG(R16)(r1)
276 source; ld r10,16(r3)
277 source; ld r11,24(r3)
280 * On POWER6 and POWER7 back to back adde instructions take 2 cycles
281 * because of the XER dependency. This means the fastest this loop can
282 * go is 16 cycles per iteration. The scheduling of the loop below has
283 * been shown to hit this on both POWER6 and POWER7.
288 source; ld r12,32(r3)
289 source; ld r14,40(r3)
292 source; ld r15,48(r3)
293 source; ld r16,56(r3)
318 source; ld r10,16(r3)
319 source; ld r11,24(r3)
324 source; ld r12,32(r3)
325 source; ld r14,40(r3)
328 source; ld r15,48(r3)
329 source; ld r16,56(r3)
352 ld r14,STK_REG(R14)(r1)
353 ld r15,STK_REG(R15)(r1)
354 ld r16,STK_REG(R16)(r1)
355 addi r1,r1,STACKFRAMESIZE
359 .Lcopy_tail_doublewords: /* Up to 127 bytes to go */
374 .Lcopy_tail_word: /* Up to 7 bytes to go */
376 beq .Lcopy_tail_halfword
385 .Lcopy_tail_halfword: /* Up to 3 bytes to go */
396 .Lcopy_tail_byte: /* Up to 1 byte to go */
401 sldi r9,r6,8 /* Pad the byte out to 16 bits */
406 addze r0,r0 /* add in final carry */
407 rldicl r4,r0,32,0 /* fold two 32 bit halves together */
413 ld r14,STK_REG(R14)(r1)
414 ld r15,STK_REG(R15)(r1)
415 ld r16,STK_REG(R16)(r1)
416 addi r1,r1,STACKFRAMESIZE
425 ld r14,STK_REG(R14)(r1)
426 ld r15,STK_REG(R15)(r1)
427 ld r16,STK_REG(R16)(r1)
428 addi r1,r1,STACKFRAMESIZE
435 EXPORT_SYMBOL(csum_partial_copy_generic)