real_sse_2hv_template.c 56.3 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
#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
68 69
#define _SSE_SET _mm_set_pd
#define _SSE_SET1 _mm_set1_pd
70 71 72 73 74 75 76 77 78 79
#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
80 81
#define _SSE_SET _mm_set_ps
#define _SSE_SET1 _mm_set1_ps
82 83 84 85 86 87 88 89
#define offset 4
#endif


#ifdef HAVE_SSE_INTRINSICS
#undef __AVX__
#endif

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


131
#ifdef HAVE_SSE_INTRINSICS
132 133 134 135 136 137
#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
138 139 140 141 142 143 144 145 146 147
#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
148

149 150 151 152
/*
!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
153 154 155 156 157
!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)
158 159 160 161 162 163 164 165 166
!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
167 168 169 170 171
!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)
172 173 174 175
!f>   end subroutine
!f> end interface
!f>#endif
*/
176 177 178 179
/*
!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
180 181 182 183 184
!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)
185 186 187 188 189 190 191 192 193
!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
194 195 196 197 198
!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)
199 200 201 202 203
!f>   end subroutine
!f> end interface
!f>#endif
*/

204
#ifdef HAVE_SSE_INTRINSICS
205 206 207 208 209 210
#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
211 212 213 214 215 216 217 218 219
#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
220
{
Andreas Marek's avatar
Andreas Marek committed
221 222 223 224 225 226 227 228 229 230 231
        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
232
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
233
        double s = hh[(ldh)+1]*1.0;
234 235
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
236
        float s = hh[(ldh)+1]*1.0;
237
#endif
238 239

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

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

Andreas Marek's avatar
Andreas Marek committed
273 274 275 276
        if (nq == i)
        {
                return;
        }
277 278

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

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

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

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


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

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

Andreas Marek's avatar
Andreas Marek committed
354 355
                worked_on += 12;
        }
356 357 358
#endif

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

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

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

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

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

Andreas Marek's avatar
Andreas Marek committed
420 421
                abort();
        }
422
#endif
423 424 425 426 427 428 429 430 431 432 433 434 435
}

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

Andreas Marek's avatar
Andreas Marek committed
468 469 470 471 472 473
        __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]);
474

475
#ifdef HAVE_SSE_INTRINSICS
476
        __SSE_DATATYPE h1 = _SSE_SET1(hh[ldh+1]);
477 478
#endif
#ifdef HAVE_SPARC64_SSE
479
        __SSE_DATATYPE h1 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
480 481
#endif

Andreas Marek's avatar
Andreas Marek committed
482
        __SSE_DATATYPE h2;
483

Andreas Marek's avatar
Andreas Marek committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497
        __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++)
        {
498
#ifdef HAVE_SSE_INTRINSICS
499 500
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
501 502
#endif
#ifdef HAVE_SPARC64_SSE
503 504
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
505
#endif
506

Andreas Marek's avatar
Andreas Marek committed
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
                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));
        }
526
#ifdef HAVE_SSE_INTRINSICS
527
        h1 = _SSE_SET1(hh[nb-1]);
528 529
#endif
#ifdef HAVE_SPARC64_SSE
530
        h1 = _SSE_SET(hh[nb-1], hh[nb-1]);
531 532
#endif

Andreas Marek's avatar
Andreas Marek committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
        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]
        /////////////////////////////////////////////////////
548
#ifdef  HAVE_SSE_INTRINSICS
549 550 551
        __SSE_DATATYPE tau1 = _SSE_SET1(hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET1(hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET1(s);
552 553
#endif
#ifdef  HAVE_SPARC64_SSE
554 555 556
        __SSE_DATATYPE tau1 = _SSE_SET(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET(s, s);
557
#endif
558

559
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
560
        h1 = _SSE_XOR(tau1, sign);
561 562
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
563
        h1 = _fjsp_neg_v2r8(tau1);
564
#endif
Andreas Marek's avatar
Andreas Marek committed
565 566 567 568 569 570
        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);
571
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
572
        h1 = _SSE_XOR(tau2, sign);
573 574
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
575
        h1 = _fjsp_neg_v2r8(tau2);
576
#endif
Andreas Marek's avatar
Andreas Marek committed
577
        h2 = _SSE_MUL(h1, vs);
578

Andreas Marek's avatar
Andreas Marek committed
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
        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);
603

604
#ifdef HAVE_SSE_INTRINSICS
605
        h2 = _SSE_SET1(hh[ldh+1]);
606 607 608
#endif

#ifdef HAVE_SPARC64_SSE
609
        h2 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
610 611
#endif

Andreas Marek's avatar
Andreas Marek committed
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
        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);
630

