real_sse_2hv_template.c 40.6 KB
Newer Older
1
2
3
4
5
6
//    This file is part of ELPA.
//
//    The ELPA library was originally created by the ELPA consortium,
//    consisting of the following organizations:
//
//    - Max Planck Computing and Data Facility (MPCDF), formerly known as
7
//	Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
8
//    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
9
//	Informatik,
10
//    - Technische Universität München, Lehrstuhl für Informatik mit
11
//	Schwerpunkt Wissenschaftliches Rechnen ,
12
13
//    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
//    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
14
15
//	Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
//	and
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//    - IBM Deutschland GmbH
//
//    This particular source code file contains additions, changes and
//    enhancements authored by Intel Corporation which is not part of
//    the ELPA consortium.
//
//    More information can be found here:
//    http://elpa.mpcdf.mpg.de/
//
//    ELPA is free software: you can redistribute it and/or modify
//    it under the terms of the version 3 of the license of the
//    GNU Lesser General Public License as published by the Free
//    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
36
//    along with ELPA.	If not, see <http://www.gnu.org/licenses/>
37
38
39
40
41
42
43
44
45
46
47
48
//
//    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.
//
// Author: Andreas Marek, MPCDF, based on the double precision case of A. Heinecke
//

#include <x86intrin.h>
49
50
#include <stdio.h>
#include <stdlib.h>
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

#define __forceinline __attribute__((always_inline)) static
#ifdef DOUBLE_PRECISION_REAL
#define __SSE_DATATYPE __m128d
#define _SSE_LOAD _mm_load_pd
#define _SSE_ADD _mm_add_pd
#define _SSE_MUL _mm_mul_pd
#define _SSE_XOR _mm_xor_pd
#define _SSE_STORE _mm_store_pd
#define offset 2
#endif

#ifdef SINGLE_PRECISION_REAL
#define __SSE_DATATYPE __m128
#define _SSE_LOAD _mm_load_ps
#define _SSE_ADD _mm_add_ps
#define _SSE_MUL _mm_mul_ps
#define _SSE_XOR _mm_xor_ps
#define _SSE_STORE _mm_store_ps
#define offset 4
#endif


#ifdef HAVE_SSE_INTRINSICS
#undef __AVX__
#endif

//Forward declaration
#ifdef DOUBLE_PRECISION_REAL
80
__forceinline void hh_trafo_kernel_2_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
81
__forceinline void hh_trafo_kernel_4_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
82
__forceinline void hh_trafo_kernel_6_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
83
__forceinline void hh_trafo_kernel_8_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
84
__forceinline void hh_trafo_kernel_10_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
85
86
87
88
89
90
__forceinline void hh_trafo_kernel_12_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
#endif
#ifdef SINGLE_PRECISION_REAL
__forceinline void hh_trafo_kernel_4_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_8_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_12_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
91
92
93
__forceinline void hh_trafo_kernel_16_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_20_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_24_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#endif


