elpa2_kernels_real_avx-avx2_6hv.c 96.1 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
//Forward declaration
#ifdef __AVX__
static void hh_trafo_kernel_4_AVX_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods);
static void hh_trafo_kernel_8_AVX_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods);
#else
static void hh_trafo_kernel_2_SSE_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods);
static void hh_trafo_kernel_4_SSE_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods);
#endif

Andreas Marek's avatar
Andreas Marek committed
94
void hexa_hh_trafo_real_sse_avx_6hv_(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
95
96
97
98
#if 0
void hexa_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 hexa_hh_trafo_real_sse_avx_6hv_(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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
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
354
355
356
357
358
359
360
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;

	// calculating scalar products to compute
	// 6 householder vectors simultaneously
	double scalarprods[15];

//	scalarprods[0] = s_1_2;
//	scalarprods[1] = s_1_3;
//	scalarprods[2] = s_2_3;
//	scalarprods[3] = s_1_4;
//	scalarprods[4] = s_2_4;
//	scalarprods[5] = s_3_4;
//	scalarprods[6] = s_1_5;
//	scalarprods[7] = s_2_5;
//	scalarprods[8] = s_3_5;
//	scalarprods[9] = s_4_5;
//	scalarprods[10] = s_1_6;
//	scalarprods[11] = s_2_6;
//	scalarprods[12] = s_3_6;
//	scalarprods[13] = s_4_6;
//	scalarprods[14] = s_5_6;

	scalarprods[0] = hh[(ldh+1)];
	scalarprods[1] = hh[(ldh*2)+2];
	scalarprods[2] = hh[(ldh*2)+1];
	scalarprods[3] = hh[(ldh*3)+3];
	scalarprods[4] = hh[(ldh*3)+2];
	scalarprods[5] = hh[(ldh*3)+1];
	scalarprods[6] = hh[(ldh*4)+4];
	scalarprods[7] = hh[(ldh*4)+3];
	scalarprods[8] = hh[(ldh*4)+2];
	scalarprods[9] = hh[(ldh*4)+1];
	scalarprods[10] = hh[(ldh*5)+5];
	scalarprods[11] = hh[(ldh*5)+4];
	scalarprods[12] = hh[(ldh*5)+3];
	scalarprods[13] = hh[(ldh*5)+2];
	scalarprods[14] = hh[(ldh*5)+1];

	// calculate scalar product of first and fourth householder vector
	// loop counter = 2
	scalarprods[0] += hh[1] * hh[(2+ldh)];
	scalarprods[2] += hh[(ldh)+1] * hh[2+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+1] * hh[2+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+1] * hh[2+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+1] * hh[2+(ldh*5)];

	// loop counter = 3
	scalarprods[0] += hh[2] * hh[(3+ldh)];
	scalarprods[2] += hh[(ldh)+2] * hh[3+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+2] * hh[3+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+2] * hh[3+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+2] * hh[3+(ldh*5)];

	scalarprods[1] += hh[1] * hh[3+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+1] * hh[3+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+1] * hh[3+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+1] * hh[3+(ldh*5)];

	// loop counter = 4
	scalarprods[0] += hh[3] * hh[(4+ldh)];
	scalarprods[2] += hh[(ldh)+3] * hh[4+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+3] * hh[4+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+3] * hh[4+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+3] * hh[4+(ldh*5)];

	scalarprods[1] += hh[2] * hh[4+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+2] * hh[4+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+2] * hh[4+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+2] * hh[4+(ldh*5)];

	scalarprods[3] += hh[1] * hh[4+(ldh*3)];
	scalarprods[7] += hh[(ldh)+1] * hh[4+(ldh*4)];
	scalarprods[12] += hh[(ldh*2)+1] * hh[4+(ldh*5)];

	// loop counter = 5
	scalarprods[0] += hh[4] * hh[(5+ldh)];
	scalarprods[2] += hh[(ldh)+4] * hh[5+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+4] * hh[5+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+4] * hh[5+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+4] * hh[5+(ldh*5)];

	scalarprods[1] += hh[3] * hh[5+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+3] * hh[5+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+3] * hh[5+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+3] * hh[5+(ldh*5)];

	scalarprods[3] += hh[2] * hh[5+(ldh*3)];
	scalarprods[7] += hh[(ldh)+2] * hh[5+(ldh*4)];
	scalarprods[12] += hh[(ldh*2)+2] * hh[5+(ldh*5)];

	scalarprods[6] += hh[1] * hh[5+(ldh*4)];
	scalarprods[11] += hh[(ldh)+1] * hh[5+(ldh*5)];

	#pragma ivdep
	for (i = 6; i < nb; i++)
	{
		scalarprods[0] += hh[i-1] * hh[(i+ldh)];
		scalarprods[2] += hh[(ldh)+i-1] * hh[i+(ldh*2)];
		scalarprods[5] += hh[(ldh*2)+i-1] * hh[i+(ldh*3)];
		scalarprods[9] += hh[(ldh*3)+i-1] * hh[i+(ldh*4)];
		scalarprods[14] += hh[(ldh*4)+i-1] * hh[i+(ldh*5)];

		scalarprods[1] += hh[i-2] * hh[i+(ldh*2)];
		scalarprods[4] += hh[(ldh*1)+i-2] * hh[i+(ldh*3)];
		scalarprods[8] += hh[(ldh*2)+i-2] * hh[i+(ldh*4)];
		scalarprods[13] += hh[(ldh*3)+i-2] * hh[i+(ldh*5)];

		scalarprods[3] += hh[i-3] * hh[i+(ldh*3)];
		scalarprods[7] += hh[(ldh)+i-3] * hh[i+(ldh*4)];
		scalarprods[12] += hh[(ldh*2)+i-3] * hh[i+(ldh*5)];

		scalarprods[6] += hh[i-4] * hh[i+(ldh*4)];
		scalarprods[11] += hh[(ldh)+i-4] * hh[i+(ldh*5)];

		scalarprods[10] += hh[i-5] * hh[i+(ldh*5)];
	}

//	printf("s_1_2: %f\n", scalarprods[0]);
//	printf("s_1_3: %f\n", scalarprods[1]);
//	printf("s_2_3: %f\n", scalarprods[2]);
//	printf("s_1_4: %f\n", scalarprods[3]);
//	printf("s_2_4: %f\n", scalarprods[4]);
//	printf("s_3_4: %f\n", scalarprods[5]);
//	printf("s_1_5: %f\n", scalarprods[6]);
//	printf("s_2_5: %f\n", scalarprods[7]);
//	printf("s_3_5: %f\n", scalarprods[8]);
//	printf("s_4_5: %f\n", scalarprods[9]);
//	printf("s_1_6: %f\n", scalarprods[10]);
//	printf("s_2_6: %f\n", scalarprods[11]);
//	printf("s_3_6: %f\n", scalarprods[12]);
//	printf("s_4_6: %f\n", scalarprods[13]);
//	printf("s_5_6: %f\n", scalarprods[14]);

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq-4; i+=8)
	{
		hh_trafo_kernel_8_AVX_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
	if (nq == i)
	{
		return;
	}
	else
	{
		hh_trafo_kernel_4_AVX_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
#else
	for (i = 0; i < nq-2; i+=4)
	{
		hh_trafo_kernel_4_SSE_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
	if (nq == i)
	{
		return;
	}
	else
	{
		hh_trafo_kernel_2_SSE_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
#endif
}

#if 0
void hexa_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
	// 6 householder vectors simultaneously
	double scalarprods[15];

//	scalarprods[0] = s_1_2;
//	scalarprods[1] = s_1_3;
//	scalarprods[2] = s_2_3;
//	scalarprods[3] = s_1_4;
//	scalarprods[4] = s_2_4;
//	scalarprods[5] = s_3_4;
//	scalarprods[6] = s_1_5;
//	scalarprods[7] = s_2_5;
//	scalarprods[8] = s_3_5;
//	scalarprods[9] = s_4_5;
//	scalarprods[10] = s_1_6;
//	scalarprods[11] = s_2_6;
//	scalarprods[12] = s_3_6;
//	scalarprods[13] = s_4_6;
//	scalarprods[14] = s_5_6;

	scalarprods[0] = hh[(ldh+1)];
	scalarprods[1] = hh[(ldh*2)+2];
	scalarprods[2] = hh[(ldh*2)+1];
	scalarprods[3] = hh[(ldh*3)+3];
	scalarprods[4] = hh[(ldh*3)+2];
	scalarprods[5] = hh[(ldh*3)+1];
	scalarprods[6] = hh[(ldh*4)+4];
	scalarprods[7] = hh[(ldh*4)+3];
	scalarprods[8] = hh[(ldh*4)+2];
	scalarprods[9] = hh[(ldh*4)+1];
	scalarprods[10] = hh[(ldh*5)+5];
	scalarprods[11] = hh[(ldh*5)+4];
	scalarprods[12] = hh[(ldh*5)+3];
	scalarprods[13] = hh[(ldh*5)+2];
	scalarprods[14] = hh[(ldh*5)+1];

	// calculate scalar product of first and fourth householder vector
	// loop counter = 2
	scalarprods[0] += hh[1] * hh[(2+ldh)];
	scalarprods[2] += hh[(ldh)+1] * hh[2+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+1] * hh[2+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+1] * hh[2+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+1] * hh[2+(ldh*5)];

	// loop counter = 3
	scalarprods[0] += hh[2] * hh[(3+ldh)];
	scalarprods[2] += hh[(ldh)+2] * hh[3+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+2] * hh[3+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+2] * hh[3+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+2] * hh[3+(ldh*5)];

	scalarprods[1] += hh[1] * hh[3+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+1] * hh[3+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+1] * hh[3+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+1] * hh[3+(ldh*5)];

	// loop counter = 4
	scalarprods[0] += hh[3] * hh[(4+ldh)];
	scalarprods[2] += hh[(ldh)+3] * hh[4+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+3] * hh[4+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+3] * hh[4+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+3] * hh[4+(ldh*5)];

	scalarprods[1] += hh[2] * hh[4+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+2] * hh[4+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+2] * hh[4+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+2] * hh[4+(ldh*5)];

	scalarprods[3] += hh[1] * hh[4+(ldh*3)];
	scalarprods[7] += hh[(ldh)+1] * hh[4+(ldh*4)];
	scalarprods[12] += hh[(ldh*2)+1] * hh[4+(ldh*5)];

	// loop counter = 5
	scalarprods[0] += hh[4] * hh[(5+ldh)];
	scalarprods[2] += hh[(ldh)+4] * hh[5+(ldh*2)];
	scalarprods[5] += hh[(ldh*2)+4] * hh[5+(ldh*3)];
	scalarprods[9] += hh[(ldh*3)+4] * hh[5+(ldh*4)];
	scalarprods[14] += hh[(ldh*4)+4] * hh[5+(ldh*5)];

	scalarprods[1] += hh[3] * hh[5+(ldh*2)];
	scalarprods[4] += hh[(ldh*1)+3] * hh[5+(ldh*3)];
	scalarprods[8] += hh[(ldh*2)+3] * hh[5+(ldh*4)];
	scalarprods[13] += hh[(ldh*3)+3] * hh[5+(ldh*5)];

	scalarprods[3] += hh[2] * hh[5+(ldh*3)];
	scalarprods[7] += hh[(ldh)+2] * hh[5+(ldh*4)];
	scalarprods[12] += hh[(ldh*2)+2] * hh[5+(ldh*5)];

	scalarprods[6] += hh[1] * hh[5+(ldh*4)];
	scalarprods[11] += hh[(ldh)+1] * hh[5+(ldh*5)];

	#pragma ivdep
	for (i = 6; i < nb; i++)
	{
		scalarprods[0] += hh[i-1] * hh[(i+ldh)];
		scalarprods[2] += hh[(ldh)+i-1] * hh[i+(ldh*2)];
		scalarprods[5] += hh[(ldh*2)+i-1] * hh[i+(ldh*3)];
		scalarprods[9] += hh[(ldh*3)+i-1] * hh[i+(ldh*4)];
		scalarprods[14] += hh[(ldh*4)+i-1] * hh[i+(ldh*5)];

		scalarprods[1] += hh[i-2] * hh[i+(ldh*2)];
		scalarprods[4] += hh[(ldh*1)+i-2] * hh[i+(ldh*3)];
		scalarprods[8] += hh[(ldh*2)+i-2] * hh[i+(ldh*4)];
		scalarprods[13] += hh[(ldh*3)+i-2] * hh[i+(ldh*5)];

		scalarprods[3] += hh[i-3] * hh[i+(ldh*3)];
		scalarprods[7] += hh[(ldh)+i-3] * hh[i+(ldh*4)];
		scalarprods[12] += hh[(ldh*2)+i-3] * hh[i+(ldh*5)];

		scalarprods[6] += hh[i-4] * hh[i+(ldh*4)];
		scalarprods[11] += hh[(ldh)+i-4] * hh[i+(ldh*5)];

		scalarprods[10] += hh[i-5] * hh[i+(ldh*5)];
	}

//	printf("s_1_2: %f\n", scalarprods[0]);
//	printf("s_1_3: %f\n", scalarprods[1]);
//	printf("s_2_3: %f\n", scalarprods[2]);
//	printf("s_1_4: %f\n", scalarprods[3]);
//	printf("s_2_4: %f\n", scalarprods[4]);
//	printf("s_3_4: %f\n", scalarprods[5]);
//	printf("s_1_5: %f\n", scalarprods[6]);
//	printf("s_2_5: %f\n", scalarprods[7]);
//	printf("s_3_5: %f\n", scalarprods[8]);
//	printf("s_4_5: %f\n", scalarprods[9]);
//	printf("s_1_6: %f\n", scalarprods[10]);
//	printf("s_2_6: %f\n", scalarprods[11]);
//	printf("s_3_6: %f\n", scalarprods[12]);
//	printf("s_4_6: %f\n", scalarprods[13]);
//	printf("s_5_6: %f\n", scalarprods[14]);

	// Production level kernel calls with padding
#ifdef __AVX__
	for (i = 0; i < nq; i+=8)
	{
		hh_trafo_kernel_8_AVX_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
#else
	for (i = 0; i < nq; i+=4)
	{
		hh_trafo_kernel_4_SSE_6hv(&q[i], hh, nb, ldq, ldh, scalarprods);
	}
#endif
}
#endif

#ifdef __AVX__
/**
 * 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_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [8 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

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

	__m256d h_6_5 = _mm256_broadcast_sd(&hh[(ldh*5)+1]);
	__m256d h_6_4 = _mm256_broadcast_sd(&hh[(ldh*5)+2]);
	__m256d h_6_3 = _mm256_broadcast_sd(&hh[(ldh*5)+3]);
	__m256d h_6_2 = _mm256_broadcast_sd(&hh[(ldh*5)+4]);
	__m256d h_6_1 = _mm256_broadcast_sd(&hh[(ldh*5)+5]);
450
451
452
453
454
455
#ifdef __ELPA_USE_FMA__
	register __m256d t1 = _mm256_FMA_pd(a5_1, h_6_5, a6_1);
	t1 = _mm256_FMA_pd(a4_1, h_6_4, t1);
	t1 = _mm256_FMA_pd(a3_1, h_6_3, t1);
	t1 = _mm256_FMA_pd(a2_1, h_6_2, t1);
	t1 = _mm256_FMA_pd(a1_1, h_6_1, t1);
456
457
458
459
460
461
462
463
464
465
466
#else
	register __m256d t1 = _mm256_add_pd(a6_1, _mm256_mul_pd(a5_1, h_6_5));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a4_1, h_6_4));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a3_1, h_6_3));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a2_1, h_6_2));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a1_1, h_6_1));
#endif
	__m256d h_5_4 = _mm256_broadcast_sd(&hh[(ldh*4)+1]);
	__m256d h_5_3 = _mm256_broadcast_sd(&hh[(ldh*4)+2]);
	__m256d h_5_2 = _mm256_broadcast_sd(&hh[(ldh*4)+3]);
	__m256d h_5_1 = _mm256_broadcast_sd(&hh[(ldh*4)+4]);
467
468
469
470
471
#ifdef __ELPA_USE_FMA__
	register __m256d v1 = _mm256_FMA_pd(a4_1, h_5_4, a5_1);
	v1 = _mm256_FMA_pd(a3_1, h_5_3, v1);
	v1 = _mm256_FMA_pd(a2_1, h_5_2, v1);
	v1 = _mm256_FMA_pd(a1_1, h_5_1, v1);
472
473
474
475
476
477
478
479
480
#else
	register __m256d v1 = _mm256_add_pd(a5_1, _mm256_mul_pd(a4_1, h_5_4));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a3_1, h_5_3));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a2_1, h_5_2));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a1_1, h_5_1));
#endif
	__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]);
481
482
483
484
#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);
485
486
487
488
489
490
491
492
#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));
#endif
	__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]);
493
494
495
496
#ifdef __ELPA_USE_FMA__
	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);
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#else
	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));
#endif
	register __m256d x1 = a1_1;


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

512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#ifdef __ELPA_USE_FMA__
	register __m256d t2 = _mm256_FMA_pd(a5_2, h_6_5, a6_2);
	t2 = _mm256_FMA_pd(a4_2, h_6_4, t2);
	t2 = _mm256_FMA_pd(a3_2, h_6_3, t2);
	t2 = _mm256_FMA_pd(a2_2, h_6_2, t2);
	t2 = _mm256_FMA_pd(a1_2, h_6_1, t2);
	register __m256d v2 = _mm256_FMA_pd(a4_2, h_5_4, a5_2);
	v2 = _mm256_FMA_pd(a3_2, h_5_3, v2);
	v2 = _mm256_FMA_pd(a2_2, h_5_2, v2);
	v2 = _mm256_FMA_pd(a1_2, h_5_1, v2);
	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);
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#else
	register __m256d t2 = _mm256_add_pd(a6_2, _mm256_mul_pd(a5_2, h_6_5));
	t2 = _mm256_add_pd(t2, _mm256_mul_pd(a4_2, h_6_4));
	t2 = _mm256_add_pd(t2, _mm256_mul_pd(a3_2, h_6_3));
	t2 = _mm256_add_pd(t2, _mm256_mul_pd(a2_2, h_6_2));
	t2 = _mm256_add_pd(t2, _mm256_mul_pd(a1_2, h_6_1));
	register __m256d v2 = _mm256_add_pd(a5_2, _mm256_mul_pd(a4_2, h_5_4));
	v2 = _mm256_add_pd(v2, _mm256_mul_pd(a3_2, h_5_3));
	v2 = _mm256_add_pd(v2, _mm256_mul_pd(a2_2, h_5_2));
	v2 = _mm256_add_pd(v2, _mm256_mul_pd(a1_2, h_5_1));
	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));
#endif
	register __m256d x2 = a1_2;

	__m256d q1;
	__m256d q2;

	__m256d h1;
	__m256d h2;
	__m256d h3;
	__m256d h4;
	__m256d h5;
	__m256d h6;

	for(i = 6; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-5]);
		q1 = _mm256_load_pd(&q[i*ldq]);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
562
563
564
#ifdef __ELPA_USE_FMA__
		x1 = _mm256_FMA_pd(q1, h1, x1);
		x2 = _mm256_FMA_pd(q2, h1, x2);
565
566
567
568
569
#else
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
		x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif
		h2 = _mm256_broadcast_sd(&hh[ldh+i-4]);
570
571
572
#ifdef __ELPA_USE_FMA__
		y1 = _mm256_FMA_pd(q1, h2, y1);
		y2 = _mm256_FMA_pd(q2, h2, y2);
573
574
575
576
577
#else
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
		y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
#endif
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-3]);
578
579
580
#ifdef __ELPA_USE_FMA__
		z1 = _mm256_FMA_pd(q1, h3, z1);
		z2 = _mm256_FMA_pd(q2, h3, z2);
581
582
583
584
585
#else
		z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
		z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
#endif
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i-2]);
586
587
588
#ifdef __ELPA_USE_FMA__
		w1 = _mm256_FMA_pd(q1, h4, w1);
		w2 = _mm256_FMA_pd(q2, h4, w2);
589
590
591
592
593
#else
		w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
		w2 = _mm256_add_pd(w2, _mm256_mul_pd(q2,h4));
#endif
		h5 = _mm256_broadcast_sd(&hh[(ldh*4)+i-1]);
594
595
596
#ifdef __ELPA_USE_FMA__
		v1 = _mm256_FMA_pd(q1, h5, v1);
		v2 = _mm256_FMA_pd(q2, h5, v2);
597
598
599
600
601
#else
		v1 = _mm256_add_pd(v1, _mm256_mul_pd(q1,h5));
		v2 = _mm256_add_pd(v2, _mm256_mul_pd(q2,h5));
#endif
		h6 = _mm256_broadcast_sd(&hh[(ldh*5)+i]);
602
603
604
#ifdef __ELPA_USE_FMA__
		t1 = _mm256_FMA_pd(q1, h6, t1);
		t2 = _mm256_FMA_pd(q2, h6, t2);
605
606
607
608
609
610
611
612
613
#else
		t1 = _mm256_add_pd(t1, _mm256_mul_pd(q1,h6));
		t2 = _mm256_add_pd(t2, _mm256_mul_pd(q2,h6));
#endif
	}

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

	h1 = _mm256_broadcast_sd(&hh[nb-4]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
657
658
659
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
660
661
662
663
664
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-3]);
665
666
667
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
668
669
670
671
672
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-2]);
673
674
675
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
	z2 = _mm256_FMA_pd(q2, h3, z2);
676
677
678
679
680
#else
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
	z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+nb-1]);
681
682
683
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMA_pd(q1, h4, w1);
	w2 = _mm256_FMA_pd(q2, h4, w2);
684
685
686
687
688
689
690
691
#else
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
	w2 = _mm256_add_pd(w2, _mm256_mul_pd(q2,h4));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
692
693
694
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
695
696
697
698
699
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
700
701
702
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
703
704
705
706
707
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
708
709
710
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
	z2 = _mm256_FMA_pd(q2, h3, z2);
711
712
713
714
715
716
717
718
#else
	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]);
	q1 = _mm256_load_pd(&q[(nb+3)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+3)*ldq)+4]);
719
720
721
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
722
723
724
725
726
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
727
728
729
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
	y2 = _mm256_FMA_pd(q2, h2, y2);
730
731
732
733
734
735
736
737
#else
	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+4)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+4)*ldq)+4]);
738
739
740
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
	x2 = _mm256_FMA_pd(q2, h1, x2);
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
#endif

	/////////////////////////////////////////////////////
	// Apply tau, correct wrong calculation using pre-calculated scalar products
	/////////////////////////////////////////////////////

	__m256d tau1 = _mm256_broadcast_sd(&hh[0]);
	x1 = _mm256_mul_pd(x1, tau1);
	x2 = _mm256_mul_pd(x2, tau1);

	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs_1_2 = _mm256_broadcast_sd(&scalarprods[0]);
	h2 = _mm256_mul_pd(tau2, vs_1_2);
757
758
759
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMSUB_pd(y1, tau2, _mm256_mul_pd(x1,h2));
	y2 = _mm256_FMSUB_pd(y2, tau2, _mm256_mul_pd(x2,h2));
760
761
762
763
764
765
766
767
768
769
#else
	y1 = _mm256_sub_pd(_mm256_mul_pd(y1,tau2), _mm256_mul_pd(x1,h2));
	y2 = _mm256_sub_pd(_mm256_mul_pd(y2,tau2), _mm256_mul_pd(x2,h2));
#endif

	__m256d tau3 = _mm256_broadcast_sd(&hh[ldh*2]);
	__m256d vs_1_3 = _mm256_broadcast_sd(&scalarprods[1]);
	__m256d vs_2_3 = _mm256_broadcast_sd(&scalarprods[2]);
	h2 = _mm256_mul_pd(tau3, vs_1_3);
	h3 = _mm256_mul_pd(tau3, vs_2_3);
770
771
772
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_pd(z1, tau3, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)));
	z2 = _mm256_FMSUB_pd(z2, tau3, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2)));
773
774
775
776
777
778
779
780
781
782
783
784
#else
	z1 = _mm256_sub_pd(_mm256_mul_pd(z1,tau3), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)));
	z2 = _mm256_sub_pd(_mm256_mul_pd(z2,tau3), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2)));
#endif

	__m256d tau4 = _mm256_broadcast_sd(&hh[ldh*3]);
	__m256d vs_1_4 = _mm256_broadcast_sd(&scalarprods[3]);
	__m256d vs_2_4 = _mm256_broadcast_sd(&scalarprods[4]);
	h2 = _mm256_mul_pd(tau4, vs_1_4);
	h3 = _mm256_mul_pd(tau4, vs_2_4);
	__m256d vs_3_4 = _mm256_broadcast_sd(&scalarprods[5]);
	h4 = _mm256_mul_pd(tau4, vs_3_4);
785
786
787
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_pd(w1, tau4, _mm256_FMA_pd(z1, h4, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
	w2 = _mm256_FMSUB_pd(w2, tau4, _mm256_FMA_pd(z2, h4, _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2))));
788
789
790
791
792
793
794
795
796
797
798
799
800
801
#else
	w1 = _mm256_sub_pd(_mm256_mul_pd(w1,tau4), _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,tau4), _mm256_add_pd(_mm256_mul_pd(z2,h4), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2))));
#endif

	__m256d tau5 = _mm256_broadcast_sd(&hh[ldh*4]);
	__m256d vs_1_5 = _mm256_broadcast_sd(&scalarprods[6]);
	__m256d vs_2_5 = _mm256_broadcast_sd(&scalarprods[7]);
	h2 = _mm256_mul_pd(tau5, vs_1_5);
	h3 = _mm256_mul_pd(tau5, vs_2_5);
	__m256d vs_3_5 = _mm256_broadcast_sd(&scalarprods[8]);
	__m256d vs_4_5 = _mm256_broadcast_sd(&scalarprods[9]);
	h4 = _mm256_mul_pd(tau5, vs_3_5);
	h5 = _mm256_mul_pd(tau5, vs_4_5);
802
803
804
#ifdef __ELPA_USE_FMA__
	v1 = _mm256_FMSUB_pd(v1, tau5, _mm256_add_pd(_mm256_FMA_pd(w1, h5, _mm256_mul_pd(z1,h4)), _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
	v2 = _mm256_FMSUB_pd(v2, tau5, _mm256_add_pd(_mm256_FMA_pd(w2, h5, _mm256_mul_pd(z2,h4)), _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2))));
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#else
	v1 = _mm256_sub_pd(_mm256_mul_pd(v1,tau5), _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w1,h5), _mm256_mul_pd(z1,h4)), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
	v2 = _mm256_sub_pd(_mm256_mul_pd(v2,tau5), _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w2,h5), _mm256_mul_pd(z2,h4)), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2))));
#endif

	__m256d tau6 = _mm256_broadcast_sd(&hh[ldh*5]);
	__m256d vs_1_6 = _mm256_broadcast_sd(&scalarprods[10]);
	__m256d vs_2_6 = _mm256_broadcast_sd(&scalarprods[11]);
	h2 = _mm256_mul_pd(tau6, vs_1_6);
	h3 = _mm256_mul_pd(tau6, vs_2_6);
	__m256d vs_3_6 = _mm256_broadcast_sd(&scalarprods[12]);
	__m256d vs_4_6 = _mm256_broadcast_sd(&scalarprods[13]);
	__m256d vs_5_6 = _mm256_broadcast_sd(&scalarprods[14]);
	h4 = _mm256_mul_pd(tau6, vs_3_6);
	h5 = _mm256_mul_pd(tau6, vs_4_6);
	h6 = _mm256_mul_pd(tau6, vs_5_6);
821
822
823
#ifdef __ELPA_USE_FMA__
	t1 = _mm256_FMSUB_pd(t1, tau6, _mm256_FMA_pd(v1, h6, _mm256_add_pd(_mm256_FMA_pd(w1, h5, _mm256_mul_pd(z1,h4)), _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)))));
	t2 = _mm256_FMSUB_pd(t2, tau6, _mm256_FMA_pd(v2, h6, _mm256_add_pd(_mm256_FMA_pd(w2, h5, _mm256_mul_pd(z2,h4)), _mm256_FMA_pd(y2, h3, _mm256_mul_pd(x2,h2)))));
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
#else
	t1 = _mm256_sub_pd(_mm256_mul_pd(t1,tau6), _mm256_add_pd( _mm256_mul_pd(v1,h6), _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w1,h5), _mm256_mul_pd(z1,h4)), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)))));
	t2 = _mm256_sub_pd(_mm256_mul_pd(t2,tau6), _mm256_add_pd( _mm256_mul_pd(v2,h6), _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w2,h5), _mm256_mul_pd(z2,h4)), _mm256_add_pd(_mm256_mul_pd(y2,h3), _mm256_mul_pd(x2,h2)))));
#endif

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

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

	h6 = _mm256_broadcast_sd(&hh[(ldh*5)+1]);
	q1 = _mm256_load_pd(&q[ldq]);
	q2 = _mm256_load_pd(&q[(ldq+4)]);
	q1 = _mm256_sub_pd(q1, v1);
	q2 = _mm256_sub_pd(q2, v2);
845
846
847
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(t1, h6, q1);
	q2 = _mm256_NFMA_pd(t2, h6, q2);
848
849
850
851
852
853
854
855
856
857
858
859
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
	_mm256_store_pd(&q[ldq],q1);
	_mm256_store_pd(&q[(ldq+4)],q2);

	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+1]);
	q1 = _mm256_load_pd(&q[ldq*2]);
	q2 = _mm256_load_pd(&q[(ldq*2)+4]);
	q1 = _mm256_sub_pd(q1, w1);
	q2 = _mm256_sub_pd(q2, w2);
860
861
862
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(v1, h5, q1);
	q2 = _mm256_NFMA_pd(v2, h5, q2);
863
864
865
866
867
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
	h6 = _mm256_broadcast_sd(&hh[(ldh*5)+2]);
868
869
870
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(t1, h6, q1);
	q2 = _mm256_NFMA_pd(t2, h6, q2);
871
872
873
874
875
876
877
878
879
880
881
882
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
	_mm256_store_pd(&q[ldq*2],q1);
	_mm256_store_pd(&q[(ldq*2)+4],q2);

	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+1]);
	q1 = _mm256_load_pd(&q[ldq*3]);
	q2 = _mm256_load_pd(&q[(ldq*3)+4]);
	q1 = _mm256_sub_pd(q1, z1);
	q2 = _mm256_sub_pd(q2, z2);
883
884
885
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
886
887
888
889
890
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+2]);
891
892
893
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(v1, h5, q1);
	q2 = _mm256_NFMA_pd(v2, h5, q2);
894
895
896
897
898
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
	h6 = _mm256_broadcast_sd(&hh[(ldh*5)+3]);
899
900
901
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(t1, h6, q1);
	q2 = _mm256_NFMA_pd(t2, h6, q2);
902
903
904
905
906
907
908
909
910
911
912
913
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
	_mm256_store_pd(&q[ldq*3],q1);
	_mm256_store_pd(&q[(ldq*3)+4],q2);

	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+1]);
	q1 = _mm256_load_pd(&q[ldq*4]);
	q2 = _mm256_load_pd(&q[(ldq*4)+4]);
	q1 = _mm256_sub_pd(q1, y1);
	q2 = _mm256_sub_pd(q2, y2);
914
915
916
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
917
918
919
920
921
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+2]);
922
923
924
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
925
926
927
928
929
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+3]);
930
931
932
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(v1, h5, q1);
	q2 = _mm256_NFMA_pd(v2, h5, q2);
933
934
935
936
937
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
	h6 = _mm256_broadcast_sd(&hh[(ldh*5)+4]);
938
939
940
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(t1, h6, q1);
	q2 = _mm256_NFMA_pd(t2, h6, q2);
941
942
943
944
945
946
947
948
949
950
951
952
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
	_mm256_store_pd(&q[ldq*4],q1);
	_mm256_store_pd(&q[(ldq*4)+4],q2);

	h2 = _mm256_broadcast_sd(&hh[(ldh)+1]);
	q1 = _mm256_load_pd(&q[ldq*5]);
	q2 = _mm256_load_pd(&q[(ldq*5)+4]);
	q1 = _mm256_sub_pd(q1, x1);
	q2 = _mm256_sub_pd(q2, x2);
953
954
955
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
956
957
958
959
960
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+2]);
961
962
963
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
964
965
966
967
968
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+3]);
969
970
971
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
972
973
974
975
976
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+4]);
977
978
979
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(v1, h5, q1);
	q2 = _mm256_NFMA_pd(v2, h5, q2);
980
981
982
983
984
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
	h6 = _mm256_broadcast_sd(&hh[(ldh*5)+5]);
985
986
987
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(t1, h6, q1);
	q2 = _mm256_NFMA_pd(t2, h6, q2);
988
989
990
991
992
993
994
995
996
997
998
999
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
	_mm256_store_pd(&q[ldq*5],q1);
	_mm256_store_pd(&q[(ldq*5)+4],q2);

	for (i = 6; i < nb; i++)
	{
		q1 = _mm256_load_pd(&q[i*ldq]);
		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
		h1 = _mm256_broadcast_sd(&hh[i-5]);
1000
1001
1002
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(x1, h1, q1);
		q2 = _mm256_NFMA_pd(x2, h1, q2);
1003
1004
1005
1006
1007
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
		h2 = _mm256_broadcast_sd(&hh[ldh+i-4]);
1008
1009
1010
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(y1, h2, q1);
		q2 = _mm256_NFMA_pd(y2, h2, q2);
1011
1012
1013
1014
1015
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-3]);
1016
1017
1018
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(z1, h3, q1);
		q2 = _mm256_NFMA_pd(z2, h3, q2);
1019
1020
1021
1022
1023
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i-2]);
1024
1025
1026
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(w1, h4, q1);
		q2 = _mm256_NFMA_pd(w2, h4, q2);
1027
1028
1029
1030
1031
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
		h5 = _mm256_broadcast_sd(&hh[(ldh*4)+i-1]);
1032
1033
1034
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(v1, h5, q1);
		q2 = _mm256_NFMA_pd(v2, h5, q2);
1035
1036
1037
1038
1039
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
		h6 = _mm256_broadcast_sd(&hh[(ldh*5)+i]);
1040
1041
1042
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_pd(t1, h6, q1);
		q2 = _mm256_NFMA_pd(t2, h6, q2);
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
#else
		q1 = _mm256_sub_pd(q1, _mm256_mul_pd(t1, h6));
		q2 = _mm256_sub_pd(q2, _mm256_mul_pd(t2, h6));
#endif
		_mm256_store_pd(&q[i*ldq],q1);
		_mm256_store_pd(&q[(i*ldq)+4],q2);
	}

	h1 = _mm256_broadcast_sd(&hh[nb-5]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
	q2 = _mm256_load_pd(&q[(nb*ldq)+4]);
1054
1055
1056
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
1057
1058
1059
1060
1061
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-4]);
1062
1063
1064
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
1065
1066
1067
1068
1069
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-3]);
1070
1071
1072
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
1073
1074
1075
1076
1077
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+nb-2]);
1078
1079
1080
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
1081
1082
1083
1084
1085
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+nb-1]);
1086
1087
1088
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(v1, h5, q1);
	q2 = _mm256_NFMA_pd(v2, h5, q2);
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(v1, h5));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(v2, h5));
#endif
	_mm256_store_pd(&q[nb*ldq],q1);
	_mm256_store_pd(&q[(nb*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-4]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
1099
1100
1101
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
1102
1103
1104
1105
1106
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-3]);
1107
1108
1109
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
1110
1111
1112
1113
1114
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-2]);
1115
1116
1117
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
1118
1119
1120
1121
1122
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+nb-1]);
1123
1124
1125
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(w1, h4, q1);
	q2 = _mm256_NFMA_pd(w2, h4, q2);
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(w1, h4));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(w2, h4));
#endif
	_mm256_store_pd(&q[(nb+1)*ldq],q1);
	_mm256_store_pd(&q[((nb+1)*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
1136
1137
1138
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
1139
1140
1141
1142
1143
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
1144
1145
1146
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
1147
1148
1149
1150
1151
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
1152
1153
1154
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(z1, h3, q1);
	q2 = _mm256_NFMA_pd(z2, h3, q2);
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(z1, h3));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(z2, h3));
#endif
	_mm256_store_pd(&q[(nb+2)*ldq],q1);
	_mm256_store_pd(&q[((nb+2)*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	q1 = _mm256_load_pd(&q[(nb+3)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+3)*ldq)+4]);
1165
1166
1167
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
1168
1169
1170
1171
1172
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(x1, h1));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(x2, h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
1173
1174
1175
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(y1, h2, q1);
	q2 = _mm256_NFMA_pd(y2, h2, q2);
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
#else
	q1 = _mm256_sub_pd(q1, _mm256_mul_pd(y1, h2));
	q2 = _mm256_sub_pd(q2, _mm256_mul_pd(y2, h2));
#endif
	_mm256_store_pd(&q[(nb+3)*ldq],q1);
	_mm256_store_pd(&q[((nb+3)*ldq)+4],q2);

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
	q1 = _mm256_load_pd(&q[(nb+4)*ldq]);
	q2 = _mm256_load_pd(&q[((nb+4)*ldq)+4]);
1186
1187
1188
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_pd(x1, h1, q1);
	q2 = _mm256_NFMA_pd(x2, h1, q2);
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
#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+4)*ldq],q1);
	_mm256_store_pd(&q[((nb+4)*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_6hv(double* q, double* hh, int nb, int ldq, int ldh, double* scalarprods)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [8 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

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

	__m256d h_6_5 = _mm256_broadcast_sd(&hh[(ldh*5)+1]);
	__m256d h_6_4 = _mm256_broadcast_sd(&hh[(ldh*5)+2]);
	__m256d h_6_3 = _mm256_broadcast_sd(&hh[(ldh*5)+3]);
	__m256d h_6_2 = _mm256_broadcast_sd(&hh[(ldh*5)+4]);
	__m256d h_6_1 = _mm256_broadcast_sd(&hh[(ldh*5)+5]);
1223
1224
1225
1226
1227
1228
#ifdef __ELPA_USE_FMA__
	register __m256d t1 = _mm256_FMA_pd(a5_1, h_6_5, a6_1);
	t1 = _mm256_FMA_pd(a4_1, h_6_4, t1);
	t1 = _mm256_FMA_pd(a3_1, h_6_3, t1);
	t1 = _mm256_FMA_pd(a2_1, h_6_2, t1);
	t1 = _mm256_FMA_pd(a1_1, h_6_1, t1);
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
#else
	register __m256d t1 = _mm256_add_pd(a6_1, _mm256_mul_pd(a5_1, h_6_5));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a4_1, h_6_4));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a3_1, h_6_3));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a2_1, h_6_2));
	t1 = _mm256_add_pd(t1, _mm256_mul_pd(a1_1, h_6_1));
#endif
	__m256d h_5_4 = _mm256_broadcast_sd(&hh[(ldh*4)+1]);
	__m256d h_5_3 = _mm256_broadcast_sd(&hh[(ldh*4)+2]);
	__m256d h_5_2 = _mm256_broadcast_sd(&hh[(ldh*4)+3]);
	__m256d h_5_1 = _mm256_broadcast_sd(&hh[(ldh*4)+4]);
1240
1241
1242
1243
1244
#ifdef __ELPA_USE_FMA__
	register __m256d v1 = _mm256_FMA_pd(a4_1, h_5_4, a5_1);
	v1 = _mm256_FMA_pd(a3_1, h_5_3, v1);
	v1 = _mm256_FMA_pd(a2_1, h_5_2, v1);
	v1 = _mm256_FMA_pd(a1_1, h_5_1, v1);
1245
1246
1247
1248
1249
1250
1251
1252
1253
#else
	register __m256d v1 = _mm256_add_pd(a5_1, _mm256_mul_pd(a4_1, h_5_4));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a3_1, h_5_3));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a2_1, h_5_2));
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(a1_1, h_5_1));
#endif
	__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]);
1254
1255
1256
1257
#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);
1258
1259
1260
1261
1262
1263
1264
1265
#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));
#endif
	__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]);
1266
1267
1268
1269
#ifdef __ELPA_USE_FMA__
	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);
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
#else
	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));
#endif
	register __m256d x1 = a1_1;

	__m256d q1;

	__m256d h1;
	__m256d h2;
	__m256d h3;
	__m256d h4;
	__m256d h5;
	__m256d h6;

	for(i = 6; i < nb; i++)
	{
		h1 = _mm256_broadcast_sd(&hh[i-5]);
		q1 = _mm256_load_pd(&q[i*ldq]);
1290
1291
#ifdef __ELPA_USE_FMA__
		x1 = _mm256_FMA_pd(q1, h1, x1);
1292
1293
1294
1295
#else
		x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif
		h2 = _mm256_broadcast_sd(&hh[ldh+i-4]);
1296
1297
#ifdef __ELPA_USE_FMA__
		y1 = _mm256_FMA_pd(q1, h2, y1);
1298
1299
1300
1301
#else
		y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif
		h3 = _mm256_broadcast_sd(&hh[(ldh*2)+i-3]);
1302
1303
#ifdef __ELPA_USE_FMA__
		z1 = _mm256_FMA_pd(q1, h3, z1);
1304
1305
1306
1307
#else
		z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
#endif
		h4 = _mm256_broadcast_sd(&hh[(ldh*3)+i-2]);
1308
1309
#ifdef __ELPA_USE_FMA__
		w1 = _mm256_FMA_pd(q1, h4, w1);
1310
1311
1312
1313
#else
		w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
#endif
		h5 = _mm256_broadcast_sd(&hh[(ldh*4)+i-1]);
1314
1315
#ifdef __ELPA_USE_FMA__
		v1 = _mm256_FMA_pd(q1, h5, v1);
1316
1317
1318
1319
#else
		v1 = _mm256_add_pd(v1, _mm256_mul_pd(q1,h5));
#endif
		h6 = _mm256_broadcast_sd(&hh[(ldh*5)+i]);
1320
1321
#ifdef __ELPA_USE_FMA__
		t1 = _mm256_FMA_pd(q1, h6, t1);
1322
1323
1324
1325
1326
1327
1328
#else
		t1 = _mm256_add_pd(t1, _mm256_mul_pd(q1,h6));
#endif
	}

	h1 = _mm256_broadcast_sd(&hh[nb-5]);
	q1 = _mm256_load_pd(&q[nb*ldq]);
1329
1330
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1331
1332
1333
1334
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-4]);
1335
1336
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
1337
1338
1339
1340
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-3]);
1341
1342
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
1343
1344
1345
1346
#else
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+nb-2]);
1347
1348
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMA_pd(q1, h4, w1);
1349
1350
1351
1352
#else
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
#endif
	h5 = _mm256_broadcast_sd(&hh[(ldh*4)+nb-1]);
1353
1354
#ifdef __ELPA_USE_FMA__
	v1 = _mm256_FMA_pd(q1, h5, v1);
1355
1356
1357
1358
1359
1360
#else
	v1 = _mm256_add_pd(v1, _mm256_mul_pd(q1,h5));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-4]);
	q1 = _mm256_load_pd(&q[(nb+1)*ldq]);
1361
1362
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1363
1364
1365
1366
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-3]);
1367
1368
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
1369
1370
1371
1372
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-2]);
1373
1374
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
1375
1376
1377
1378
#else
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
#endif
	h4 = _mm256_broadcast_sd(&hh[(ldh*3)+nb-1]);
1379
1380
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMA_pd(q1, h4, w1);
1381
1382
1383
1384
1385
1386
#else
	w1 = _mm256_add_pd(w1, _mm256_mul_pd(q1,h4));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-3]);
	q1 = _mm256_load_pd(&q[(nb+2)*ldq]);
1387
1388
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1389
1390
1391
1392
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-2]);
1393
1394
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
1395
1396
1397
1398
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif
	h3 = _mm256_broadcast_sd(&hh[(ldh*2)+nb-1]);
1399
1400
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMA_pd(q1, h3, z1);
1401
1402
1403
1404
1405
1406
#else
	z1 = _mm256_add_pd(z1, _mm256_mul_pd(q1,h3));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-2]);
	q1 = _mm256_load_pd(&q[(nb+3)*ldq]);
1407
1408
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1409
1410
1411
1412
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif
	h2 = _mm256_broadcast_sd(&hh[ldh+nb-1]);
1413
1414
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMA_pd(q1, h2, y1);
1415
1416
1417
1418
1419
1420
#else
	y1 = _mm256_add_pd(y1, _mm256_mul_pd(q1,h2));
#endif

	h1 = _mm256_broadcast_sd(&hh[nb-1]);
	q1 = _mm256_load_pd(&q[(nb+4)*ldq]);
1421
1422
#ifdef __ELPA_USE_FMA__
	x1 = _mm256_FMA_pd(q1, h1, x1);
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
#else
	x1 = _mm256_add_pd(x1, _mm256_mul_pd(q1,h1));
#endif

	/////////////////////////////////////////////////////
	// Apply tau, correct wrong calculation using pre-calculated scalar products
	/////////////////////////////////////////////////////

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

	__m256d tau2 = _mm256_broadcast_sd(&hh[ldh]);
	__m256d vs_1_2 = _mm256_broadcast_sd(&scalarprods[0]);
	h2 = _mm256_mul_pd(tau2, vs_1_2);
1437
1438
#ifdef __ELPA_USE_FMA__
	y1 = _mm256_FMSUB_pd(y1, tau2, _mm256_mul_pd(x1,h2));
1439
1440
1441
1442
1443
1444
1445
1446
1447
#else
	y1 = _mm256_sub_pd(_mm256_mul_pd(y1,tau2), _mm256_mul_pd(x1,h2));
#endif

	__m256d tau3 = _mm256_broadcast_sd(&hh[ldh*2]);
	__m256d vs_1_3 = _mm256_broadcast_sd(&scalarprods[1]);
	__m256d vs_2_3 = _mm256_broadcast_sd(&scalarprods[2]);
	h2 = _mm256_mul_pd(tau3, vs_1_3);
	h3 = _mm256_mul_pd(tau3, vs_2_3);
1448
1449
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_pd(z1, tau3, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)));
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
#else
	z1 = _mm256_sub_pd(_mm256_mul_pd(z1,tau3), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2)));
#endif

	__m256d tau4 = _mm256_broadcast_sd(&hh[ldh*3]);
	__m256d vs_1_4 = _mm256_broadcast_sd(&scalarprods[3]);
	__m256d vs_2_4 = _mm256_broadcast_sd(&scalarprods[4]);
	h2 = _mm256_mul_pd(tau4, vs_1_4);
	h3 = _mm256_mul_pd(tau4, vs_2_4);
	__m256d vs_3_4 = _mm256_broadcast_sd(&scalarprods[5]);
	h4 = _mm256_mul_pd(tau4, vs_3_4);
1461
1462
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_pd(w1, tau4, _mm256_FMA_pd(z1, h4, _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
#else
	w1 = _mm256_sub_pd(_mm256_mul_pd(w1,tau4), _mm256_add_pd(_mm256_mul_pd(z1,h4), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
#endif

	__m256d tau5 = _mm256_broadcast_sd(&hh[ldh*4]);
	__m256d vs_1_5 = _mm256_broadcast_sd(&scalarprods[6]);
	__m256d vs_2_5 = _mm256_broadcast_sd(&scalarprods[7]);
	h2 = _mm256_mul_pd(tau5, vs_1_5);
	h3 = _mm256_mul_pd(tau5, vs_2_5);
	__m256d vs_3_5 = _mm256_broadcast_sd(&scalarprods[8]);
	__m256d vs_4_5 = _mm256_broadcast_sd(&scalarprods[9]);
	h4 = _mm256_mul_pd(tau5, vs_3_5);
	h5 = _mm256_mul_pd(tau5, vs_4_5);
1476
1477
#ifdef __ELPA_USE_FMA__
	v1 = _mm256_FMSUB_pd(v1, tau5, _mm256_add_pd(_mm256_FMA_pd(w1, h5, _mm256_mul_pd(z1,h4)), _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2))));
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
#else
	v1 = _mm256_sub_pd(_mm256_mul_pd(v1,tau5), _mm256_add_pd(_mm256_add_pd(_mm256_mul_pd(w1,h5), _mm256_mul_pd(z1,h4)), _mm256_add_pd(_mm256_mul_pd(y1,h3), _mm256_mul_pd(x1,h2))));
#endif

	__m256d tau6 = _mm256_broadcast_sd(&hh[ldh*5]);
	__m256d vs_1_6 = _mm256_broadcast_sd(&scalarprods[10]);
	__m256d vs_2_6 = _mm256_broadcast_sd(&scalarprods[11]);
	h2 = _mm256_mul_pd(tau6, vs_1_6);
	h3 = _mm256_mul_pd(tau6, vs_2_6);
	__m256d vs_3_6 = _mm256_broadcast_sd(&scalarprods[12]);
	__m256d vs_4_6 = _mm256_broadcast_sd(&scalarprods[13]);
	__m256d vs_5_6 = _mm256_broadcast_sd(&scalarprods[14]);
	h4 = _mm256_mul_pd(tau6, vs_3_6);
	h5 = _mm256_mul_pd(tau6, vs_4_6);
	h6 = _mm256_mul_pd(tau6, vs_5_6);
1493
1494
#ifdef __ELPA_USE_FMA__
	t1 = _mm256_FMSUB_pd(t1, tau6, _mm256_FMA_pd(v1, h6, _mm256_add_pd(_mm256_FMA_pd(w1, h5, _mm256_mul_pd(z1,h4)), _mm256_FMA_pd(y1, h3, _mm256_mul_pd(x1,h2)))));
1495
1496
1497
1498
1499
1500
1501
1502
1503