elpa2_kernels_real_avx-avx2_4hv_single_precision.c 59 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
//      Schwerpunkt Wissenschaftliches Rechnen ,
//    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
13
//    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
Andreas Marek's avatar
Andreas Marek committed
14
15
//      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
//    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.
//
45
// Author: Andreas Marek, MPCDF, based on the double precision case of A. Heinecke
46
//
47
#include "config-f90.h"
48
49
50
51
52

#include <x86intrin.h>

#define __forceinline __attribute__((always_inline)) static

53
54
#ifdef HAVE_AVX2

55
56
#ifdef __FMA4__
#define __ELPA_USE_FMA__
57
58
59
60
#define _mm256_FMA_ps(a,b,c) _mm256_macc_ps(a,b,c)
#define _mm256_NFMA_ps(a,b,c) _mm256_nmacc_ps(a,b,c)
#error "This should prop. be _mm256_msub_ps instead of _mm256_msub"
#define _mm256_FMSUB_ps(a,b,c) _mm256_msub_ps(a,b,c)
61
62
63
64
#endif

#ifdef __AVX2__
#define __ELPA_USE_FMA__
65
66
67
#define _mm256_FMA_ps(a,b,c) _mm256_fmadd_ps(a,b,c)
#define _mm256_NFMA_ps(a,b,c) _mm256_fnmadd_ps(a,b,c)
#define _mm256_FMSUB_ps(a,b,c) _mm256_fmsub_ps(a,b,c)
68
69
#endif

70
71
#endif

72
//Forward declaration
73
74
75
76
__forceinline void hh_trafo_kernel_4_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_8_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_16_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_24_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
77

78
void quad_hh_trafo_real_avx_avx2_4hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh);
79

80
/*
81
!f>#if defined(HAVE_AVX) || defined(HAVE_AVX2)
82
83
84
85
86
87
88
89
90
91
92
93
94
!f> interface
!f>   subroutine quad_hh_trafo_real_avx_avx2_4hv_single(q, hh, pnb, pnq, pldq, pldh) &
!f>                             bind(C, name="quad_hh_trafo_real_avx_avx2_4hv_single")
!f>     use, intrinsic :: iso_c_binding
!f>     integer(kind=c_int)     :: pnb, pnq, pldq, pldh
!f>     type(c_ptr), value      :: q
!f>     real(kind=c_float)      :: hh(pnb,6)
!f>   end subroutine
!f> end interface
!f>#endif
*/

void quad_hh_trafo_real_avx_avx2_4hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh)
95
96
97
98
99
100
101
102
103
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;

	// calculating scalar products to compute
	// 4 householder vectors simultaneously
104
105
106
107
108
109
	float s_1_2 = hh[(ldh)+1];
	float s_1_3 = hh[(ldh*2)+2];
	float s_2_3 = hh[(ldh*2)+1];
	float s_1_4 = hh[(ldh*3)+3];
	float s_2_4 = hh[(ldh*3)+2];
	float s_3_4 = hh[(ldh*3)+1];
110

111
	// calculate scalar product of first and fourth householder Vector
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
	// 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)];
	}

138
	for (i = 0; i < nq-16; i+=24)
139
	{
140
		hh_trafo_kernel_24_AVX_4hv_single(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
141
142
143
144
145
	}
	if (nq == i)
	{
		return;
	}
146
	if (nq-i == 16)
147
	{
148
		hh_trafo_kernel_16_AVX_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
149
	}
150
        else
151
	{
152
		hh_trafo_kernel_8_AVX_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
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
//	// Production level kernel calls with padding
//	for (i = 0; i < nq-20; i+=24)
//	{
//		hh_trafo_kernel_24_AVX_4hv_single(&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;
//	}
//	if (nq-i == 20)
//	{
//		hh_trafo_kernel_16_AVX_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
//		hh_trafo_kernel_4_AVX_4hv_single(&q[i+16], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
//	}
//	else if (nq-i == 16)
//	{
//		hh_trafo_kernel_16_AVX_4hv_single(&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 if (nq-i == 12)
//	{
//		hh_trafo_kernel_8_AVX_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
//		hh_trafo_kernel_4_AVX_4hv_single(&q[i+8], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
//	}
//	else if (nq-i == 8)
//	{
//		hh_trafo_kernel_8_AVX_4hv_single(&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_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
//	}

187
}
188

189
190
191

/**
 * Unrolled kernel that computes
192
 * 24 rows of Q simultaneously, a
193
 * matrix Vector product with two householder
194
195
 * vectors + a rank 1 update is performed
 */
196
__forceinline void hh_trafo_kernel_24_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
197
198
199
200
201
202
203
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

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
	__m256 a1_1 = _mm256_load_ps(&q[ldq*3]); // q(1,4) |                                                  .. | q(8,4)
	__m256 a2_1 = _mm256_load_ps(&q[ldq*2]); // q(1,3) | q(2,3) | q(3,3) | q(4,3) | q(5,3) | q(6,3) | q(7,3) | q(8,3)
	__m256 a3_1 = _mm256_load_ps(&q[ldq]);   // q(1,2) | q(2,2) | q(3,2) | q(4,2) | q(5,2) | q(6,2) | q(7,2) | q(8,2)
	__m256 a4_1 = _mm256_load_ps(&q[0]);     // q(1,1) | q(2,1) | q(3,1) | q(4,1) | q(5,1) | q(6,1) | q(7,1) | q(8,1)

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

#ifdef __ELPA_USE_FMA__
	register __m256 w1 = _mm256_FMA_ps(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_ps(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_ps(a1_1, h_4_1, w1);
	register __m256 z1 = _mm256_FMA_ps(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_ps(a1_1, h_3_1, z1);
	register __m256 y1 = _mm256_FMA_ps(a1_1, h_2_1, a2_1);
	register __m256 x1 = a1_1;
#else
	register __m256 w1 = _mm256_add_ps(a4_1, _mm256_mul_ps(a3_1, h_4_3));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a2_1, h_4_2));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a1_1, h_4_1));
	register __m256 z1 = _mm256_add_ps(a3_1, _mm256_mul_ps(a2_1, h_3_2));
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(a1_1, h_3_1));
	register __m256 y1 = _mm256_add_ps(a2_1, _mm256_mul_ps(a1_1, h_2_1));
	register __m256 x1 = a1_1;
#endif

	__m256 a1_2 = _mm256_load_ps(&q[(ldq*3)+8]); // q(9,4) | ...          | q(16,4)
	__m256 a2_2 = _mm256_load_ps(&q[(ldq*2)+8]);
	__m256 a3_2 = _mm256_load_ps(&q[ldq+8]);     // q(9,2) | ...          | q(16,2)
	__m256 a4_2 = _mm256_load_ps(&q[0+8]);       // q(9,1) | q(10,1) .... | q(16,1)

#ifdef __ELPA_USE_FMA__
	register __m256 w2 = _mm256_FMA_ps(a3_2, h_4_3, a4_2);
	w2 = _mm256_FMA_ps(a2_2, h_4_2, w2);
	w2 = _mm256_FMA_ps(a1_2, h_4_1, w2);
	register __m256 z2 = _mm256_FMA_ps(a2_2, h_3_2, a3_2);
	z2 = _mm256_FMA_ps(a1_2, h_3_1, z2);
	register __m256 y2 = _mm256_FMA_ps(a1_2, h_2_1, a2_2);
	register __m256 x2 = a1_2;
