real_sse_2hv_template.c 68.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
Andreas Marek's avatar
Andreas Marek committed
7
//      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
8
//    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
Andreas Marek's avatar
Andreas Marek committed
9
//      Informatik,
10
//    - Technische Universität München, Lehrstuhl für Informatik mit
Andreas Marek's avatar
Andreas Marek committed
11
//      Schwerpunkt Wissenschaftliches Rechnen ,
12 13
//    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
//    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
Andreas Marek's avatar
Andreas Marek committed
14 15
//      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
//      and
16 17 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
Andreas Marek's avatar
Andreas Marek committed
36
//    along with ELPA. If not, see <http://www.gnu.org/licenses/>
37 38 39 40 41 42 43 44 45 46
//
//    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
//
47
#include "config-f90.h"
48

49
#ifdef HAVE_SSE_INTRINSICS
50
#include <x86intrin.h>
51 52 53 54 55
#endif
#ifdef HAVE_SPARC64_SSE
#include <fjmfunc.h>
#include <emmintrin.h>
#endif
56 57
#include <stdio.h>
#include <stdlib.h>
58

59

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#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

86
#ifdef HAVE_SSE_INTRINSICS
87 88
//Forward declaration
#ifdef DOUBLE_PRECISION_REAL
89
__forceinline void hh_trafo_kernel_2_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
90
__forceinline void hh_trafo_kernel_4_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
91
__forceinline void hh_trafo_kernel_6_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
92
__forceinline void hh_trafo_kernel_8_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
93
__forceinline void hh_trafo_kernel_10_SSE_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
94 95 96 97 98 99
__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);
100 101 102
__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);
103
#endif
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#endif

#ifdef HAVE_SPARC64_SSE
//Forward declaration
#ifdef DOUBLE_PRECISION_REAL
__forceinline void hh_trafo_kernel_2_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_4_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_6_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_8_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_10_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_12_SPARC64_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_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_8_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_12_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_16_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_20_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_24_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
#endif
#endif
125 126


127
#ifdef HAVE_SSE_INTRINSICS
128 129 130 131 132 133
#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
134 135 136 137 138 139 140 141 142 143
#endif

