elpa2_kernels_real_avx-avx2_4hv_single_precision.c 58.5 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
//    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
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

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

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

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

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

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

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

	// Production level kernel calls with padding
139
	for (i = 0; i < nq-20; i+=24)
140
	{
141
		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);
142
143
144
145
146
	}
	if (nq == i)
	{
		return;
	}
147
	if (nq-i == 20)
148
	{
149
150
		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);
151
	}
152
	else if (nq-i == 16)
153
	{
154
		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);
155
	}
156
	else if (nq-i == 12)
157
	{
158
159
		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);
160
	}
161
	else if (nq-i == 8)
162
	{
163
		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);
164
	}
165
	else
166
	{
167
		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);
168
169
170
	}

}
171

172
173
174

/**
 * Unrolled kernel that computes
175
 * 24 rows of Q simultaneously, a
176
177
178
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
179
__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)
180
181
182
183
184
185
186
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

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
	__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;
271
272
273

	for(i = 4; i < nb; i++)
	{
274
275
276
277
		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]);
278
#ifdef __ELPA_USE_FMA__
279
280
281
		x1 = _mm256_FMA_ps(q1, h1, x1);
		x2 = _mm256_FMA_ps(q2, h1, x2);
		x3 = _mm256_FMA_ps(q3, h1, x3);
282
#else
283
284
285
		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));
286
287
#endif

288
		h2 = _mm256_broadcast_ss(&hh[ldh+i-2]);
289
#ifdef __ELPA_USE_FMA__
290
291
292
		y1 = _mm256_FMA_ps(q1, h2, y1);
		y2 = _mm256_FMA_ps(q2, h2, y2);
		y3 = _mm256_FMA_ps(q3, h2, y3);
293
#else
294
295
296
		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));
297
298
#endif

299
		h3 = _mm256_broadcast_ss(&hh[(ldh*2)+i-1]);
300
#ifdef __ELPA_USE_FMA__
301
302
303
		z1 = _mm256_FMA_ps(q1, h3, z1);
		z2 = _mm256_FMA_ps(q2, h3, z2);
		z3 = _mm256_FMA_ps(q3, h3, z3);
304
#else
305
306
307
		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));
308
309
#endif

310
		h4 = _mm256_broadcast_ss(&hh[(ldh*3)+i]);
311
#ifdef __ELPA_USE_FMA__
312
313
314
		w1 = _mm256_FMA_ps(q1, h4, w1);
		w2 = _mm256_FMA_ps(q2, h4, w2);
		w3 = _mm256_FMA_ps(q3, h4, w3);
315
#else
316
317
318
		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));
319
320
321
#endif
	}

322
	h1 = _mm256_broadcast_ss(&hh[nb-3]);
323

324
325
326
327
328
	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]);
329

330
#ifdef __ELPA_USE_FMA__
331
332
333
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
334
#else
335
336
337
	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));
338
339
#endif

340
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
341
#ifdef __FMA4_
342
343
344
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
	y3 = _mm256_FMA_ps(q3, h2, y3);
345
#else
346
347
348
	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));
349
350
#endif

351
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
352
#ifdef __ELPA_USE_FMA__
353
354
355
	z1 = _mm256_FMA_ps(q1, h3, z1);
	z2 = _mm256_FMA_ps(q2, h3, z2);
	z3 = _mm256_FMA_ps(q3, h3, z3);
356
#else
357
358
359
	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));
360
361
#endif

362
	h1 = _mm256_broadcast_ss(&hh[nb-2]);
363

364
365
366
	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]);
367

368
#ifdef __ELPA_USE_FMA__
369
370
371
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
372
#else
373
374
375
	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));
376
377
#endif

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

380
#ifdef __ELPA_USE_FMA__
381
382
	y1 = _mm256_FMA_ps(q1, h2, y1);
	y2 = _mm256_FMA_ps(q2, h2, y2);
383
//	y3 = _mm256_FMA_ps(q3, h2, y3);
384
#else
385
386
387
	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));
388
389
#endif

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

392
393
394
395
	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]);
396

397
#ifdef __ELPA_USE_FMA__
398
399
400
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
	x3 = _mm256_FMA_ps(q3, h1, x3);
401
#else
402
403
404
	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));
405
406
407
408
409
410
#endif

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

411
	__m256 tau1 = _mm256_broadcast_ss(&hh[0]);
412
413

	h1 = tau1;
414
415
416
	x1 = _mm256_mul_ps(x1, h1);
	x2 = _mm256_mul_ps(x2, h1);
	x3 = _mm256_mul_ps(x3, h1);
417

418
419
	__m256 tau2 = _mm256_broadcast_ss(&hh[ldh]);
	__m256 vs_1_2 = _mm256_broadcast_ss(&s_1_2);
420
421

	h1 = tau2;
422
	h2 = _mm256_mul_ps(h1, vs_1_2);
423
#ifdef __ELPA_USE_FMA__
424
425
426
	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));
427
#else
428
429
430
	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));
431
432
#endif

433
434
435
	__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);
436
437

	h1 = tau3;
438
439
	h2 = _mm256_mul_ps(h1, vs_1_3);
	h3 = _mm256_mul_ps(h1, vs_2_3);
440
#ifdef __ELPA_USE_FMA__
441
442
443
	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)));
444
#else
445
446
447
	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)));
448
449
#endif

450
451
452
453
	__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);
454
455

	h1 = tau4;
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
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
	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);
574
575
576

	for (i = 4; i < nb; i++)
	{
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
		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
592

593
594
595
596
597
598
599
600
601
602
		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
603

604
		h3 = _mm256_broadcast_ss(&hh[(ldh*2)+i-1]);
605
#ifdef __ELPA_USE_FMA__
606
607
608
		q1 = _mm256_NFMA_ps(z1, h3, q1);
		q2 = _mm256_NFMA_ps(z2, h3, q2);
		q3 = _mm256_NFMA_ps(z3, h3, q3);
609
#else
610
611
612
		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));
613
614
#endif

615
		h4 = _mm256_broadcast_ss(&hh[(ldh*3)+i]);
616
#ifdef __ELPA_USE_FMA__
617
618
619
		q1 = _mm256_NFMA_ps(w1, h4, q1);
		q2 = _mm256_NFMA_ps(w2, h4, q2);
		q3 = _mm256_NFMA_ps(w3, h4, q3);
620
#else
621
622
623
		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));
624
625
#endif

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
		_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]);
657
#ifdef __ELPA_USE_FMA__
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
	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);
680
#else
681
682
683
	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));
684
#endif
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
	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
 * matrix vector product with two householder
 * 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]);
801

802
		q1 = _mm256_load_ps(&q[i*ldq]);
803
#ifdef __ELPA_USE_FMA__
804
805
806
807
		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);
808
#else
809
810
811
812
		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));
813
814
#endif

815
816
817
818
819
820
821
822
823
824
825
826
		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
827
828
	}

829
830
831
832
833
834
835
	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]);

836
#ifdef __ELPA_USE_FMA__
837
838
839
840
841
842
	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);
843
#else
844
845
846
847
848
849
	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));
850
#endif
851
852
853
854
855
856
857

	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]);

858
#ifdef __ELPA_USE_FMA__
859
860
861
862
	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);
863
#else
864
865
866
867
	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));
868
#endif
869
870
871
872
873
874

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

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

875
#ifdef __ELPA_USE_FMA__
876
877
	x1 = _mm256_FMA_ps(q1, h1, x1);
	x2 = _mm256_FMA_ps(q2, h1, x2);
878
#else
879
880
	x1 = _mm256_add_ps(x1, _mm256_mul_ps(q1,h1));
	x2 = _mm256_add_ps(x2, _mm256_mul_ps(q2,h1));
881
882
#endif

883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
	/////////////////////////////////////////////////////
	// 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);
905
#ifdef __ELPA_USE_FMA__
906
907
	y1 = _mm256_FMSUB_ps(y1, h1, _mm256_mul_ps(x1,h2));
	y2 = _mm256_FMSUB_ps(y2, h1, _mm256_mul_ps(x2,h2));
908
#else
909
910
	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));
911
#endif
912
913
914
915
916
917

	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)));
918
	z2 = _mm256_FMSUB_ps(z2, h1, _mm256_FMA_ps(y2, h3, _mm256_mul_ps(x2,h2)));
919
920
921
922
923
924
925
926
927
#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);
928
#ifdef __ELPA_USE_FMA__
929
930
	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))));
931
#else
932
933
	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))));
934
935
#endif

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
	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]);
979
#ifdef __ELPA_USE_FMA__
980
981
982
983
984
985
986
987
        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);
988
#else
989
990
	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)))));
991
#endif
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
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
	_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);
1073
1074
1075
1076
1077
1078
1079
1080
}

/**
 * Unrolled kernel that computes
 * 8 rows of Q simultaneously, a
 * matrix vector product with two householder
 * vectors + a rank 1 update is performed
 */
