2 * include/asm-x86_64/xor.h
4 * Optimized RAID-5 checksumming functions for MMX and SSE.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * You should have received a copy of the GNU General Public License
12 * (for example /usr/src/linux/COPYING); if not, write to the Free
13 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * Cache avoiding checksumming functions utilizing KNI instructions
19 * Copyright (C) 1999 Zach Brown (with obvious credit due Ingo)
24 * High-speed RAID5 checksumming functions utilizing SSE instructions.
25 * Copyright (C) 1998 Ingo Molnar.
29 * x86-64 changes / gcc fixes from Andi Kleen.
30 * Copyright 2002 Andi Kleen, SuSE Labs.
32 * This hasn't been optimized for the hammer yet, but there are likely
33 * no advantages to be gotten from x86-64 here anyways.
36 typedef struct { unsigned long a,b; } __attribute__((aligned(16))) xmm_store_t;
38 /* Doesn't use gcc to save the XMM registers, because there is no easy way to
39 tell it to do a clts before the register saving. */
40 #define XMMS_SAVE do { \
43 "movq %%cr0,%0 ;\n\t" \
45 "movups %%xmm0,(%1) ;\n\t" \
46 "movups %%xmm1,0x10(%1) ;\n\t" \
47 "movups %%xmm2,0x20(%1) ;\n\t" \
48 "movups %%xmm3,0x30(%1) ;\n\t" \
54 #define XMMS_RESTORE do { \
57 "movups (%1),%%xmm0 ;\n\t" \
58 "movups 0x10(%1),%%xmm1 ;\n\t" \
59 "movups 0x20(%1),%%xmm2 ;\n\t" \
60 "movups 0x30(%1),%%xmm3 ;\n\t" \
61 "movq %0,%%cr0 ;\n\t" \
63 : "r" (cr0), "r" (xmm_save) \
68 #define OFFS(x) "16*("#x")"
69 #define PF_OFFS(x) "256+16*("#x")"
70 #define PF0(x) " prefetchnta "PF_OFFS(x)"(%[p1]) ;\n"
71 #define LD(x,y) " movaps "OFFS(x)"(%[p1]), %%xmm"#y" ;\n"
72 #define ST(x,y) " movaps %%xmm"#y", "OFFS(x)"(%[p1]) ;\n"
73 #define PF1(x) " prefetchnta "PF_OFFS(x)"(%[p2]) ;\n"
74 #define PF2(x) " prefetchnta "PF_OFFS(x)"(%[p3]) ;\n"
75 #define PF3(x) " prefetchnta "PF_OFFS(x)"(%[p4]) ;\n"
76 #define PF4(x) " prefetchnta "PF_OFFS(x)"(%[p5]) ;\n"
77 #define PF5(x) " prefetchnta "PF_OFFS(x)"(%[p6]) ;\n"
78 #define XO1(x,y) " xorps "OFFS(x)"(%[p2]), %%xmm"#y" ;\n"
79 #define XO2(x,y) " xorps "OFFS(x)"(%[p3]), %%xmm"#y" ;\n"
80 #define XO3(x,y) " xorps "OFFS(x)"(%[p4]), %%xmm"#y" ;\n"
81 #define XO4(x,y) " xorps "OFFS(x)"(%[p5]), %%xmm"#y" ;\n"
82 #define XO5(x,y) " xorps "OFFS(x)"(%[p6]), %%xmm"#y" ;\n"
86 xor_sse_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
88 unsigned int lines = bytes >> 8;
90 xmm_store_t xmm_save[4];
126 " addq %[inc], %[p1] ;\n"
127 " addq %[inc], %[p2] ;\n"
128 " decl %[cnt] ; jnz 1b"
129 : [p1] "+r" (p1), [p2] "+r" (p2), [cnt] "+r" (lines)
137 xor_sse_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
140 unsigned int lines = bytes >> 8;
141 xmm_store_t xmm_save[4];
146 __asm__ __volatile__ (
184 " addq %[inc], %[p1] ;\n"
185 " addq %[inc], %[p2] ;\n"
186 " addq %[inc], %[p3] ;\n"
187 " decl %[cnt] ; jnz 1b"
188 : [cnt] "+r" (lines),
189 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3)
196 xor_sse_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
197 unsigned long *p3, unsigned long *p4)
199 unsigned int lines = bytes >> 8;
200 xmm_store_t xmm_save[4];
205 __asm__ __volatile__ (
249 " addq %[inc], %[p1] ;\n"
250 " addq %[inc], %[p2] ;\n"
251 " addq %[inc], %[p3] ;\n"
252 " addq %[inc], %[p4] ;\n"
253 " decl %[cnt] ; jnz 1b"
254 : [cnt] "+c" (lines),
255 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4)
263 xor_sse_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
264 unsigned long *p3, unsigned long *p4, unsigned long *p5)
266 unsigned int lines = bytes >> 8;
267 xmm_store_t xmm_save[4];
272 __asm__ __volatile__ (
322 " addq %[inc], %[p1] ;\n"
323 " addq %[inc], %[p2] ;\n"
324 " addq %[inc], %[p3] ;\n"
325 " addq %[inc], %[p4] ;\n"
326 " addq %[inc], %[p5] ;\n"
327 " decl %[cnt] ; jnz 1b"
328 : [cnt] "+c" (lines),
329 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4),
337 static struct xor_block_template xor_block_sse = {
338 .name = "generic_sse",
345 #undef XOR_TRY_TEMPLATES
346 #define XOR_TRY_TEMPLATES \
348 xor_speed(&xor_block_sse); \
351 /* We force the use of the SSE xor block because it can write around L2.
352 We may also be able to load into the L1 only depending on how the cpu
353 deals with a load to a line that is being prefetched. */
354 #define XOR_SELECT_TEMPLATE(FASTEST) (&xor_block_sse)