#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
void double_hh_trafo_real_sparc64_2hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif
#ifdef SINGLE_PRECISION_REAL
void double_hh_trafo_real_sparc64_2hv_single_(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif
#endif
144

145 146 147 148
/*
!f>#ifdef HAVE_SPARC64_SSE
!f> interface
!f>   subroutine double_hh_trafo_real_sparc64_2hv_double(q, hh, pnb, pnq, pldq, pldh) &
Andreas Marek's avatar
Andreas Marek committed
149 150 151 152 153
!f>              bind(C, name="double_hh_trafo_real_sparc64_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)
154 155 156 157 158 159 160 161 162
!f>   end subroutine
!f> end interface
!f>#endif
*/

/*
!f>#ifdef HAVE_SPARC64_SSE
!f> interface
!f>   subroutine double_hh_trafo_real_sparc64_2hv_single(q, hh, pnb, pnq, pldq, pldh) &
Andreas Marek's avatar
Andreas Marek committed
163 164 165 166 167
!f>              bind(C, name="double_hh_trafo_real_sparc64_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)
168 169 170 171
!f>   end subroutine
!f> end interface
!f>#endif
*/
172 173 174 175
/*
!f>#ifdef HAVE_SSE_INTRINSICS
!f> interface
!f>   subroutine double_hh_trafo_real_sse_2hv_double(q, hh, pnb, pnq, pldq, pldh) &
Andreas Marek's avatar
Andreas Marek committed
176 177 178 179 180
!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)
181 182 183 184 185 186 187 188 189
!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) &
Andreas Marek's avatar
Andreas Marek committed
190 191 192 193 194
!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)
195 196 197 198 199
!f>   end subroutine
!f> end interface
!f>#endif
*/

200
#ifdef HAVE_SSE_INTRINSICS
201 202 203 204 205 206
#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
207 208 209 210 211 212 213 214 215
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
void double_hh_trafo_real_sparc64_2hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
#ifdef SINGLE_PRECISION_REAL
void double_hh_trafo_real_sparc64_2hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
#endif
216
{
Andreas Marek's avatar
Andreas Marek committed
217 218 219 220 221 222 223 224 225 226 227
        int i;
        int nb = *pnb;
        int nq = *pldq;
        int ldq = *pldq;
        int ldh = *pldh;
        int worked_on;
        
        worked_on = 0;
        
// calculating scalar product to compute
// 2 householder vectors simultaneously
228
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
229
        double s = hh[(ldh)+1]*1.0;
230 231
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
232
        float s = hh[(ldh)+1]*1.0;
233
#endif
234 235

#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
236
        #pragma ivdep
237
#endif
Andreas Marek's avatar
Andreas Marek committed
238 239 240 241
        for (i = 2; i < nb; i++)
        {
                s += hh[i-1] * hh[(i+ldh)];
        }
242

Andreas Marek's avatar
Andreas Marek committed
243
        // Production level kernel calls with padding
244
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
245 246
        for (i = 0; i < nq-10; i+=12)
        {
247
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
248
                hh_trafo_kernel_12_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
249 250
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
251
                hh_trafo_kernel_12_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
252
#endif
Andreas Marek's avatar
Andreas Marek committed
253 254
                worked_on += 12;
        }
255 256
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
257 258
        for (i = 0; i < nq-20; i+=24)
        {
259
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
260
                hh_trafo_kernel_24_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
261 262
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
263
                hh_trafo_kernel_24_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
264
#endif
Andreas Marek's avatar
Andreas Marek committed
265 266
                worked_on += 24;
        }
267
#endif
268

Andreas Marek's avatar
Andreas Marek committed
269 270 271 272
        if (nq == i)
        {
                return;
        }
273 274

#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
275 276
        if (nq-i == 10)
        {
277
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
278
                hh_trafo_kernel_10_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
279 280
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
281
                hh_trafo_kernel_10_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
282
#endif
Andreas Marek's avatar
Andreas Marek committed
283 284
                worked_on += 10;
        }
285 286 287
#endif

#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
288 289
        if (nq-i == 20)
        {
290
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
291
                hh_trafo_kernel_20_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
292 293
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
294
                hh_trafo_kernel_20_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
295
#endif
Andreas Marek's avatar
Andreas Marek committed
296 297
                worked_on += 20;
        }
298 299 300
#endif

#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
301 302
        if (nq-i == 8)
        {
303
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
304
                hh_trafo_kernel_8_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
305 306
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
307
                hh_trafo_kernel_8_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
308
#endif
Andreas Marek's avatar
Andreas Marek committed
309 310
                worked_on += 8;
        }
311 312 313
#endif

#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
314 315
        if (nq-i == 16)
        {
316
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
317
                hh_trafo_kernel_16_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
318 319
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
320
                hh_trafo_kernel_16_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
321
#endif
Andreas Marek's avatar
Andreas Marek committed
322 323
                worked_on += 16;
        }
324 325 326 327
#endif


#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
328 329
        if (nq-i == 6)
        {
330
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
331
                hh_trafo_kernel_6_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
332 333
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
334
                hh_trafo_kernel_6_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
335
#endif
Andreas Marek's avatar
Andreas Marek committed
336 337
                worked_on += 6;
        }
338 339 340
#endif

#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
341 342
        if (nq-i == 12)
        {
343
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
344
                hh_trafo_kernel_12_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
345 346
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
347
                hh_trafo_kernel_12_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
348 349
#endif

Andreas Marek's avatar
Andreas Marek committed
350 351
                worked_on += 12;
        }
352 353 354
#endif

#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
355 356
        if (nq-i == 4)
        {
357
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
358
                hh_trafo_kernel_4_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
359 360
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
361
                hh_trafo_kernel_4_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
362
#endif
Andreas Marek's avatar
Andreas Marek committed
363 364
                worked_on += 4;
        }
365 366
#endif

367
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
368 369
        if (nq-i == 8)
        {
370
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
371
                hh_trafo_kernel_8_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
372 373
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
374
                hh_trafo_kernel_8_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
375
#endif
Andreas Marek's avatar
Andreas Marek committed
376 377
                worked_on += 8;
        }
378 379 380
#endif

#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
381 382
        if (nq-i == 2)
        {
383
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
384
                hh_trafo_kernel_2_SSE_2hv_double(&q[i], hh, nb, ldq, ldh, s);
385 386
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
387
                hh_trafo_kernel_2_SPARC64_2hv_double(&q[i], hh, nb, ldq, ldh, s);
388
#endif
Andreas Marek's avatar
Andreas Marek committed
389 390
                worked_on += 2;
        }
391 392 393
#endif

#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
394 395
        if (nq-i == 4)
        {
396
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
397
                hh_trafo_kernel_4_SSE_2hv_single(&q[i], hh, nb, ldq, ldh, s);
398 399
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
400
                hh_trafo_kernel_4_SPARC64_2hv_single(&q[i], hh, nb, ldq, ldh, s);
401 402
#endif

Andreas Marek's avatar
Andreas Marek committed
403 404
                worked_on += 4;
        }
405
#endif
406
#ifdef WITH_DEBUG
Andreas Marek's avatar
Andreas Marek committed
407 408
        if (worked_on != nq)
        {
409
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
410
                printf("Error in real SSE BLOCK2 kernel %d %d\n", worked_on, nq);
411 412
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
413
                printf("Error in real SPARC64 BLOCK2 kernel %d %d\n", worked_on, nq);
414 415
#endif

Andreas Marek's avatar
Andreas Marek committed
416 417
                abort();
        }
418
#endif
419 420 421 422 423 424 425 426 427 428 429 430 431
}

/**
 * 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
 */
432
#ifdef HAVE_SSE_INTRINSICS
433 434
#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)
435
#endif
436 437 438
#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
439 440 441 442 443 444 445 446 447
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_12_SPARC64_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_24_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
#endif
448
{
Andreas Marek's avatar
Andreas Marek committed
449 450 451 452 453
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [12 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
454
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
455
        // Needed bit mask for floating point sign flip
456
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
457
        __SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
458 459
#endif
#ifdef SINGLE_PRECISION_REAL
460 461
        __SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif
462 463
#endif

Andreas Marek's avatar
Andreas Marek committed
464 465 466 467 468 469
        __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]);
470

471
#ifdef HAVE_SSE_INTRINSICS
472
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
473
        __SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
474 475
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
476
        __SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
477
#endif
478 479 480 481 482 483 484 485 486 487
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
        __SSE_DATATYPE h1 = _mm_set_pd(hh[ldh+1], hh[ldh+1]);
#endif
#ifdef SINGLE_PRECISION_REAL
        __SSE_DATATYPE h1 = _mm_set_ps(hh[ldh+1], hh[ldh+1]);
#endif
#endif

Andreas Marek's avatar
Andreas Marek committed
488
        __SSE_DATATYPE h2;
489

Andreas Marek's avatar
Andreas Marek committed
490 491 492 493 494 495 496 497 498 499 500 501 502 503
        __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++)
        {
504
#ifdef HAVE_SSE_INTRINSICS
505
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
506 507
                h1 = _mm_set1_pd(hh[i-1]);
                h2 = _mm_set1_pd(hh[ldh+i]);
508 509
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
510 511
                h1 = _mm_set1_ps(hh[i-1]);
                h2 = _mm_set1_ps(hh[ldh+i]);
512
#endif
513 514 515
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
516 517
                h1 = _mm_set_pd(hh[i-1], hh[i-1]);
                h2 = _mm_set_pd(hh[ldh+i], hh[ldh+i]);
518 519
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
520 521
                h1 = _mm_set_ps(hh[i-1], hh[i-1]);
                h2 = _mm_set_ps(hh[ldh+i], hh[ldh+i]);
522 523
#endif
#endif
524

Andreas Marek's avatar
Andreas Marek committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
                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));
        }