#else
	register __m256 w2 = _mm256_add_ps(a4_2, _mm256_mul_ps(a3_2, h_4_3));
	w2 = _mm256_add_ps(w2, _mm256_mul_ps(a2_2, h_4_2));
	w2 = _mm256_add_ps(w2, _mm256_mul_ps(a1_2, h_4_1));
	register __m256 z2 = _mm256_add_ps(a3_2, _mm256_mul_ps(a2_2, h_3_2));
	z2 = _mm256_add_ps(z2, _mm256_mul_ps(a1_2, h_3_1));
	register __m256 y2 = _mm256_add_ps(a2_2, _mm256_mul_ps(a1_2, h_2_1));
	register __m256 x2 = a1_2;
#endif

	__m256 a1_3 = _mm256_load_ps(&q[(ldq*3)+16]);
	__m256 a2_3 = _mm256_load_ps(&q[(ldq*2)+16]);
	__m256 a3_3 = _mm256_load_ps(&q[ldq+16]);
	__m256 a4_3 = _mm256_load_ps(&q[0+16]);

#ifdef __ELPA_USE_FMA__
	register __m256 w3 = _mm256_FMA_ps(a3_3, h_4_3, a4_3);
	w3 = _mm256_FMA_ps(a2_3, h_4_2, w3);
	w3 = _mm256_FMA_ps(a1_3, h_4_1, w3);
	register __m256 z3 = _mm256_FMA_ps(a2_3, h_3_2, a3_3);
	z3 = _mm256_FMA_ps(a1_3, h_3_1, z3);
	register __m256 y3 = _mm256_FMA_ps(a1_3, h_2_1, a2_3);
	register __m256 x3 = a1_3;
#else
	register __m256 w3 = _mm256_add_ps(a4_3, _mm256_mul_ps(a3_3, h_4_3));
	w3 = _mm256_add_ps(w3, _mm256_mul_ps(a2_3, h_4_2));
	w3 = _mm256_add_ps(w3, _mm256_mul_ps(a1_3, h_4_1));
	register __m256 z3 = _mm256_add_ps(a3_3, _mm256_mul_ps(a2_3, h_3_2));
	z3 = _mm256_add_ps(z3, _mm256_mul_ps(a1_3, h_3_1));
	register __m256 y3 = _mm256_add_ps(a2_3, _mm256_mul_ps(a1_3, h_2_1));
	register __m256 x3 = a1_3;
#endif

	__m256 q1;
	__m256 q2;
	__m256 q3;

	__m256 h1;
	__m256 h2;
	__m256 h3;
	__m256 h4;
288
289
290

	for(i = 4; i < nb; i++)
	{
291
292
293
294
		h1 = _mm256_broadcast_ss(&hh[i-3]);
		q1 = _mm256_load_ps(&q[i*ldq]);       // | q(i,2) | q(i+1,2) | q(i+2,2) | q(i+3,2) | q(i+4,2) | q(i+5,2) | q(i+5,2) | q(i+7,2)
		q2 = _mm256_load_ps(&q[(i*ldq)+8]);
		q3 = _mm256_load_ps(&q[(i*ldq)+16]);
295
#ifdef __ELPA_USE_FMA__
296
297
298
		x1 = _mm256_FMA_ps(q1, h1, x1);
		x2 = _mm256_FMA_ps(q2, h1, x2);
		x3 = _mm256_FMA_ps(q3, h1, x3);
299
#else
300
301
302
		x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
		x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
		x3 = _mm256_add_ps(x3, _mm256_mul_ps(q3,h1));
303
304
#endif

305
		h2 = _mm256_broadcast_ss(&hh[ldh+i-2]);
306
#ifdef __ELPA_USE_FMA__
307
308
309
		y1 = _mm256_FMA_ps(q1, h2, y1);
		y2 = _mm256_FMA_ps(q2, h2, y2);
		y3 = _mm256_FMA_ps(q3, h2, y3);
310
#else
311
312
313
		y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
		y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
		y3 = _mm256_add_ps(y3, _mm256_mul_ps(q3,h2));
314
315
#endif

316
		h3 = _mm256_broadcast_ss(&hh[(ldh*2)+i-1]);
317
#ifdef __ELPA_USE_FMA__
318
319
320
		z1 = _mm256_FMA_ps(q1, h3, z1);
		z2 = _mm256_FMA_ps(q2, h3, z2);
		z3 = _mm256_FMA_ps(q3, h3, z3);
321
#else
322
323
324
		z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
		z2 = _mm256_add_ps(z2, _mm256_mul_ps(q2,h3));
		z3 = _mm256_add_ps(z3, _mm256_mul_ps(q3,h3));
325
326
#endif

327
		h4 = _mm256_broadcast_ss(&hh[(ldh*3)+i]);
328
#ifdef __ELPA_USE_FMA__
329
330
331
		w1 = _mm256_FMA_ps(q1, h4, w1);
		w2 = _mm256_FMA_ps(q2, h4, w2);
		w3 = _mm256_FMA_ps(q3, h4, w3);
332
#else
333
334
335
		w1 = _mm256_add_ps(w1, _mm256_mul_ps(q1,h4));
		w2 = _mm256_add_ps(w2, _mm256_mul_ps(q2,h4));
		w3 = _mm256_add_ps(w3, _mm256_mul_ps(q3,h4));
336
337
338
#endif
	}

339
	h1 = _mm256_broadcast_ss(&hh[nb-3]);
340

341
342
343
344
345
	q1 = _mm256_load_ps(&q[nb*ldq]);
//	// carefull we just need another 4 floats, the rest is zero'd
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[(nb*ldq)+8]));
	q2 = _mm256_load_ps(&q[(nb*ldq)+8]);
	q3 = _mm256_load_ps(&q[(nb*ldq)+16]);
346

347
#ifdef __ELPA_USE_FMA__
348
349
350
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
351
#else
352
353
354
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
	x3 = _mm256_add_ps(x3, _mm256_mul_ps(q3,h1));
355
356
#endif

357
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
358
#ifdef __FMA4_
359
360
361
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
	y3 = _mm256_FMA_ps(q3, h2, y3);
362
#else
363
364
365
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
	y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
	y3 = _mm256_add_ps(y3, _mm256_mul_ps(q3,h2));
366
367
#endif

368
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
369
#ifdef __ELPA_USE_FMA__
370
371
372
	z1 = _mm256_FMA_ps(q1, h3, z1);
	z2 = _mm256_FMA_ps(q2, h3, z2);
	z3 = _mm256_FMA_ps(q3, h3, z3);
373
#else
374
375
376
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
	z2 = _mm256_add_ps(z2, _mm256_mul_ps(q2,h3));
	z3 = _mm256_add_ps(z3, _mm256_mul_ps(q3,h3));
377
378
#endif

379
	h1 = _mm256_broadcast_ss(&hh[nb-2]);
