Blame view

arch/x86/include/asm/xor_64.h 7.86 KB
1965aae3c   H. Peter Anvin   x86: Fix ASM_X86_...
1
2
  #ifndef _ASM_X86_XOR_64_H
  #define _ASM_X86_XOR_64_H
0db125c46   Vegard Nossum   x86: more header ...
3

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
   * Optimized RAID-5 checksumming functions for MMX and SSE.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2, or (at your option)
   * any later version.
   *
   * You should have received a copy of the GNU General Public License
   * (for example /usr/src/linux/COPYING); if not, write to the Free
   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   */
  
  
  /*
   * Cache avoiding checksumming functions utilizing KNI instructions
   * Copyright (C) 1999 Zach Brown (with obvious credit due Ingo)
   */
  
  /*
   * Based on
   * High-speed RAID5 checksumming functions utilizing SSE instructions.
   * Copyright (C) 1998 Ingo Molnar.
   */
  
  /*
687c80540   Joe Perches   include/asm-x86/x...
30
   * x86-64 changes / gcc fixes from Andi Kleen.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
   * Copyright 2002 Andi Kleen, SuSE Labs.
   *
   * This hasn't been optimized for the hammer yet, but there are likely
   * no advantages to be gotten from x86-64 here anyways.
   */
687c80540   Joe Perches   include/asm-x86/x...
36
37
38
  typedef struct {
  	unsigned long a, b;
  } __attribute__((aligned(16))) xmm_store_t;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39

687c80540   Joe Perches   include/asm-x86/x...
40
  /* Doesn't use gcc to save the XMM registers, because there is no easy way to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
     tell it to do a clts before the register saving. */
