Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | /* * Copyright 2002 Andi Kleen * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. No warranty for anything given at all. */ #include <linux/linkage.h> #include <asm/errno.h> // #define FIX_ALIGNMENT 1 /* * Checksum copy with exception handling. * On exceptions src_err_ptr or dst_err_ptr is set to -EFAULT and the * destination is zeroed. * * Input * rdi source * rsi destination * edx len (32bit) * ecx sum (32bit) * r8 src_err_ptr (int) * r9 dst_err_ptr (int) * * Output * eax 64bit sum. undefined in case of exception. * * Wrappers need to take care of valid exception sum and zeroing. */ .macro source 10: .section __ex_table,"a" .align 8 .quad 10b,bad_source .previous .endm .macro dest 20: .section __ex_table,"a" .align 8 .quad 20b,bad_dest .previous .endm .globl csum_partial_copy_generic .p2align csum_partial_copy_generic: prefetchnta (%rdi) pushq %rbx pushq %r12 pushq %r14 pushq %r15 movq %r8,%r14 movq %r9,%r15 movl %ecx,%eax movl %edx,%ecx #ifdef FIX_ALIGNMENT /* align source to 8 bytes */ movl %edi,%r8d andl $7,%r8d jnz bad_alignment after_bad_alignment: #endif movl $64,%r10d xorl %r9d,%r9d movq %rcx,%r12 shrq $6,%r12 /* loopcounter is maintained as one less to test efficiently for the previous to last iteration. This is needed to stop the prefetching. */ decq %r12 js handle_tail /* < 64 */ jz loop_no_prefetch /* = 64 + X */ /* main loop. clear in 64 byte blocks */ /* tries hard not to prefetch over the boundary */ /* r10: 64, r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */ /* r11: temp3, rdx: temp4, r12 loopcnt */ .p2align loop: /* Could prefetch more than one loop, but then it would be even trickier to avoid prefetching over the boundary. The hardware prefetch should take care of this anyways. The reason for this prefetch is just the non temporal hint to avoid cache pollution. Hopefully this will be handled properly by the hardware. */ prefetchnta 64(%rdi) loop_no_prefetch: source movq (%rdi),%rbx source movq 8(%rdi),%r8 source movq 16(%rdi),%r11 source movq 24(%rdi),%rdx dest movnti %rbx,(%rsi) dest movnti %r8,8(%rsi) dest movnti %r11,16(%rsi) dest movnti %rdx,24(%rsi) addq %rbx,%rax adcq %r8,%rax adcq %r11,%rax adcq %rdx,%rax source movq 32(%rdi),%rbx source movq 40(%rdi),%r8 source movq 48(%rdi),%r11 source movq 56(%rdi),%rdx dest movnti %rbx,32(%rsi) dest movnti %r8,40(%rsi) dest movnti %r11,48(%rsi) dest movnti %rdx,56(%rsi) adcq %rbx,%rax adcq %r8,%rax adcq %r11,%rax adcq %rdx,%rax adcq %r9,%rax /* add in carry */ addq %r10,%rdi addq %r10,%rsi decq %r12 jz loop_no_prefetch /* previous to last iteration? */ jns loop /* do last upto 56 bytes */ handle_tail: /* ecx: count */ movl %ecx,%r10d andl $63,%ecx shrl $3,%ecx jz fold clc movl $8,%edx loop_8: source movq (%rdi),%rbx adcq %rbx,%rax dest movnti %rbx,(%rsi) leaq (%rsi,%rdx),%rsi /* preserve carry */ leaq (%rdi,%rdx),%rdi loop loop_8 adcq %r9,%rax /* add in carry */ fold: movl %eax,%ebx shrq $32,%rax addq %rbx,%rax /* do last upto 6 bytes */ handle_7: movl %r10d,%ecx andl $7,%ecx shrl $1,%ecx jz handle_1 movl $2,%edx xorl %ebx,%ebx clc loop_1: source movw (%rdi),%bx adcq %rbx,%rax dest movw %bx,(%rsi) addq %rdx,%rdi addq %rdx,%rsi loop loop_1 adcw %r9w,%ax /* add in carry */ /* handle last odd byte */ handle_1: testl $1,%r10d jz ende xorl %ebx,%ebx source movb (%rdi),%bl dest movb %bl,(%rsi) addw %bx,%ax adcw %r9w,%ax /* carry */ ende: sfence popq %r15 popq %r14 popq %r12 popq %rbx ret #ifdef FIX_ALIGNMENT /* align source to 8 bytes. */ /* r8d: unalignedness, ecx len */ bad_alignment: testl $1,%edi jnz odd_source /* compute distance to next aligned position */ movl $8,%r8d xchgl %r8d,%ecx subl %r8d,%ecx /* handle unaligned part */ shrl $1,%ecx xorl %ebx,%ebx movl $2,%r10d align_loop: source movw (%rdi),%bx addq %rbx,%rax /* carry cannot happen */ dest movw %bx,(%rsi) addq %r10,%rdi addq %r10,%rsi loop align_loop jmp after_bad_alignment /* weird case. need to swap the sum at the end because the spec requires 16 bit words of the sum to be always paired. handle it recursively because it should be rather rare. */ odd_source: /* copy odd byte */ xorl %ebx,%ebx source movb (%rdi),%bl addl %ebx,%eax /* add to old checksum */ adcl $0,%ecx dest movb %al,(%rsi) /* fix arguments */ movl %eax,%ecx incq %rsi incq %rdi decq %rdx call csum_partial_copy_generic bswap %eax /* this should work, but check */ jmp ende #endif /* Exception handlers. Very simple, zeroing is done in the wrappers */ bad_source: movl $-EFAULT,(%r14) jmp ende bad_dest: movl $-EFAULT,(%r15) jmp ende |