380

381
382
383
	q1 = _mm256_load_ps(&q[(nb+1)*ldq]);
	q2 = _mm256_load_ps(&q[((nb+1)*ldq)+8]);
	q3 = _mm256_load_ps(&q[((nb+1)*ldq)+16]);
384

385
#ifdef __ELPA_USE_FMA__
386
387
388
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
389
#else
390
391
392
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
	x3 = _mm256_add_ps(x3, _mm256_mul_ps(q3,h1));
393
394
#endif

395
	h2 = _mm256_broadcast_ss(&hh[(ldh*1)+nb-1]);
396

397
#ifdef __ELPA_USE_FMA__
398
399
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
400
	y3 = _mm256_FMA_ps(q3, h2, y3);
401
#else
402
403
404
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
	y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
	y3 = _mm256_add_ps(y3, _mm256_mul_ps(q3,h2));
405
406
#endif

407
	h1 = _mm256_broadcast_ss(&hh[nb-1]);
408

409
410
411
412
	q1 = _mm256_load_ps(&q[(nb+2)*ldq]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[((nb+2)*ldq)+8]));
	q2 = _mm256_load_ps(&q[((nb+2)*ldq)+8]);
	q3 = _mm256_load_ps(&q[((nb+2)*ldq)+16]);
413

414
#ifdef __ELPA_USE_FMA__
415
416
417
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
418
#else
419
420
421
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
	x3 = _mm256_add_ps(x3, _mm256_mul_ps(q3,h1));
422
423
424
425
426
427
#endif

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

428
	__m256 tau1 = _mm256_broadcast_ss(&hh[0]);
429
430

	h1 = tau1;
431
432
433
	x1 = _mm256_mul_ps(x1, h1);
	x2 = _mm256_mul_ps(x2, h1);
	x3 = _mm256_mul_ps(x3, h1);
434

435
436
	__m256 tau2 = _mm256_broadcast_ss(&hh[ldh]);
	__m256 vs_1_2 = _mm256_broadcast_ss(&s_1_2);
437
438

	h1 = tau2;
439
	h2 = _mm256_mul_ps(h1, vs_1_2);
440
#ifdef __ELPA_USE_FMA__
441
442
443
	y1 = _mm256_FMSUB_ps(y1, h1, _mm256_mul_ps(x1,h2));
	y2 = _mm256_FMSUB_ps(y2, h1, _mm256_mul_ps(x2,h2));
	y3 = _mm256_FMSUB_ps(y3, h1, _mm256_mul_ps(x3,h2));
444
#else
445
446
447
	y1 = _mm256_sub_ps(_mm256_mul_ps(y1,h1), _mm256_mul_ps(x1,h2));
	y2 = _mm256_sub_ps(_mm256_mul_ps(y2,h1), _mm256_mul_ps(x2,h2));
	y3 = _mm256_sub_ps(_mm256_mul_ps(y3,h1), _mm256_mul_ps(x3,h2));
448
449
#endif

450
451
452
	__m256 tau3 = _mm256_broadcast_ss(&hh[ldh*2]);
	__m256 vs_1_3 = _mm256_broadcast_ss(&s_1_3);
	__m256 vs_2_3 = _mm256_broadcast_ss(&s_2_3);
453
454

	h1 = tau3;
455
456
	h2 = _mm256_mul_ps(h1, vs_1_3);
	h3 = _mm256_mul_ps(h1, vs_2_3);
457
#ifdef __ELPA_USE_FMA__
458
459
460
	z1 = _mm256_FMSUB_ps(z1, h1, _mm256_FMA_ps(y1, h3, _mm256_mul_ps(x1,h2)));
	z2 = _mm256_FMSUB_ps(z2, h1, _mm256_FMA_ps(y2, h3, _mm256_mul_ps(x2,h2)));
	z3 = _mm256_FMSUB_ps(z3, h1, _mm256_FMA_ps(y3, h3, _mm256_mul_ps(x3,h2)));
461
#else
462
463
464
	z1 = _mm256_sub_ps(_mm256_mul_ps(z1,h1), _mm256_add_ps(_mm256_mul_ps(y1,h3), _mm256_mul_ps(x1,h2)));
	z2 = _mm256_sub_ps(_mm256_mul_ps(z2,h1), _mm256_add_ps(_mm256_mul_ps(y2,h3), _mm256_mul_ps(x2,h2)));
	z3 = _mm256_sub_ps(_mm256_mul_ps(z3,h1), _mm256_add_ps(_mm256_mul_ps(y3,h3), _mm256_mul_ps(x3,h2)));
465
466
#endif

467
468
469
470
	__m256 tau4 = _mm256_broadcast_ss(&hh[ldh*3]);
	__m256 vs_1_4 = _mm256_broadcast_ss(&s_1_4);
	__m256 vs_2_4 = _mm256_broadcast_ss(&s_2_4);
	__m256 vs_3_4 = _mm256_broadcast_ss(&s_3_4);
471
472

	h1 = tau4;
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
	h2 = _mm256_mul_ps(h1, vs_1_4);
	h3 = _mm256_mul_ps(h1, vs_2_4);
	h4 = _mm256_mul_ps(h1, vs_3_4);
#ifdef __ELPA_USE_FMA__
	w1 = _mm256_FMSUB_ps(w1, h1, _mm256_FMA_ps(z1, h4, _mm256_FMA_ps(y1, h3, _mm256_mul_ps(x1,h2))));
	w2 = _mm256_FMSUB_ps(w2, h1, _mm256_FMA_ps(z2, h4, _mm256_FMA_ps(y2, h3, _mm256_mul_ps(x2,h2))));
	w3 = _mm256_FMSUB_ps(w3, h1, _mm256_FMA_ps(z3, h4, _mm256_FMA_ps(y3, h3, _mm256_mul_ps(x3,h2))));
#else
	w1 = _mm256_sub_ps(_mm256_mul_ps(w1,h1), _mm256_add_ps(_mm256_mul_ps(z1,h4), _mm256_add_ps(_mm256_mul_ps(y1,h3), _mm256_mul_ps(x1,h2))));
	w2 = _mm256_sub_ps(_mm256_mul_ps(w2,h1), _mm256_add_ps(_mm256_mul_ps(z2,h4), _mm256_add_ps(_mm256_mul_ps(y2,h3), _mm256_mul_ps(x2,h2))));
	w3 = _mm256_sub_ps(_mm256_mul_ps(w3,h1), _mm256_add_ps(_mm256_mul_ps(z3,h4), _mm256_add_ps(_mm256_mul_ps(y3,h3), _mm256_mul_ps(x3,h2))));
#endif

	q1 = _mm256_load_ps(&q[0]);
//	q2 =  _mm256_castps128_ps256(_mm_load_ps(&q[8]));
	q2 = _mm256_load_ps(&q[8]);
	q3 = _mm256_load_ps(&q[16]);
	q1 = _mm256_sub_ps(q1, w1);
	q2 = _mm256_sub_ps(q2, w2);
	q3 = _mm256_sub_ps(q3, w3);
	_mm256_store_ps(&q[0],q1);
