elpa2_kernels_real_sse_4hv.c 78.9 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
// --------------------------------------------------------------------------------------------------

#include <x86intrin.h>

#define __forceinline __attribute__((always_inline)) static

#ifdef __USE_AVX128__
#undef __AVX__
#endif

71
72
73
74
#ifdef __FMA4__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_macc_pd(a,b,c)
#define _mm256_NFMA_pd(a,b,c) _mm256_nmacc_pd(a,b,c)
Andreas Marek's avatar
Andreas Marek committed
75
#define _mm256_FMSUB_pd(a,b,c) _mm256_msub(a,b,c)
76
77
78
79
80
81
#endif

#ifdef __AVX2__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_fmadd_pd(a,b,c)
#define _mm256_NFMA_pd(a,b,c) _mm256_fnmadd_pd(a,b,c)
Andreas Marek's avatar
Andreas Marek committed
82
#define _mm256_FMSUB_pd(a,b,c) _mm256_fmsub_pd(a,b,c)
83
84
#endif

85
86
87
88
89
90
91
92
93
94
95
//Forward declaration
#ifdef __AVX__
__forceinline void hh_trafo_kernel_4_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_8_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_12_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
#else
__forceinline void hh_trafo_kernel_2_SSE_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_4_SSE_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_6_SSE_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
#endif

Andreas Marek's avatar
Andreas Marek committed
96
void quad_hh_trafo_real_sse_avx_4hv_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
97
98
99
100
#if 0
void quad_hh_trafo_fast_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif

Andreas Marek's avatar
Andreas Marek committed
101
void quad_hh_trafo_real_sse_avx_4hv_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;

	// calculating scalar products to compute
	// 4 householder vectors simultaneously
	double s_1_2 = hh[(ldh)+1];
	double s_1_3 = hh[(ldh*2)+2];
	double s_2_3 = hh[(ldh*2)+1];
	double s_1_4 = hh[(ldh*3)+3];
	double s_2_4 = hh[(ldh*3)+2];
	double s_3_4 = hh[(ldh*3)+1];

	// calculate scalar product of first and fourth householder vector
	// loop counter = 2
	s_1_2 += hh[2-1] * hh[(2+ldh)];
	s_2_3 += hh[(ldh)+2-1] * hh[2+(ldh*2)];
	s_3_4 += hh[(ldh*2)+2-1] * hh[2+(ldh*3)];

	// loop counter = 3
	s_1_2 += hh[3-1] * hh[(3+ldh)];
	s_2_3 += hh[(ldh)+3-1] * hh[3+(ldh*2)];
	s_3_4 += hh[(ldh*2)+3-1] * hh[3+(ldh*3)];

	s_1_3 += hh[3-2] * hh[3+(ldh*2)];
	s_2_4 += hh[(ldh*1)+3-2] * hh[3+(ldh*3)];

	#pragma ivdep
	for (i = 4; i < nb; i++)
	{
		s_1_2 += hh[i-1] * hh[(i+ldh)];
		s_2_3 += hh[(ldh)+i-1] * hh[i+(ldh*2)];
		s_3_4 += hh[(ldh*2)+i-1] * hh[i+(ldh*3)];

		s_1_3 += hh[i-2] * hh[i+(ldh*2)];
		s_2_4 += hh[(ldh*1)+i-2] * hh[i+(ldh*3)];

		s_1_4 += hh[i-3] * hh[i+(ldh*3)];
	}

//	printf("s_1_2: %f\n", s_1_2);
//	printf("s_1_3: %f\n", s_1_3);
//	printf("s_2_3: %f\n", s_2_3);
//	printf("s_1_4: %f\n", s_1_4);
//	printf("s_2_4: %f\n", s_2_4);
//	printf("s_3_4: %f\n", s_3_4);

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq-8; i+=12)
	{
		hh_trafo_kernel_12_AVX_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
	}
	if (nq == i)
	{
		return;
	}
	else
	{
		if (nq-i > 4)
		{
			hh_trafo_kernel_8_AVX_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
		}
		else
		{
			hh_trafo_kernel_4_AVX_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
		}
	}
#else
	for (i = 0; i < nq-4; i+=6)
	{
		hh_trafo_kernel_6_SSE_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
	}
	if (nq == i)
	{
		return;
	}
	else
	{
		if (nq-i > 2)
		{
			hh_trafo_kernel_4_SSE_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
		}
		else
		{
			hh_trafo_kernel_2_SSE_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
		}
	}
#endif
}

#if 0
void quad_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 products to compute
	// 4 householder vectors simultaneously
	double s_1_2 = hh[(ldh)+1];
	double s_1_3 = hh[(ldh*2)+2];
	double s_2_3 = hh[(ldh*2)+1];
	double s_1_4 = hh[(ldh*3)+3];
	double s_2_4 = hh[(ldh*3)+2];
	double s_3_4 = hh[(ldh*3)+1];

	// calculate scalar product of first and fourth householder vector
	// loop counter = 2
	s_1_2 += hh[2-1] * hh[(2+ldh)];
	s_2_3 += hh[(ldh)+2-1] * hh[2+(ldh*2)];
	s_3_4 += hh[(ldh*2)+2-1] * hh[2+(ldh*3)];

	// loop counter = 3
	s_1_2 += hh[3-1] * hh[(3+ldh)];
	s_2_3 += hh[(ldh)+3-1] * hh[3+(ldh*2)];
	s_3_4 += hh[(ldh*2)+3-1] * hh[3+(ldh*3)];

	s_1_3 += hh[3-2] * hh[3+(ldh*2)];
	s_2_4 += hh[(ldh*1)+3-2] * hh[3+(ldh*3)];

	#pragma ivdep
	for (i = 4; i < nb; i++)
	{
		s_1_2 += hh[i-1] * hh[(i+ldh)];
		s_2_3 += hh[(ldh)+i-1] * hh[i+(ldh*2)];
		s_3_4 += hh[(ldh*2)+i-1] * hh[i+(ldh*3)];

		s_1_3 += hh[i-2] * hh[i+(ldh*2)];
		s_2_4 += hh[(ldh*1)+i-2] * hh[i+(ldh*3)];

		s_1_4 += hh[i-3] * hh[i+(ldh*3)];
	}

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq; i+=12)
	{
		hh_trafo_kernel_12_AVX_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
	}
#else
	for (i = 0; i < nq; i+=6)
	{
		hh_trafo_kernel_6_SSE_4hv(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
	}
#endif
}
#endif