#ifdef DOUBLE_PRECISION_REAL
void double_hh_trafo_real_sse_2hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif
#ifdef SINGLE_PRECISION_REAL
void double_hh_trafo_real_sse_2hv_single_(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif

/*
!f>#ifdef HAVE_SSE_INTRINSICS
!f> interface
!f>   subroutine double_hh_trafo_real_sse_2hv_double(q, hh, pnb, pnq, pldq, pldh) &
108
109
110
111
112
!f>				bind(C, name="double_hh_trafo_real_sse_2hv_double")
!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_double) :: hh(pnb,6)
113
114
115
116
117
118
119
120
121
!f>   end subroutine
!f> end interface
!f>#endif
*/

/*
!f>#ifdef HAVE_SSE_INTRINSICS
!f> interface
!f>   subroutine double_hh_trafo_real_sse_2hv_single(q, hh, pnb, pnq, pldq, pldh) &
122
123
124
125
126
!f>				bind(C, name="double_hh_trafo_real_sse_2hv_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)
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
!f>   end subroutine
!f> end interface
!f>#endif
*/

#ifdef DOUBLE_PRECISION_REAL
void double_hh_trafo_real_sse_2hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
#ifdef SINGLE_PRECISION_REAL
void double_hh_trafo_real_sse_2hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
{
	int i;
	int nb = *pnb;
	int nq = *pldq;
	int ldq = *pldq;
	int ldh = *pldh;
144
145
146
	int worked_on;

	worked_on = 0;
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

	// calculating scalar product to compute
	// 2 householder vectors simultaneously
#ifdef DOUBLE_PRECISION_REAL
	double s = hh[(ldh)+1]*1.0;
#endif
#ifdef SINGLE_PRECISION_REAL
	float s = hh[(ldh)+1]*1.0;
#endif
	#pragma ivdep
	for (i = 2; i < nb; i++)
	{
		s += hh[i-1] * hh[(i+ldh)];
	}

	// Production level kernel calls with padding
#ifdef DOUBLE_PRECISION_REAL
164
165
	for (i = 0; i < nq-10; i+=12)
	{
166
		hh_trafo_kernel_12_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
167
		worked_on += 12;
168
	}
169
170
#endif
#ifdef SINGLE_PRECISION_REAL
171
172
	for (i = 0; i < nq-20; i+=24)
	{
173
		hh_trafo_kernel_24_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
174
		worked_on += 24;
175
	}
176
#endif
177

178
179
180
181
	if (nq == i)
	{
		return;
	}
182
183

#ifdef DOUBLE_PRECISION_REAL
184
	if (nq-i == 10)
185
186
187
	{
		hh_trafo_kernel_10_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 10;
188
	}
189
190
191
#endif

#ifdef SINGLE_PRECISION_REAL
192
	if (nq-i == 20)
193
194
195
	{
		hh_trafo_kernel_20_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 20;
196
	}
197
198
199
#endif

#ifdef DOUBLE_PRECISION_REAL
200
	if (nq-i == 8)
201
202
203
	{
		hh_trafo_kernel_8_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 8;
204
	}
205
206
207
#endif

#ifdef SINGLE_PRECISION_REAL
208
	if (nq-i == 16)
209
210
211
	{
		hh_trafo_kernel_16_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 16;
212
	}
213
214
215
216
#endif


#ifdef DOUBLE_PRECISION_REAL
217
	if (nq-i == 6)
218
219
220
	{
		hh_trafo_kernel_6_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 6;
221
	}
222
223
224
#endif

#ifdef SINGLE_PRECISION_REAL
225
	if (nq-i == 12)
226
227
228
	{
		hh_trafo_kernel_12_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 12;
229
	}
230
231
232
#endif

#ifdef DOUBLE_PRECISION_REAL
233
	if (nq-i == 4)
234
235
236
	{
		hh_trafo_kernel_4_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 4;
237
	}
238
239
#endif

240
#ifdef SINGLE_PRECISION_REAL
241
	if (nq-i == 8)
242
243
	{
		hh_trafo_kernel_8_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
244
		worked_on += 8;
245
	}
246
247
248
#endif

#ifdef DOUBLE_PRECISION_REAL
249
	if (nq-i == 2)
250
251
252
	{
		hh_trafo_kernel_2_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 2;
253
	}
254
255
256
#endif

#ifdef SINGLE_PRECISION_REAL
257
	if (nq-i == 4)
258
259
260
	{
		hh_trafo_kernel_4_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
		worked_on += 4;
261
	}
262
263
#endif

264
	if (worked_on != nq)
265
	{
266
267
		printf("Error in real SSE BLOCK2 kernel %d %d\n", worked_on, nq);
		abort();
268
	}
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
}

/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 12 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 24 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_12_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
284
#endif
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_24_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);
	__SSE_DATATYPE x2 = _SSE_LOAD(&q[ldq+offset]);
	__SSE_DATATYPE x3 = _SSE_LOAD(&q[ldq+2*offset]);
	__SSE_DATATYPE x4 = _SSE_LOAD(&q[ldq+3*offset]);
	__SSE_DATATYPE x5 = _SSE_LOAD(&q[ldq+4*offset]);
	__SSE_DATATYPE x6 = _SSE_LOAD(&q[ldq+5*offset]);

#ifdef DOUBLE_PRECISION_REAL
310
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
311
312
#endif
#ifdef SINGLE_PRECISION_REAL
313
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	__SSE_DATATYPE q2 = _SSE_LOAD(&q[offset]);
	__SSE_DATATYPE y2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	__SSE_DATATYPE q3 = _SSE_LOAD(&q[2*offset]);
	__SSE_DATATYPE y3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	__SSE_DATATYPE q4 = _SSE_LOAD(&q[3*offset]);
	__SSE_DATATYPE y4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	__SSE_DATATYPE q5 = _SSE_LOAD(&q[4*offset]);
	__SSE_DATATYPE y5 = _SSE_ADD(q5, _SSE_MUL(x5, h1));
	__SSE_DATATYPE q6 = _SSE_LOAD(&q[5*offset]);
	__SSE_DATATYPE y6 = _SSE_ADD(q6, _SSE_MUL(x6, h1));
	for(i = 2; i < nb; i++)
330
331
	{
#ifdef DOUBLE_PRECISION_REAL
332
333
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
334
335
#endif
#ifdef SINGLE_PRECISION_REAL
336
337
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
338
#endif
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
		y2 = _SSE_ADD(y2, _SSE_MUL(q2,h2));
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
		y3 = _SSE_ADD(y3, _SSE_MUL(q3,h2));
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
		y4 = _SSE_ADD(y4, _SSE_MUL(q4,h2));
		q5 = _SSE_LOAD(&q[(i*ldq)+4*offset]);
		x5 = _SSE_ADD(x5, _SSE_MUL(q5,h1));
		y5 = _SSE_ADD(y5, _SSE_MUL(q5,h2));
		q6 = _SSE_LOAD(&q[(i*ldq)+5*offset]);
		x6 = _SSE_ADD(x6, _SSE_MUL(q6,h1));
		y6 = _SSE_ADD(y6, _SSE_MUL(q6,h2));
359
	}
360
361

#ifdef DOUBLE_PRECISION_REAL
362
	h1 = _mm_set1_pd(hh[nb-1]);