//	_mm_store_ps(&q[8], _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[8],q2);
	_mm256_store_ps(&q[16],q3);

	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+1]);
	q1 = _mm256_load_ps(&q[ldq]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[ldq+8]));
	q2 = _mm256_load_ps(&q[ldq+8]);
	q3 = _mm256_load_ps(&q[ldq+16]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_sub_ps(q1, _mm256_FMA_ps(w1, h4, z1));
	q2 = _mm256_sub_ps(q2, _mm256_FMA_ps(w2, h4, z2));
	q3 = _mm256_sub_ps(q3, _mm256_FMA_ps(w3, h4, z3));
#else
	q1 = _mm256_sub_ps(q1, _mm256_add_ps(z1, _mm256_mul_ps(w1, h4)));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps(z2, _mm256_mul_ps(w2, h4)));
	q3 = _mm256_sub_ps(q3, _mm256_add_ps(z3, _mm256_mul_ps(w3, h4)));
#endif
	_mm256_store_ps(&q[ldq],q1);
//        _mm_store_ps(&q[ldq+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[ldq+8],q2);
	_mm256_store_ps(&q[ldq+16],q3);

	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+2]);
	q1 = _mm256_load_ps(&q[ldq*2]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[(ldq*2)+8]));
	q2 = _mm256_load_ps(&q[(ldq*2)+8]);
	q3 = _mm256_load_ps(&q[(ldq*2)+16]);
	q1 = _mm256_sub_ps(q1, y1);
	q2 = _mm256_sub_ps(q2, y2);
	q3 = _mm256_sub_ps(q3, y3);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(w1, h4, q1);
	q2 = _mm256_NFMA_ps(w2, h4, q2);
	q3 = _mm256_NFMA_ps(w3, h4, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(w1, h4));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(w2, h4));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(w3, h4));
#endif
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+1]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(z1, h3, q1);
	q2 = _mm256_NFMA_ps(z2, h3, q2);
	q3 = _mm256_NFMA_ps(z3, h3, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(z1, h3));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(z2, h3));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(z3, h3));
#endif
	_mm256_store_ps(&q[ldq*2],q1);
//	_mm_store_ps(&q[(ldq*2)+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[(ldq*2)+8],q2);
	_mm256_store_ps(&q[(ldq*2)+16],q3);

	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+3]);
	q1 = _mm256_load_ps(&q[ldq*3]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[(ldq*3)+8]));
	q2 = _mm256_load_ps(&q[(ldq*3)+8]);
	q3 = _mm256_load_ps(&q[(ldq*3)+16]);

	q1 = _mm256_sub_ps(q1, x1);
	q2 = _mm256_sub_ps(q2, x2);
	q3 = _mm256_sub_ps(q3, x3);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(w1, h4, q1);
	q2 = _mm256_NFMA_ps(w2, h4, q2);
	q3 = _mm256_NFMA_ps(w3, h4, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(w1, h4));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(w2, h4));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(w3, h4));
#endif
	h2 = _mm256_broadcast_ss(&hh[ldh+1]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(y1, h2, q1);
	q2 = _mm256_NFMA_ps(y2, h2, q2);
	q3 = _mm256_NFMA_ps(y3, h2, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(y1, h2));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(y2, h2));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(y3, h2));
#endif
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+2]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(z1, h3, q1);
	q2 = _mm256_NFMA_ps(z2, h3, q2);
	q3 = _mm256_NFMA_ps(z3, h3, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(z1, h3));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(z2, h3));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(z3, h3));
#endif
	_mm256_store_ps(&q[ldq*3], q1);
//	_mm_store_ps(&q[(ldq*3)+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[(ldq*3)+8], q2);
	_mm256_store_ps(&q[(ldq*3)+16], q3);
591
592
593

	for (i = 4; i < nb; i++)
	{
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
		h1 = _mm256_broadcast_ss(&hh[i-3]);

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

#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_ps(x1, h1, q1);
		q2 = _mm256_NFMA_ps(x2, h1, q2);
		q3 = _mm256_NFMA_ps(x3, h1, q3);
#else
		q1 = _mm256_sub_ps(q1, _mm256_mul_ps(x1,h1));
		q2 = _mm256_sub_ps(q2, _mm256_mul_ps(x2,h1));
		q3 = _mm256_sub_ps(q3, _mm256_mul_ps(x3,h1));
#endif
609

610
611
612
613
614
615
616
617
618
619
		h2 = _mm256_broadcast_ss(&hh[ldh+i-2]);
#ifdef __ELPA_USE_FMA__
		q1 = _mm256_NFMA_ps(y1, h2, q1);
		q2 = _mm256_NFMA_ps(y2, h2, q2);
		q3 = _mm256_NFMA_ps(y3, h2, q3);
#else
		q1 = _mm256_sub_ps(q1, _mm256_mul_ps(y1,h2));
		q2 = _mm256_sub_ps(q2, _mm256_mul_ps(y2,h2));
		q3 = _mm256_sub_ps(q3, _mm256_mul_ps(y3,h2));
#endif
620

621
		h3 = _mm256_broadcast_ss(&hh[(ldh*2)+i-1]);
622
#ifdef __ELPA_USE_FMA__
623
624
625
		q1 = _mm256_NFMA_ps(z1, h3, q1);
		q2 = _mm256_NFMA_ps(z2, h3, q2);
		q3 = _mm256_NFMA_ps(z3, h3, q3);
626
#else
627
628
629
		q1 = _mm256_sub_ps(q1, _mm256_mul_ps(z1,h3));
		q2 = _mm256_sub_ps(q2, _mm256_mul_ps(z2,h3));
		q3 = _mm256_sub_ps(q3, _mm256_mul_ps(z3,h3));
630
631
#endif

632
		h4 = _mm256_broadcast_ss(&hh[(ldh*3)+i]);
633
#ifdef __ELPA_USE_FMA__
634
635
636
		q1 = _mm256_NFMA_ps(w1, h4, q1);
		q2 = _mm256_NFMA_ps(w2, h4, q2);
		q3 = _mm256_NFMA_ps(w3, h4, q3);
637
#else
638
639
640
		q1 = _mm256_sub_ps(q1, _mm256_mul_ps(w1,h4));
		q2 = _mm256_sub_ps(q2, _mm256_mul_ps(w2,h4));
		q3 = _mm256_sub_ps(q3, _mm256_mul_ps(w3,h4));
641
642
#endif

643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
		_mm256_store_ps(&q[i*ldq],q1);
//           	_mm_store_ps(&q[(i*ldq)+8],  _mm256_castps256_ps128(q2));
		_mm256_store_ps(&q[(i*ldq)+8],q2);
		_mm256_store_ps(&q[(i*ldq)+16],q3);
	}

	h1 = _mm256_broadcast_ss(&hh[nb-3]);
	q1 = _mm256_load_ps(&q[nb*ldq]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[(nb*ldq)+8]));
	q2 = _mm256_load_ps(&q[(nb*ldq)+8]);
	q3 = _mm256_load_ps(&q[(nb*ldq)+16]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(x1, h1, q1);
	q2 = _mm256_NFMA_ps(x2, h1, q2);
	q3 = _mm256_NFMA_ps(x3, h1, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(x1,h1));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(x2,h1));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(x3,h1));