544
#ifdef HAVE_SSE_INTRINSICS
545
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
546
        h1 = _mm_set1_pd(hh[nb-1]);
547 548
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
549
        h1 = _mm_set1_ps(hh[nb-1]);
550 551 552 553
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
554
        h1 = _mm_set_pd(hh[nb-1], hh[nb-1]);
555 556
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
557
        h1 = _mm_set_ps(hh[nb-1], hh[nb-1]);
558
#endif
559 560
#endif

Andreas Marek's avatar
Andreas Marek committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        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]
        /////////////////////////////////////////////////////
576
#ifdef  HAVE_SSE_INTRINSICS
577
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
578 579 580
        __SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
        __SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
        __SSE_DATATYPE vs = _mm_set1_pd(s);
581 582
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
583 584 585
        __SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
        __SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
        __SSE_DATATYPE vs = _mm_set1_ps(s);
586
#endif
587 588 589
#endif
#ifdef  HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
590 591 592
        __SSE_DATATYPE tau1 = _mm_set_pd(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _mm_set_pd(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _mm_set_pd(s, s);
593 594
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
595 596 597
        __SSE_DATATYPE tau1 = _mm_set_ps(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _mm_set_ps(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _mm_set_ps(s, s);
598 599
#endif
#endif
600

601
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
602
        h1 = _SSE_XOR(tau1, sign);
603 604
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
605
        h1 = _fjsp_neg_v2r8(tau1);
606
#endif
Andreas Marek's avatar
Andreas Marek committed
607 608 609 610 611 612
        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);
613
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
614
        h1 = _SSE_XOR(tau2, sign);
615 616
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
617
        h1 = _fjsp_neg_v2r8(tau2);
618
#endif
Andreas Marek's avatar
Andreas Marek committed
619
        h2 = _SSE_MUL(h1, vs);
620

Andreas Marek's avatar
Andreas Marek committed
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
        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);
645

646
#ifdef HAVE_SSE_INTRINSICS
647
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
648
        h2 = _mm_set1_pd(hh[ldh+1]);
649 650
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
651
        h2 = _mm_set1_ps(hh[ldh+1]);
652 653 654 655 656
#endif
#endif

#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
657
        h2 = _mm_set_pd(hh[ldh+1], hh[ldh+1]);
658 659
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
660
        h2 = _mm_set_ps(hh[ldh+1], hh[ldh+1]);
661
#endif
662 663
#endif

Andreas Marek's avatar
Andreas Marek committed
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
        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);
682

Andreas Marek's avatar
Andreas Marek committed
683 684
        for (i = 2; i < nb; i++)
        {
685
#ifdef HAVE_SSE_INTRINSICS
686
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
687 688
                h1 = _mm_set1_pd(hh[i-1]);
                h2 = _mm_set1_pd(hh[ldh+i]);
689 690
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
691 692
                h1 = _mm_set1_ps(hh[i-1]);
                h2 = _mm_set1_ps(hh[ldh+i]);
693 694 695 696
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
697 698
                h1 = _mm_set_pd(hh[i-1], hh[i-1]);
                h2 = _mm_set_pd(hh[ldh+i], hh[ldh+i]);
699 700
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
701 702
                h1 = _mm_set_ps(hh[i-1], hh[i-1]);
                h2 = _mm_set_ps(hh[ldh+i], hh[ldh+i]);
703
#endif
704 705
#endif

Andreas Marek's avatar
Andreas Marek committed
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
                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);
        }