687c80540   Joe Perches   include/asm-x86/x...
42
43
  #define XMMS_SAVE				\
  do {						\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  	preempt_disable();			\
687c80540   Joe Perches   include/asm-x86/x...
45
  	asm volatile(				\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  		"movq %%cr0,%0		;
  \t"	\
  		"clts			;
  \t"	\
  		"movups %%xmm0,(%1)	;
  \t"	\
  		"movups %%xmm1,0x10(%1)	;
  \t"	\
  		"movups %%xmm2,0x20(%1)	;
  \t"	\
  		"movups %%xmm3,0x30(%1)	;
  \t"	\
  		: "=&r" (cr0)			\
  		: "r" (xmm_save) 		\
  		: "memory");			\
687c80540   Joe Perches   include/asm-x86/x...
61
  } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62

687c80540   Joe Perches   include/asm-x86/x...
63
64
65
  #define XMMS_RESTORE				\
  do {						\
  	asm volatile(				\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  		"sfence			;
  \t"	\
  		"movups (%1),%%xmm0	;
  \t"	\
  		"movups 0x10(%1),%%xmm1	;
  \t"	\
  		"movups 0x20(%1),%%xmm2	;
  \t"	\
  		"movups 0x30(%1),%%xmm3	;
  \t"	\
  		"movq 	%0,%%cr0	;
  \t"	\
  		:				\
  		: "r" (cr0), "r" (xmm_save)	\
  		: "memory");			\
  	preempt_enable();			\
687c80540   Joe Perches   include/asm-x86/x...
82
  } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
87
  
  #define OFFS(x)		"16*("#x")"
  #define PF_OFFS(x)	"256+16*("#x")"
  #define	PF0(x)		"	prefetchnta "PF_OFFS(x)"(%[p1])		;
  "
687c80540   Joe Perches   include/asm-x86/x...
88
89
90
91
  #define LD(x, y)	"       movaps   "OFFS(x)"(%[p1]), %%xmm"#y"	;
  "
  #define ST(x, y)	"       movaps %%xmm"#y",   "OFFS(x)"(%[p1])	;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
97
98
99
100
101
  #define PF1(x)		"	prefetchnta "PF_OFFS(x)"(%[p2])		;
  "
  #define PF2(x)		"	prefetchnta "PF_OFFS(x)"(%[p3])		;
  "
  #define PF3(x)		"	prefetchnta "PF_OFFS(x)"(%[p4])		;
  "
  #define PF4(x)		"	prefetchnta "PF_OFFS(x)"(%[p5])		;
  "
  #define PF5(x)		"	prefetchnta "PF_OFFS(x)"(%[p6])		;
  "
687c80540   Joe Perches   include/asm-x86/x...
102
103
104
105
106
107
108
109
110
111
  #define XO1(x, y)	"       xorps   "OFFS(x)"(%[p2]), %%xmm"#y"	;
  "
  #define XO2(x, y)	"       xorps   "OFFS(x)"(%[p3]), %%xmm"#y"	;
  "
  #define XO3(x, y)	"       xorps   "OFFS(x)"(%[p4]), %%xmm"#y"	;
  "
  #define XO4(x, y)	"       xorps   "OFFS(x)"(%[p5]), %%xmm"#y"	;
  "
  #define XO5(x, y)	"       xorps   "OFFS(x)"(%[p6]), %%xmm"#y"	;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
114
115
116
  
  
  static void
  xor_sse_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
  {
687c80540   Joe Perches   include/asm-x86/x...
117
  	unsigned int lines = bytes >> 8;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
120
121
  	unsigned long cr0;
  	xmm_store_t xmm_save[4];
  
  	XMMS_SAVE;
687c80540   Joe Perches   include/asm-x86/x...
122
  	asm volatile(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
  #undef BLOCK
  #define BLOCK(i) \
687c80540   Joe Perches   include/asm-x86/x...
125
126
  		LD(i, 0)				\
  			LD(i + 1, 1)			\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  		PF1(i)					\
687c80540   Joe Perches   include/asm-x86/x...
128
129
130
131
132
133
134
135
136
137
138
139
140
  				PF1(i + 2)		\
  				LD(i + 2, 2)		\
  					LD(i + 3, 3)	\
  		PF0(i + 4)				\
  				PF0(i + 6)		\
  		XO1(i, 0)				\
  			XO1(i + 1, 1)			\
  				XO1(i + 2, 2)		\
  					XO1(i + 3, 3)	\
  		ST(i, 0)				\
  			ST(i + 1, 1)			\
  				ST(i + 2, 2)		\
  					ST(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
143
144
145
146
147
  
  
  		PF0(0)
  				PF0(2)
  
  	" .align 32			;
  "
687c80540   Joe Perches   include/asm-x86/x...
148
149
  	" 1:                            ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
151
152
153
154
  
  		BLOCK(0)
  		BLOCK(4)
  		BLOCK(8)
  		BLOCK(12)
687c80540   Joe Perches   include/asm-x86/x...
155
156
157
158
  	"       addq %[inc], %[p1]           ;
  "
  	"       addq %[inc], %[p2]           ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
160
  		"		decl %[cnt] ; jnz 1b"
  	: [p1] "+r" (p1), [p2] "+r" (p2), [cnt] "+r" (lines)
687c80540   Joe Perches   include/asm-x86/x...
161
162
  	: [inc] "r" (256UL)
  	: "memory");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
164
165
166
167
168
169
170
171
172
173
174
175
  
  	XMMS_RESTORE;
  }
  
  static void
  xor_sse_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
  	  unsigned long *p3)
  {
  	unsigned int lines = bytes >> 8;
  	xmm_store_t xmm_save[4];
  	unsigned long cr0;
  
  	XMMS_SAVE;
687c80540   Joe Perches   include/asm-x86/x...
176
  	asm volatile(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
  #undef BLOCK
  #define BLOCK(i) \
  		PF1(i)					\
687c80540   Joe Perches   include/asm-x86/x...
180
181
182
183
184
  				PF1(i + 2)		\
  		LD(i, 0)					\
  			LD(i + 1, 1)			\
  				LD(i + 2, 2)		\
  					LD(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
  		PF2(i)					\
687c80540   Joe Perches   include/asm-x86/x...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  				PF2(i + 2)		\
  		PF0(i + 4)				\
  				PF0(i + 6)		\
  		XO1(i, 0)				\
  			XO1(i + 1, 1)			\
  				XO1(i + 2, 2)		\
  					XO1(i + 3, 3)	\
  		XO2(i, 0)				\
  			XO2(i + 1, 1)			\
  				XO2(i + 2, 2)		\
  					XO2(i + 3, 3)	\
  		ST(i, 0)				\
  			ST(i + 1, 1)			\
  				ST(i + 2, 2)		\
  					ST(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201
202
203
204
205
206
207
  
  
  		PF0(0)
  				PF0(2)
  
  	" .align 32			;
  "
687c80540   Joe Perches   include/asm-x86/x...
208
209
  	" 1:                            ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210
211
212
213
214
  
  		BLOCK(0)
  		BLOCK(4)
  		BLOCK(8)
  		BLOCK(12)
687c80540   Joe Perches   include/asm-x86/x...
215
216
217
218
219
220
  	"       addq %[inc], %[p1]           ;
  "
  	"       addq %[inc], %[p2]          ;
  "
  	"       addq %[inc], %[p3]           ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
223
224
  		"		decl %[cnt] ; jnz 1b"
  	: [cnt] "+r" (lines),
  	  [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3)
  	: [inc] "r" (256UL)
687c80540   Joe Perches   include/asm-x86/x...
225
  	: "memory");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
226
227
228
229
230
231
232
233
  	XMMS_RESTORE;
  }
  
  static void
  xor_sse_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
  	  unsigned long *p3, unsigned long *p4)
  {
  	unsigned int lines = bytes >> 8;
687c80540   Joe Perches   include/asm-x86/x...
234
  	xmm_store_t xmm_save[4];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
  	unsigned long cr0;
  
  	XMMS_SAVE;
687c80540   Joe Perches   include/asm-x86/x...
238
  	asm volatile(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
241
  #undef BLOCK
  #define BLOCK(i) \
  		PF1(i)					\
687c80540   Joe Perches   include/asm-x86/x...
242
243
244
245
246
  				PF1(i + 2)		\
  		LD(i, 0)				\
  			LD(i + 1, 1)			\
  				LD(i + 2, 2)		\
  					LD(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  		PF2(i)					\
687c80540   Joe Perches   include/asm-x86/x...
248
249
250
251
252
  				PF2(i + 2)		\
  		XO1(i, 0)				\
  			XO1(i + 1, 1)			\
  				XO1(i + 2, 2)		\
  					XO1(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
  		PF3(i)					\
687c80540   Joe Perches   include/asm-x86/x...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  				PF3(i + 2)		\
  		PF0(i + 4)				\
  				PF0(i + 6)		\
  		XO2(i, 0)				\
  			XO2(i + 1, 1)			\
  				XO2(i + 2, 2)		\
  					XO2(i + 3, 3)	\
  		XO3(i, 0)				\
  			XO3(i + 1, 1)			\
  				XO3(i + 2, 2)		\
  					XO3(i + 3, 3)	\
  		ST(i, 0)				\
  			ST(i + 1, 1)			\
  				ST(i + 2, 2)		\
  					ST(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
272
273
274
275
  
  
  		PF0(0)
  				PF0(2)
  
  	" .align 32			;
  "
687c80540   Joe Perches   include/asm-x86/x...
276
277
  	" 1:                            ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278
279
280
281
282
  
  		BLOCK(0)
  		BLOCK(4)
  		BLOCK(8)
  		BLOCK(12)
687c80540   Joe Perches   include/asm-x86/x...
283
284
285
286
287
288
289
290
  	"       addq %[inc], %[p1]           ;
  "
  	"       addq %[inc], %[p2]           ;
  "
  	"       addq %[inc], %[p3]           ;
  "
  	"       addq %[inc], %[p4]           ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
292
293
294
  	"	decl %[cnt] ; jnz 1b"
  	: [cnt] "+c" (lines),
  	  [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4)
  	: [inc] "r" (256UL)
687c80540   Joe Perches   include/asm-x86/x...
295
  	: "memory" );
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
297
298
299
300
301
302
303
  
  	XMMS_RESTORE;
  }
  
  static void
  xor_sse_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
  	  unsigned long *p3, unsigned long *p4, unsigned long *p5)
  {
687c80540   Joe Perches   include/asm-x86/x...
304
  	unsigned int lines = bytes >> 8;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
307
308
  	xmm_store_t xmm_save[4];
  	unsigned long cr0;
  
  	XMMS_SAVE;
687c80540   Joe Perches   include/asm-x86/x...
309
  	asm volatile(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
  #undef BLOCK
  #define BLOCK(i) \
  		PF1(i)					\
687c80540   Joe Perches   include/asm-x86/x...
313
314
315
316
317
  				PF1(i + 2)		\
  		LD(i, 0)				\
  			LD(i + 1, 1)			\
  				LD(i + 2, 2)		\
  					LD(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
  		PF2(i)					\
687c80540   Joe Perches   include/asm-x86/x...
319
320
321
322
323
  				PF2(i + 2)		\
  		XO1(i, 0)				\
  			XO1(i + 1, 1)			\
  				XO1(i + 2, 2)		\
  					XO1(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324
  		PF3(i)					\
687c80540   Joe Perches   include/asm-x86/x...
325
326
327
328
329
  				PF3(i + 2)		\
  		XO2(i, 0)				\
  			XO2(i + 1, 1)			\
  				XO2(i + 2, 2)		\
  					XO2(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
  		PF4(i)					\
687c80540   Joe Perches   include/asm-x86/x...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  				PF4(i + 2)		\
  		PF0(i + 4)				\
  				PF0(i + 6)		\
  		XO3(i, 0)				\
  			XO3(i + 1, 1)			\
  				XO3(i + 2, 2)		\
  					XO3(i + 3, 3)	\
  		XO4(i, 0)				\
  			XO4(i + 1, 1)			\
  				XO4(i + 2, 2)		\
  					XO4(i + 3, 3)	\
  		ST(i, 0)				\
  			ST(i + 1, 1)			\
  				ST(i + 2, 2)		\
  					ST(i + 3, 3)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346
347
348
349
350
351
352
  
  
  		PF0(0)
  				PF0(2)
  
  	" .align 32			;
  "
687c80540   Joe Perches   include/asm-x86/x...
353
354
  	" 1:                            ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
357
358
359
  
  		BLOCK(0)
  		BLOCK(4)
  		BLOCK(8)
  		BLOCK(12)
687c80540   Joe Perches   include/asm-x86/x...
360
361
362
363
364
365
366
367
368
369
  	"       addq %[inc], %[p1]           ;
  "
  	"       addq %[inc], %[p2]           ;
  "
  	"       addq %[inc], %[p3]           ;
  "
  	"       addq %[inc], %[p4]           ;
  "
  	"       addq %[inc], %[p5]           ;
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370
371
  	"	decl %[cnt] ; jnz 1b"
  	: [cnt] "+c" (lines),
687c80540   Joe Perches   include/asm-x86/x...
372
  	  [p1] "+r" (p1), [p2] "+r" (p2), [p3] "+r" (p3), [p4] "+r" (p4),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
374
375
376
377
378
379
380
  	  [p5] "+r" (p5)
  	: [inc] "r" (256UL)
  	: "memory");
  
  	XMMS_RESTORE;
  }
  
  static struct xor_block_template xor_block_sse = {
687c80540   Joe Perches   include/asm-x86/x...
381
382
383
384
385
  	.name = "generic_sse",
  	.do_2 = xor_sse_2,
  	.do_3 = xor_sse_3,
  	.do_4 = xor_sse_4,
  	.do_5 = xor_sse_5,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
  };
  
  #undef XOR_TRY_TEMPLATES
687c80540   Joe Perches   include/asm-x86/x...
389
390
391
392
  #define XOR_TRY_TEMPLATES			\
  do {						\
  	xor_speed(&xor_block_sse);		\
  } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
394
395
396
397
  
  /* We force the use of the SSE xor block because it can write around L2.
     We may also be able to load into the L1 only depending on how the cpu
     deals with a load to a line that is being prefetched.  */
  #define XOR_SELECT_TEMPLATE(FASTEST) (&xor_block_sse)
0db125c46   Vegard Nossum   x86: more header ...
398

1965aae3c   H. Peter Anvin   x86: Fix ASM_X86_...
399
  #endif /* _ASM_X86_XOR_64_H */