1081
__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)
1082
1083
1084
1085
1086
1087
1088
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [4 x nb+3] * hh
	// hh contains four householder vectors
	/////////////////////////////////////////////////////
	int i;

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
	__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;
1149
1150
1151

	for(i = 4; i < nb; i++)
	{
1152
1153
1154
1155
		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]);
1156

1157
		q1 = _mm256_load_ps(&q[i*ldq]);
1158
#ifdef __ELPA_USE_FMA__
1159
1160
1161
1162
		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);
1163
#else
1164
1165
1166
1167
		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));
1168
1169
#endif

1170
//		q2 = _mm256_load_pd(&q[(i*ldq)+4]);
1171
#ifdef __ELPA_USE_FMA__
1172
1173
1174
1175
//		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);
1176
#else
1177
1178
1179
1180
//		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));
1181
1182
1183
#endif
	}

1184
1185
1186
	h1 = _mm256_broadcast_ss(&hh[nb-3]);
	h2 = _mm256_broadcast_ss(&hh[ldh+nb-2]);
	h3 = _mm256_broadcast_ss(&hh[(ldh*2)+nb-1]);
1187

1188
1189
	q1 = _mm256_load_ps(&q[nb*ldq]);
//	q2 = _mm256_load_ps(&q[(nb*ldq)+4]);
1190