#endif
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(y1, h2, q1);
	q2 = _mm256_NFMA_ps(y2, h2, q2);
	q3 = _mm256_NFMA_ps(y3, h2, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(y1,h2));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(y2,h2));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(y3,h2));
#endif
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
674
#ifdef __ELPA_USE_FMA__
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
	q1 = _mm256_NFMA_ps(z1, h3, q1);
	q2 = _mm256_NFMA_ps(z2, h3, q2);
	q3 = _mm256_NFMA_ps(z3, h3, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(z1,h3));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(z2,h3));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(z3,h3));
#endif
	_mm256_store_ps(&q[nb*ldq],q1);
//        _mm_store_ps(&q[(nb*ldq)+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[(nb*ldq)+8],q2);
	_mm256_store_ps(&q[(nb*ldq)+16],q3);

	h1 = _mm256_broadcast_ss(&hh[nb-2]);
	q1 = _mm256_load_ps(&q[(nb+1)*ldq]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[((nb+1)*ldq)+8]));
	q2 = _mm256_load_ps(&q[((nb+1)*ldq)+8]);
	q3 = _mm256_load_ps(&q[((nb+1)*ldq)+16]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(x1, h1, q1);
	q2 = _mm256_NFMA_ps(x2, h1, q2);
	q3 = _mm256_NFMA_ps(x3, h1, q3);
697
#else
698
699
700
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(x1,h1));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(x2,h1));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(x3,h1));
701
#endif
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-1]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(y1, h2, q1);
	q2 = _mm256_NFMA_ps(y2, h2, q2);
	q3 = _mm256_NFMA_ps(y3, h2, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(y1,h2));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(y2,h2));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(y3,h2));
#endif
	_mm256_store_ps(&q[(nb+1)*ldq],q1);
//        _mm_store_ps(&q[((nb+1)*ldq)+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[((nb+1)*ldq)+8],q2);
	_mm256_store_ps(&q[((nb+1)*ldq)+16],q3);

	h1 = _mm256_broadcast_ss(&hh[nb-1]);
	q1 = _mm256_load_ps(&q[(nb+2)*ldq]);
//	q2 = _mm256_castps128_ps256(_mm_load_ps(&q[((nb+2)*ldq)+8]));
	q2 = _mm256_load_ps(&q[((nb+2)*ldq)+8]);
	q3 = _mm256_load_ps(&q[((nb+2)*ldq)+16]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(x1, h1, q1);
	q2 = _mm256_NFMA_ps(x2, h1, q2);
	q3 = _mm256_NFMA_ps(x3, h1, q3);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(x1,h1));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(x2,h1));
	q3 = _mm256_sub_ps(q3, _mm256_mul_ps(x3,h1));
#endif
	_mm256_store_ps(&q[(nb+2)*ldq],q1);
//        _mm_store_ps(&q[((nb+2)*ldq)+8],  _mm256_castps256_ps128(q2));
	_mm256_store_ps(&q[((nb+2)*ldq)+8],q2);
	_mm256_store_ps(&q[((nb+2)*ldq)+16],q3);
}

/**
 * Unrolled kernel that computes
 * 16 rows of Q simultaneously, a
740
 * matrix Vector product with two householder
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
811
812
813
814
815
816
817
 * vectors + a rank 1 update is performed
 */
__forceinline void hh_trafo_kernel_16_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

	__m256 a1_1 = _mm256_load_ps(&q[ldq*3]);  // q(1,4) | ...                                                 | q(8,4)
	__m256 a2_1 = _mm256_load_ps(&q[ldq*2]);  // q(1,3) | ...                                                 | q(8,3)
	__m256 a3_1 = _mm256_load_ps(&q[ldq]);    // q(1,2) | ...                                                 | q(8,2)
	__m256 a4_1 = _mm256_load_ps(&q[0]);      // q(1,1) | q(2,1) | q(3,1) | q(4,1) | q(5,1) | q(6,1) | q(7,1) | q(8,1)

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

#ifdef __ELPA_USE_FMA__
	__m256 w1 = _mm256_FMA_ps(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_ps(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_ps(a1_1, h_4_1, w1);
	__m256 z1 = _mm256_FMA_ps(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_ps(a1_1, h_3_1, z1);
	__m256 y1 = _mm256_FMA_ps(a1_1, h_2_1, a2_1);
	__m256 x1 = a1_1;
#else
	__m256 w1 = _mm256_add_ps(a4_1, _mm256_mul_ps(a3_1, h_4_3));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a2_1, h_4_2));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a1_1, h_4_1));
	__m256 z1 = _mm256_add_ps(a3_1, _mm256_mul_ps(a2_1, h_3_2));
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(a1_1, h_3_1));
	__m256 y1 = _mm256_add_ps(a2_1, _mm256_mul_ps(a1_1, h_2_1));
	__m256 x1 = a1_1;
#endif

	__m256 a1_2 = _mm256_load_ps(&q[(ldq*3)+8]);
	__m256 a2_2 = _mm256_load_ps(&q[(ldq*2)+8]);
	__m256 a3_2 = _mm256_load_ps(&q[ldq+8]);
	__m256 a4_2 = _mm256_load_ps(&q[0+8]);       // q(9,1) | q(10,1) | q(11,1) | q(12,1) | q(13,1) | q(14,1) | q(15,1) | q(16,1)

#ifdef __ELPA_USE_FMA__
	__m256 w2 = _mm256_FMA_ps(a3_2, h_4_3, a4_2);
	w2 = _mm256_FMA_ps(a2_2, h_4_2, w2);
	w2 = _mm256_FMA_ps(a1_2, h_4_1, w2);
	__m256 z2 = _mm256_FMA_ps(a2_2, h_3_2, a3_2);
	z2 = _mm256_FMA_ps(a1_2, h_3_1, z2);
	__m256 y2 = _mm256_FMA_ps(a1_2, h_2_1, a2_2);
	__m256 x2 = a1_2;
#else
	__m256 w2 = _mm256_add_ps(a4_2, _mm256_mul_ps(a3_2, h_4_3));
	w2 = _mm256_add_ps(w2, _mm256_mul_ps(a2_2, h_4_2));
	w2 = _mm256_add_ps(w2, _mm256_mul_ps(a1_2, h_4_1));
	__m256 z2 = _mm256_add_ps(a3_2, _mm256_mul_ps(a2_2, h_3_2));
	z2 = _mm256_add_ps(z2, _mm256_mul_ps(a1_2, h_3_1));
	__m256 y2 = _mm256_add_ps(a2_2, _mm256_mul_ps(a1_2, h_2_1));
	__m256 x2 = a1_2;
#endif

	__m256 q1;
	__m256 q2;

	__m256 h1;
	__m256 h2;
	__m256 h3;
	__m256 h4;

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

819
		q1 = _mm256_load_ps(&q[i*ldq]);