Andreas Marek's avatar
Andreas Marek committed
631 632
        for (i = 2; i < nb; i++)
        {
633
#ifdef HAVE_SSE_INTRINSICS
634 635
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
636 637
#endif
#ifdef HAVE_SPARC64_SSE
638 639
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
640 641
#endif

Andreas Marek's avatar
Andreas Marek committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
                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);
        }
661
#ifdef HAVE_SSE_INTRINSICS
662
        h1 = _SSE_SET1(hh[nb-1]);
663 664
#endif
#ifdef HAVE_SPARC64_SSE
665
        h1 = _SSE_SET(hh[nb-1], hh[nb-1]);
666 667 668
#endif


Andreas Marek's avatar
Andreas Marek committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
        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);
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
}



/**
 * 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
 */
702
#ifdef HAVE_SSE_INTRINSICS
703 704 705 706 707
#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)
708 709 710 711 712 713 714 715 716 717
#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

718 719
#endif
{
Andreas Marek's avatar
Andreas Marek committed
720 721 722 723 724
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [12 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
725
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
726
        // Needed bit mask for floating point sign flip
727
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
728
        __SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
729 730
#endif
#ifdef SINGLE_PRECISION_REAL
731 732
        __SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif
733 734
#endif

Andreas Marek's avatar
Andreas Marek committed
735 736 737 738 739
        __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]);
740

741
#ifdef HAVE_SSE_INTRINSICS
742
        __SSE_DATATYPE h1 = _SSE_SET1(hh[ldh+1]);
743 744
#endif
#ifdef HAVE_SPARC64_SSE
745
        __SSE_DATATYPE h1 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
746 747
#endif

Andreas Marek's avatar
Andreas Marek committed
748
        __SSE_DATATYPE h2;
749

Andreas Marek's avatar
Andreas Marek committed
750 751 752 753 754 755 756 757 758 759 760 761
        __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++)
        {
762
#ifdef HAVE_SSE_INTRINSICS
763 764
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
765 766
#endif
#ifdef HAVE_SPARC64_SSE
767 768
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
769
#endif
770 771


Andreas Marek's avatar
Andreas Marek committed
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
                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));
        }
788

789
#ifdef HAVE_SSE_INTRINSICS
790
        h1 = _SSE_SET1(hh[nb-1]);
791 792
#endif
#ifdef HAVE_SPARC64_SSE
793
        h1 = _SSE_SET(hh[nb-1], hh[nb-1]);
794 795
#endif

Andreas Marek's avatar
Andreas Marek committed
796 797 798 799 800 801 802 803 804 805 806 807 808
        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]
        /////////////////////////////////////////////////////
809
#ifdef HAVE_SSE_INTRINSICS
810 811 812
        __SSE_DATATYPE tau1 = _SSE_SET1(hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET1(hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET1(s);
813 814
#endif
#ifdef HAVE_SPARC64_SSE
815 816 817
        __SSE_DATATYPE tau1 = _SSE_SET(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET(s, s);
818
#endif
819

820
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
821
        h1 = _SSE_XOR(tau1, sign);
822 823
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
824
        h1 = _fjsp_neg_v2r8(tau1);
825
#endif
Andreas Marek's avatar
Andreas Marek committed
826 827 828 829 830
        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);
831
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
832
        h1 = _SSE_XOR(tau2, sign);
833 834
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
835
        h1 = _fjsp_neg_v2r8(tau2);
836
#endif
Andreas Marek's avatar
Andreas Marek committed
837
        h2 = _SSE_MUL(h1, vs);
838

Andreas Marek's avatar
Andreas Marek committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
        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);
859

860
#ifdef HAVE_SSE_INTRINSICS
861
        h2 = _SSE_SET1(hh[ldh+1]);
862 863
#endif
#ifdef HAVE_SPARC64_SSE
864
        h2 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
865 866
#endif

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

Andreas Marek's avatar
Andreas Marek committed
883 884
        for (i = 2; i < nb; i++)
        {
885
#ifdef HAVE_SSE_INTRINSICS
886 887
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
888 889
#endif
#ifdef HAVE_SPARC64_SSE
890 891
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
892 893
#endif

Andreas Marek's avatar
Andreas Marek committed
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
                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);
        }
910
#ifdef HAVE_SSE_INTRINSICS
911
        h1 = _SSE_SET1(hh[nb-1]);
912 913
#endif
#ifdef HAVE_SPARC64_SSE
914
        h1 = _SSE_SET(hh[nb-1], hh[nb-1]);
915 916
#endif

Andreas Marek's avatar
Andreas Marek committed
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
        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);
932 933 934 935 936 937 938 939 940 941 942 943 944
}

/**
 * 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
 */