363
364
#endif
#ifdef SINGLE_PRECISION_REAL
365
	h1 = _mm_set1_ps(hh[nb-1]);
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
	q5 = _SSE_LOAD(&q[(nb*ldq)+4*offset]);
	x5 = _SSE_ADD(x5, _SSE_MUL(q5,h1));
	q6 = _SSE_LOAD(&q[(nb*ldq)+5*offset]);
	x6 = _SSE_ADD(x6, _SSE_MUL(q6,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
384
385
386
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
387
388
#endif
#ifdef SINGLE_PRECISION_REAL
389
390
391
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	x2 = _SSE_MUL(x2, h1);
	x3 = _SSE_MUL(x3, h1);
	x4 = _SSE_MUL(x4, h1);
	x5 = _SSE_MUL(x5, h1);
	x6 = _SSE_MUL(x6, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	y2 = _SSE_ADD(_SSE_MUL(y2,h1), _SSE_MUL(x2,h2));
	y3 = _SSE_ADD(_SSE_MUL(y3,h1), _SSE_MUL(x3,h2));
	y4 = _SSE_ADD(_SSE_MUL(y4,h1), _SSE_MUL(x4,h2));
	y5 = _SSE_ADD(_SSE_MUL(y5,h1), _SSE_MUL(x5,h2));
	y6 = _SSE_ADD(_SSE_MUL(y6,h1), _SSE_MUL(x6,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);
	q2 = _SSE_LOAD(&q[offset]);
	q2 = _SSE_ADD(q2, y2);
	_SSE_STORE(&q[offset],q2);
	q3 = _SSE_LOAD(&q[2*offset]);
	q3 = _SSE_ADD(q3, y3);
	_SSE_STORE(&q[2*offset],q3);
	q4 = _SSE_LOAD(&q[3*offset]);
	q4 = _SSE_ADD(q4, y4);
	_SSE_STORE(&q[3*offset],q4);
	q5 = _SSE_LOAD(&q[4*offset]);
	q5 = _SSE_ADD(q5, y5);
	_SSE_STORE(&q[4*offset],q5);
	q6 = _SSE_LOAD(&q[5*offset]);
	q6 = _SSE_ADD(q6, y6);
	_SSE_STORE(&q[5*offset],q6);

#ifdef DOUBLE_PRECISION_REAL
430
	h2 = _mm_set1_pd(hh[ldh+1]);
431
432
#endif
#ifdef SINGLE_PRECISION_REAL
433
	h2 = _mm_set1_ps(hh[ldh+1]);
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);
	q2 = _SSE_LOAD(&q[ldq+offset]);
	q2 = _SSE_ADD(q2, _SSE_ADD(x2, _SSE_MUL(y2, h2)));
	_SSE_STORE(&q[ldq+offset],q2);
	q3 = _SSE_LOAD(&q[ldq+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_ADD(x3, _SSE_MUL(y3, h2)));
	_SSE_STORE(&q[ldq+2*offset],q3);
	q4 = _SSE_LOAD(&q[ldq+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_ADD(x4, _SSE_MUL(y4, h2)));
	_SSE_STORE(&q[ldq+3*offset],q4);
	q5 = _SSE_LOAD(&q[ldq+4*offset]);
	q5 = _SSE_ADD(q5, _SSE_ADD(x5, _SSE_MUL(y5, h2)));
	_SSE_STORE(&q[ldq+4*offset],q5);
	q6 = _SSE_LOAD(&q[ldq+5*offset]);
	q6 = _SSE_ADD(q6, _SSE_ADD(x6, _SSE_MUL(y6, h2)));
	_SSE_STORE(&q[ldq+5*offset],q6);

	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
458
459
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
460
461
#endif
#ifdef SINGLE_PRECISION_REAL
462
463
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		q2 = _SSE_ADD(q2, _SSE_ADD(_SSE_MUL(x2,h1), _SSE_MUL(y2, h2)));
		_SSE_STORE(&q[(i*ldq)+offset],q2);
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		q3 = _SSE_ADD(q3, _SSE_ADD(_SSE_MUL(x3,h1), _SSE_MUL(y3, h2)));
		_SSE_STORE(&q[(i*ldq)+2*offset],q3);
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		q4 = _SSE_ADD(q4, _SSE_ADD(_SSE_MUL(x4,h1), _SSE_MUL(y4, h2)));
		_SSE_STORE(&q[(i*ldq)+3*offset],q4);
		q5 = _SSE_LOAD(&q[(i*ldq)+4*offset]);
		q5 = _SSE_ADD(q5, _SSE_ADD(_SSE_MUL(x5,h1), _SSE_MUL(y5, h2)));
		_SSE_STORE(&q[(i*ldq)+4*offset],q5);
		q6 = _SSE_LOAD(&q[(i*ldq)+5*offset]);
		q6 = _SSE_ADD(q6, _SSE_ADD(_SSE_MUL(x6,h1), _SSE_MUL(y6, h2)));
		_SSE_STORE(&q[(i*ldq)+5*offset],q6);
	}
#ifdef DOUBLE_PRECISION_REAL
486
	h1 = _mm_set1_pd(hh[nb-1]);
487
488
#endif
#ifdef SINGLE_PRECISION_REAL
489
	h1 = _mm_set1_ps(hh[nb-1]);
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
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	q2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	_SSE_STORE(&q[(nb*ldq)+offset],q2);
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	_SSE_STORE(&q[(nb*ldq)+2*offset],q3);
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	_SSE_STORE(&q[(nb*ldq)+3*offset],q4);
	q5 = _SSE_LOAD(&q[(nb*ldq)+4*offset]);
	q5 = _SSE_ADD(q5, _SSE_MUL(x5, h1));
	_SSE_STORE(&q[(nb*ldq)+4*offset],q5);
	q6 = _SSE_LOAD(&q[(nb*ldq)+5*offset]);
	q6 = _SSE_ADD(q6, _SSE_MUL(x6, h1));
	_SSE_STORE(&q[(nb*ldq)+5*offset],q6);
}



/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 10 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 20 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_10_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_20_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);
	__SSE_DATATYPE x2 = _SSE_LOAD(&q[ldq+offset]);
	__SSE_DATATYPE x3 = _SSE_LOAD(&q[ldq+2*offset]);
	__SSE_DATATYPE x4 = _SSE_LOAD(&q[ldq+3*offset]);
	__SSE_DATATYPE x5 = _SSE_LOAD(&q[ldq+4*offset]);

#ifdef DOUBLE_PRECISION_REAL
551
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
552
553
#endif
#ifdef SINGLE_PRECISION_REAL
554
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	__SSE_DATATYPE q2 = _SSE_LOAD(&q[offset]);
	__SSE_DATATYPE y2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	__SSE_DATATYPE q3 = _SSE_LOAD(&q[2*offset]);
	__SSE_DATATYPE y3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	__SSE_DATATYPE q4 = _SSE_LOAD(&q[3*offset]);
	__SSE_DATATYPE y4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	__SSE_DATATYPE q5 = _SSE_LOAD(&q[4*offset]);
	__SSE_DATATYPE y5 = _SSE_ADD(q5, _SSE_MUL(x5, h1));
	for(i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
571
572
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
573
574
#endif
#ifdef SINGLE_PRECISION_REAL
575
576
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
#endif


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
		y2 = _SSE_ADD(y2, _SSE_MUL(q2,h2));
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
		y3 = _SSE_ADD(y3, _SSE_MUL(q3,h2));
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
		y4 = _SSE_ADD(y4, _SSE_MUL(q4,h2));
		q5 = _SSE_LOAD(&q[(i*ldq)+4*offset]);
		x5 = _SSE_ADD(x5, _SSE_MUL(q5,h1));
		y5 = _SSE_ADD(y5, _SSE_MUL(q5,h2));
	}

#ifdef DOUBLE_PRECISION_REAL
598
	h1 = _mm_set1_pd(hh[nb-1]);
599
600
#endif
#ifdef SINGLE_PRECISION_REAL
601
	h1 = _mm_set1_ps(hh[nb-1]);
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
	q5 = _SSE_LOAD(&q[(nb*ldq)+4*offset]);
	x5 = _SSE_ADD(x5, _SSE_MUL(q5,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
618
619
620
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
621
622
#endif
#ifdef SINGLE_PRECISION_REAL
623
624
625
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
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
657
658
659

#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	x2 = _SSE_MUL(x2, h1);
	x3 = _SSE_MUL(x3, h1);
	x4 = _SSE_MUL(x4, h1);
	x5 = _SSE_MUL(x5, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	y2 = _SSE_ADD(_SSE_MUL(y2,h1), _SSE_MUL(x2,h2));
	y3 = _SSE_ADD(_SSE_MUL(y3,h1), _SSE_MUL(x3,h2));
	y4 = _SSE_ADD(_SSE_MUL(y4,h1), _SSE_MUL(x4,h2));
	y5 = _SSE_ADD(_SSE_MUL(y5,h1), _SSE_MUL(x5,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);
	q2 = _SSE_LOAD(&q[offset]);
	q2 = _SSE_ADD(q2, y2);
	_SSE_STORE(&q[offset],q2);
	q3 = _SSE_LOAD(&q[2*offset]);
	q3 = _SSE_ADD(q3, y3);
	_SSE_STORE(&q[2*offset],q3);
	q4 = _SSE_LOAD(&q[3*offset]);
	q4 = _SSE_ADD(q4, y4);
	_SSE_STORE(&q[3*offset],q4);
	q5 = _SSE_LOAD(&q[4*offset]);
	q5 = _SSE_ADD(q5, y5);
	_SSE_STORE(&q[4*offset],q5);

#ifdef DOUBLE_PRECISION_REAL
660
	h2 = _mm_set1_pd(hh[ldh+1]);
661
662
#endif
#ifdef SINGLE_PRECISION_REAL
663
	h2 = _mm_set1_ps(hh[ldh+1]);
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);
	q2 = _SSE_LOAD(&q[ldq+offset]);
	q2 = _SSE_ADD(q2, _SSE_ADD(x2, _SSE_MUL(y2, h2)));
	_SSE_STORE(&q[ldq+offset],q2);
	q3 = _SSE_LOAD(&q[ldq+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_ADD(x3, _SSE_MUL(y3, h2)));
	_SSE_STORE(&q[ldq+2*offset],q3);
	q4 = _SSE_LOAD(&q[ldq+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_ADD(x4, _SSE_MUL(y4, h2)));
	_SSE_STORE(&q[ldq+3*offset],q4);
	q5 = _SSE_LOAD(&q[ldq+4*offset]);
	q5 = _SSE_ADD(q5, _SSE_ADD(x5, _SSE_MUL(y5, h2)));
	_SSE_STORE(&q[ldq+4*offset],q5);

	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
685
686
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
687
688
#endif
#ifdef SINGLE_PRECISION_REAL
689
690
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		q2 = _SSE_ADD(q2, _SSE_ADD(_SSE_MUL(x2,h1), _SSE_MUL(y2, h2)));
		_SSE_STORE(&q[(i*ldq)+offset],q2);
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		q3 = _SSE_ADD(q3, _SSE_ADD(_SSE_MUL(x3,h1), _SSE_MUL(y3, h2)));
		_SSE_STORE(&q[(i*ldq)+2*offset],q3);
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		q4 = _SSE_ADD(q4, _SSE_ADD(_SSE_MUL(x4,h1), _SSE_MUL(y4, h2)));
		_SSE_STORE(&q[(i*ldq)+3*offset],q4);
		q5 = _SSE_LOAD(&q[(i*ldq)+4*offset]);
		q5 = _SSE_ADD(q5, _SSE_ADD(_SSE_MUL(x5,h1), _SSE_MUL(y5, h2)));
		_SSE_STORE(&q[(i*ldq)+4*offset],q5);
	}
#ifdef DOUBLE_PRECISION_REAL
710
	h1 = _mm_set1_pd(hh[nb-1]);
711
712
#endif
#ifdef SINGLE_PRECISION_REAL
713
	h1 = _mm_set1_ps(hh[nb-1]);
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
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	q2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	_SSE_STORE(&q[(nb*ldq)+offset],q2);
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	_SSE_STORE(&q[(nb*ldq)+2*offset],q3);
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	_SSE_STORE(&q[(nb*ldq)+3*offset],q4);
	q5 = _SSE_LOAD(&q[(nb*ldq)+4*offset]);
	q5 = _SSE_ADD(q5, _SSE_MUL(x5, h1));
	_SSE_STORE(&q[(nb*ldq)+4*offset],q5);
}

/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 8 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 16 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_8_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_16_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);
	__SSE_DATATYPE x2 = _SSE_LOAD(&q[ldq+offset]);
	__SSE_DATATYPE x3 = _SSE_LOAD(&q[ldq+2*offset]);
	__SSE_DATATYPE x4 = _SSE_LOAD(&q[ldq+3*offset]);

#ifdef DOUBLE_PRECISION_REAL
769
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
770
771
#endif
#ifdef SINGLE_PRECISION_REAL
772
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
773
774
775
776
777
778
779
780
781
782
783
784
785
786
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	__SSE_DATATYPE q2 = _SSE_LOAD(&q[offset]);
	__SSE_DATATYPE y2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	__SSE_DATATYPE q3 = _SSE_LOAD(&q[2*offset]);
	__SSE_DATATYPE y3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	__SSE_DATATYPE q4 = _SSE_LOAD(&q[3*offset]);
	__SSE_DATATYPE y4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	for(i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
787
788
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
789
790
#endif
#ifdef SINGLE_PRECISION_REAL
791
792
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
#endif


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
		y2 = _SSE_ADD(y2, _SSE_MUL(q2,h2));
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
		y3 = _SSE_ADD(y3, _SSE_MUL(q3,h2));
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
		y4 = _SSE_ADD(y4, _SSE_MUL(q4,h2));
	}

#ifdef DOUBLE_PRECISION_REAL
811
	h1 = _mm_set1_pd(hh[nb-1]);
812
813
#endif
#ifdef SINGLE_PRECISION_REAL
814
	h1 = _mm_set1_ps(hh[nb-1]);
815
816
817
818
819
820
821
822
823
824
825
826
827
828
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	x4 = _SSE_ADD(x4, _SSE_MUL(q4,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
829
830
831
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
832
833
#endif
#ifdef SINGLE_PRECISION_REAL
834
835
836
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	x2 = _SSE_MUL(x2, h1);
	x3 = _SSE_MUL(x3, h1);
	x4 = _SSE_MUL(x4, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	y2 = _SSE_ADD(_SSE_MUL(y2,h1), _SSE_MUL(x2,h2));
	y3 = _SSE_ADD(_SSE_MUL(y3,h1), _SSE_MUL(x3,h2));
	y4 = _SSE_ADD(_SSE_MUL(y4,h1), _SSE_MUL(x4,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);
	q2 = _SSE_LOAD(&q[offset]);
	q2 = _SSE_ADD(q2, y2);
	_SSE_STORE(&q[offset],q2);
	q3 = _SSE_LOAD(&q[2*offset]);
	q3 = _SSE_ADD(q3, y3);
	_SSE_STORE(&q[2*offset],q3);
	q4 = _SSE_LOAD(&q[3*offset]);
	q4 = _SSE_ADD(q4, y4);
	_SSE_STORE(&q[3*offset],q4);

#ifdef DOUBLE_PRECISION_REAL
866
	h2 = _mm_set1_pd(hh[ldh+1]);
867
868
#endif
#ifdef SINGLE_PRECISION_REAL
869
	h2 = _mm_set1_ps(hh[ldh+1]);
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);
	q2 = _SSE_LOAD(&q[ldq+offset]);
	q2 = _SSE_ADD(q2, _SSE_ADD(x2, _SSE_MUL(y2, h2)));
	_SSE_STORE(&q[ldq+offset],q2);
	q3 = _SSE_LOAD(&q[ldq+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_ADD(x3, _SSE_MUL(y3, h2)));
	_SSE_STORE(&q[ldq+2*offset],q3);
	q4 = _SSE_LOAD(&q[ldq+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_ADD(x4, _SSE_MUL(y4, h2)));
	_SSE_STORE(&q[ldq+3*offset],q4);

	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
888
889
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
890
891
#endif
#ifdef SINGLE_PRECISION_REAL
892
893
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		q2 = _SSE_ADD(q2, _SSE_ADD(_SSE_MUL(x2,h1), _SSE_MUL(y2, h2)));
		_SSE_STORE(&q[(i*ldq)+offset],q2);
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		q3 = _SSE_ADD(q3, _SSE_ADD(_SSE_MUL(x3,h1), _SSE_MUL(y3, h2)));
		_SSE_STORE(&q[(i*ldq)+2*offset],q3);
		q4 = _SSE_LOAD(&q[(i*ldq)+3*offset]);
		q4 = _SSE_ADD(q4, _SSE_ADD(_SSE_MUL(x4,h1), _SSE_MUL(y4, h2)));
		_SSE_STORE(&q[(i*ldq)+3*offset],q4);
	}
#ifdef DOUBLE_PRECISION_REAL
910
	h1 = _mm_set1_pd(hh[nb-1]);
911
912
#endif
#ifdef SINGLE_PRECISION_REAL
913
	h1 = _mm_set1_ps(hh[nb-1]);
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
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
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	q2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	_SSE_STORE(&q[(nb*ldq)+offset],q2);
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	_SSE_STORE(&q[(nb*ldq)+2*offset],q3);
	q4 = _SSE_LOAD(&q[(nb*ldq)+3*offset]);
	q4 = _SSE_ADD(q4, _SSE_MUL(x4, h1));
	_SSE_STORE(&q[(nb*ldq)+3*offset],q4);
}

/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 6 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 12 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_6_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_12_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);
	__SSE_DATATYPE x2 = _SSE_LOAD(&q[ldq+offset]);
	__SSE_DATATYPE x3 = _SSE_LOAD(&q[ldq+2*offset]);

#ifdef DOUBLE_PRECISION_REAL
965
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
966
967
#endif
#ifdef SINGLE_PRECISION_REAL
968
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
969
970
971
972
973
974
975
976
977
978
979
980
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	__SSE_DATATYPE q2 = _SSE_LOAD(&q[offset]);
	__SSE_DATATYPE y2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	__SSE_DATATYPE q3 = _SSE_LOAD(&q[2*offset]);
	__SSE_DATATYPE y3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	for(i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
981
982
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
983
984
#endif
#ifdef SINGLE_PRECISION_REAL
985
986
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
#endif


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
		y2 = _SSE_ADD(y2, _SSE_MUL(q2,h2));
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
		y3 = _SSE_ADD(y3, _SSE_MUL(q3,h2));
	}

#ifdef DOUBLE_PRECISION_REAL
1002
	h1 = _mm_set1_pd(hh[nb-1]);
1003
1004
#endif
#ifdef SINGLE_PRECISION_REAL
1005
	h1 = _mm_set1_ps(hh[nb-1]);
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	x3 = _SSE_ADD(x3, _SSE_MUL(q3,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
1018
1019
1020
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
1021
1022
#endif
#ifdef SINGLE_PRECISION_REAL
1023
1024
1025
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049

#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	x2 = _SSE_MUL(x2, h1);
	x3 = _SSE_MUL(x3, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	y2 = _SSE_ADD(_SSE_MUL(y2,h1), _SSE_MUL(x2,h2));
	y3 = _SSE_ADD(_SSE_MUL(y3,h1), _SSE_MUL(x3,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);
	q2 = _SSE_LOAD(&q[offset]);
	q2 = _SSE_ADD(q2, y2);
	_SSE_STORE(&q[offset],q2);
	q3 = _SSE_LOAD(&q[2*offset]);
	q3 = _SSE_ADD(q3, y3);
	_SSE_STORE(&q[2*offset],q3);

#ifdef DOUBLE_PRECISION_REAL
1050
	h2 = _mm_set1_pd(hh[ldh+1]);
1051
1052
#endif
#ifdef SINGLE_PRECISION_REAL
1053
	h2 = _mm_set1_ps(hh[ldh+1]);
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);
	q2 = _SSE_LOAD(&q[ldq+offset]);
	q2 = _SSE_ADD(q2, _SSE_ADD(x2, _SSE_MUL(y2, h2)));
	_SSE_STORE(&q[ldq+offset],q2);
	q3 = _SSE_LOAD(&q[ldq+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_ADD(x3, _SSE_MUL(y3, h2)));
	_SSE_STORE(&q[ldq+2*offset],q3);

	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
1069
1070
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
1071
1072
#endif
#ifdef SINGLE_PRECISION_REAL
1073
1074
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		q2 = _SSE_ADD(q2, _SSE_ADD(_SSE_MUL(x2,h1), _SSE_MUL(y2, h2)));
		_SSE_STORE(&q[(i*ldq)+offset],q2);
		q3 = _SSE_LOAD(&q[(i*ldq)+2*offset]);
		q3 = _SSE_ADD(q3, _SSE_ADD(_SSE_MUL(x3,h1), _SSE_MUL(y3, h2)));
		_SSE_STORE(&q[(i*ldq)+2*offset],q3);
	}
#ifdef DOUBLE_PRECISION_REAL
1088
	h1 = _mm_set1_pd(hh[nb-1]);
1089
1090
#endif
#ifdef SINGLE_PRECISION_REAL
1091
	h1 = _mm_set1_ps(hh[nb-1]);
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	q2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	_SSE_STORE(&q[(nb*ldq)+offset],q2);
	q3 = _SSE_LOAD(&q[(nb*ldq)+2*offset]);
	q3 = _SSE_ADD(q3, _SSE_MUL(x3, h1));
	_SSE_STORE(&q[(nb*ldq)+2*offset],q3);
1102
1103
}

1104

1105
1106
/**
 * Unrolled kernel that computes
1107
1108
1109
1110
1111
1112
#ifdef DOUBLE_PRECISION_REAL
 * 4 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 8 rows of Q simultaneously, a
#endif
1113
1114
1115
1116
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
1117
 __forceinline void hh_trafo_kernel_4_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
1118
1119
#endif
#ifdef SINGLE_PRECISION_REAL
1120
 __forceinline void hh_trafo_kernel_8_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);
	__SSE_DATATYPE x2 = _SSE_LOAD(&q[ldq+offset]);

#ifdef DOUBLE_PRECISION_REAL
1140
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
1141
1142
#endif
#ifdef SINGLE_PRECISION_REAL
1143
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	__SSE_DATATYPE q2 = _SSE_LOAD(&q[offset]);
	__SSE_DATATYPE y2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	for(i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
1154
1155
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
1156
1157
#endif
#ifdef SINGLE_PRECISION_REAL
1158
1159
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
#endif


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
		y2 = _SSE_ADD(y2, _SSE_MUL(q2,h2));
	}

#ifdef DOUBLE_PRECISION_REAL
1172
	h1 = _mm_set1_pd(hh[nb-1]);
1173
1174
#endif
#ifdef SINGLE_PRECISION_REAL
1175
	h1 = _mm_set1_ps(hh[nb-1]);
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	x2 = _SSE_ADD(x2, _SSE_MUL(q2,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
1186
1187
1188
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
1189
1190
#endif
#ifdef SINGLE_PRECISION_REAL
1191
1192
1193
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212

#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	x2 = _SSE_MUL(x2, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	y2 = _SSE_ADD(_SSE_MUL(y2,h1), _SSE_MUL(x2,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);
	q2 = _SSE_LOAD(&q[offset]);
	q2 = _SSE_ADD(q2, y2);
	_SSE_STORE(&q[offset],q2);

#ifdef DOUBLE_PRECISION_REAL
1213
	h2 = _mm_set1_pd(hh[ldh+1]);
1214
1215
#endif
#ifdef SINGLE_PRECISION_REAL
1216
	h2 = _mm_set1_ps(hh[ldh+1]);
1217
1218
1219
1220
1221
1222
1223
1224
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);
	q2 = _SSE_LOAD(&q[ldq+offset]);
	q2 = _SSE_ADD(q2, _SSE_ADD(x2, _SSE_MUL(y2, h2)));
	_SSE_STORE(&q[ldq+offset],q2);
1225

1226
1227
1228
	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
1229
1230
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
1231
1232
#endif
#ifdef SINGLE_PRECISION_REAL
1233
1234
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
		q2 = _SSE_LOAD(&q[(i*ldq)+offset]);
		q2 = _SSE_ADD(q2, _SSE_ADD(_SSE_MUL(x2,h1), _SSE_MUL(y2, h2)));
		_SSE_STORE(&q[(i*ldq)+offset],q2);
	}
#ifdef DOUBLE_PRECISION_REAL
1245
	h1 = _mm_set1_pd(hh[nb-1]);
1246
1247
#endif
#ifdef SINGLE_PRECISION_REAL
1248
	h1 = _mm_set1_ps(hh[nb-1]);
1249
1250
1251
1252
1253
1254
1255
1256
1257
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
	q2 = _SSE_LOAD(&q[(nb*ldq)+offset]);
	q2 = _SSE_ADD(q2, _SSE_MUL(x2, h1));
	_SSE_STORE(&q[(nb*ldq)+offset],q2);
}

1258

1259
1260
/**
 * Unrolled kernel that computes
1261
1262
1263
1264
1265
1266
#ifdef DOUBLE_PRECISION_REAL
 * 2 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 4 rows of Q simultaneously, a
#endif
1267
1268
1269
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_2_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_4_SSE_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
	/////////////////////////////////////////////////////
	// Matrix Vector Multiplication, Q [12 x nb+1] * hh
	// hh contains two householder vectors, with offset 1
	/////////////////////////////////////////////////////
	int i;
	// Needed bit mask for floating point sign flip
#ifdef DOUBLE_PRECISION_REAL
	__SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
#endif
#ifdef SINGLE_PRECISION_REAL
__SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif

	__SSE_DATATYPE x1 = _SSE_LOAD(&q[ldq]);

#ifdef DOUBLE_PRECISION_REAL
1293
	__SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
1294
1295
#endif
#ifdef SINGLE_PRECISION_REAL
1296
	__SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
1297
1298
1299
1300
1301
1302
1303
1304
#endif
	__SSE_DATATYPE h2;

	__SSE_DATATYPE q1 = _SSE_LOAD(q);
	__SSE_DATATYPE y1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	for(i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
1305
1306
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
1307
1308
#endif
#ifdef SINGLE_PRECISION_REAL
1309
1310
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
1311
1312
1313
1314
1315
1316
1317
1318
1319
#endif


		q1 = _SSE_LOAD(&q[i*ldq]);
		x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
		y1 = _SSE_ADD(y1, _SSE_MUL(q1,h2));
	}

#ifdef DOUBLE_PRECISION_REAL
1320
	h1 = _mm_set1_pd(hh[nb-1]);
1321
1322
#endif
#ifdef SINGLE_PRECISION_REAL
1323
	h1 = _mm_set1_ps(hh[nb-1]);
1324
1325
1326
1327
1328
1329
1330
1331
#endif

	q1 = _SSE_LOAD(&q[nb*ldq]);
	x1 = _SSE_ADD(x1, _SSE_MUL(q1,h1));
	/////////////////////////////////////////////////////
	// Rank-2 update of Q [12 x nb+1]
	/////////////////////////////////////////////////////
#ifdef DOUBLE_PRECISION_REAL
1332
1333
1334
	__SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_pd(s);
1335
1336
#endif
#ifdef SINGLE_PRECISION_REAL
1337
1338
1339
	__SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
	__SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
	__SSE_DATATYPE vs = _mm_set1_ps(s);
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353

#endif

	h1 = _SSE_XOR(tau1, sign);
	x1 = _SSE_MUL(x1, h1);
	h1 = _SSE_XOR(tau2, sign);
	h2 = _SSE_MUL(h1, vs);

	y1 = _SSE_ADD(_SSE_MUL(y1,h1), _SSE_MUL(x1,h2));
	q1 = _SSE_LOAD(q);
	q1 = _SSE_ADD(q1, y1);
	_SSE_STORE(q,q1);

#ifdef DOUBLE_PRECISION_REAL
1354
	h2 = _mm_set1_pd(hh[ldh+1]);
1355
1356
#endif
#ifdef SINGLE_PRECISION_REAL
1357
	h2 = _mm_set1_ps(hh[ldh+1]);
1358
1359
1360
1361
1362
1363
1364
1365
1366
#endif

	q1 = _SSE_LOAD(&q[ldq]);
	q1 = _SSE_ADD(q1, _SSE_ADD(x1, _SSE_MUL(y1, h2)));
	_SSE_STORE(&q[ldq],q1);

	for (i = 2; i < nb; i++)
	{
#ifdef DOUBLE_PRECISION_REAL
1367
1368
		h1 = _mm_set1_pd(hh[i-1]);
		h2 = _mm_set1_pd(hh[ldh+i]);
1369
1370
#endif
#ifdef SINGLE_PRECISION_REAL
1371
1372
		h1 = _mm_set1_ps(hh[i-1]);
		h2 = _mm_set1_ps(hh[ldh+i]);
1373
1374
1375
1376
1377
1378
1379
#endif

		q1 = _SSE_LOAD(&q[i*ldq]);
		q1 = _SSE_ADD(q1, _SSE_ADD(_SSE_MUL(x1,h1), _SSE_MUL(y1, h2)));
		_SSE_STORE(&q[i*ldq],q1);
	}
#ifdef DOUBLE_PRECISION_REAL
1380
	h1 = _mm_set1_pd(hh[nb-1]);
1381
1382
#endif
#ifdef SINGLE_PRECISION_REAL
1383
	h1 = _mm_set1_ps(hh[nb-1]);
1384
1385
1386
1387
1388
#endif
	q1 = _SSE_LOAD(&q[nb*ldq]);
	q1 = _SSE_ADD(q1, _SSE_MUL(x1, h1));
	_SSE_STORE(&q[nb*ldq],q1);
}