2 * Optimized RAID-5 checksumming functions for MMX and SSE.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * You should have received a copy of the GNU General Public License
10 * (for example /usr/src/linux/COPYING); if not, write to the Free
11 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 * Cache avoiding checksumming functions utilizing KNI instructions
17 * Copyright (C) 1999 Zach Brown (with obvious credit due Ingo)
22 * High-speed RAID5 checksumming functions utilizing SSE instructions.
23 * Copyright (C) 1998 Ingo Molnar.
27 * x86-64 changes / gcc fixes from Andi Kleen.
28 * Copyright 2002 Andi Kleen, SuSE Labs.
30 * This hasn't been optimized for the hammer yet, but there are likely
31 * no advantages to be gotten from x86-64 here anyways.
34 typedef struct { unsigned long a
,b
; } __attribute__((aligned(16))) xmm_store_t
;
36 /* Doesn't use gcc to save the XMM registers, because there is no easy way to
37 tell it to do a clts before the register saving. */
38 #define XMMS_SAVE do { \
41 "movq %%cr0,%0 ;\n\t" \
43 "movups %%xmm0,(%1) ;\n\t" \
44 "movups %%xmm1,0x10(%1) ;\n\t" \
45 "movups %%xmm2,0x20(%1) ;\n\t" \
46 "movups %%xmm3,0x30(%1) ;\n\t" \
52 #define XMMS_RESTORE do { \
55 "movups (%1),%%xmm0 ;\n\t" \
56 "movups 0x10(%1),%%xmm1 ;\n\t" \
57 "movups 0x20(%1),%%xmm2 ;\n\t" \
58 "movups 0x30(%1),%%xmm3 ;\n\t" \
59 "movq %0,%%cr0 ;\n\t" \
61 : "r" (cr0), "r" (xmm_save) \
66 #define OFFS(x) "16*("#x")"
67 #define PF_OFFS(x) "256+16*("#x")"
68 #define PF0(x) " prefetchnta "PF_OFFS(x)"(%[p1]) ;\n"
69 #define LD(x,y) " movaps "OFFS(x)"(%[p1]), %%xmm"#y" ;\n"
70 #define ST(x,y) " movaps %%xmm"#y", "OFFS(x)"(%[p1]) ;\n"
71 #define PF1(x) " prefetchnta "PF_OFFS(x)"(%[p2]) ;\n"
72 #define PF2(x) " prefetchnta "PF_OFFS(x)"(%[p3]) ;\n"
73 #define PF3(x) " prefetchnta "PF_OFFS(x)"(%[p4]) ;\n"
74 #define PF4(x) " prefetchnta "PF_OFFS(x)"(%[p5]) ;\n"
75 #define PF5(x) " prefetchnta "PF_OFFS(x)"(%[p6]) ;\n"
76 #define XO1(x,y) " xorps "OFFS(x)"(%[p2]), %%xmm"#y" ;\n"
77 #define XO2(x,y) " xorps "OFFS(x)"(%[p3]), %%xmm"#y" ;\n"
78 #define XO3(x,y) " xorps "OFFS(x)"(%[p4]), %%xmm"#y" ;\n"
79 #define XO4(x,y) " xorps "OFFS(x)"(%[p5]), %%xmm"#y" ;\n"
80 #define XO5(x,y) " xorps "OFFS(x)"(%[p6]), %%xmm"#y" ;\n"
84 xor_sse_2(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
)
86 unsigned int lines
= bytes
>> 8;
88 xmm_store_t xmm_save
[4];
124 " addq %[inc], %[p1] ;\n"
125 " addq %[inc], %[p2] ;\n"
126 " decl %[cnt] ; jnz 1b"
127 : [p1
] "+r" (p1
), [p2
] "+r" (p2
), [cnt
] "+r" (lines
)
135 xor_sse_3(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
138 unsigned int lines
= bytes
>> 8;
139 xmm_store_t xmm_save
[4];
144 __asm__
__volatile__ (
182 " addq %[inc], %[p1] ;\n"
183 " addq %[inc], %[p2] ;\n"
184 " addq %[inc], %[p3] ;\n"
185 " decl %[cnt] ; jnz 1b"
186 : [cnt
] "+r" (lines
),
187 [p1
] "+r" (p1
), [p2
] "+r" (p2
), [p3
] "+r" (p3
)
194 xor_sse_4(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
195 unsigned long *p3
, unsigned long *p4
)
197 unsigned int lines
= bytes
>> 8;
198 xmm_store_t xmm_save
[4];
203 __asm__
__volatile__ (
247 " addq %[inc], %[p1] ;\n"
248 " addq %[inc], %[p2] ;\n"
249 " addq %[inc], %[p3] ;\n"
250 " addq %[inc], %[p4] ;\n"
251 " decl %[cnt] ; jnz 1b"
252 : [cnt
] "+c" (lines
),
253 [p1
] "+r" (p1
), [p2
] "+r" (p2
), [p3
] "+r" (p3
), [p4
] "+r" (p4
)
261 xor_sse_5(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
262 unsigned long *p3
, unsigned long *p4
, unsigned long *p5
)
264 unsigned int lines
= bytes
>> 8;
265 xmm_store_t xmm_save
[4];
270 __asm__
__volatile__ (
320 " addq %[inc], %[p1] ;\n"
321 " addq %[inc], %[p2] ;\n"
322 " addq %[inc], %[p3] ;\n"
323 " addq %[inc], %[p4] ;\n"
324 " addq %[inc], %[p5] ;\n"
325 " decl %[cnt] ; jnz 1b"
326 : [cnt
] "+c" (lines
),
327 [p1
] "+r" (p1
), [p2
] "+r" (p2
), [p3
] "+r" (p3
), [p4
] "+r" (p4
),
335 static struct xor_block_template xor_block_sse
= {
336 .name
= "generic_sse",
343 #undef XOR_TRY_TEMPLATES
344 #define XOR_TRY_TEMPLATES \
346 xor_speed(&xor_block_sse); \
349 /* We force the use of the SSE xor block because it can write around L2.
350 We may also be able to load into the L1 only depending on how the cpu
351 deals with a load to a line that is being prefetched. */
352 #define XOR_SELECT_TEMPLATE(FASTEST) (&xor_block_sse)