725
#ifdef HAVE_SSE_INTRINSICS
726
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
727
        h1 = _mm_set1_pd(hh[nb-1]);
728 729
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
730
        h1 = _mm_set1_ps(hh[nb-1]);
731
#endif
732 733 734
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
735
        h1 = _mm_set_pd(hh[nb-1], hh[nb-1]);
736 737
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
738
        h1 = _mm_set_ps(hh[nb-1], hh[nb-1]);
739 740 741 742
#endif
#endif


Andreas Marek's avatar
Andreas Marek committed
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
        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);
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
}



/**
 * 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
 */
776
#ifdef HAVE_SSE_INTRINSICS
777 778 779 780 781
#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)
782 783 784 785 786 787 788 789 790 791
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_10_SPARC64_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_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif

792 793
#endif
{
Andreas Marek's avatar
Andreas Marek committed
794 795 796 797 798
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [12 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
799
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
800
        // Needed bit mask for floating point sign flip
801
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
802
        __SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
803 804
#endif
#ifdef SINGLE_PRECISION_REAL
805 806
        __SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif
807 808
#endif

Andreas Marek's avatar
Andreas Marek committed
809 810 811 812 813
        __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]);
814

815
#ifdef HAVE_SSE_INTRINSICS
816
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
817
        __SSE_DATATYPE h1 = _mm_set1_pd(hh[ldh+1]);