#ifdef __AVX__
/**
 * Unrolled kernel that computes
 * 12 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
__forceinline void hh_trafo_kernel_12_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

	__m256d a1_1 = _mm256_load_pd(&q[ldq*3]);
	__m256d a2_1 = _mm256_load_pd(&q[ldq*2]);
	__m256d a3_1 = _mm256_load_pd(&q[ldq]);
	__m256d a4_1 = _mm256_load_pd(&q[0]);

	__m256d h_2_1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h_3_2 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	__m256d h_3_1 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
	__m256d h_4_3 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	__m256d h_4_2 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	__m256d h_4_1 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);

283
284
285
286
287
288
289
#ifdef __ELPA_USE_FMA__
	register __m256d w1 = _mm256_FMA_pd(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_pd(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_pd(a1_1, h_4_1, w1);
	register __m256d z1 = _mm256_FMA_pd(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_pd(a1_1, h_3_1, z1);
	register __m256d y1 = _mm256_FMA_pd(a1_1, h_2_1, a2_1);
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
	register __m256d x1 = a1_1;
#else
	register __m256d w1 = _mm256_add_pd(a4_1, _mm256_mul_pd(a3_1, h_4_3));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a2_1, h_4_2));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a1_1, h_4_1));
	register __m256d z1 = _mm256_add_pd(a3_1, _mm256_mul_pd(a2_1, h_3_2));
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(a1_1, h_3_1));
	register __m256d y1 = _mm256_add_pd(a2_1, _mm256_mul_pd(a1_1, h_2_1));
	register __m256d x1 = a1_1;
#endif

	__m256d a1_2 = _mm256_load_pd(&q[(ldq*3)+4]);
	__m256d a2_2 = _mm256_load_pd(&q[(ldq*2)+4]);
	__m256d a3_2 = _mm256_load_pd(&q[ldq+4]);
	__m256d a4_2 = _mm256_load_pd(&q[0+4]);

306
307
308
309
310
311
312
#ifdef __ELPA_USE_FMA__
	register __m256d w2 = _mm256_FMA_pd(a3_2, h_4_3, a4_2);
	w2 = _mm256_FMA_pd(a2_2, h_4_2, w2);
	w2 = _mm256_FMA_pd(a1_2, h_4_1, w2);
	register __m256d z2 = _mm256_FMA_pd(a2_2, h_3_2, a3_2);
	z2 = _mm256_FMA_pd(a1_2, h_3_1, z2);
	register __m256d y2 = _mm256_FMA_pd(a1_2, h_2_1, a2_2);
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
	register __m256d x2 = a1_2;
#else
	register __m256d w2 = _mm256_add_pd(a4_2, _mm256_mul_pd(a3_2, h_4_3));
	w2 = _mm256_add_pd(w2, _mm256_mul_pd(a2_2, h_4_2));
	w2 = _mm256_add_pd(w2, _mm256_mul_pd(a1_2, h_4_1));
	register __m256d z2 = _mm256_add_pd(a3_2, _mm256_mul_pd(a2_2, h_3_2));
	z2 = _mm256_add_pd(z2, _mm256_mul_pd(a1_2, h_3_1));
	register __m256d y2 = _mm256_add_pd(a2_2, _mm256_mul_pd(a1_2, h_2_1));
	register __m256d x2 = a1_2;
#endif

	__m256d a1_3 = _mm256_load_pd(&q[(ldq*3)+8]);
	__m256d a2_3 = _mm256_load_pd(&q[(ldq*2)+8]);
	__m256d a3_3 = _mm256_load_pd(&q[ldq+8]);
	__m256d a4_3 = _mm256_load_pd(&q[0+8]);

329
330
331
332
333
334
335
#ifdef __ELPA_USE_FMA__
	register __m256d w3 = _mm256_FMA_pd(a3_3, h_4_3, a4_3);
	w3 = _mm256_FMA_pd(a2_3, h_4_2, w3);
	w3 = _mm256_FMA_pd(a1_3, h_4_1, w3);
	register __m256d z3 = _mm256_FMA_pd(a2_3, h_3_2, a3_3);
	z3 = _mm256_FMA_pd(a1_3, h_3_1, z3);
	register __m256d y3 = _mm256_FMA_pd(a1_3, h_2_1, a2_3);
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
	register __m256d x3 = a1_3;
#else
	register __m256d w3 = _mm256_add_pd(a4_3, _mm256_mul_pd(a3_3, h_4_3));
	w3 = _mm256_add_pd(w3, _mm256_mul_pd(a2_3, h_4_2));
	w3 = _mm256_add_pd(w3, _mm256_mul_pd(a1_3, h_4_1));
	register __m256d z3 = _mm256_add_pd(a3_3, _mm256_mul_pd(a2_3, h_3_2));
	z3 = _mm256_add_pd(z3, _mm256_mul_pd(a1_3, h_3_1));
	register __m256d y3 = _mm256_add_pd(a2_3, _mm256_mul_pd(a1_3, h_2_1));
	register __m256d x3 = a1_3;
#endif

	__m256d q1;
	__m256d q2;
	__m256d q3;

	__m256d h1;
	__m256d h2;
	__m256d h3;
	__m256d h4;

	for(i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);
		q1 = _mm256_load_pd(&q[i*ldq]);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);
362
363
364
365
#ifdef __ELPA_USE_FMA__
		x1 = _mm256_FMA_pd(q1, h1, x1);
		x2 = _mm256_FMA_pd(q2, h1, x2);
		x3 = _mm256_FMA_pd(q3, h1, x3);
366
367
368
369
370
371
372
#else
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
		x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
#endif

		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
373
374
375
376
#ifdef __ELPA_USE_FMA__
		y1 = _mm256_FMA_pd(q1, h2, y1);
		y2 = _mm256_FMA_pd(q2, h2, y2);
		y3 = _mm256_FMA_pd(q3, h2, y3);
377
378
379
380
381
382
383
#else
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
		y3 = _mm256_add_pd(y3, _mm256_mul_pd(q3,h2));
#endif

		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
384
385
386
387
#ifdef __ELPA_USE_FMA__
		z1 = _mm256_FMA_pd(q1, h3, z1);
		z2 = _mm256_FMA_pd(q2, h3, z2);
		z3 = _mm256_FMA_pd(q3, h3, z3);
388
389
390
391
392
393
394
#else
		z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
		z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
		z3 = _mm256_add_pd(z3, _mm256_mul_pd(q3,h3));
#endif

		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);
395
396
397
398
#ifdef __ELPA_USE_FMA__
		w1 = _mm256_FMA_pd(q1, h4, w1);
		w2 = _mm256_FMA_pd(q2, h4, w2);
		w3 = _mm256_FMA_pd(q3, h4, w3);
399
400
401
402
403
404
405
406
407
408
409
410
411
#else
		w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
		w2 = _mm256_add_pd(w2, _mm256_mul_pd(q2,h4));
		w3 = _mm256_add_pd(w3, _mm256_mul_pd(q3,h4));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);

	q1 = _mm256_load_pd(&q[nb*ldq]);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);

412
413
414
415
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
	x3 = _mm256_FMA_pd(q3, h1, x3);
416
417
418
419
420
421
422
423
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
#endif

	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
#ifdef __FMA4_
424
425
426
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
	y3 = _mm256_FMA_pd(q3, h2, y3);
427
428
429
430
431
432
433
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
	y3 = _mm256_add_pd(y3, _mm256_mul_pd(q3,h2));
#endif

	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
434
435
436
437
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
	z2 = _mm256_FMA_pd(q2, h3, z2);
	z3 = _mm256_FMA_pd(q3, h3, z3);
438
439
440
441
442
443
444
445
446
447
448
449
#else
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
	z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
	z3 = _mm256_add_pd(z3, _mm256_mul_pd(q3,h3));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-2]);

	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
	q3 = _mm256_load_pd(&q[((nb+1)*ldq)+8]);

450
451
452
453
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
	x3 = _mm256_FMA_pd(q3, h1, x3);
454
455
456
457
458
459
460
461
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
#endif

	h2 = _mm256_broadcast_sd(&hh[(ldh*1)+nb-1]);

462
463
464
465
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
	y3 = _mm256_FMA_pd(q3, h2, y3);
466
467
468
469
470
471
472
473
474
475
476
477
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
	y3 = _mm256_add_pd(y3, _mm256_mul_pd(q3,h2));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-1]);

	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
	q3 = _mm256_load_pd(&q[((nb+2)*ldq)+8]);

478
479
480
481
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
	x3 = _mm256_FMA_pd(q3, h1, x3);
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	x3 = _mm256_add_pd(x3, _mm256_mul_pd(q3,h1));
#endif

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

	__m256d tau1 = _mm256_broadcast_sd(&hh[0]);

	h1 = tau1;
	x1 = _mm256_mul_pd(x1, h1);
	x2 = _mm256_mul_pd(x2, h1);
	x3 = _mm256_mul_pd(x3, h1);

	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs_1_2 = _mm256_broadcast_sd(&s_1_2);

	h1 = tau2;
	h2 = _mm256_mul_pd(h1, vs_1_2);
504
505
506
507
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMSUB_pd(y1, h1, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMSUB_pd(y2, h1, _mm256_mul_pd(x2,h2));
	y3 = _mm256_FMSUB_pd(y3, h1, _mm256_mul_pd(x3,h2));
508
509
510
511
512
513
514
515
516
517
518
519
520
#else
	y1 = _mm256_sub_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
	y2 = _mm256_sub_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
	y3 = _mm256_sub_pd(_mm256_mul_pd(y3,h1), _mm256_mul_pd(x3,h2));
#endif

	__m256d tau3 = _mm256_broadcast_sd(&hh[ldh*2]);
	__m256d vs_1_3 = _mm256_broadcast_sd(&s_1_3);
	__m256d vs_2_3 = _mm256_broadcast_sd(&s_2_3);

	h1 = tau3;
	h2 = _mm256_mul_pd(h1, vs_1_3);
	h3 = _mm256_mul_pd(h1, vs_2_3);
521
522
523
524
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_pd(z1, h1, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)));
	z2 = _mm256_FMSUB_pd(z2, h1, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2)));
	z3 = _mm256_FMSUB_pd(z3, h1, _mm256_FMA_pd(y3, h3, _mm256_mul_pd(x3,h2)));
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
#else
	z1 = _mm256_sub_pd(_mm256_mul_pd(z1,h1), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)));
	z2 = _mm256_sub_pd(_mm256_mul_pd(z2,h1), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2)));
	z3 = _mm256_sub_pd(_mm256_mul_pd(z3,h1), _mm256_add_pd(_mm256_mul_pd(y3,h3), _mm256_mul_pd(x3,h2)));
#endif

	__m256d tau4 = _mm256_broadcast_sd(&hh[ldh*3]);
	__m256d vs_1_4 = _mm256_broadcast_sd(&s_1_4);
	__m256d vs_2_4 = _mm256_broadcast_sd(&s_2_4);
	__m256d vs_3_4 = _mm256_broadcast_sd(&s_3_4);

	h1 = tau4;
	h2 = _mm256_mul_pd(h1, vs_1_4);
	h3 = _mm256_mul_pd(h1, vs_2_4);
	h4 = _mm256_mul_pd(h1, vs_3_4);
540
541
542
543
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_pd(w1, h1, _mm256_FMA_pd(z1, h4, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
	w2 = _mm256_FMSUB_pd(w2, h1, _mm256_FMA_pd(z2, h4, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2))));
	w3 = _mm256_FMSUB_pd(w3, h1, _mm256_FMA_pd(z3, h4, _mm256_FMA_pd(y3, h3, _mm256_mul_pd(x3,h2))));
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
#else
	w1 = _mm256_sub_pd(_mm256_mul_pd(w1,h1), _mm256_add_pd(_mm256_mul_pd(z1,h4), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
	w2 = _mm256_sub_pd(_mm256_mul_pd(w2,h1), _mm256_add_pd(_mm256_mul_pd(z2,h4), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2))));
	w3 = _mm256_sub_pd(_mm256_mul_pd(w3,h1), _mm256_add_pd(_mm256_mul_pd(z3,h4), _mm256_add_pd(_mm256_mul_pd(y3,h3), _mm256_mul_pd(x3,h2))));
#endif

	q1 = _mm256_load_pd(&q[0]);
	q2 = _mm256_load_pd(&q[4]);
	q3 = _mm256_load_pd(&q[8]);
	q1 = _mm256_sub_pd(q1, w1);
	q2 = _mm256_sub_pd(q2, w2);
	q3 = _mm256_sub_pd(q3, w3);
	_mm256_store_pd(&q[0],q1);
	_mm256_store_pd(&q[4],q2);
	_mm256_store_pd(&q[8],q3);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	q1 = _mm256_load_pd(&q[ldq]);
	q2 = _mm256_load_pd(&q[ldq+4]);
	q3 = _mm256_load_pd(&q[ldq+8]);
564
565
566
567
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_sub_pd(q1, _mm256_FMA_pd(w1, h4, z1));
	q2 = _mm256_sub_pd(q2, _mm256_FMA_pd(w2, h4, z2));
	q3 = _mm256_sub_pd(q3, _mm256_FMA_pd(w3, h4, z3));
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(z1, _mm256_mul_pd(w1, h4)));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd(z2, _mm256_mul_pd(w2, h4)));
	q3 = _mm256_sub_pd(q3, _mm256_add_pd(z3, _mm256_mul_pd(w3, h4)));
#endif
	_mm256_store_pd(&q[ldq],q1);
	_mm256_store_pd(&q[ldq+4],q2);
	_mm256_store_pd(&q[ldq+8],q3);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	q1 = _mm256_load_pd(&q[ldq*2]);
	q2 = _mm256_load_pd(&q[(ldq*2)+4]);
	q3 = _mm256_load_pd(&q[(ldq*2)+8]);
	q1 = _mm256_sub_pd(q1, y1);
	q2 = _mm256_sub_pd(q2, y2);
	q3 = _mm256_sub_pd(q3, y3);
584
585
586
587
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
	q3 = _mm256_NFMA_pd(w3, h4, q3);
588
589
590
591
592
593
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(w3, h4));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
594
595
596
597
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
	q3 = _mm256_NFMA_pd(z3, h3, q3);
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(z3, h3));
#endif
	_mm256_store_pd(&q[ldq*2],q1);
	_mm256_store_pd(&q[(ldq*2)+4],q2);
	_mm256_store_pd(&q[(ldq*2)+8],q3);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);
	q1 = _mm256_load_pd(&q[ldq*3]);
	q2 = _mm256_load_pd(&q[(ldq*3)+4]);
	q3 = _mm256_load_pd(&q[(ldq*3)+8]);
	q1 = _mm256_sub_pd(q1, x1);
	q2 = _mm256_sub_pd(q2, x2);
	q3 = _mm256_sub_pd(q3, x3);
614
615
616
617
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
	q3 = _mm256_NFMA_pd(w3, h4, q3);
618
619
620
621
622
623
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(w3, h4));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
624
625
626
627
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
	q3 = _mm256_NFMA_pd(y3, h2, q3);
628
629
630
631
632
633
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(y3, h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
634
635
636
637
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
	q3 = _mm256_NFMA_pd(z3, h3, q3);
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(z3, h3));
#endif
	_mm256_store_pd(&q[ldq*3], q1);
	_mm256_store_pd(&q[(ldq*3)+4], q2);
	_mm256_store_pd(&q[(ldq*3)+8], q3);

	for (i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);

		q1 = _mm256_load_pd(&q[i*ldq]);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		q3 = _mm256_load_pd(&q[(i*ldq)+8]);

655
656
657
658
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(x1, h1, q1);
		q2 = _mm256_NFMA_pd(x2, h1, q2);
		q3 = _mm256_NFMA_pd(x3, h1, q3);
659
660
661
662
663
664
665
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1,h1));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2,h1));
		q3 = _mm256_sub_pd(q3, _mm256_mul_pd(x3,h1));
#endif

		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
666
667
668
669
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(y1, h2, q1);
		q2 = _mm256_NFMA_pd(y2, h2, q2);
		q3 = _mm256_NFMA_pd(y3, h2, q3);
670
671
672
673
674
675
676
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1,h2));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2,h2));
		q3 = _mm256_sub_pd(q3, _mm256_mul_pd(y3,h2));
#endif

		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
677
678
679
680
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(z1, h3, q1);
		q2 = _mm256_NFMA_pd(z2, h3, q2);
		q3 = _mm256_NFMA_pd(z3, h3, q3);
681
682
683
684
685
686
687
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1,h3));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2,h3));
		q3 = _mm256_sub_pd(q3, _mm256_mul_pd(z3,h3));
#endif

		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);
688
689
690
691
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(w1, h4, q1);
		q2 = _mm256_NFMA_pd(w2, h4, q2);
		q3 = _mm256_NFMA_pd(w3, h4, q3);
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1,h4));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2,h4));
		q3 = _mm256_sub_pd(q3, _mm256_mul_pd(w3,h4));
#endif

		_mm256_store_pd(&q[i*ldq],q1);
		_mm256_store_pd(&q[(i*ldq)+4],q2);
		_mm256_store_pd(&q[(i*ldq)+8],q3);
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
	q3 = _mm256_load_pd(&q[(nb*ldq)+8]);
707
708
709
710
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
	q3 = _mm256_NFMA_pd(x3, h1, q3);
711
712
713
714
715
716
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1,h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2,h1));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(x3,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
717
718
719
720
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
	q3 = _mm256_NFMA_pd(y3, h2, q3);
721
722
723
724
725
726
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1,h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2,h2));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(y3,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
727
728
729
730
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
	q3 = _mm256_NFMA_pd(z3, h3, q3);
731
732
733
734
735
736
737
738
739
740
741
742
743
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1,h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2,h3));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(z3,h3));
#endif
	_mm256_store_pd(&q[nb*ldq],q1);
	_mm256_store_pd(&q[(nb*ldq)+4],q2);
	_mm256_store_pd(&q[(nb*ldq)+8],q3);

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
	q3 = _mm256_load_pd(&q[((nb+1)*ldq)+8]);
744
745
746
747
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
	q3 = _mm256_NFMA_pd(x3, h1, q3);
748
749
750
751
752
753
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1,h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2,h1));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(x3,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
754
755
756
757
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
	q3 = _mm256_NFMA_pd(y3, h2, q3);
758
759
760
761
762
763
764
765
766
767
768
769
770
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1,h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2,h2));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(y3,h2));
#endif
	_mm256_store_pd(&q[(nb+1)*ldq],q1);
	_mm256_store_pd(&q[((nb+1)*ldq)+4],q2);
	_mm256_store_pd(&q[((nb+1)*ldq)+8],q3);

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
	q3 = _mm256_load_pd(&q[((nb+2)*ldq)+8]);
771
772
773
774
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
	q3 = _mm256_NFMA_pd(x3, h1, q3);
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1,h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2,h1));
	q3 = _mm256_sub_pd(q3, _mm256_mul_pd(x3,h1));
#endif
	_mm256_store_pd(&q[(nb+2)*ldq],q1);
	_mm256_store_pd(&q[((nb+2)*ldq)+4],q2);
	_mm256_store_pd(&q[((nb+2)*ldq)+8],q3);
}

/**
 * Unrolled kernel that computes
 * 8 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
__forceinline void hh_trafo_kernel_8_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

	__m256d a1_1 = _mm256_load_pd(&q[ldq*3]);
	__m256d a2_1 = _mm256_load_pd(&q[ldq*2]);
	__m256d a3_1 = _mm256_load_pd(&q[ldq]);
	__m256d a4_1 = _mm256_load_pd(&q[0]);

	__m256d h_2_1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h_3_2 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	__m256d h_3_1 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
	__m256d h_4_3 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	__m256d h_4_2 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	__m256d h_4_1 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);

811
812
813
814
815
816
817
#ifdef __ELPA_USE_FMA__
	__m256d w1 = _mm256_FMA_pd(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_pd(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_pd(a1_1, h_4_1, w1);
	__m256d z1 = _mm256_FMA_pd(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_pd(a1_1, h_3_1, z1);
	__m256d y1 = _mm256_FMA_pd(a1_1, h_2_1, a2_1);
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
	__m256d x1 = a1_1;
#else
	__m256d w1 = _mm256_add_pd(a4_1, _mm256_mul_pd(a3_1, h_4_3));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a2_1, h_4_2));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a1_1, h_4_1));
	__m256d z1 = _mm256_add_pd(a3_1, _mm256_mul_pd(a2_1, h_3_2));
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(a1_1, h_3_1));
	__m256d y1 = _mm256_add_pd(a2_1, _mm256_mul_pd(a1_1, h_2_1));
	__m256d x1 = a1_1;
#endif

	__m256d a1_2 = _mm256_load_pd(&q[(ldq*3)+4]);
	__m256d a2_2 = _mm256_load_pd(&q[(ldq*2)+4]);
	__m256d a3_2 = _mm256_load_pd(&q[ldq+4]);
	__m256d a4_2 = _mm256_load_pd(&q[0+4]);

834
835
836
837
838
839
840
#ifdef __ELPA_USE_FMA__
	__m256d w2 = _mm256_FMA_pd(a3_2, h_4_3, a4_2);
	w2 = _mm256_FMA_pd(a2_2, h_4_2, w2);
	w2 = _mm256_FMA_pd(a1_2, h_4_1, w2);
	__m256d z2 = _mm256_FMA_pd(a2_2, h_3_2, a3_2);
	z2 = _mm256_FMA_pd(a1_2, h_3_1, z2);
	__m256d y2 = _mm256_FMA_pd(a1_2, h_2_1, a2_2);
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
	__m256d x2 = a1_2;
#else
	__m256d w2 = _mm256_add_pd(a4_2, _mm256_mul_pd(a3_2, h_4_3));
	w2 = _mm256_add_pd(w2, _mm256_mul_pd(a2_2, h_4_2));
	w2 = _mm256_add_pd(w2, _mm256_mul_pd(a1_2, h_4_1));
	__m256d z2 = _mm256_add_pd(a3_2, _mm256_mul_pd(a2_2, h_3_2));
	z2 = _mm256_add_pd(z2, _mm256_mul_pd(a1_2, h_3_1));
	__m256d y2 = _mm256_add_pd(a2_2, _mm256_mul_pd(a1_2, h_2_1));
	__m256d x2 = a1_2;
#endif

	__m256d q1;
	__m256d q2;

	__m256d h1;
	__m256d h2;
	__m256d h3;
	__m256d h4;

	for(i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);

		q1 = _mm256_load_pd(&q[i*ldq]);
868
869
870
871
872
#ifdef __ELPA_USE_FMA__
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
		z1 = _mm256_FMA_pd(q1, h3, z1);
		w1 = _mm256_FMA_pd(q1, h4, w1);
873
874
875
876
877
878
879
880
#else
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
		w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
#endif

		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
881
882
883
884
885
#ifdef __ELPA_USE_FMA__
		x2 = _mm256_FMA_pd(q2, h1, x2);
		y2 = _mm256_FMA_pd(q2, h2, y2);
		z2 = _mm256_FMA_pd(q2, h3, z2);
		w2 = _mm256_FMA_pd(q2, h4, w2);
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
#else
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
		z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
		w2 = _mm256_add_pd(w2, _mm256_mul_pd(q2,h4));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);

	q1 = _mm256_load_pd(&q[nb*ldq]);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);

901
902
903
904
905
906
907
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
	z1 = _mm256_FMA_pd(q1, h3, z1);
	z2 = _mm256_FMA_pd(q2, h3, z2);
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
	z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	h2 = _mm256_broadcast_sd(&hh[(ldh*1)+nb-1]);

	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);

923
924
925
926
927
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
928
929
930
931
932
933
934
935
936
937
938
939
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-1]);

	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);

940
941
942
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif

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

	__m256d tau1 = _mm256_broadcast_sd(&hh[0]);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d tau3 = _mm256_broadcast_sd(&hh[ldh*2]);
	__m256d tau4 = _mm256_broadcast_sd(&hh[ldh*3]);

	__m256d vs_1_2 = _mm256_broadcast_sd(&s_1_2);
	__m256d vs_1_3 = _mm256_broadcast_sd(&s_1_3);
	__m256d vs_2_3 = _mm256_broadcast_sd(&s_2_3);
	__m256d vs_1_4 = _mm256_broadcast_sd(&s_1_4);
	__m256d vs_2_4 = _mm256_broadcast_sd(&s_2_4);
	__m256d vs_3_4 = _mm256_broadcast_sd(&s_3_4);

	h1 = tau1;
	x1 = _mm256_mul_pd(x1, h1);
	x2 = _mm256_mul_pd(x2, h1);

	h1 = tau2;
	h2 = _mm256_mul_pd(h1, vs_1_2);
970
971
972
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMSUB_pd(y1, h1, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMSUB_pd(y2, h1, _mm256_mul_pd(x2,h2));
973
974
975
976
977
978
979
980
#else
	y1 = _mm256_sub_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
	y2 = _mm256_sub_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
#endif

	h1 = tau3;
	h2 = _mm256_mul_pd(h1, vs_1_3);
	h3 = _mm256_mul_pd(h1, vs_2_3);
981
982
983
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_pd(z1, h1, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)));
	z2 = _mm256_FMSUB_pd(z2, h1, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2)));
984
985
986
987
988
989
990
991
992
#else
	z1 = _mm256_sub_pd(_mm256_mul_pd(z1,h1), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)));
	z2 = _mm256_sub_pd(_mm256_mul_pd(z2,h1), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2)));
#endif

	h1 = tau4;
	h2 = _mm256_mul_pd(h1, vs_1_4);
	h3 = _mm256_mul_pd(h1, vs_2_4);
	h4 = _mm256_mul_pd(h1, vs_3_4);
993
994
995
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_pd(w1, h1, _mm256_FMA_pd(z1, h4, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
	w2 = _mm256_FMSUB_pd(w2, h1, _mm256_FMA_pd(z2, h4, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2))));
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
#else
	w1 = _mm256_sub_pd(_mm256_mul_pd(w1,h1), _mm256_add_pd(_mm256_mul_pd(z1,h4), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
	w2 = _mm256_sub_pd(_mm256_mul_pd(w2,h1), _mm256_add_pd(_mm256_mul_pd(z2,h4), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2))));
#endif

	q1 = _mm256_load_pd(&q[0]);
	q2 = _mm256_load_pd(&q[4]);
	q1 = _mm256_sub_pd(q1, w1);
	q2 = _mm256_sub_pd(q2, w2);
	_mm256_store_pd(&q[0],q1);
	_mm256_store_pd(&q[4],q2);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	q1 = _mm256_load_pd(&q[ldq]);
	q2 = _mm256_load_pd(&q[ldq+4]);
1011
1012
1013
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_sub_pd(q1, _mm256_FMA_pd(w1, h4, z1));
	q2 = _mm256_sub_pd(q2, _mm256_FMA_pd(w2, h4, z2));
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(z1, _mm256_mul_pd(w1, h4)));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd(z2, _mm256_mul_pd(w2, h4)));
#endif
	_mm256_store_pd(&q[ldq],q1);
	_mm256_store_pd(&q[ldq+4],q2);

	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	q1 = _mm256_load_pd(&q[ldq*2]);
	q2 = _mm256_load_pd(&q[(ldq*2)+4]);
1025
1026
1027
1028
1029
1030
1031
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_sub_pd(q1, y1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
        q1 = _mm256_NFMA_pd(w1, h4, q1);
        q2 = _mm256_sub_pd(q2, y2);
        q2 = _mm256_NFMA_pd(z2, h3, q2);
        q2 = _mm256_NFMA_pd(w2, h4, q2);
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(y1, _mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(w1, h4))));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd(y2, _mm256_add_pd(_mm256_mul_pd(z2, h3), _mm256_mul_pd(w2, h4))));
#endif
	_mm256_store_pd(&q[ldq*2],q1);
	_mm256_store_pd(&q[(ldq*2)+4],q2);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);
	q1 = _mm256_load_pd(&q[ldq*3]);
	q2 = _mm256_load_pd(&q[(ldq*3)+4]);
1044
1045
1046
1047
1048
1049
1050
1051
1052
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_sub_pd(q1, x1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
        q1 = _mm256_NFMA_pd(w1, h4, q1);
        q2 = _mm256_sub_pd(q2, x2);
        q2 = _mm256_NFMA_pd(y2, h2, q2);
        q2 = _mm256_NFMA_pd(z2, h3, q2);
        q2 = _mm256_NFMA_pd(w2, h4, q2);
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(x1, _mm256_add_pd(_mm256_mul_pd(y1, h2), _mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(w1, h4)))));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd(x2, _mm256_add_pd(_mm256_mul_pd(y2, h2), _mm256_add_pd(_mm256_mul_pd(z2, h3), _mm256_mul_pd(w2, h4)))));
#endif
	_mm256_store_pd(&q[ldq*3], q1);
	_mm256_store_pd(&q[(ldq*3)+4], q2);

	for (i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);

1067
#ifdef __ELPA_USE_FMA__
1068
		q1 = _mm256_load_pd(&q[i*ldq]);
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
                q1 = _mm256_NFMA_pd(x1, h1, q1);
                q1 = _mm256_NFMA_pd(y1, h2, q1);
                q1 = _mm256_NFMA_pd(z1, h3, q1);
                q1 = _mm256_NFMA_pd(w1, h4, q1);
                q2 = _mm256_NFMA_pd(x2, h1, q2);
                q2 = _mm256_NFMA_pd(y2, h2, q2);
                q2 = _mm256_NFMA_pd(z2, h3, q2);
                q2 = _mm256_NFMA_pd(w2, h4, q2);
		_mm256_store_pd(&q[i*ldq],q1);
		_mm256_store_pd(&q[(i*ldq)+4],q2);
1080
#else
1081
		q1 = _mm256_load_pd(&q[i*ldq]);
1082
1083
1084
1085
1086
1087
		q1 = _mm256_sub_pd(q1, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w1, h4), _mm256_mul_pd(z1, h3)), _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_sub_pd(q2, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w2, h4), _mm256_mul_pd(z2, h3)), _mm256_add_pd(_mm256_mul_pd(x2,h1), _mm256_mul_pd(y2, h2))));
		_mm256_store_pd(&q[(i*ldq)+4],q2);
1088
#endif
1089
1090
1091
1092
1093
1094
1095
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
1096
1097
1098
1099
1100
1101
1102
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_pd(x1, h1, q1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
        q2 = _mm256_NFMA_pd(x2, h1, q2);
        q2 = _mm256_NFMA_pd(y2, h2, q2);
        q2 = _mm256_NFMA_pd(z2, h3, q2);
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(y1, h2)) , _mm256_mul_pd(x1, h1)));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(z2, h3), _mm256_mul_pd(y2, h2)) , _mm256_mul_pd(x2, h1)));
#endif
	_mm256_store_pd(&q[nb*ldq],q1);
	_mm256_store_pd(&q[(nb*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
1114
1115
1116
1117
1118
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_pd(x1, h1, q1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
        q2 = _mm256_NFMA_pd(x2, h1, q2);
        q2 = _mm256_NFMA_pd(y2, h2, q2);
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd( _mm256_mul_pd(y1, h2) , _mm256_mul_pd(x1, h1)));
	q2 = _mm256_sub_pd(q2, _mm256_add_pd( _mm256_mul_pd(y2, h2) , _mm256_mul_pd(x2, h1)));
#endif
	_mm256_store_pd(&q[(nb+1)*ldq],q1);
	_mm256_store_pd(&q[((nb+1)*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
1129
1130
1131
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
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
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
	_mm256_store_pd(&q[(nb+2)*ldq],q1);
	_mm256_store_pd(&q[((nb+2)*ldq)+4],q2);
}

/**
 * Unrolled kernel that computes
 * 4 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
__forceinline void hh_trafo_kernel_4_AVX_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

	__m256d a1_1 = _mm256_load_pd(&q[ldq*3]);
	__m256d a2_1 = _mm256_load_pd(&q[ldq*2]);
	__m256d a3_1 = _mm256_load_pd(&q[ldq]);
	__m256d a4_1 = _mm256_load_pd(&q[0]);

	__m256d h_2_1 = _mm256_broadcast_sd(&hh[ldh+1]);
	__m256d h_3_2 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	__m256d h_3_1 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
	__m256d h_4_3 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	__m256d h_4_2 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	__m256d h_4_1 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);

1166
1167
1168
1169
1170
1171
1172
#ifdef __ELPA_USE_FMA__
	__m256d w1 = _mm256_FMA_pd(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_pd(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_pd(a1_1, h_4_1, w1);
	__m256d z1 = _mm256_FMA_pd(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_pd(a1_1, h_3_1, z1);
	__m256d y1 = _mm256_FMA_pd(a1_1, h_2_1, a2_1);
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
	__m256d x1 = a1_1;
#else
	__m256d w1 = _mm256_add_pd(a4_1, _mm256_mul_pd(a3_1, h_4_3));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a2_1, h_4_2));
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(a1_1, h_4_1));
	__m256d z1 = _mm256_add_pd(a3_1, _mm256_mul_pd(a2_1, h_3_2));
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(a1_1, h_3_1));
	__m256d y1 = _mm256_add_pd(a2_1, _mm256_mul_pd(a1_1, h_2_1));
	__m256d x1 = a1_1;
#endif

	__m256d q1;

	__m256d h1;
	__m256d h2;
	__m256d h3;
	__m256d h4;

	for(i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);

		q1 = _mm256_load_pd(&q[i*ldq]);
1199
1200
1201
1202
1203
#ifdef __ELPA_USE_FMA__
		x1 = _mm256_FMA_pd(q1, h1, x1);
		y1 = _mm256_FMA_pd(q1, h2, y1);
		z1 = _mm256_FMA_pd(q1, h3, z1);
		w1 = _mm256_FMA_pd(q1, h4, w1);
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
#else
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
		w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
#ifdef _FMA4__
1217
1218
1219
	x1 = _mm256_FMA_pd(q1, h1, x1);
	y1 = _mm256_FMA_pd(q1, h2, y1);
	z1 = _mm256_FMA_pd(q1, h3, z1);
1220
1221
1222
1223
1224
1225
1226
1227
1228
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	h2 = _mm256_broadcast_sd(&hh[(ldh*1)+nb-1]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
1229
1230
1231
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	y1 = _mm256_FMA_pd(q1, h2, y1);
1232
1233
1234
1235
1236
1237
1238
#else
	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]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
1239
1240
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif

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

	__m256d tau1 = _mm256_broadcast_sd(&hh[0]);
	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d tau3 = _mm256_broadcast_sd(&hh[ldh*2]);
	__m256d tau4 = _mm256_broadcast_sd(&hh[ldh*3]);

	__m256d vs_1_2 = _mm256_broadcast_sd(&s_1_2);
	__m256d vs_1_3 = _mm256_broadcast_sd(&s_1_3);
	__m256d vs_2_3 = _mm256_broadcast_sd(&s_2_3);
	__m256d vs_1_4 = _mm256_broadcast_sd(&s_1_4);
	__m256d vs_2_4 = _mm256_broadcast_sd(&s_2_4);
	__m256d vs_3_4 = _mm256_broadcast_sd(&s_3_4);

	h1 = tau1;
	x1 = _mm256_mul_pd(x1, h1);

	h1 = tau2;
	h2 = _mm256_mul_pd(h1, vs_1_2);
1266
1267
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMSUB_pd(y1, h1, _mm256_mul_pd(x1,h2));
1268
1269
1270
1271
1272
1273
1274
#else
	y1 = _mm256_sub_pd(_mm256_mul_pd(y1,h1), _mm256_mul_pd(x1,h2));
#endif

	h1 = tau3;
	h2 = _mm256_mul_pd(h1, vs_1_3);
	h3 = _mm256_mul_pd(h1, vs_2_3);
1275
1276
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_pd(z1, h1, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)));
1277
1278
1279
1280
1281
1282
1283
1284
#else
	z1 = _mm256_sub_pd(_mm256_mul_pd(z1,h1), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)));
#endif

	h1 = tau4;
	h2 = _mm256_mul_pd(h1, vs_1_4);
	h3 = _mm256_mul_pd(h1, vs_2_4);
	h4 = _mm256_mul_pd(h1, vs_3_4);
1285
1286
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_pd(w1, h1, _mm256_FMA_pd(z1, h4, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
#else
	w1 = _mm256_sub_pd(_mm256_mul_pd(w1,h1), _mm256_add_pd(_mm256_mul_pd(z1,h4), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
#endif

	q1 = _mm256_load_pd(&q[0]);
	q1 = _mm256_sub_pd(q1, w1);
	_mm256_store_pd(&q[0],q1);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	q1 = _mm256_load_pd(&q[ldq]);
1297
1298
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_sub_pd(q1, _mm256_FMA_pd(w1, h4, z1));
1299
1300
1301
1302
1303
1304
1305
1306
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(z1, _mm256_mul_pd(w1, h4)));
#endif
	_mm256_store_pd(&q[ldq],q1);

	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
	q1 = _mm256_load_pd(&q[ldq*2]);
1307
1308
1309
1310
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_sub_pd(q1, y1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
        q1 = _mm256_NFMA_pd(w1, h4, q1);
1311
1312
1313
1314
1315
1316
1317
1318
1319
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(y1, _mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(w1, h4))));
#endif
	_mm256_store_pd(&q[ldq*2],q1);

	h2 = _mm256_broadcast_sd(&hh[ldh+1]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);
	q1 = _mm256_load_pd(&q[ldq*3]);
1320
1321
1322
1323
1324
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_sub_pd(q1, x1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
        q1 = _mm256_NFMA_pd(w1, h4, q1);
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(x1, _mm256_add_pd(_mm256_mul_pd(y1, h2), _mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(w1, h4)))));
#endif
	_mm256_store_pd(&q[ldq*3], q1);

	for (i = 4; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-3]);
		h2 = _mm256_broadcast_sd(&hh[ldh+i-2]);
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-1]);
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i]);

		q1 = _mm256_load_pd(&q[i*ldq]);
1338
1339
1340
1341
1342
#ifdef __ELPA_USE_FMA__
                q1 = _mm256_NFMA_pd(x1, h1, q1);
                q1 = _mm256_NFMA_pd(y1, h2, q1);
                q1 = _mm256_NFMA_pd(z1, h3, q1);
                q1 = _mm256_NFMA_pd(w1, h4, q1);
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
#else
		q1 = _mm256_sub_pd(q1, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w1, h4), _mm256_mul_pd(z1, h3)), _mm256_add_pd(_mm256_mul_pd(x1,h1), _mm256_mul_pd(y1, h2))));
#endif
		_mm256_store_pd(&q[i*ldq],q1);
	}

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
1353
1354
1355
1356
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_pd(x1, h1, q1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
        q1 = _mm256_NFMA_pd(z1, h3, q1);
1357
1358
1359
1360
1361
1362
1363
1364
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(z1, h3), _mm256_mul_pd(y1, h2)) , _mm256_mul_pd(x1, h1)));
#endif
	_mm256_store_pd(&q[nb*ldq],q1);

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
1365
1366
1367
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_pd(x1, h1, q1);
        q1 = _mm256_NFMA_pd(y1, h2, q1);
1368
1369
1370
1371
1372
1373
1374
#else
	q1 = _mm256_sub_pd(q1, _mm256_add_pd( _mm256_mul_pd(y1, h2) , _mm256_mul_pd(x1, h1)));
#endif
	_mm256_store_pd(&q[(nb+1)*ldq],q1);

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
1375
1376
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
#endif
	_mm256_store_pd(&q[(nb+2)*ldq],q1);
}
#else
/**
 * Unrolled kernel that computes
 * 6 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
__forceinline void hh_trafo_kernel_6_SSE_4hv(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [6 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

	__m128d a1_1 = _mm_load_pd(&q[ldq*3]);
	__m128d a2_1 = _mm_load_pd(&q[ldq*2]);
	__m128d a3_1 = _mm_load_pd(&q[ldq]);
	__m128d a4_1 = _mm_load_pd(&q[0]);

	__m128d h_2_1 = _mm_loaddup_pd(&hh[ldh+1]);
	__m128d h_3_2 = _mm_loaddup_pd(&hh[(ldh*2)+1]);
	__m128d h_3_1 = _mm_loaddup_pd(&hh[(ldh*2)+2]);
	__m128d h_4_3 = _mm_loaddup_pd(&hh[(ldh*3)+1]);
	__m128d h_4_2 = _mm_loaddup_pd(&hh[(ldh*3)+2]);
	__m128d h_4_1 = _mm_loaddup_pd(&hh[(ldh*3)+3]);

1409
#ifdef __ELPA_USE_FMA__
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
	register __m128d w1 = _mm_macc_pd(a3_1, h_4_3, a4_1);
	w1 = _mm_macc_pd(a2_1, h_4_2, w1);
	w1 = _mm_macc_pd(a1_1, h_4_1, w1);
	register __m128d z1 = _mm_macc_pd(a2_1, h_3_2, a3_1);
	z1 = _mm_macc_pd(a1_1, h_3_1, z1);
	register __m128d y1 = _mm_macc_pd(a1_1, h_2_1, a2_1);
	register __m128d x1 = a1_1;
#else
	register __m128d w1 = _mm_add_pd(a4_1, _mm_mul_pd(a3_1, h_4_3));
	w1 = _mm_add_pd(w1, _mm_mul_pd(a2_1, h_4_2));
	w1 = _mm_add_pd(w1, _mm_mul_pd(a1_1, h_4_1));
	register __m128d z1 = _mm_add_pd(a3_1, _mm_mul_pd(a2_1, h_3_2));
	z1 = _mm_add_pd(z1, _mm_mul_pd(a1_1, h_3_1));
	register __m128d y1 = _mm_add_pd(a2_1, _mm_mul_pd(a1_1, h_2_1));
	register __m128d x1 = a1_1;
#endif

	__m128d a1_2 = _mm_load_pd(&q[(ldq*3)+2]);
	__m128d a2_2 = _mm_load_pd(&q[(ldq*2)+2]);
	__m128d a3_2 = _mm_load_pd(&q[ldq+2]);
	__m128d a4_2 = _mm_load_pd(&q[0+2]);

1432
#ifdef __ELPA_USE_FMA__
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
	register __m128d w2 = _mm_macc_pd(a3_2, h_4_3, a4_2);
	w2 = _mm_macc_pd(a2_2, h_4_2, w2);
	w2 = _mm_macc_pd(a1_2, h_4_1, w2);
	register __m128d z2 = _mm_macc_pd(a2_2, h_3_2, a3_2);
	z2 = _mm_macc_pd(a1_2, h_3_1, z2);
	register __m128d y2 = _mm_macc_pd(a1_2, h_2_1, a2_2);
	register __m128d x2 = a1_2;
#else
	register __m128d w2 = _mm_add_pd(a4_2, _mm_mul_pd(a3_2, h_4_3));
	w2 = _mm_add_pd(w2, _mm_mul_pd(a2_2, h_4_2));
	w2 = _mm_add_pd(w2, _mm_mul_pd(a1_2, h_4_1));
	register __m128d z2 = _mm_add_pd(a3_2, _mm_mul_pd(a2_2, h_3_2));
	z2 = _mm_add_pd(z2, _mm_mul_pd(a1_2, h_3_1));
	register __m128d y2 = _mm_add_pd(a2_2, _mm_mul_pd(a1_2, h_2_1));
	register __m128d x2 = a1_2;
#endif

	__m128d a1_3 = _mm_load_pd(&q[(ldq*3)+4]);
	__m128d a2_3 = _mm_load_pd(&q[(ldq*2)+4]);
	__m128d a3_3 = _mm_load_pd(&q[ldq+4]);
	__m128d a4_3 = _mm_load_pd(&q[0+4]);

1455
#ifdef __ELPA_USE_FMA__
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
	register __m128d w3 = _mm_macc_pd(a3_3, h_4_3, a4_3);
	w3 = _mm_macc_pd(a2_3, h_4_2, w3);
	w3 = _mm_macc_pd(a1_3, h_4_1, w3);
	register __m128d z3 = _mm_macc_pd(a2_3, h_3_2, a3_3);
	z3 = _mm_macc_pd(a1_3, h_3_1, z3);
	register __m128d y3 = _mm_macc_pd(a1_3, h_2_1, a2_3);
	register __m128d x3 = a1_3;
#else
	register __m128d w3 = _mm_add_pd(a4_3, _mm_mul_pd(a3_3, h_4_3));
	w3 = _mm_add_pd(w3, _mm_mul_pd(a2_3, h_4_2));
	w3 = _mm_add_pd(w3, _mm_mul_pd(a1_3, h_4_1));
	register __m128d z3 = _mm_add_pd(a3_3, _mm_mul_pd(a2_3, h_3_2));
	z3 = _mm_add_pd(z3, _mm_mul_pd(a1_3, h_3_1));
	register __m128d y3 = _mm_add_pd(a2_3, _mm_mul_pd(a1_3, h_2_1));
	register __m128d x3 = a1_3;
#endif

	__m128d q1;
	__m128d q2;
	__m128d q3;

	__m128d h1;
	__m128d h2;
	__m128d h3;
	__m128d h4;

	for(i = 4; i < nb; i++)
	{
		h1 = _mm_loaddup_pd(&hh[i-3]);
		q1 = _mm_load_pd(&q[i*ldq]);
		q2 = _mm_load_pd(&q[(i*ldq)+2]);
		q3 = _mm_load_pd(&q[(i*ldq)+4]);

1489
#ifdef __ELPA_USE_FMA__
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
		x1 = _mm_macc_pd(q1, h1, x1);
		x2 = _mm_macc_pd(q2, h1, x2);
		x3 = _mm_macc_pd(q3, h1, x3);
#else
		x1 = _mm_add_pd(x1, _mm_mul_pd(q1,h1));
		x2 = _mm_add_pd(x2, _mm_mul_pd(q2,h1));
		x3 = _mm_add_pd(x3, _mm_mul_pd(q3,h1));
#endif

		h2 = _mm_loaddup_pd(&hh[ldh+i-2]);
1500
#ifdef __ELPA_USE_FMA__
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
		y1 = _mm_macc_pd(q1, h2, y1);
		y2 = _mm_macc_pd(q2, h2, y2);
		y3 = _mm_macc_pd(q3, h2, y3);
#else
		y1 = _mm_add_pd(y1, _mm_mul_pd(q1,h2));
		y2 = _mm_add_pd(y2, _mm_mul_pd(q2,h2));
		y3 = _mm_add_pd(y3, _mm_mul_pd(q3,h2));
#endif

		h3 = _mm_loaddup_pd(&hh[(ldh*2)+i-1]);
1511
#ifdef __ELPA_USE_FMA__
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
		z1 = _mm_macc_pd(q1, h3, z1);
		z2 = _mm_macc_pd(q2, h3, z2);
		z3 = _mm_macc_pd(q3, h3, z3);
#else
		z1 = _mm_add_pd(z1, _mm_mul_pd(q1,h3));
		z2 = _mm_add_pd(z2, _mm_mul_pd(q2,h3));
		z3 = _mm_add_pd(z3, _mm_mul_pd(q3,h3));
#endif

		h4 = _mm_loaddup_pd(&hh[(ldh*3)+i]);
1522
#ifdef __ELPA_USE_FMA__
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
		w1 = _mm_macc_pd(q1, h4, w1);
		w2 = _mm_macc_pd(q2, h4, w2);
		w3 = _mm_macc_pd(q3, h4, w3);
#else
		w1 = _mm_add_pd(w1, _mm_mul_pd(q1,h4));
		w2 = _mm_add_pd(w2, _mm_mul_pd(q2,h4));
		w3 = _mm_add_pd(w3, _mm_mul_pd(q3,h4));
#endif
	}

	h1 = _mm_loaddup_pd(&hh[nb-3]);

	q1 = _mm_load_pd(&q[nb*ldq]);
	q2 = _mm_load_pd(&q[(nb*ldq)+2]);
	q3 = _mm_load_pd(&q[(nb*ldq)+4]);

1539
#ifdef __ELPA_USE_FMA__
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
	x1 = _mm_macc_pd(q1, h1, x1);
	x2 = _mm_macc_pd(q2, h1, x2);
	x3 = _mm_macc_pd(q3, h1, x3);
#else
	x1 = _mm_add_pd(x1, _mm_mul_pd(q1,h1));
	x2 = _mm_add_pd(x2, _mm_mul_pd(q2,h1));
	x3 = _mm_add_pd(x3, _mm_mul_pd(q3,h1));
#endif

	h2 = _mm_loaddup_pd(&hh[ldh+nb-2]);
1550
#ifdef __ELPA_USE_FMA__
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
	y1 = _mm_macc_pd(q1, h2, y1);
	y2 = _mm_macc_pd(q2, h2, y2);
	y3 = _mm_macc_pd(q3, h2, y3);
#else
	y1 = _mm_add_pd(y1, _mm_mul_pd(q1,h2));
	y2 = _mm_add_pd(y2, _mm_mul_pd(q2,h2));
	y3 = _mm_add_pd(y3, _mm_mul_pd(q3,h2));
#endif

	h3 = _mm_loaddup_pd(&hh[(ldh*2)+nb-1]);
1561
#ifdef __ELPA_USE_FMA__
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
	z1 = _mm_macc_pd(q1, h3, z1);
	z2 = _mm_macc_pd(q2, h3, z2);
	z3 = _mm_macc_pd(q3, h3, z3);
#else
	z1 = _mm_add_pd(z1, _mm_mul_pd(q1,h3));
	z2 = _mm_add_pd(z2, _mm_mul_pd(q2,h3));
	z3 = _mm_add_pd(z3, _mm_mul_pd(q3,h3));
#endif

	h1 = _mm_loaddup_pd(&hh[nb-2]);

	q1 = _mm_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm_load_pd(&q[((nb+1)*ldq)+2]);
	q3 = _mm_load_pd(&q[((nb+1)*ldq)+4]);
1576
#ifdef __ELPA_USE_FMA__
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
	x1 = _mm_macc_pd(q1, h1, x1);
	x2 = _mm_macc_pd(q2, h1, x2);
	x3 = _mm_macc_pd(q3, h1, x3);
#else
	x1 = _mm_add_pd(x1, _mm_mul_pd(q1,h1));
	x2 = _mm_add_pd(x2, _mm_mul_pd(q2,h1));
	x3 = _mm_add_pd(x3, _mm_mul_pd(q3,h1));
#endif

	h2 = _mm_loaddup_pd(&hh[(ldh*1)+nb-1]);
1587
#ifdef __ELPA_USE_FMA__
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
	y1 = _mm_macc_pd(q1, h2, y1);
	y2 = _mm_macc_pd(q2, h2, y2);
	y3 = _mm_macc_pd(q3, h2, y3);
#else
	y1 = _mm_add_pd(y1, _mm_mul_pd(q1,h2));
	y2 = _mm_add_pd(y2, _mm_mul_pd(q2,h2));
	y3 = _mm_add_pd(y3, _mm_mul_pd(q3,h2));
#endif

	h1 = _mm_loaddup_pd(&hh[nb-1]);

	q1 = _mm_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm_load_pd(&q[((nb+2)*ldq)+2]);
	q3 = _mm_load_pd(&q[((nb+2)*ldq)+4]);
1602
#ifdef __ELPA_USE_FMA__
1603
1604
1605
1606