820
#ifdef __ELPA_USE_FMA__
821
822
823
824
		x1 = _mm256_FMA_ps(q1, h1, x1);
		y1 = _mm256_FMA_ps(q1, h2, y1);
		z1 = _mm256_FMA_ps(q1, h3, z1);
		w1 = _mm256_FMA_ps(q1, h4, w1);
825
#else
826
827
828
829
		x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
		y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
		z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
		w1 = _mm256_add_ps(w1, _mm256_mul_ps(q1,h4));
830
831
#endif

832
833
834
835
836
837
838
839
840
841
842
843
		q2 = _mm256_load_ps(&q[(i*ldq)+8]);
#ifdef __ELPA_USE_FMA__
		x2 = _mm256_FMA_ps(q2, h1, x2);
		y2 = _mm256_FMA_ps(q2, h2, y2);
		z2 = _mm256_FMA_ps(q2, h3, z2);
		w2 = _mm256_FMA_ps(q2, h4, w2);
#else
		x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
		y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
		z2 = _mm256_add_ps(z2, _mm256_mul_ps(q2,h3));
		w2 = _mm256_add_ps(w2, _mm256_mul_ps(q2,h4));
#endif
844
845
	}

846
847
848
849
850
851
852
	h1 = _mm256_broadcast_ss(&hh[nb-3]);
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);

	q1 = _mm256_load_ps(&q[nb*ldq]);
	q2 = _mm256_load_ps(&q[(nb*ldq)+8]);

853
#ifdef __ELPA_USE_FMA__
854
855
856
857
858
859
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
	z1 = _mm256_FMA_ps(q1, h3, z1);
	z2 = _mm256_FMA_ps(q2, h3, z2);
860
#else
861
862
863
864
865
866
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
	y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
	z2 = _mm256_add_ps(z2, _mm256_mul_ps(q2,h3));
867
#endif
868
869
870
871
872
873
874

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

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

875
#ifdef __ELPA_USE_FMA__
876
877
878
879
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
880
#else
881
882
883
884
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
	y2 = _mm256_add_ps(y2, _mm256_mul_ps(q2,h2));
885
#endif
886
887
888
889
890
891

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

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

892
#ifdef __ELPA_USE_FMA__
893
894
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
895
#else
896
897
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
898
899
#endif

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
	/////////////////////////////////////////////////////
	// Rank-1 update of Q [8 x nb+3]
	/////////////////////////////////////////////////////

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

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

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

	h1 = tau2;
	h2 = _mm256_mul_ps(h1, vs_1_2);
922
#ifdef __ELPA_USE_FMA__
923
924
	y1 = _mm256_FMSUB_ps(y1, h1, _mm256_mul_ps(x1,h2));
	y2 = _mm256_FMSUB_ps(y2, h1, _mm256_mul_ps(x2,h2));
925
#else
926
927
	y1 = _mm256_sub_ps(_mm256_mul_ps(y1,h1), _mm256_mul_ps(x1,h2));
	y2 = _mm256_sub_ps(_mm256_mul_ps(y2,h1), _mm256_mul_ps(x2,h2));
928
#endif
929
930
931
932
933
934

	h1 = tau3;
	h2 = _mm256_mul_ps(h1, vs_1_3);
	h3 = _mm256_mul_ps(h1, vs_2_3);
#ifdef __ELPA_USE_FMA__
	z1 = _mm256_FMSUB_ps(z1, h1, _mm256_FMA_ps(y1, h3, _mm256_mul_ps(x1,h2)));
935
	z2 = _mm256_FMSUB_ps(z2, h1, _mm256_FMA_ps(y2, h3, _mm256_mul_ps(x2,h2)));
936
937
938
939
940
941
942
943
944
#else
	z1 = _mm256_sub_ps(_mm256_mul_ps(z1,h1), _mm256_add_ps(_mm256_mul_ps(y1,h3), _mm256_mul_ps(x1,h2)));
	z2 = _mm256_sub_ps(_mm256_mul_ps(z2,h1), _mm256_add_ps(_mm256_mul_ps(y2,h3), _mm256_mul_ps(x2,h2)));
#endif

	h1 = tau4;
	h2 = _mm256_mul_ps(h1, vs_1_4);
	h3 = _mm256_mul_ps(h1, vs_2_4);
	h4 = _mm256_mul_ps(h1, vs_3_4);
945
#ifdef __ELPA_USE_FMA__
946
947
	w1 = _mm256_FMSUB_ps(w1, h1, _mm256_FMA_ps(z1, h4, _mm256_FMA_ps(y1, h3, _mm256_mul_ps(x1,h2))));
	w2 = _mm256_FMSUB_ps(w2, h1, _mm256_FMA_ps(z2, h4, _mm256_FMA_ps(y2, h3, _mm256_mul_ps(x2,h2))));
948
#else
949
950
	w1 = _mm256_sub_ps(_mm256_mul_ps(w1,h1), _mm256_add_ps(_mm256_mul_ps(z1,h4), _mm256_add_ps(_mm256_mul_ps(y1,h3), _mm256_mul_ps(x1,h2))));
	w2 = _mm256_sub_ps(_mm256_mul_ps(w2,h1), _mm256_add_ps(_mm256_mul_ps(z2,h4), _mm256_add_ps(_mm256_mul_ps(y2,h3), _mm256_mul_ps(x2,h2))));
951
952
#endif

953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
	q1 = _mm256_load_ps(&q[0]);
	q2 = _mm256_load_ps(&q[8]);
	q1 = _mm256_sub_ps(q1, w1);
	q2 = _mm256_sub_ps(q2, w2);
	_mm256_store_ps(&q[0],q1);
	_mm256_store_ps(&q[8],q2);

	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+1]);
	q1 = _mm256_load_ps(&q[ldq]);
	q2 = _mm256_load_ps(&q[ldq+8]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_sub_ps(q1, _mm256_FMA_ps(w1, h4, z1));
	q2 = _mm256_sub_ps(q2, _mm256_FMA_ps(w2, h4, z2));
#else
	q1 = _mm256_sub_ps(q1, _mm256_add_ps(z1, _mm256_mul_ps(w1, h4)));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps(z2, _mm256_mul_ps(w2, h4)));
#endif
	_mm256_store_ps(&q[ldq],q1);
	_mm256_store_ps(&q[ldq+8],q2);

	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+1]);
	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+2]);
	q1 = _mm256_load_ps(&q[ldq*2]);
	q2 = _mm256_load_ps(&q[(ldq*2)+8]);
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_sub_ps(q1, y1);
        q1 = _mm256_NFMA_ps(z1, h3, q1);
        q1 = _mm256_NFMA_ps(w1, h4, q1);
        q2 = _mm256_sub_ps(q2, y2);
        q2 = _mm256_NFMA_ps(z2, h3, q2);
        q2 = _mm256_NFMA_ps(w2, h4, q2);
#else
	q1 = _mm256_sub_ps(q1, _mm256_add_ps(y1, _mm256_add_ps(_mm256_mul_ps(z1, h3), _mm256_mul_ps(w1, h4))));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps(y2, _mm256_add_ps(_mm256_mul_ps(z2, h3), _mm256_mul_ps(w2, h4))));
#endif
	_mm256_store_ps(&q[ldq*2],q1);
	_mm256_store_ps(&q[(ldq*2)+8],q2);

	h2 = _mm256_broadcast_ss(&hh[ldh+1]);
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+2]);
	h4 = _mm256_broadcast_ss(&hh[(ldh*3)+3]);
	q1 = _mm256_load_ps(&q[ldq*3]);
	q2 = _mm256_load_ps(&q[(ldq*3)+8]);
996
#ifdef __ELPA_USE_FMA__
997
998
999
1000
1001
1002
1003
1004
        q1 = _mm256_sub_ps(q1, x1);
        q1 = _mm256_NFMA_ps(y1, h2, q1);
        q1 = _mm256_NFMA_ps(z1, h3, q1);
        q1 = _mm256_NFMA_ps(w1, h4, q1);
        q2 = _mm256_sub_ps(q2, x2);
        q2 = _mm256_NFMA_ps(y2, h2, q2);
        q2 = _mm256_NFMA_ps(z2, h3, q2);
        q2 = _mm256_NFMA_ps(w2, h4, q2);
1005
#else
1006
1007
	q1 = _mm256_sub_ps(q1, _mm256_add_ps(x1, _mm256_add_ps(_mm256_mul_ps(y1, h2), _mm256_add_ps(_mm256_mul_ps(z1, h3), _mm256_mul_ps(w1, h4)))));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps(x2, _mm256_add_ps(_mm256_mul_ps(y2, h2), _mm256_add_ps(_mm256_mul_ps(z2, h3), _mm256_mul_ps(w2, h4)))));
1008
#endif
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
	_mm256_store_ps(&q[ldq*3], q1);
	_mm256_store_ps(&q[(ldq*3)+8], q2);

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

#ifdef __ELPA_USE_FMA__
		q1 = _mm256_load_ps(&q[i*ldq]);
		q2 = _mm256_load_ps(&q[(i*ldq)+8]);
                q1 = _mm256_NFMA_ps(x1, h1, q1);
                q1 = _mm256_NFMA_ps(y1, h2, q1);
                q1 = _mm256_NFMA_ps(z1, h3, q1);
                q1 = _mm256_NFMA_ps(w1, h4, q1);
                q2 = _mm256_NFMA_ps(x2, h1, q2);
                q2 = _mm256_NFMA_ps(y2, h2, q2);
                q2 = _mm256_NFMA_ps(z2, h3, q2);
                q2 = _mm256_NFMA_ps(w2, h4, q2);
		_mm256_store_ps(&q[i*ldq],q1);
		_mm256_store_ps(&q[(i*ldq)+8],q2);
#else
		q1 = _mm256_load_ps(&q[i*ldq]);
		q1 = _mm256_sub_ps(q1, _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(w1, h4), _mm256_mul_ps(z1, h3)), _mm256_add_ps(_mm256_mul_ps(x1,h1), _mm256_mul_ps(y1, h2))));
		_mm256_store_ps(&q[i*ldq],q1);

		q2 = _mm256_load_ps(&q[(i*ldq)+8]);
		q2 = _mm256_sub_ps(q2, _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(w2, h4), _mm256_mul_ps(z2, h3)), _mm256_add_ps(_mm256_mul_ps(x2,h1), _mm256_mul_ps(y2, h2))));
		_mm256_store_ps(&q[(i*ldq)+8],q2);
#endif
	}

	h1 = _mm256_broadcast_ss(&hh[nb-3]);
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
	q1 = _mm256_load_ps(&q[nb*ldq]);
	q2 = _mm256_load_ps(&q[(nb*ldq)+8]);
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_ps(x1, h1, q1);
        q1 = _mm256_NFMA_ps(y1, h2, q1);
        q1 = _mm256_NFMA_ps(z1, h3, q1);
        q2 = _mm256_NFMA_ps(x2, h1, q2);
        q2 = _mm256_NFMA_ps(y2, h2, q2);
        q2 = _mm256_NFMA_ps(z2, h3, q2);
#else
	q1 = _mm256_sub_ps(q1, _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(z1, h3), _mm256_mul_ps(y1, h2)) , _mm256_mul_ps(x1, h1)));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(z2, h3), _mm256_mul_ps(y2, h2)) , _mm256_mul_ps(x2, h1)));
#endif
	_mm256_store_ps(&q[nb*ldq],q1);
	_mm256_store_ps(&q[(nb*ldq)+8],q2);

	h1 = _mm256_broadcast_ss(&hh[nb-2]);
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-1]);
	q1 = _mm256_load_ps(&q[(nb+1)*ldq]);
	q2 = _mm256_load_ps(&q[((nb+1)*ldq)+8]);
#ifdef __ELPA_USE_FMA__
        q1 = _mm256_NFMA_ps(x1, h1, q1);
        q1 = _mm256_NFMA_ps(y1, h2, q1);
        q2 = _mm256_NFMA_ps(x2, h1, q2);
        q2 = _mm256_NFMA_ps(y2, h2, q2);
#else
	q1 = _mm256_sub_ps(q1, _mm256_add_ps( _mm256_mul_ps(y1, h2) , _mm256_mul_ps(x1, h1)));
	q2 = _mm256_sub_ps(q2, _mm256_add_ps( _mm256_mul_ps(y2, h2) , _mm256_mul_ps(x2, h1)));
#endif
	_mm256_store_ps(&q[(nb+1)*ldq],q1);
	_mm256_store_ps(&q[((nb+1)*ldq)+8],q2);

	h1 = _mm256_broadcast_ss(&hh[nb-1]);
	q1 = _mm256_load_ps(&q[(nb+2)*ldq]);
	q2 = _mm256_load_ps(&q[((nb+2)*ldq)+8]);
#ifdef __ELPA_USE_FMA__
	q1 = _mm256_NFMA_ps(x1, h1, q1);
	q2 = _mm256_NFMA_ps(x2, h1, q2);
#else
	q1 = _mm256_sub_ps(q1, _mm256_mul_ps(x1, h1));
	q2 = _mm256_sub_ps(q2, _mm256_mul_ps(x2, h1));
#endif
	_mm256_store_ps(&q[(nb+2)*ldq],q1);
	_mm256_store_ps(&q[((nb+2)*ldq)+8],q2);
1090
1091
1092
1093
1094
}

/**
 * Unrolled kernel that computes
 * 8 rows of Q simultaneously, a
1095
 * matrix Vector product with two householder
1096
1097
 * vectors + a rank 1 update is performed
 */
1098
__forceinline void hh_trafo_kernel_8_AVX_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
1099
1100
1101
1102
1103
1104
1105
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
	__m256 a1_1 = _mm256_load_ps(&q[ldq*3]);  // q(1,4) | ...                                                 | q(8,4)
	__m256 a2_1 = _mm256_load_ps(&q[ldq*2]);  // q(1,3) | ...                                                 | q(8,3)
	__m256 a3_1 = _mm256_load_ps(&q[ldq]);    // q(1,2) | ...                                                 | q(8,2)
	__m256 a4_1 = _mm256_load_ps(&q[0]);      // q(1,1) | q(2,1) | q(3,1) | q(4,1) | q(5,1) | q(6,1) | q(7,1) | q(8,1)

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

#ifdef __ELPA_USE_FMA__
	__m256 w1 = _mm256_FMA_ps(a3_1, h_4_3, a4_1);
	w1 = _mm256_FMA_ps(a2_1, h_4_2, w1);
	w1 = _mm256_FMA_ps(a1_1, h_4_1, w1);
	__m256 z1 = _mm256_FMA_ps(a2_1, h_3_2, a3_1);
	z1 = _mm256_FMA_ps(a1_1, h_3_1, z1);
	__m256 y1 = _mm256_FMA_ps(a1_1, h_2_1, a2_1);
	__m256 x1 = a1_1;
#else
	__m256 w1 = _mm256_add_ps(a4_1, _mm256_mul_ps(a3_1, h_4_3));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a2_1, h_4_2));
	w1 = _mm256_add_ps(w1, _mm256_mul_ps(a1_1, h_4_1));
	__m256 z1 = _mm256_add_ps(a3_1, _mm256_mul_ps(a2_1, h_3_2));
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(a1_1, h_3_1));
	__m256 y1 = _mm256_add_ps(a2_1, _mm256_mul_ps(a1_1, h_2_1));
	__m256 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]);

#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);
//	__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

	__m256 q1;
	__m256 q2;

	__m256 h1;
	__m256 h2;
	__m256 h3;
	__m256 h4;
1166
1167
1168

	for(i = 4; i < nb; i++)
	{
1169
1170
1171
1172
		h1 = _mm256_broadcast_ss(&hh[i-3]);
		h2 = _mm256_broadcast_ss(&hh[ldh+i-2]);
		h3 = _mm256_broadcast_ss(&hh[(ldh*2)+i-1]);
		h4 = _mm256_broadcast_ss(&hh[(ldh*3)+i]);
1173

1174
		q1 = _mm256_load_ps(&q[i*ldq]);
1175
#ifdef __ELPA_USE_FMA__
1176
1177
1178
1179
		x1 = _mm256_FMA_ps(q1, h1, x1);
		y1 = _mm256_FMA_ps(q1, h2, y1);
		z1 = _mm256_FMA_ps(q1, h3, z1);
		w1 = _mm256_FMA_ps(q1, h4, w1);
1180
#else
1181
1182
1183
1184
		x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
		y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
		z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
		w1 = _mm256_add_ps(w1, _mm256_mul_ps(q1,h4));
1185
1186
#endif

1187
//		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
1188
#ifdef __ELPA_USE_FMA__
1189
1190
1191
1192
//		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);
1193
#else
1194
1195
1196
1197
//		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));
1198
1199
1200
#endif
	}

1201
1202
1203
	h1 = _mm256_broadcast_ss(&hh[nb-3]);
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
1204

1205
1206
	q1 = _mm256_load_ps(&q[nb*ldq]);
//	q2 = _mm256_load_ps(&q[(nb*ldq)+4]);
1207

1208
#ifdef __ELPA_USE_FMA__
1209
1210
1211
1212
1213
1214
	x1 = _mm256_FMA_ps(q1, h1, x1);
//	x2 = _mm256_FMA_pd(q2, h1, x2);
	y1 = _mm256_FMA_ps(q1, h2, y1);
//	y2 = _mm256_FMA_pd(q2, h2, y2);
	z1 = _mm256_FMA_ps(q1, h3, z1);
//	z2 = _mm256_FMA_pd(q2, h3, z2);
1215
#else
1216
1217
1218
1219
1220
1221
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
//	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
//	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
	z1 = _mm256_add_ps(z1, _mm256_mul_ps(q1,h3));
//	z2 = _mm256_add_pd(z2, _mm256_mul_pd(q2,h3));
1222
1223
#endif

1224
1225
	h1 = _mm256_broadcast_ss(&hh[nb-2]);
	h2 = _mm256_broadcast_ss(&hh[(ldh*1)+nb-1]);
1226

1227
1228
	q1 = _mm256_load_ps(&q[(nb+1)*ldq]);
//	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
1229

1230
#ifdef __ELPA_USE_FMA__
1231
1232
1233
1234
	x1 = _mm256_FMA_ps(q1, h1, x1);
//	x2 = _mm256_FMA_pd(q2, h1, x2);
	y1 = _mm256_FMA_ps(q1, h2, y1);
//	y2 = _mm256_FMA_pd(q2, h2, y2);
1235
#else
1236
1237
1238
1239
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
//	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
	y1 = _mm256_add_ps(y1, _mm256_mul_ps(q1,h2));
//	y2 = _mm256_add_pd(y2, _mm256_mul_pd(q2,h2));
1240
1241
#endif

1242
	h1 = _mm256_broadcast_ss(&hh[nb-1]);
1243

1244
1245
	q1 = _mm256_load_ps(&q[(nb+2)*ldq]);
//	q2 = _mm256_load_pd(&q[((nb+2)*ldq)+4]);
1246

1247
#ifdef __ELPA_USE_FMA__
1248
1249
	x1 = _mm256_FMA_ps(q1, h1, x1);
//	x2 = _mm256_FMA_pd(q2, h1, x2);
1250
#else
1251
1252
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
//	x2 = _mm256_add_pd(x2, _mm256_mul_pd(q2,h1));
1253
1254
1255
1256
1257
1258
#endif

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

1259
1260
1261
1262
	__m256 tau1 = _mm256_broadcast_ss(&hh[0]);
	__m256 tau2 = _mm256_broadcast_ss(&hh[ldh]);
	__m256 tau3 = _mm256_broadcast_ss(&hh[ldh*2]);
	__m256 tau4 = _mm256_broadcast_ss(&hh[ldh*3]);
1263

1264
1265
1266
1267
1268
1269
	__m256 vs_1_2 = _mm256_broadcast_ss(&s_1_2);
	__m256 vs_1_3 = _mm256_broadcast_ss(&s_1_3);
	__m256 vs_2_3 = _mm256_broadcast_ss(&s_2_3);
	__m256 vs_1_4 = _mm256_broadcast_ss(&s_1_4);
	__m256 vs_2_4 = _mm256_broadcast_ss(&s_2_4);
	__m256 vs_3_4 = _mm256_broadcast_ss(&s_3_4);
1270
1271

	h1 = tau1;
1272
1273
	x1 = _mm256_mul_ps(x1, h1);
//	x2 = _mm256_mul_pd(x2, h1);
1274
1275

	h1 = tau2;
1276
	h2 = _mm256_mul_ps(h1, vs_1_2);
1277
#ifdef __ELPA_USE_FMA__
1278
1279
	y1 = _mm256_FMSUB_ps(y1, h1, _mm256_mul_ps(x1,h2));
//	y2 = _mm256_FMSUB_pd(y2, h1, _mm256_mul_pd(x2,h2));
1280
#else
1281
1282
	y1 = _mm256_sub_ps(_mm256_mul_ps(y1,h1), _mm256_mul_ps(x1,h2));
//	y2 = _mm256_sub_pd(_mm256_mul_pd(y2,h1), _mm256_mul_pd(x2,h2));
1283
1284
1285
#endif

	h1 = tau3;