818 819
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
820
        __SSE_DATATYPE h1 = _mm_set1_ps(hh[ldh+1]);
821
#endif
822 823 824
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
825
        __SSE_DATATYPE h1 = _mm_set_pd(hh[ldh+1], hh[ldh+1]);
826 827
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
828
        __SSE_DATATYPE h1 = _mm_set_ps(hh[ldh+1], hh[ldh+1]);
829 830 831
#endif
#endif

Andreas Marek's avatar
Andreas Marek committed
832
        __SSE_DATATYPE h2;
833

Andreas Marek's avatar
Andreas Marek committed
834 835 836 837 838 839 840 841 842 843 844 845
        __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++)
        {
846
#ifdef HAVE_SSE_INTRINSICS
847
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
848 849
                h1 = _mm_set1_pd(hh[i-1]);
                h2 = _mm_set1_pd(hh[ldh+i]);
850 851
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
852 853
                h1 = _mm_set1_ps(hh[i-1]);
                h2 = _mm_set1_ps(hh[ldh+i]);
854
#endif
855 856 857
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
858 859
                h1 = _mm_set_pd(hh[i-1], hh[i-1]);
                h2 = _mm_set_pd(hh[ldh+i], hh[ldh+i]);
860 861
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
862 863
                h1 = _mm_set_ps(hh[i-1], hh[i-1]);
                h2 = _mm_set_ps(hh[ldh+i], hh[ldh+i]);
864 865
#endif
#endif
866 867


Andreas Marek's avatar
Andreas Marek committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
                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));
        }
884

885
#ifdef HAVE_SSE_INTRINSICS
886
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
887
        h1 = _mm_set1_pd(hh[nb-1]);
888 889
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
890
        h1 = _mm_set1_ps(hh[nb-1]);
891 892 893 894
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
895
        h1 = _mm_set_pd(hh[nb-1], hh[nb-1]);
896 897
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
898
        h1 = _mm_set_ps(hh[nb-1], hh[nb-1]);
899
#endif
900 901
#endif

Andreas Marek's avatar
Andreas Marek committed
902 903 904 905 906 907 908 909 910 911 912 913 914
        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]
        /////////////////////////////////////////////////////
915
#ifdef HAVE_SSE_INTRINSICS
916
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
917 918 919
        __SSE_DATATYPE tau1 = _mm_set1_pd(hh[0]);
        __SSE_DATATYPE tau2 = _mm_set1_pd(hh[ldh]);
        __SSE_DATATYPE vs = _mm_set1_pd(s);
920 921
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
922 923 924
        __SSE_DATATYPE tau1 = _mm_set1_ps(hh[0]);
        __SSE_DATATYPE tau2 = _mm_set1_ps(hh[ldh]);
        __SSE_DATATYPE vs = _mm_set1_ps(s);
925 926

#endif
927 928 929
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
930 931 932
        __SSE_DATATYPE tau1 = _mm_set_pd(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _mm_set_pd(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _mm_set_pd(s, s);
933 934
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
935 936 937
        __SSE_DATATYPE tau1 = _mm_set_ps(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _mm_set_ps(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _mm_set_ps(s, s);
938 939 940

#endif
#endif
941

942
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
943
        h1 = _SSE_XOR(tau1, sign);
944 945
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
946
        h1 = _fjsp_neg_v2r8(tau1);
947
#endif
Andreas Marek's avatar
Andreas Marek committed
948 949 950 951 952
        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);
953
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
954
        h1 = _SSE_XOR(tau2, sign);
955 956
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
957
        h1 = _fjsp_neg_v2r8(tau2);
958
#endif
Andreas Marek's avatar
Andreas Marek committed
959
        h2 = _SSE_MUL(h1, vs);
960

Andreas Marek's avatar
Andreas Marek committed
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
        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);
981

982
#ifdef HAVE_SSE_INTRINSICS
983
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
984
        h2 = _mm_set1_pd(hh[ldh+1]);
985 986
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
987
        h2 = _mm_set1_ps(hh[ldh+1]);
988 989 990 991
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
992
        h2 = _mm_set_pd(hh[ldh+1], hh[ldh+1]);
993 994
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar