elpa2_kernels_real_sse_2hv.c 54.8 KB
Newer Older
1
2
//    This file is part of ELPA.
//
Andreas Marek's avatar
Andreas Marek committed
3
//    The ELPA library was originally created by the ELPA consortium,
4
5
//    consisting of the following organizations:
//
6
7
//    - Max Planck Computing and Data Facility (MPCDF), formerly known as
//      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
8
9
10
//    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
//      Informatik,
//    - Technische Universität München, Lehrstuhl für Informatik mit
Andreas Marek's avatar
Andreas Marek committed
11
12
13
14
15
//      Schwerpunkt Wissenschaftliches Rechnen ,
//    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
//    - Max-Plack-Institut für Mathematik in den Naturwissenschaftrn,
//      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
//      and
16
17
//    - IBM Deutschland GmbH
//
18
//    This particular source code file contains additions, changes and
Andreas Marek's avatar
Andreas Marek committed
19
//    enhancements authored by Intel Corporation which is not part of
20
//    the ELPA consortium.
21
22
//
//    More information can be found here:
23
//    http://elpa.mpcdf.mpg.de/
24
25
//
//    ELPA is free software: you can redistribute it and/or modify
Andreas Marek's avatar
Andreas Marek committed
26
27
//    it under the terms of the version 3 of the license of the
//    GNU Lesser General Public License as published by the Free
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
//    Software Foundation.
//
//    ELPA is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
//
//    ELPA reflects a substantial effort on the part of the original
//    ELPA consortium, and we ask you to respect the spirit of the
//    license that we chose: i.e., please contribute any changes you
//    may have back to the original ELPA library distribution, and keep
//    any derivatives of ELPA under the same license that we chose for
//    the original distribution, the GNU Lesser General Public License.
//
//
// --------------------------------------------------------------------------------------------------
//
// This file contains the compute intensive kernels for the Householder transformations.
// It should be compiled with the highest possible optimization level.
//
// On Intel Nehalem or Intel Westmere or AMD Magny Cours use -O3 -msse3
// On Intel Sandy Bridge use -O3 -mavx
//
// Copyright of the original code rests with the authors inside the ELPA
// consortium. The copyright of any additional modifications shall rest
// with their original authors, but shall adhere to the licensing terms
// distributed along with the original code in the file "COPYING".
//
// Author: Alexander Heinecke (alexander.heinecke@mytum.de)
60
// Adapted for building a shared-library by Andreas Marek, MPCDF (andreas.marek@mpcdf.mpg.de)
61
62
63
64
65
66
67
68
69
70
71
// --------------------------------------------------------------------------------------------------

#include <x86intrin.h>

#define __forceinline __attribute__((always_inline)) static


#ifdef __USE_AVX128__
#undef __AVX__
#endif

72
73
74
75
76
77
78
79
80
81
#ifdef __FMA4__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_macc_pd(a,b,c)
#endif

#ifdef __AVX2__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_fmadd_pd(a,b,c)
#endif

82
83
84
85
86
87
88
89
90
91
92
93
//Forward declaration
#ifdef __AVX__
__forceinline void hh_trafo_kernel_4_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_8_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_16_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_24_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
#else
__forceinline void hh_trafo_kernel_4_SSE_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_8_SSE_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_12_SSE_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s);
#endif

Andreas Marek's avatar
Andreas Marek committed
94
void double_hh_trafo_real_sse_avx_2hv_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
95
96
97
98
#if 0
void double_hh_trafo_fast_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif

Andreas Marek's avatar
Andreas Marek committed
99
void double_hh_trafo_real_sse_avx_2hv_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
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
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;

	// calculating scalar product to compute
	// 2 householder vectors simultaneously
	double s = hh[(ldh)+1]*1.0;

	#pragma ivdep
	for (i = 2; i < nb; i++)
	{
		s += hh[i-1] * hh[(i+ldh)];
	}

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq-20; i+=24)
	{
		hh_trafo_kernel_24_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
	}

	if (nq == i)
	{
		return;
	}

	if (nq-i == 20)
	{
		hh_trafo_kernel_16_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
		hh_trafo_kernel_4_AVX_2hv(&q[i+16], hh, nb, ldq, ldh, s);
	}
	else if (nq-i == 16)
	{
		hh_trafo_kernel_16_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
	else if (nq-i == 12)
	{
		hh_trafo_kernel_8_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
		hh_trafo_kernel_4_AVX_2hv(&q[i+8], hh, nb, ldq, ldh, s);
	}
	else if (nq-i == 8)
	{
		hh_trafo_kernel_8_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
	else
	{
		hh_trafo_kernel_4_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
#else
	for (i = 0; i < nq-8; i+=12)
	{
		hh_trafo_kernel_12_SSE_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
	if (nq == i)
	{
		return;
	}
	else
	{
		if (nq-i > 4)
		{
			hh_trafo_kernel_8_SSE_2hv(&q[i], hh, nb, ldq, ldh, s);
		}
		else if (nq-i > 0)
		{
			hh_trafo_kernel_4_SSE_2hv(&q[i], hh, nb, ldq, ldh, s);
		}
	}
#endif
}

#if 0
void double_hh_trafo_fast_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;

	// calculating scalar product to compute
	// 2 householder vectors simultaneously
	double s = hh[(ldh)+1]*1.0;

	#pragma ivdep
	for (i = 2; i < nb; i++)
	{
		s += hh[i-1] * hh[(i+ldh)];
	}

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq; i+=24)
	{
		hh_trafo_kernel_24_AVX_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
#else
	for (i = 0; i < nq; i+=12)
	{
		hh_trafo_kernel_12_SSE_2hv(&q[i], hh, nb, ldq, ldh, s);
	}
#endif
}
#endif

#ifdef __AVX__
/**
 * Unrolled kernel that computes
 * 24 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 2 update is performed
 */
 __forceinline void hh_trafo_kernel_24_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [24 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
	__m256d sign = (__m256d)_mm256_set1_epi64x(0x8000000000000000);

	__m256d x1 = _mm256_load_pd(&q[ldq]);
	__m256d x2 = _mm256_load_pd(&q[ldq+4]);
	__m256d x3 = _mm256_load_pd(&q[ldq+8]);
	__m256d x4 = _mm256_load_pd(&q[ldq+12]);
	__m256d x5 = _mm256_load_pd(&q[ldq+16]);
	__m256d x6 = _mm256_load_pd(&q[ldq+20]);

	__m256d h1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h2;

235
#ifdef __ELPA_USE_FMA__
236
	__m256d q1 = _mm256_load_pd(q);
237
	__m256d y1 = _mm256_FMA_pd(x1, h1, q1);
238
	__m256d q2 = _mm256_load_pd(&q[4]);
239
	__m256d y2 = _mm256_FMA_pd(x2, h1, q2);
240
	__m256d q3 = _mm256_load_pd(&q[8]);
241
	__m256d y3 = _mm256_FMA_pd(x3, h1, q3);
242
	__m256d q4 = _mm256_load_pd(&q[12]);
243
	__m256d y4 = _mm256_FMA_pd(x4, h1, q4);
244
	__m256d q5 = _mm256_load_pd(&q[16]);
245
	__m256d y5 = _mm256_FMA_pd(x5, h1, q5);
246
	__m256d q6 = _mm256_load_pd(&q[20]);
247
	__m256d y6 = _mm256_FMA_pd(x6, h1, q6);
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#else
	__m256d q1 = _mm256_load_pd(q);
	__m256d y1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	__m256d q2 = _mm256_load_pd(&q[4]);
	__m256d y2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
	__m256d q3 = _mm256_load_pd(&q[8]);
	__m256d y3 = _mm256_add_pd(q3, _mm256_mul_pd(x3, h1));
	__m256d q4 = _mm256_load_pd(&q[12]);
	__m256d y4 = _mm256_add_pd(q4, _mm256_mul_pd(x4, h1));
	__m256d q5 = _mm256_load_pd(&q[16]);
	__m256d y5 = _mm256_add_pd(q5, _mm256_mul_pd(x5, h1));
	__m256d q6 = _mm256_load_pd(&q[20]);
	__m256d y6 = _mm256_add_pd(q6, _mm256_mul_pd(x6, h1));
#endif

	for(i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
267
#ifdef __ELPA_USE_FMA__
268
		q1 = _mm256_load_pd(&q[i*ldq]);
269
270
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
271
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
272
273
		x2 = _mm256_FMA_pd(q2, h1, x2);
		y2 = _mm256_FMA_pd(q2, h2, y2);
274
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
275
276
		x3 = _mm256_FMA_pd(q3, h1, x3);
		y3 = _mm256_FMA_pd(q3, h2, y3);
277
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
278
279
		x4 = _mm256_FMA_pd(q4, h1, x4);
		y4 = _mm256_FMA_pd(q4, h2, y4);
280
		q5 = _mm256_load_pd(&q[(i*ldq)+16]);
281
282
		x5 = _mm256_FMA_pd(q5, h1, x5);
		y5 = _mm256_FMA_pd(q5, h2, y5);
283
		q6 = _mm256_load_pd(&q[(i*ldq)+20]);
284
285
		x6 = _mm256_FMA_pd(q6, h1, x6);
		y6 = _mm256_FMA_pd(q6, h2, y6);
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
		x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
		y3 = _mm256_add_pd(y3, _mm256_mul_pd(q3,h2));
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
		x4 = _mm256_add_pd(x4, _mm256_mul_pd(q4,h1));
		y4 = _mm256_add_pd(y4, _mm256_mul_pd(q4,h2));
		q5 = _mm256_load_pd(&q[(i*ldq)+16]);
		x5 = _mm256_add_pd(x5, _mm256_mul_pd(q5,h1));
		y5 = _mm256_add_pd(y5, _mm256_mul_pd(q5,h2));
		q6 = _mm256_load_pd(&q[(i*ldq)+20]);
		x6 = _mm256_add_pd(x6, _mm256_mul_pd(q6,h1));
		y6 = _mm256_add_pd(y6, _mm256_mul_pd(q6,h2));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
309
#ifdef __ELPA_USE_FMA__
310
	q1 = _mm256_load_pd(&q[nb*ldq]);
311
	x1 = _mm256_FMA_pd(q1, h1, x1);
312
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
313
	x2 = _mm256_FMA_pd(q2, h1, x2);
314
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
315
	x3 = _mm256_FMA_pd(q3, h1, x3);
316
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
317
	x4 = _mm256_FMA_pd(q4, h1, x4);
318
	q5 = _mm256_load_pd(&q[(nb*ldq)+16]);
319
	x5 = _mm256_FMA_pd(q5, h1, x5);
320
	q6 = _mm256_load_pd(&q[(nb*ldq)+20]);
321
	x6 = _mm256_FMA_pd(q6, h1, x6);
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
	x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
	x4 = _mm256_add_pd(x4, _mm256_mul_pd(q4,h1));
	q5 = _mm256_load_pd(&q[(nb*ldq)+16]);
	x5 = _mm256_add_pd(x5, _mm256_mul_pd(q5,h1));
	q6 = _mm256_load_pd(&q[(nb*ldq)+20]);
	x6 = _mm256_add_pd(x6, _mm256_mul_pd(q6,h1));
#endif

	/////////////////////////////////////////////////////
	// Rank-2 update of Q [24 x nb+1]
	/////////////////////////////////////////////////////

	__m256d tau1 = _mm256_broadcast_sd(hh);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs = _mm256_broadcast_sd(&s);

	h1 = _mm256_xor_pd(tau1, sign);
	x1 = _mm256_mul_pd(x1, h1);
	x2 = _mm256_mul_pd(x2, h1);
	x3 = _mm256_mul_pd(x3, h1);
	x4 = _mm256_mul_pd(x4, h1);
	x5 = _mm256_mul_pd(x5, h1);
	x6 = _mm256_mul_pd(x6, h1);
	h1 = _mm256_xor_pd(tau2, sign);
	h2 = _mm256_mul_pd(h1, vs);
354
355
356
357
358
359
360
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(y1, h1, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMA_pd(y2, h1, _mm256_mul_pd(x2,h2));
	y3 = _mm256_FMA_pd(y3, h1, _mm256_mul_pd(x3,h2));
	y4 = _mm256_FMA_pd(y4, h1, _mm256_mul_pd(x4,h2));
	y5 = _mm256_FMA_pd(y5, h1, _mm256_mul_pd(x5,h2));
	y6 = _mm256_FMA_pd(y6, h1, _mm256_mul_pd(x6,h2));
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#else
	y1 = _mm256_add_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
	y2 = _mm256_add_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
	y3 = _mm256_add_pd(_mm256_mul_pd(y3,h1), _mm256_mul_pd(x3,h2));
	y4 = _mm256_add_pd(_mm256_mul_pd(y4,h1), _mm256_mul_pd(x4,h2));
	y5 = _mm256_add_pd(_mm256_mul_pd(y5,h1), _mm256_mul_pd(x5,h2));
	y6 = _mm256_add_pd(_mm256_mul_pd(y6,h1), _mm256_mul_pd(x6,h2));
#endif

	q1 = _mm256_load_pd(q);
	q1 = _mm256_add_pd(q1, y1);
	_mm256_store_pd(q,q1);
	q2 = _mm256_load_pd(&q[4]);
	q2 = _mm256_add_pd(q2, y2);
	_mm256_store_pd(&q[4],q2);
	q3 = _mm256_load_pd(&q[8]);
	q3 = _mm256_add_pd(q3, y3);
	_mm256_store_pd(&q[8],q3);
	q4 = _mm256_load_pd(&q[12]);
	q4 = _mm256_add_pd(q4, y4);
	_mm256_store_pd(&q[12],q4);
	q5 = _mm256_load_pd(&q[16]);
	q5 = _mm256_add_pd(q5, y5);
	_mm256_store_pd(&q[16],q5);
	q6 = _mm256_load_pd(&q[20]);
	q6 = _mm256_add_pd(q6, y6);
	_mm256_store_pd(&q[20],q6);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
390
#ifdef __ELPA_USE_FMA__
391
	q1 = _mm256_load_pd(&q[ldq]);
392
	q1 = _mm256_add_pd(q1, _mm256_FMA_pd(y1, h2, x1));
393
394
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
395
	q2 = _mm256_add_pd(q2, _mm256_FMA_pd(y2, h2, x2));
396
397
	_mm256_store_pd(&q[ldq+4],q2);
	q3 = _mm256_load_pd(&q[ldq+8]);
398
	q3 = _mm256_add_pd(q3, _mm256_FMA_pd(y3, h2, x3));
399
400
	_mm256_store_pd(&q[ldq+8],q3);
	q4 = _mm256_load_pd(&q[ldq+12]);
401
	q4 = _mm256_add_pd(q4, _mm256_FMA_pd(y4, h2, x4));
402
403
	_mm256_store_pd(&q[ldq+12],q4);
	q5 = _mm256_load_pd(&q[ldq+16]);
404
	q5 = _mm256_add_pd(q5, _mm256_FMA_pd(y5, h2, x5));
405
406
	_mm256_store_pd(&q[ldq+16],q5);
	q6 = _mm256_load_pd(&q[ldq+20]);
407
	q6 = _mm256_add_pd(q6, _mm256_FMA_pd(y6, h2, x6));
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
	_mm256_store_pd(&q[ldq+20],q6);
#else
	q1 = _mm256_load_pd(&q[ldq]);
	q1 = _mm256_add_pd(q1, _mm256_add_pd(x1, _mm256_mul_pd(y1, h2)));
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
	q2 = _mm256_add_pd(q2, _mm256_add_pd(x2, _mm256_mul_pd(y2, h2)));
	_mm256_store_pd(&q[ldq+4],q2);
	q3 = _mm256_load_pd(&q[ldq+8]);
	q3 = _mm256_add_pd(q3, _mm256_add_pd(x3, _mm256_mul_pd(y3, h2)));
	_mm256_store_pd(&q[ldq+8],q3);
	q4 = _mm256_load_pd(&q[ldq+12]);
	q4 = _mm256_add_pd(q4, _mm256_add_pd(x4, _mm256_mul_pd(y4, h2)));
	_mm256_store_pd(&q[ldq+12],q4);
	q5 = _mm256_load_pd(&q[ldq+16]);
	q5 = _mm256_add_pd(q5, _mm256_add_pd(x5, _mm256_mul_pd(y5, h2)));
	_mm256_store_pd(&q[ldq+16],q5);
	q6 = _mm256_load_pd(&q[ldq+20]);
	q6 = _mm256_add_pd(q6, _mm256_add_pd(x6, _mm256_mul_pd(y6, h2)));
	_mm256_store_pd(&q[ldq+20],q6);
#endif

	for (i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
434
#ifdef __ELPA_USE_FMA__
435
		q1 = _mm256_load_pd(&q[i*ldq]);
436
437
		q1 = _mm256_FMA_pd(x1, h1, q1);
		q1 = _mm256_FMA_pd(y1, h2, q1);
438
439
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
440
441
		q2 = _mm256_FMA_pd(x2, h1, q2);
		q2 = _mm256_FMA_pd(y2, h2, q2);
442
443
		_mm256_store_pd(&q[(i*ldq)+4],q2);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
444
445
		q3 = _mm256_FMA_pd(x3, h1, q3);
		q3 = _mm256_FMA_pd(y3, h2, q3);
446
447
		_mm256_store_pd(&q[(i*ldq)+8],q3);
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
448
449
		q4 = _mm256_FMA_pd(x4, h1, q4);
		q4 = _mm256_FMA_pd(y4, h2, q4);
450
451
		_mm256_store_pd(&q[(i*ldq)+12],q4);
		q5 = _mm256_load_pd(&q[(i*ldq)+16]);
452
453
		q5 = _mm256_FMA_pd(x5, h1, q5);
		q5 = _mm256_FMA_pd(y5, h2, q5);
454
455
		_mm256_store_pd(&q[(i*ldq)+16],q5);
		q6 = _mm256_load_pd(&q[(i*ldq)+20]);
456
457
		q6 = _mm256_FMA_pd(x6, h1, q6);
		q6 = _mm256_FMA_pd(y6, h2, q6);
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
		_mm256_store_pd(&q[(i*ldq)+20],q6);
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		q1 = _mm256_add_pd(q1, _mm256_add_pd(_mm256_mul_pd(x1,h1), _mm256_mul_pd(y1, h2)));
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		q2 = _mm256_add_pd(q2, _mm256_add_pd(_mm256_mul_pd(x2,h1), _mm256_mul_pd(y2, h2)));
		_mm256_store_pd(&q[(i*ldq)+4],q2);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
		q3 = _mm256_add_pd(q3, _mm256_add_pd(_mm256_mul_pd(x3,h1), _mm256_mul_pd(y3, h2)));
		_mm256_store_pd(&q[(i*ldq)+8],q3);
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
		q4 = _mm256_add_pd(q4, _mm256_add_pd(_mm256_mul_pd(x4,h1), _mm256_mul_pd(y4, h2)));
		_mm256_store_pd(&q[(i*ldq)+12],q4);
		q5 = _mm256_load_pd(&q[(i*ldq)+16]);
		q5 = _mm256_add_pd(q5, _mm256_add_pd(_mm256_mul_pd(x5,h1), _mm256_mul_pd(y5, h2)));
		_mm256_store_pd(&q[(i*ldq)+16],q5);
		q6 = _mm256_load_pd(&q[(i*ldq)+20]);
		q6 = _mm256_add_pd(q6, _mm256_add_pd(_mm256_mul_pd(x6,h1), _mm256_mul_pd(y6, h2)));
		_mm256_store_pd(&q[(i*ldq)+20],q6);
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
482
#ifdef __ELPA_USE_FMA__
483
	q1 = _mm256_load_pd(&q[nb*ldq]);
484
	q1 = _mm256_FMA_pd(x1, h1, q1);
485
486
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
487
	q2 = _mm256_FMA_pd(x2, h1, q2);
488
489
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
490
	q3 = _mm256_FMA_pd(x3, h1, q3);
491
492
	_mm256_store_pd(&q[(nb*ldq)+8],q3);
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
493
	q4 = _mm256_FMA_pd(x4, h1, q4);
494
495
	_mm256_store_pd(&q[(nb*ldq)+12],q4);
	q5 = _mm256_load_pd(&q[(nb*ldq)+16]);
496
	q5 = _mm256_FMA_pd(x5, h1, q5);
497
498
	_mm256_store_pd(&q[(nb*ldq)+16],q5);
	q6 = _mm256_load_pd(&q[(nb*ldq)+20]);
499
	q6 = _mm256_FMA_pd(x6, h1, q6);
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
	_mm256_store_pd(&q[(nb*ldq)+20],q6);
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	q2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
	q3 = _mm256_add_pd(q3, _mm256_mul_pd(x3, h1));
	_mm256_store_pd(&q[(nb*ldq)+8],q3);
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
	q4 = _mm256_add_pd(q4, _mm256_mul_pd(x4, h1));
	_mm256_store_pd(&q[(nb*ldq)+12],q4);
	q5 = _mm256_load_pd(&q[(nb*ldq)+16]);
	q5 = _mm256_add_pd(q5, _mm256_mul_pd(x5, h1));
	_mm256_store_pd(&q[(nb*ldq)+16],q5);
	q6 = _mm256_load_pd(&q[(nb*ldq)+20]);
	q6 = _mm256_add_pd(q6, _mm256_mul_pd(x6, h1));
	_mm256_store_pd(&q[(nb*ldq)+20],q6);
#endif
}

/**
 * Unrolled kernel that computes
 * 16 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 2 update is performed
 */
 __forceinline void hh_trafo_kernel_16_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [16 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
	__m256d sign = (__m256d)_mm256_set1_epi64x(0x8000000000000000);

	__m256d x1 = _mm256_load_pd(&q[ldq]);
	__m256d x2 = _mm256_load_pd(&q[ldq+4]);
	__m256d x3 = _mm256_load_pd(&q[ldq+8]);
	__m256d x4 = _mm256_load_pd(&q[ldq+12]);

	__m256d h1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h2;

547
#ifdef __ELPA_USE_FMA__
548
	__m256d q1 = _mm256_load_pd(q);
549
	__m256d y1 = _mm256_FMA_pd(x1, h1, q1);
550
	__m256d q2 = _mm256_load_pd(&q[4]);
551
	__m256d y2 = _mm256_FMA_pd(x2, h1, q2);
552
	__m256d q3 = _mm256_load_pd(&q[8]);
553
	__m256d y3 = _mm256_FMA_pd(x3, h1, q3);
554
	__m256d q4 = _mm256_load_pd(&q[12]);
555
	__m256d y4 = _mm256_FMA_pd(x4, h1, q4);
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
#else
	__m256d q1 = _mm256_load_pd(q);
	__m256d y1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	__m256d q2 = _mm256_load_pd(&q[4]);
	__m256d y2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
	__m256d q3 = _mm256_load_pd(&q[8]);
	__m256d y3 = _mm256_add_pd(q3, _mm256_mul_pd(x3, h1));
	__m256d q4 = _mm256_load_pd(&q[12]);
	__m256d y4 = _mm256_add_pd(q4, _mm256_mul_pd(x4, h1));
#endif

	for(i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
571
#ifdef __ELPA_USE_FMA__
572
		q1 = _mm256_load_pd(&q[i*ldq]);
573
574
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
575
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
576
577
		x2 = _mm256_FMA_pd(q2, h1, x2);
		y2 = _mm256_FMA_pd(q2, h2, y2);
578
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
579
580
		x3 = _mm256_FMA_pd(q3, h1, x3);
		y3 = _mm256_FMA_pd(q3, h2, y3);
581
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
582
583
		x4 = _mm256_FMA_pd(q4, h1, x4);
		y4 = _mm256_FMA_pd(q4, h2, y4);
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
		x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
		y3 = _mm256_add_pd(y3, _mm256_mul_pd(q3,h2));
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
		x4 = _mm256_add_pd(x4, _mm256_mul_pd(q4,h1));
		y4 = _mm256_add_pd(y4, _mm256_mul_pd(q4,h2));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
601
#ifdef __ELPA_USE_FMA__
602
	q1 = _mm256_load_pd(&q[nb*ldq]);
603
	x1 = _mm256_FMA_pd(q1, h1, x1);
604
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
605
	x2 = _mm256_FMA_pd(q2, h1, x2);
606
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
607
	x3 = _mm256_FMA_pd(q3, h1, x3);
608
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
609
	x4 = _mm256_FMA_pd(q4, h1, x4);
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
	x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
	x4 = _mm256_add_pd(x4, _mm256_mul_pd(q4,h1));
#endif

	/////////////////////////////////////////////////////
	// Rank-2 update of Q [16 x nb+1]
	/////////////////////////////////////////////////////

	__m256d tau1 = _mm256_broadcast_sd(hh);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs = _mm256_broadcast_sd(&s);

	h1 = _mm256_xor_pd(tau1, sign);
	x1 = _mm256_mul_pd(x1, h1);
	x2 = _mm256_mul_pd(x2, h1);
	x3 = _mm256_mul_pd(x3, h1);
	x4 = _mm256_mul_pd(x4, h1);
	h1 = _mm256_xor_pd(tau2, sign);
	h2 = _mm256_mul_pd(h1, vs);
636
637
638
639
640
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(y1, h1, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMA_pd(y2, h1, _mm256_mul_pd(x2,h2));
	y3 = _mm256_FMA_pd(y3, h1, _mm256_mul_pd(x3,h2));
	y4 = _mm256_FMA_pd(y4, h1, _mm256_mul_pd(x4,h2));
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#else
	y1 = _mm256_add_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
	y2 = _mm256_add_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
	y3 = _mm256_add_pd(_mm256_mul_pd(y3,h1), _mm256_mul_pd(x3,h2));
	y4 = _mm256_add_pd(_mm256_mul_pd(y4,h1), _mm256_mul_pd(x4,h2));
#endif

	q1 = _mm256_load_pd(q);
	q1 = _mm256_add_pd(q1, y1);
	_mm256_store_pd(q,q1);
	q2 = _mm256_load_pd(&q[4]);
	q2 = _mm256_add_pd(q2, y2);
	_mm256_store_pd(&q[4],q2);
	q3 = _mm256_load_pd(&q[8]);
	q3 = _mm256_add_pd(q3, y3);
	_mm256_store_pd(&q[8],q3);
	q4 = _mm256_load_pd(&q[12]);
	q4 = _mm256_add_pd(q4, y4);
	_mm256_store_pd(&q[12],q4);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
662
#ifdef __ELPA_USE_FMA__
663
	q1 = _mm256_load_pd(&q[ldq]);
664
	q1 = _mm256_add_pd(q1, _mm256_FMA_pd(y1, h2, x1));
665
666
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
667
	q2 = _mm256_add_pd(q2, _mm256_FMA_pd(y2, h2, x2));
668
669
	_mm256_store_pd(&q[ldq+4],q2);
	q3 = _mm256_load_pd(&q[ldq+8]);
670
	q3 = _mm256_add_pd(q3, _mm256_FMA_pd(y3, h2, x3));
671
672
	_mm256_store_pd(&q[ldq+8],q3);
	q4 = _mm256_load_pd(&q[ldq+12]);
673
	q4 = _mm256_add_pd(q4, _mm256_FMA_pd(y4, h2, x4));
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
	_mm256_store_pd(&q[ldq+12],q4);
#else
	q1 = _mm256_load_pd(&q[ldq]);
	q1 = _mm256_add_pd(q1, _mm256_add_pd(x1, _mm256_mul_pd(y1, h2)));
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
	q2 = _mm256_add_pd(q2, _mm256_add_pd(x2, _mm256_mul_pd(y2, h2)));
	_mm256_store_pd(&q[ldq+4],q2);
	q3 = _mm256_load_pd(&q[ldq+8]);
	q3 = _mm256_add_pd(q3, _mm256_add_pd(x3, _mm256_mul_pd(y3, h2)));
	_mm256_store_pd(&q[ldq+8],q3);
	q4 = _mm256_load_pd(&q[ldq+12]);
	q4 = _mm256_add_pd(q4, _mm256_add_pd(x4, _mm256_mul_pd(y4, h2)));
	_mm256_store_pd(&q[ldq+12],q4);
#endif

	for (i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
694
#ifdef __ELPA_USE_FMA__
695
		q1 = _mm256_load_pd(&q[i*ldq]);
696
697
		q1 = _mm256_FMA_pd(x1, h1, q1);
		q1 = _mm256_FMA_pd(y1, h2, q1);
698
699
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
700
701
		q2 = _mm256_FMA_pd(x2, h1, q2);
		q2 = _mm256_FMA_pd(y2, h2, q2);
702
703
		_mm256_store_pd(&q[(i*ldq)+4],q2);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
704
705
		q3 = _mm256_FMA_pd(x3, h1, q3);
		q3 = _mm256_FMA_pd(y3, h2, q3);
706
707
		_mm256_store_pd(&q[(i*ldq)+8],q3);
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
708
709
		q4 = _mm256_FMA_pd(x4, h1, q4);
		q4 = _mm256_FMA_pd(y4, h2, q4);
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
		_mm256_store_pd(&q[(i*ldq)+12],q4);
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		q1 = _mm256_add_pd(q1, _mm256_add_pd(_mm256_mul_pd(x1,h1), _mm256_mul_pd(y1, h2)));
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		q2 = _mm256_add_pd(q2, _mm256_add_pd(_mm256_mul_pd(x2,h1), _mm256_mul_pd(y2, h2)));
		_mm256_store_pd(&q[(i*ldq)+4],q2);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
		q3 = _mm256_add_pd(q3, _mm256_add_pd(_mm256_mul_pd(x3,h1), _mm256_mul_pd(y3, h2)));
		_mm256_store_pd(&q[(i*ldq)+8],q3);
		q4 = _mm256_load_pd(&q[(i*ldq)+12]);
		q4 = _mm256_add_pd(q4, _mm256_add_pd(_mm256_mul_pd(x4,h1), _mm256_mul_pd(y4, h2)));
		_mm256_store_pd(&q[(i*ldq)+12],q4);
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
728
#ifdef __ELPA_USE_FMA__
729
	q1 = _mm256_load_pd(&q[nb*ldq]);
730
	q1 = _mm256_FMA_pd(x1, h1, q1);
731
732
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
733
	q2 = _mm256_FMA_pd(x2, h1, q2);
734
735
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
736
	q3 = _mm256_FMA_pd(x3, h1, q3);
737
738
	_mm256_store_pd(&q[(nb*ldq)+8],q3);
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
739
	q4 = _mm256_FMA_pd(x4, h1, q4);
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
	_mm256_store_pd(&q[(nb*ldq)+12],q4);
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	q2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
	q3 = _mm256_add_pd(q3, _mm256_mul_pd(x3, h1));
	_mm256_store_pd(&q[(nb*ldq)+8],q3);
	q4 = _mm256_load_pd(&q[(nb*ldq)+12]);
	q4 = _mm256_add_pd(q4, _mm256_mul_pd(x4, h1));
	_mm256_store_pd(&q[(nb*ldq)+12],q4);
#endif
}

/**
 * Unrolled kernel that computes
 * 8 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 2 update is performed
 */
 __forceinline void hh_trafo_kernel_8_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [8 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
	__m256d sign = (__m256d)_mm256_set1_epi64x(0x8000000000000000);

	__m256d x1 = _mm256_load_pd(&q[ldq]);
	__m256d x2 = _mm256_load_pd(&q[ldq+4]);

	__m256d h1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h2;

779
#ifdef __ELPA_USE_FMA__
780
	__m256d q1 = _mm256_load_pd(q);
781
	__m256d y1 = _mm256_FMA_pd(x1, h1, q1);
782
	__m256d q2 = _mm256_load_pd(&q[4]);
783
	__m256d y2 = _mm256_FMA_pd(x2, h1, q2);
784
785
786
787
788
789
790
791
792
793
794
#else
	__m256d q1 = _mm256_load_pd(q);
	__m256d y1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	__m256d q2 = _mm256_load_pd(&q[4]);
	__m256d y2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
#endif

	for(i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
795
#ifdef __ELPA_USE_FMA__
796
		q1 = _mm256_load_pd(&q[i*ldq]);
797
798
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
799
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
800
801
		x2 = _mm256_FMA_pd(q2, h1, x2);
		y2 = _mm256_FMA_pd(q2, h2, y2);
802
803
804
805
806
807
808
809
810
811
812
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
813
#ifdef __ELPA_USE_FMA__
814
	q1 = _mm256_load_pd(&q[nb*ldq]);
815
	x1 = _mm256_FMA_pd(q1, h1, x1);
816
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
817
	x2 = _mm256_FMA_pd(q2, h1, x2);
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif

	/////////////////////////////////////////////////////
	// Rank-2 update of Q [8 x nb+1]
	/////////////////////////////////////////////////////

	__m256d tau1 = _mm256_broadcast_sd(hh);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs = _mm256_broadcast_sd(&s);

	h1 = _mm256_xor_pd(tau1, sign);
	x1 = _mm256_mul_pd(x1, h1);
	x2 = _mm256_mul_pd(x2, h1);
	h1 = _mm256_xor_pd(tau2, sign);
	h2 = _mm256_mul_pd(h1, vs);
838
839
840
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(y1, h1, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMA_pd(y2, h1, _mm256_mul_pd(x2,h2));
841
842
843
844
845
846
847
848
849
850
851
852
853
#else
	y1 = _mm256_add_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
	y2 = _mm256_add_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
#endif

	q1 = _mm256_load_pd(q);
	q1 = _mm256_add_pd(q1, y1);
	_mm256_store_pd(q,q1);
	q2 = _mm256_load_pd(&q[4]);
	q2 = _mm256_add_pd(q2, y2);
	_mm256_store_pd(&q[4],q2);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
854
#ifdef __ELPA_USE_FMA__
855
	q1 = _mm256_load_pd(&q[ldq]);
856
	q1 = _mm256_add_pd(q1, _mm256_FMA_pd(y1, h2, x1));
857
858
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
859
	q2 = _mm256_add_pd(q2, _mm256_FMA_pd(y2, h2, x2));
860
861
862
863
864
865
866
867
868
869
870
871
872
873
	_mm256_store_pd(&q[ldq+4],q2);
#else
	q1 = _mm256_load_pd(&q[ldq]);
	q1 = _mm256_add_pd(q1, _mm256_add_pd(x1, _mm256_mul_pd(y1, h2)));
	_mm256_store_pd(&q[ldq],q1);
	q2 = _mm256_load_pd(&q[ldq+4]);
	q2 = _mm256_add_pd(q2, _mm256_add_pd(x2, _mm256_mul_pd(y2, h2)));
	_mm256_store_pd(&q[ldq+4],q2);
#endif

	for (i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
874
#ifdef __ELPA_USE_FMA__
875
		q1 = _mm256_load_pd(&q[i*ldq]);
876
877
		q1 = _mm256_FMA_pd(x1, h1, q1);
		q1 = _mm256_FMA_pd(y1, h2, q1);
878
879
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
880
881
		q2 = _mm256_FMA_pd(x2, h1, q2);
		q2 = _mm256_FMA_pd(y2, h2, q2);
882
883
884
885
886
887
888
889
890
891
892
893
		_mm256_store_pd(&q[(i*ldq)+4],q2);
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		q1 = _mm256_add_pd(q1, _mm256_add_pd(_mm256_mul_pd(x1,h1), _mm256_mul_pd(y1, h2)));
		_mm256_store_pd(&q[i*ldq],q1);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		q2 = _mm256_add_pd(q2, _mm256_add_pd(_mm256_mul_pd(x2,h1), _mm256_mul_pd(y2, h2)));
		_mm256_store_pd(&q[(i*ldq)+4],q2);
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
894
#ifdef __ELPA_USE_FMA__
895
	q1 = _mm256_load_pd(&q[nb*ldq]);
896
	q1 = _mm256_FMA_pd(x1, h1, q1);
897
898
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
899
	q2 = _mm256_FMA_pd(x2, h1, q2);
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	_mm256_store_pd(&q[nb*ldq],q1);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	q2 = _mm256_add_pd(q2, _mm256_mul_pd(x2, h1));
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
#endif
}

/**
 * Unrolled kernel that computes
 * 4 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 2 update is performed
 */
 __forceinline void hh_trafo_kernel_4_AVX_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
	__m256d sign = (__m256d)_mm256_set1_epi64x(0x8000000000000000);

	__m256d x1 = _mm256_load_pd(&q[ldq]);

	__m256d h1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h2;

932
#ifdef __ELPA_USE_FMA__
933
	__m256d q1 = _mm256_load_pd(q);
934
	__m256d y1 = _mm256_FMA_pd(x1, h1, q1);
935
936
937
938
939
940
941
942
943
#else
	__m256d q1 = _mm256_load_pd(q);
	__m256d y1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
#endif

	for(i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
944
#ifdef __ELPA_USE_FMA__
945
		q1 = _mm256_load_pd(&q[i*ldq]);
946
947
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
948
949
950
951
952
953
954
955
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
956
#ifdef __ELPA_USE_FMA__
957
	q1 = _mm256_load_pd(&q[nb*ldq]);
958
	x1 = _mm256_FMA_pd(q1, h1, x1);
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif

	/////////////////////////////////////////////////////
	// Rank-2 update of Q [4 x nb+1]
	/////////////////////////////////////////////////////

	__m256d tau1 = _mm256_broadcast_sd(hh);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs = _mm256_broadcast_sd(&s);

	h1 = _mm256_xor_pd(tau1, sign);
	x1 = _mm256_mul_pd(x1, h1);
	h1 = _mm256_xor_pd(tau2, sign);
	h2 = _mm256_mul_pd(h1, vs);
976
977
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(y1, h1, _mm256_mul_pd(x1,h2));
978
979
980
981
982
983
984
985
986
#else
	y1 = _mm256_add_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
#endif

	q1 = _mm256_load_pd(q);
	q1 = _mm256_add_pd(q1, y1);
	_mm256_store_pd(q,q1);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
987
#ifdef __ELPA_USE_FMA__
988
	q1 = _mm256_load_pd(&q[ldq]);
989
	q1 = _mm256_add_pd(q1, _mm256_FMA_pd(y1, h2, x1));
990
991
992
993
994
995
996
997
998
999
1000
	_mm256_store_pd(&q[ldq],q1);
#else
	q1 = _mm256_load_pd(&q[ldq]);
	q1 = _mm256_add_pd(q1, _mm256_add_pd(x1, _mm256_mul_pd(y1, h2)));
	_mm256_store_pd(&q[ldq],q1);
#endif

	for (i = 2; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-1]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i]);
1001
#ifdef __ELPA_USE_FMA__
1002
		q1 = _mm256_load_pd(&q[i*ldq]);
1003
1004
		q1 = _mm256_FMA_pd(x1, h1, q1);
		q1 = _mm256_FMA_pd(y1, h2, q1);
1005
1006
1007
1008
1009
1010
1011
1012
1013
		_mm256_store_pd(&q[i*ldq],q1);
#else
		q1 = _mm256_load_pd(&q[i*ldq]);
		q1 = _mm256_add_pd(q1, _mm256_add_pd(_mm256_mul_pd(x1,h1), _mm256_mul_pd(y1, h2)));
		_mm256_store_pd(&q[i*ldq],q1);
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
1014
#ifdef __ELPA_USE_FMA__
1015
	q1 = _mm256_load_pd(&q[nb*ldq]);
1016
	q1 = _mm256_FMA_pd(x1, h1, q1);
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
	_mm256_store_pd(&q[nb*ldq],q1);
#else
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q1 = _mm256_add_pd(q1, _mm256_mul_pd(x1, h1));
	_mm256_store_pd(&q[nb*ldq],q1);
#endif
}
#else
/**
 * Unrolled kernel that computes
 * 12 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 2 update is performed
 */
 __forceinline void hh_trafo_kernel_12_SSE_2hv(double* q, double* hh, int nb, int ldq, int ldh, double s)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
	__m64 smallsign = _mm_set_pi32(0x80000000, 0x00000000);
	__m128d sign = (__m128d)_mm_set1_epi64(smallsign);

	__m128d x1 = _mm_load_pd(&q[ldq]);
	__m128d x2 = _mm_load_pd(&q[ldq+2]);
	__m128d x3 = _mm_load_pd(&q[ldq+4]);
	__m128d x4 = _mm_load_pd(&q[ldq+6]);
	__m128d x5 = _mm_load_pd(&q[ldq+8]);
	__m128d x6 = _mm_load_pd(&q[ldq+10]);

	__m128d h1 = _mm_loaddup_pd(&hh[ldh+1]);
	__m128d h2;

1052
#ifdef __ELPA_USE_FMA__
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
	__m128d q1 = _mm_load_pd(q);
	__m128d y1 = _mm_macc_pd(x1, h1, q1);
	__m128d q2 = _mm_load_pd(&q[2]);
	__m128d y2 = _mm_macc_pd(x2, h1, q2);
	__m128d q3 = _mm_load_pd(&q[4]);
	__m128d y3 = _mm_macc_pd(x3, h1, q3);
	__m128d q4 = _mm_load_pd(&q[6]);
	__m128d y4 = _mm_macc_pd(x4, h1, q4);
	__m128d q5 = _mm_load_pd(&q[8]);
	__m128d y5 = _mm_macc_pd(x5, h1, q5);
	__m128d q6 = _mm_load_pd(&q[10]);
	__m128d y6 = _mm_macc_pd(x6, h1, q6);
#else
	__m128d q1 = _mm_load_pd(q);
	__m128d y1 = _mm_add_pd(q1, _mm_mul_pd(x1, h1));
	__m128d q2 = _mm_load_pd(&q[2]);
	__m128d y2 = _mm_add_pd(q2, _mm_mul_pd(x2, h1));
	__m128d q3 = _mm_load_pd(&q[4]);
	__m128d y3 = _mm_add_pd(q3, _mm_mul_pd(x3, h1));
	__m128d q4 = _mm_load_pd(&q[6]);
	__m128d y4 = _mm_add_pd(q4, _mm_mul_pd(x4, h1));
	__m128d q5 = _mm_load_pd(&q[8]);
	__m128d y5 = _mm_add_pd(q5, _mm_mul_pd(x5, h1));
	__m128d q6 = _mm_load_pd(&q[10]);
	__m128d y6 = _mm_add_pd(q6, _mm_mul_pd(x6, h1));
#endif
	for(i = 2; i < nb; i++)
	{
		h1 = _mm_loaddup_pd(&hh[i-1]);
		h2 = _mm_loaddup_pd(&hh[ldh+i]);
1083
#ifdef __ELPA_USE_FMA__
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
		q1 = _mm_load_pd(&q[i*ldq]);
		x1 = _mm_macc_pd(q1, h1, x1);
		y1 = _mm_macc_pd(q1, h2, y1);
		q2 = _mm_load_pd(&q[(i*ldq)+2]);
		x2 = _mm_macc_pd(q2, h1, x2);
		y2 = _mm_macc_pd(q2, h2, y2);
		q3 = _mm_load_pd(&q[(i*ldq)+4]);
		x3 = _mm_macc_pd(q3, h1, x3);
		y3 = _mm_macc_pd(q3, h2, y3);
		q4 = _mm_load_pd(&q[(i*ldq)+6]);
		x4 = _mm_macc_pd(q4, h1, x4);
		y4 = _mm_macc_pd(q4, h2, y4);
		q5 = _mm_load_pd(&q[(i*ldq)+8]);
		x5 = _mm_macc_pd(q5, h1, x5);
		y5 = _mm_macc_pd(q5, h2, y5);
		q6 = _mm_load_pd(&q[(i*ldq)+10]);
		x6 = _mm_macc_pd(q6, h1, x6);
		y6 = _mm_macc_pd(q6, h2, y6);
#else
		q1 = _mm_load_pd(&q[i*ldq]);
		x1 = _mm_add_pd(x1, _mm_mul_pd(q1,h1));
		y1 = _mm_add_pd(y1, _mm_mul_pd(q1,h2));
		q2 = _mm_load_pd(&q[(i*ldq)+2]);
		x2 = _mm_add_pd(x2, _mm_mul_pd(q2,h1));
		y2 = _mm_add_pd(y2, _mm_mul_pd(q2,h2));
		q3 = _mm_load_pd(&q[(i*ldq)+4]);
		x3 = _mm_add_pd(x3, _mm_mul_pd(q3,h1));
		y3 = _mm_add_pd(y3, _mm_mul_pd(q3,h2));
		q4 = _mm_load_pd(&q[(i*ldq)+6]);
		x4 = _mm_add_pd(x4, _mm_mul_pd(q4,h1));
		y4 = _mm_add_pd(y4, _mm_mul_pd(q4,h2));
		q5 = _mm_load_pd(&q[(i*ldq)+8]);
		x5 = _mm_add_pd(x5, _mm_mul_pd(q5,h1));
		y5 = _mm_add_pd(y5, _mm_mul_pd(q5,h2));
		q6 = _mm_load_pd(&q[(i*ldq)+10]);
		x6 = _mm_add_pd(x6, _mm_mul_pd(q6,h1));
		y6 = _mm_add_pd(y6, _mm_mul_pd(q6,h2));
#endif
	}

	h1 = _mm_loaddup_pd(&hh[nb-1]);
1125
#ifdef __ELPA_USE_FMA__
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
	q1 = _mm_load_pd(&q[nb*ldq]);
	x1 = _mm_macc_pd(q1, h1, x1);
	q2 = _mm_load_pd(&q[(nb*ldq)+2]);
	x2 = _mm_macc_pd(q2, h1, x2);
	q3 = _mm_load_pd(&q[(nb*ldq)+4]);
	x3 = _mm_macc_pd(q3, h1, x3);
	q4 = _mm_load_pd(&q[(nb*ldq)+6]);
	x4 = _mm_macc_pd(q4, h1, x4);
	q5 = _mm_load_pd(&q[(nb*ldq)+8]);
	x5 = _mm_macc_pd(q5, h1, x5);
	q6 = _mm_load_pd(&q[(nb*ldq)+10]);
	x6 = _mm_macc_pd(q6, h1, x6);
#else
	q1 = _mm_load_pd(&q[nb*ldq]);
	x1 = _mm_add_pd(x1, _mm_mul_pd(q1,h1));
	q2 = _mm_load_pd(&q[(nb*ldq)+2]);
	x2 = _mm_add_pd(x2, _mm_mul_pd(q2,h1));
	q3 = _mm_load_pd(&q[(nb*ldq)+4]);
	x3 = _mm_add_pd(x3, _mm_mul_pd(q3,h1));
	q4 = _mm_load_pd(&q[(nb*ldq)+6]);
	x4 = _mm_add_pd(x4, _mm_mul_pd(q4,h1));
	q5 = _mm_load_pd(&q[(nb*ldq)+8]);
	x5 = _mm_add_pd(x5, _mm_mul_pd(q5,h1));
	q6 = _mm_load_pd(&q[(nb*ldq)+10]);
	x6 = _mm_add_pd(x6, _mm_mul_pd(q6,h1));
#endif

	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////

	__m128d tau1 = _mm_loaddup_pd(hh);
	__m128d tau2 = _mm_loaddup_pd(&hh[ldh]);
	__m128d vs = _mm_loaddup_pd(&s);

	h1 = _mm_xor_pd(tau1, sign);
	x1 = _mm_mul_pd(x1, h1);
	x2 = _mm_mul_pd(x2, h1);
	x3 = _mm_mul_pd(x3, h1);
	x4 = _mm_mul_pd(x4, h1);
	x5 = _mm_mul_pd(x5, h1);
	x6 = _mm_mul_pd(x6, h1);
	h1 = _mm_xor_pd(tau2, sign);
	h2 = _mm_mul_pd(h1, vs);
1170
#ifdef __ELPA_USE_FMA__
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
	y1 = _mm_macc_pd(y1, h1, _mm_mul_pd(x1,h2));
	y2 = _mm_macc_pd(y2, h1, _mm_mul_pd(x2,h2));
	y3 = _mm_macc_pd(y3, h1, _mm_mul_pd(x3,h2));
	y4 = _mm_macc_pd(y4, h1, _mm_mul_pd(x4,h2));
	y5 = _mm_macc_pd(y5, h1, _mm_mul_pd(x5,h2));
	y6 = _mm_macc_pd(y6, h1, _mm_mul_pd(x6,h2));
#else
	y1 = _mm_add_pd(_mm_mul_pd(y1,h1), _mm_mul_pd(x1,h2));
	y2 = _mm_add_pd(_mm_mul_pd(y2,h1), _mm_mul_pd(x2,h2));
	y3 = _mm_add_pd(_mm_mul_pd(y3,h1), _mm_mul_pd(x3,h2));
	y4 = _mm_add_pd(_mm_mul_pd(y4,h1), _mm_mul_pd(x4,h2));
	y5 = _mm_add_pd(_mm_mul_pd(y5,h1), _mm_mul_pd(x5,h2));
	y6 = _mm_add_pd(_mm_mul_pd(y6,h1), _mm_mul_pd(x6,h2));
#endif

	q1 = _mm_load_pd(q);
	q1 = _mm_add_pd(q1, y1);
	_mm_store_pd(q,q1);
	q2 = _mm_load_pd(&q[2]);
	q2 = _mm_add_pd(q2, y2);
	_mm_store_pd(&q[2],q2);
	q3 = _mm_load_pd(&q[4]);
	q3 = _mm_add_pd(q3, y3);
	_mm_store_pd(&q[4],q3);
	q4 = _mm_load_pd(&q[6]);
	q4 = _mm_add_pd(q4, y4);
	_mm_store_pd(&q[6],q4);
	q5 = _mm_load_pd(&q[8]);
	q5 = _mm_add_pd(q5, y5);
	_mm_store_pd(&q[8],q5);
	q6 = _mm_load_pd(&q[10]);
	q6 = _mm_add_pd(q6, y6);
	_mm_store_pd(&q[10],q6);

	h2 = _mm_loaddup_pd(&hh[ldh+1]);
1206
#ifdef __ELPA_USE_FMA__
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
	q1 = _mm_load_pd(&q[ldq]);
	q1 = _mm_add_pd(q1, _mm_macc_pd(y1, h2, x1));
	_mm_store_pd(&q[ldq],q1);
	q2 = _mm_load_pd(&q[ldq+2]);
	q2 = _mm_add_pd(q2, _mm_macc_pd(y2, h2, x2));
	_mm_store_pd(&q[ldq+2],q2);
	q3 = _mm_load_pd(&q[ldq+4]);
	q3 = _mm_add_pd(q3, _mm_macc_pd(y3, h2, x3));
	_mm_store_pd(&q[ldq+4],q3);
	q4 = _mm_load_pd(&q[ldq+6]);
	q4 = _mm_add_pd(q4, _mm_macc_pd(y4, h2, x4));
	_mm_store_pd(&q[ldq+6],q4);
	q5 = _mm_load_pd(&q[ldq+8]);
	q5 = _mm_add_pd(q5, _mm_macc_pd(y5, h2, x5));
	_mm_store_pd(&q[ldq+8],q5);
	q6 = _mm_load_pd(&q[ldq+10]);
	q6 = _mm_add_pd(q6, _mm_macc_pd(y6, h2, x6));
	_mm_store_pd(&q[ldq+10],q6);
#else
	q1 = _mm_load_pd(&q[ldq]);
	q1 = _mm_add_pd(q1, _mm_add_pd(x1, _mm_mul_pd(y1, h2)));
	_mm_store_pd(&q[ldq],q1);
	q2 = _mm_load_pd(&q[ldq+2]);
	q2 = _mm_add_pd(q2, _mm_add_pd(x2, _mm_mul_pd(y2, h2)));
	_mm_store_pd(&q[ldq+2],q2);
	q3 = _mm_load_pd(&q[ldq+4]);
	q3 = _mm_add_pd(q3, _mm_add_pd(x3, _mm_mul_pd(y3, h2)));
	_mm_store_pd(&q[ldq+4],q3);
	q4 = _mm_load_pd(&q[ldq+6]);
	q4 = _mm_add_pd(q4, _mm_add_pd(x4, _mm_mul_pd(y4, h2)));
	_mm_store_pd(&q[ldq+6],q4);
	q5 = _mm_load_pd(&q[ldq+8]);
	q5 = _mm_add_pd(q5, _mm_add_pd(x5, _mm_mul_pd(y5, h2)));
	_mm_store_pd(&q[ldq+8],q5);
	q6 = _mm_load_pd(&q[ldq+10]);
	q6 = _mm_add_pd(q6, _mm_add_pd(x6, _mm_mul_pd(y6, h2)));
	_mm_store_pd(&q[ldq+10],q6);
#endif
	for (i = 2; i < nb; i++)
	{
		h1 = _mm_loaddup_pd(&hh[i-1]);
		h2 = _mm_loaddup_pd(&hh[ldh+i]);

1250
#ifdef __ELPA_USE_FMA__
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
		q1 = _mm_load_pd(&q[i*ldq]);
		q1 = _mm_add_pd(q1, _mm_macc_pd(x1, h1, _mm_mul_pd(y1, h2)));
		_mm_store_pd(&q[i*ldq],q1);
		q2 = _mm_load_pd(&q[(i*ldq)+2]);
		q2 = _mm_add_pd(q2, _mm_macc_pd(x2, h1, _mm_mul_pd(y2, h2)));
		_mm_store_pd(&q[(i*ldq)+2],q2);
		q3 = _mm_load_pd(&q[(i*ldq)+4]);
		q3 = _mm_add_pd(q3, _mm_macc_pd(x3, h1, _mm_mul_pd(y3, h2)));
		_mm_store_pd(&q[(i*ldq)+4],q3);
		q4 = _mm_load_pd(&q[(i*ldq)+6]);
		q4 = _mm_add_pd(q4, _mm_macc_pd(x4, h1, _mm_mul_pd(y4, h2)));
		_mm_store_pd(&q[(i*ldq)+6],q4);
		q5 = _mm_load_pd(&q[(i*ldq)+8]);
		q5 = _mm_add_pd(q5, _mm_macc_pd(x5, h1, _mm_mul_pd(y5, h2)));
		_mm_store_pd(&q[(i*ldq)+8],q5);
		q6 = _mm_load_pd(&q[(i*ldq)+10]);
		q6 = _mm_add_pd(q6, _mm_macc_pd(x6, h1, _mm_mul_pd(y6, h2)));
		_mm_store_pd(&q[(i*ldq)+10],q6);
#else
		q1 = _mm_load_pd(&q[i*ldq]);
		q1 = _mm_add_pd(q1, _mm_add_pd(_mm_mul_pd(x1,h1), _mm_mul_pd(y1, h2)));
		_mm_store_pd(&q[i*ldq],q1);
		q2 = _mm_load_pd(&q[(i*ldq)+2]);
		q2 = _mm_add_pd(q2, _mm_add_pd(_mm_mul_pd(x2,h1), _mm_mul_pd(y2, h2)));
		_mm_store_pd(&q[(i*ldq)+2],q2);
		q3 = _mm_load_pd(&q[(i*ldq)+4]);
		q3 = _mm_add_pd(q3, _mm_add_pd(_mm_mul_pd(x3,h1), _mm_mul_pd(y3, h2)));
		_mm_store_pd(&q[(i*ldq)+4],q3);
		q4 = _mm_load_pd(&q[(i*ldq)+6]);
		q4 = _mm_add_pd(q4, _mm_add_pd(_mm_mul_pd(x4,h1), _mm_mul_pd(y4, h2)));
		_mm_store_pd(&q[(i*ldq)+6],q4);
		q5 = _mm_load_pd(&q[(i*ldq)+8]);
		q5 = _mm_add_pd(q5, _mm_add_pd(_mm_mul_pd(x5,h1), _mm_mul_pd(y5, h2)));
		_mm_store_pd(&q[(i*ldq)+8],q5);
		q6 = _mm_load_pd(&q[(i*ldq)+10]);
		q6 = _mm_add_pd(q6, _mm_add_pd(_mm_mul_pd(x6,h1), _mm_mul_pd(y6, h2)));
		_mm_store_pd(&q[(i*ldq)+10],q6);
#endif
	}

	h1 = _mm_loaddup_pd(&hh[nb-1]);
1292
#ifdef __ELPA_USE_FMA__
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
	q1 = _mm_load_pd(&q[nb*ldq]);
	q1 = _mm_macc_pd(x1, h1, q1);
	_mm_store_pd(&q[nb*ldq],q1);
	q2 = _mm_load_pd(&q[(nb*ldq)+2]);
	q2