945
#ifdef HAVE_SSE_INTRINSICS
946 947 948 949 950
#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)
951 952 953 954 955 956 957 958 959 960
#endif
#endif
#ifdef HAVE_SPARC64_SSE
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_8_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_16_SPARC64_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif

961 962
#endif
{
Andreas Marek's avatar
Andreas Marek committed
963 964 965 966 967
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [12 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
968 969

#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
970
        // Needed bit mask for floating point sign flip
971
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
972
        __SSE_DATATYPE sign = (__SSE_DATATYPE)_mm_set1_epi64x(0x8000000000000000LL);
973 974
#endif
#ifdef SINGLE_PRECISION_REAL
975 976
        __SSE_DATATYPE sign = _mm_castsi128_ps(_mm_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
#endif
977
#endif
Andreas Marek's avatar
Andreas Marek committed
978 979 980 981
        __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]);
982

983
#ifdef HAVE_SSE_INTRINSICS
984
        __SSE_DATATYPE h1 = _SSE_SET1(hh[ldh+1]);
985 986
#endif
#ifdef HAVE_SPARC64_SSE
987
        __SSE_DATATYPE h1 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
988 989
#endif

Andreas Marek's avatar
Andreas Marek committed
990
        __SSE_DATATYPE h2;
991

Andreas Marek's avatar
Andreas Marek committed
992 993 994 995 996 997 998 999 1000 1001
        __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++)
        {
1002
#ifdef HAVE_SSE_INTRINSICS
1003 1004
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
1005 1006
#endif
#ifdef HAVE_SPARC64_SSE
1007 1008
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
1009
#endif
1010 1011


Andreas Marek's avatar
Andreas Marek committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
                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));
        }
1025
#ifdef HAVE_SSE_INTRINSICS
1026
        h1 = _SSE_SET1(hh[nb-1]);
1027 1028
#endif
#ifdef HAVE_SPARC64_SSE
1029
        h1 = _SSE_SET(hh[nb-1], hh[nb-1]);
1030
#endif
Andreas Marek's avatar
Andreas Marek committed
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
        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]
        /////////////////////////////////////////////////////
1042
#ifdef HAVE_SSE_INTRINSICS
1043 1044 1045
        __SSE_DATATYPE tau1 = _SSE_SET1(hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET1(hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET1(s);
1046 1047
#endif
#ifdef HAVE_SPARC64_SSE
1048 1049 1050
        __SSE_DATATYPE tau1 = _SSE_SET(hh[0], hh[0]);
        __SSE_DATATYPE tau2 = _SSE_SET(hh[ldh], hh[ldh]);
        __SSE_DATATYPE vs = _SSE_SET(s, s);
1051
#endif
1052

1053
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
1054
        h1 = _SSE_XOR(tau1, sign);
1055 1056
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
1057
        h1 = _fjsp_neg_v2r8(tau1);
1058
#endif
Andreas Marek's avatar
Andreas Marek committed
1059 1060 1061 1062
        x1 = _SSE_MUL(x1, h1);
        x2 = _SSE_MUL(x2, h1);
        x3 = _SSE_MUL(x3, h1);
        x4 = _SSE_MUL(x4, h1);
1063
#ifdef HAVE_SSE_INTRINSICS
Andreas Marek's avatar
Andreas Marek committed
1064
        h1 = _SSE_XOR(tau2, sign);
1065 1066
#endif
#ifdef HAVE_SPARC64_SSE
Andreas Marek's avatar
Andreas Marek committed
1067
        h1 = _fjsp_neg_v2r8(tau2);
1068
#endif
Andreas Marek's avatar
Andreas Marek committed
1069
        h2 = _SSE_MUL(h1, vs);
1070

Andreas Marek's avatar
Andreas Marek committed
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
        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);
1087

1088
#ifdef HAVE_SSE_INTRINSICS
1089
        h2 = _SSE_SET1(hh[ldh+1]);
1090 1091
#endif
#ifdef HAVE_SPARC64_SSE
1092
        h2 = _SSE_SET(hh[ldh+1], hh[ldh+1]);
1093 1094
#endif

Andreas Marek's avatar
Andreas Marek committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
        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);
1107

Andreas Marek's avatar
Andreas Marek committed
1108 1109
        for (i = 2; i < nb; i++)
        {
1110
#ifdef HAVE_SSE_INTRINSICS
1111 1112
                h1 = _SSE_SET1(hh[i-1]);
                h2 = _SSE_SET1(hh[ldh+i]);
1113 1114
#endif
#ifdef HAVE_SPARC64_SSE
1115 1116
                h1 = _SSE_SET(hh[i-1], hh[i-1]);
                h2 = _SSE_SET(hh[ldh+i], hh[ldh+i]);
1117 1118
#endif

1119

Andreas Marek's avatar
Andreas Marek committed
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
                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*