1191
#ifdef __ELPA_USE_FMA__
1192
1193
1194
1195
1196
1197
	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);
1198
#else
1199
1200
1201
1202
1203
1204
	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));
1205
1206
#endif

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

1210
1211
	q1 = _mm256_load_ps(&q[(nb+1)*ldq]);
//	q2 = _mm256_load_pd(&q[((nb+1)*ldq)+4]);
1212

1213
#ifdef __ELPA_USE_FMA__
1214
1215
1216
1217
	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);
1218
#else
1219
1220
1221
1222
	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));
1223
1224
#endif

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

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

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

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

1242
1243
1244
1245
	__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]);
1246

1247
1248
1249
1250
1251
1252
	__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);
1253
1254

	h1 = tau1;
1255
1256
	x1 = _mm256_mul_ps(x1, h1);
//	x2 = _mm256_mul_pd(x2, h1);
1257
1258

	h1 = tau2;
1259
	h2 = _mm256_mul_ps(h1, vs_1_2);
1260
#ifdef __ELPA_USE_FMA__
1261
1262
	y1 = _mm256_FMSUB_ps(y1, h1, _mm256_mul_ps(x1,h2));
//	y2 = _mm256_FMSUB_pd(y2, h1, _mm256_mul_pd(x2,h2));
1263
#else
1264
1265
	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));
1266
1267
1268
#endif

	h1 = tau3;