1 #ifndef _ASM_X86_XOR_64_H
2 #define _ASM_X86_XOR_64_H
5 * Optimized RAID-5 checksumming functions for MMX and SSE.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * You should have received a copy of the GNU General Public License
13 * (for example /usr/src/linux/COPYING); if not, write to the Free
14 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Cache avoiding checksumming functions utilizing KNI instructions
20 * Copyright (C) 1999 Zach Brown (with obvious credit due Ingo)
25 * High-speed RAID5 checksumming functions utilizing SSE instructions.
26 * Copyright (C) 1998 Ingo Molnar.
30 * x86-64 changes / gcc fixes from Andi Kleen.
31 * Copyright 2002 Andi Kleen, SuSE Labs.
33 * This hasn't been optimized for the hammer yet, but there are likely
34 * no advantages to be gotten from x86-64 here anyways.
39 } __attribute__((aligned(16))) xmm_store_t;
41 /* Doesn't use gcc to save the XMM registers, because there is no easy way to
42 tell it to do a clts before the register saving. */
47 "movq %%cr0,%0 ;\n\t" \
49 "movups %%xmm0,(%1) ;\n\t" \
50 "movups %%xmm1,0x10(%1) ;\n\t" \
51 "movups %%xmm2,0x20(%1) ;\n\t" \
52 "movups %%xmm3,0x30(%1) ;\n\t" \
58 #define XMMS_RESTORE \
62 "movups (%1),%%xmm0 ;\n\t" \
63 "movups 0x10(%1),%%xmm1 ;\n\t" \
64 "movups 0x20(%1),%%xmm2 ;\n\t" \
65 "movups 0x30(%1),%%xmm3 ;\n\t" \
66 "movq %0,%%cr0 ;\n\t" \
68 : "r" (cr0), "r" (xmm_save) \
73 #define OFFS(x) "16*("#x")"
74 #define PF_OFFS(x) "256+16*("#x")"
75 #define PF0(x) " prefetchnta "PF_OFFS(x)"(%[p1]) ;\n"
76 #define LD(x, y) " movaps "OFFS(x)"(%[p1]), %%xmm"#y" ;\n"
77 #define ST(x, y) " movaps %%xmm"#y", "OFFS(x)"(%[p1]) ;\n"
78 #define PF1(x) " prefetchnta "PF_OFFS(x)"(%[p2]) ;\n"
79 #define PF2(x) " prefetchnta "PF_OFFS(x)"(%[p3]) ;\n"
80 #define PF3(x) " prefetchnta "PF_OFFS(x)"(%[p4]) ;\n"
81 #define PF4(x) " prefetchnta "PF_OFFS(x)"(%[p5]) ;\n"
82 #define PF5(x) " prefetchnta "PF_OFFS(x)"(%[p6]) ;\n"
83 #define XO1(x, y) " xorps "OFFS(x)"(%[p2]), %%xmm"#y" ;\n"
84 #define XO2(x, y) " xorps "OFFS(x)"(%[p3]), %%xmm"#y" ;\n"
85 #define XO3(x, y) " xorps "OFFS(x)"(%[p4]), %%xmm"#y" ;\n"
86 #define XO4(x, y) " xorps "OFFS(x)"(%[p5]), %%xmm"#y" ;\n"
87 #define XO5(x, y) " xorps "OFFS(x)"(%[p6]), %%xmm"#y" ;\n"
91 xor_sse_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
93 unsigned int lines = bytes >> 8;
95 xmm_store_t xmm_save[4];
131 " addq %[inc], %[p1] ;\n"
132 " addq %[inc], %[p2] ;\n"
133 " decl %[cnt] ; jnz 1b"
134 : [p1] "+r" (p1), [p2] "+r" (p2), [cnt] "+r" (lines)
142 xor_sse_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
145 unsigned int lines = bytes >> 8;
146 xmm_store_t xmm_save[4];
189 " addq %[inc], %[p1] ;\n"
190 " addq %[inc], %[p2] ;\n"
191 " addq %[inc], %[p3] ;\n"
192 " decl %[cnt] ; jnz 1b"
193 : [cnt] "+r" (lines),
194 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3)
201 xor_sse_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
202 unsigned long *p3, unsigned long *p4)
204 unsigned int lines = bytes >> 8;
205 xmm_store_t xmm_save[4];
254 " addq %[inc], %[p1] ;\n"
255 " addq %[inc], %[p2] ;\n"
256 " addq %[inc], %[p3] ;\n"
257 " addq %[inc], %[p4] ;\n"
258 " decl %[cnt] ; jnz 1b"
259 : [cnt] "+c" (lines),
260 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4)
268 xor_sse_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
269 unsigned long *p3, unsigned long *p4, unsigned long *p5)
271 unsigned int lines = bytes >> 8;
272 xmm_store_t xmm_save[4];
327 " addq %[inc], %[p1] ;\n"
328 " addq %[inc], %[p2] ;\n"
329 " addq %[inc], %[p3] ;\n"
330 " addq %[inc], %[p4] ;\n"
331 " addq %[inc], %[p5] ;\n"
332 " decl %[cnt] ; jnz 1b"
333 : [cnt] "+c" (lines),
334 [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4),
342 static struct xor_block_template xor_block_sse = {
343 .name = "generic_sse",
350 #undef XOR_TRY_TEMPLATES
351 #define XOR_TRY_TEMPLATES \
353 xor_speed(&xor_block_sse); \
356 /* We force the use of the SSE xor block because it can write around L2.
357 We may also be able to load into the L1 only depending on how the cpu
358 deals with a load to a line that is being prefetched. */
359 #define XOR_SELECT_TEMPLATE(FASTEST) (&xor_block_sse)
361 #endif /* _ASM_X86_XOR_64_H */