real_avx-avx2_2hv_template.c 61.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//    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
//      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
//    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
//      Informatik,
//    - Technische Universität München, Lehrstuhl für Informatik mit
//      Schwerpunkt Wissenschaftliches Rechnen ,
//    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
//    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
//      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
//      and
//    - 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
//    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
//
//    ELPA reflects a substantial effort on the part of the original
//    ELPA consortium, and we ask you to respect the spirit of the
//    license that we chose: i.e., please contribute any changes you
//    may have back to the original ELPA library distribution, and keep
//    any derivatives of ELPA under the same license that we chose for
//    the original distribution, the GNU Lesser General Public License.
//
//
// --------------------------------------------------------------------------------------------------
//
// This file contains the compute intensive kernels for the Householder transformations.
// It should be compiled with the highest possible optimization level.
//
// On Intel Nehalem or Intel Westmere or AMD Magny Cours use -O3 -msse3
// On Intel Sandy Bridge use -O3 -mavx
//
// Copyright of the original code rests with the authors inside the ELPA
// consortium. The copyright of any additional modifications shall rest
// with their original authors, but shall adhere to the licensing terms
// distributed along with the original code in the file "COPYING".
//
// Author: Alexander Heinecke (alexander.heinecke@mytum.de)
// Adapted for building a shared-library by Andreas Marek, MPCDF (andreas.marek@mpcdf.mpg.de)
// --------------------------------------------------------------------------------------------------

#include "config-f90.h"

#include <x86intrin.h>
66 67
#include <stdio.h>
#include <stdlib.h>
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

#define __forceinline __attribute__((always_inline)) static

#ifdef DOUBLE_PRECISION_REAL

#define offset 4
#define __AVX_DATATYPE __m256d
#define _AVX_LOAD _mm256_load_pd
#define _AVX_STORE _mm256_store_pd
#define _AVX_ADD _mm256_add_pd
#define _AVX_MUL _mm256_mul_pd
#define _AVX_BROADCAST _mm256_broadcast_sd
#define _AVX_XOR _mm256_xor_pd

#ifdef HAVE_AVX2
#ifdef __FMA4__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_macc_pd(a,b,c)
#endif

#ifdef __AVX2__
#define __ELPA_USE_FMA__
#define _mm256_FMA_pd(a,b,c) _mm256_fmadd_pd(a,b,c)
#endif
#endif

#define _AVX_FMA _mm256_FMA_pd

#endif /* DOUBLE_PRECISION_REAL */

#ifdef SINGLE_PRECISION_REAL

#define offset 8
#define __AVX_DATATYPE __m256
#define _AVX_LOAD _mm256_load_ps
#define _AVX_STORE _mm256_store_ps
#define _AVX_ADD _mm256_add_ps
#define _AVX_MUL _mm256_mul_ps
#define _AVX_BROADCAST _mm256_broadcast_ss
#define _AVX_XOR _mm256_xor_ps

#ifdef HAVE_AVX2
#ifdef __FMA4__
#define __ELPA_USE_FMA__
#define _mm256_FMA_ps(a,b,c) _mm256_macc_ps(a,b,c)
#endif

#ifdef __AVX2__
#define __ELPA_USE_FMA__
#define _mm256_FMA_ps(a,b,c) _mm256_fmadd_ps(a,b,c)
#endif
#endif

#define _AVX_FMA _mm256_FMA_ps
#endif /* SINGLE_PRECISION_REAL */

#ifdef DOUBLE_PRECISION_REAL
//Forward declaration
__forceinline void hh_trafo_kernel_4_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
__forceinline void hh_trafo_kernel_8_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
128
__forceinline void hh_trafo_kernel_12_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
129
__forceinline void hh_trafo_kernel_16_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
130
__forceinline void hh_trafo_kernel_20_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
131 132 133 134 135 136 137 138
__forceinline void hh_trafo_kernel_24_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s);
#endif

#ifdef SINGLE_PRECISION_REAL
//Forward declaration
__forceinline void hh_trafo_kernel_8_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_16_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_24_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
139 140 141
__forceinline void hh_trafo_kernel_32_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_40_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
__forceinline void hh_trafo_kernel_48_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
#endif

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

#ifdef DOUBLE_PRECISION_REAL
/*
!f>#if defined(HAVE_AVX) || defined(HAVE_AVX2)
!f> interface
!f>   subroutine double_hh_trafo_real_avx_avx2_2hv_double(q, hh, pnb, pnq, pldq, pldh) &
!f>                             bind(C, name="double_hh_trafo_real_avx_avx2_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)
!f>   end subroutine
!f> end interface
!f>#endif
*/
#endif
#ifdef SINGLE_PRECISION_REAL
/*
!f>#if defined(HAVE_AVX) || defined(HAVE_AVX2)
!f> interface
!f>   subroutine double_hh_trafo_real_avx_avx2_2hv_single(q, hh, pnb, pnq, pldq, pldh) &
!f>                             bind(C, name="double_hh_trafo_real_avx_avx2_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)
!f>   end subroutine
!f> end interface
!f>#endif
*/
#endif

#ifdef DOUBLE_PRECISION_REAL
void double_hh_trafo_real_avx_avx2_2hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
#ifdef SINGLE_PRECISION_REAL
void double_hh_trafo_real_avx_avx2_2hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
{
Andreas Marek's avatar
Andreas Marek committed
189 190 191 192 193 194
        int i;
        int nb = *pnb;
        int nq = *pldq;
        int ldq = *pldq;
        int ldh = *pldh;
        int worked_on;
195

Andreas Marek's avatar
Andreas Marek committed
196
        worked_on = 0;
197

Andreas Marek's avatar
Andreas Marek committed
198 199
        // calculating scalar product to compute
        // 2 householder vectors simultaneously
200
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
201
        double s = hh[(ldh)+1]*1.0;
202 203
#endif
#ifdef SINGLE_PRECISION_REAL
204
        float s = hh[(ldh)+1]*1.0f;
205
#endif
Andreas Marek's avatar
Andreas Marek committed
206 207 208 209 210
        #pragma ivdep
        for (i = 2; i < nb; i++)
        {
                s += hh[i-1] * hh[(i+ldh)];
        }
211

Andreas Marek's avatar
Andreas Marek committed
212
        // Production level kernel calls with padding
213
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
214 215 216 217 218
        for (i = 0; i < nq-20; i+=24)
        {
                hh_trafo_kernel_24_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 24;
        }
219 220
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
221 222
        for (i = 0; i < nq-40; i+=48)
        {
223
                hh_trafo_kernel_48_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
Andreas Marek's avatar
Andreas Marek committed
224 225
                worked_on += 48;
        }
226
#endif
227

Andreas Marek's avatar
Andreas Marek committed
228 229 230 231
        if (nq == i)
        {
                return;
        }
232
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
233 234 235 236 237
        if (nq-i == 20)
        {
                hh_trafo_kernel_20_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 20;
        }
238 239
#endif

240
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
241 242 243 244 245
        if (nq-i == 40)
        {
                hh_trafo_kernel_40_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 40;
        }
246 247 248
#endif


249
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
250 251 252 253 254
        if (nq-i == 16)
        {
                hh_trafo_kernel_16_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 16;
        }
255
#endif
256

257
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
258 259 260 261 262
        if (nq-i == 32)
        {
                hh_trafo_kernel_32_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 32;
        }
263 264 265
#endif


266
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
267 268 269 270 271
        if (nq-i == 12)
        {
                hh_trafo_kernel_12_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 12;
        }
272
#endif
273

274
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
275 276 277 278 279
        if (nq-i == 24)
        {
                hh_trafo_kernel_24_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 24;
        }
280 281
#endif

282
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
283 284 285 286 287
        if (nq-i == 8)
        {
                hh_trafo_kernel_8_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 8;
        }
288
#endif
289

290
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
291 292 293 294 295
        if (nq-i == 16)
        {
                hh_trafo_kernel_16_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 16;
        }
296 297
#endif

298
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
299 300 301 302 303
        if (nq-i == 4)
        {
                hh_trafo_kernel_4_AVX_2hv_double(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 4;
        }
304
#endif
305

306
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
307 308 309 310 311
        if (nq-i == 8)
        {
                hh_trafo_kernel_8_AVX_2hv_single(&q[i], hh, nb, ldq, ldh, s);
                worked_on += 8;
        }
312
#endif
313
#ifdef WITH_DEBUG
314
        if (worked_on != nq)
Andreas Marek's avatar
Andreas Marek committed
315 316 317 318
        {
           printf("Error in real avx/avx2 BLOCK 2 kernel \n");
           abort();
        }
319
#endif
320
}
321

322 323
/**
 * Unrolled kernel that computes
324
#ifdef DOUBLE_PRECISION_REAL
325
 * 24 rows of Q simultaneously, a
326 327 328 329
#endif
#ifdef SINGLE_PRECISION_REAL
 * 48 rows of Q simultaneously, a
#endif
330 331 332 333 334 335 336
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_24_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
#endif
#ifdef SINGLE_PRECISION_REAL
337
 __forceinline void hh_trafo_kernel_48_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
338 339
#endif
{
Andreas Marek's avatar
Andreas Marek committed
340 341 342 343 344 345
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [24 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
        // Needed bit mask for floating point sign flip
346
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
347
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi64x(0x8000000000000000);
348 349
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
350
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi32(0x80000000);
351 352
#endif

Andreas Marek's avatar
Andreas Marek committed
353 354 355 356 357 358
        __AVX_DATATYPE x1 = _AVX_LOAD(&q[ldq]);
        __AVX_DATATYPE x2 = _AVX_LOAD(&q[ldq+offset]);
        __AVX_DATATYPE x3 = _AVX_LOAD(&q[ldq+2*offset]);
        __AVX_DATATYPE x4 = _AVX_LOAD(&q[ldq+3*offset]);
        __AVX_DATATYPE x5 = _AVX_LOAD(&q[ldq+4*offset]);
        __AVX_DATATYPE x6 = _AVX_LOAD(&q[ldq+5*offset]);
359

Andreas Marek's avatar
Andreas Marek committed
360 361
        __AVX_DATATYPE h1 = _AVX_BROADCAST(&hh[ldh+1]);
        __AVX_DATATYPE h2;
362 363

#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
364 365 366 367 368 369 370 371 372 373 374 375
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_FMA(x1, h1, q1);
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_FMA(x2, h1, q2);
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_FMA(x3, h1, q3);
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_FMA(x4, h1, q4);
        __AVX_DATATYPE q5 = _AVX_LOAD(&q[4*offset]);
        __AVX_DATATYPE y5 = _AVX_FMA(x5, h1, q5);
        __AVX_DATATYPE q6 = _AVX_LOAD(&q[5*offset]);
        __AVX_DATATYPE y6 = _AVX_FMA(x6, h1, q6);
376 377

#else
Andreas Marek's avatar
Andreas Marek committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
        __AVX_DATATYPE q5 = _AVX_LOAD(&q[4*offset]);
        __AVX_DATATYPE y5 = _AVX_ADD(q5, _AVX_MUL(x5, h1));
        __AVX_DATATYPE q6 = _AVX_LOAD(&q[5*offset]);
        __AVX_DATATYPE y6 = _AVX_ADD(q6, _AVX_MUL(x6, h1));

#endif

        for(i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
397
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_FMA(q1, h1, x1);
                y1 = _AVX_FMA(q1, h2, y1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_FMA(q2, h1, x2);
                y2 = _AVX_FMA(q2, h2, y2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_FMA(q3, h1, x3);
                y3 = _AVX_FMA(q3, h2, y3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_FMA(q4, h1, x4);
                y4 = _AVX_FMA(q4, h2, y4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                x5 = _AVX_FMA(q5, h1, x5);
                y5 = _AVX_FMA(q5, h2, y5);
                q6 = _AVX_LOAD(&q[(i*ldq)+5*offset]);
                x6 = _AVX_FMA(q6, h1, x6);
                y6 = _AVX_FMA(q6, h2, y6);
416 417

#else
Andreas Marek's avatar
Andreas Marek committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
                y1 = _AVX_ADD(y1, _AVX_MUL(q1,h2));
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
                y2 = _AVX_ADD(y2, _AVX_MUL(q2,h2));
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
                y3 = _AVX_ADD(y3, _AVX_MUL(q3,h2));
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));
                y4 = _AVX_ADD(y4, _AVX_MUL(q4,h2));
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                x5 = _AVX_ADD(x5, _AVX_MUL(q5,h1));
                y5 = _AVX_ADD(y5, _AVX_MUL(q5,h2));
                q6 = _AVX_LOAD(&q[(i*ldq)+5*offset]);
                x6 = _AVX_ADD(x6, _AVX_MUL(q6,h1));
                y6 = _AVX_ADD(y6, _AVX_MUL(q6,h2));

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
441
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
442 443 444 445 446 447 448 449 450 451 452 453
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_FMA(q1, h1, x1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_FMA(q2, h1, x2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_FMA(q3, h1, x3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_FMA(q4, h1, x4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        x5 = _AVX_FMA(q5, h1, x5);
        q6 = _AVX_LOAD(&q[(nb*ldq)+5*offset]);
        x6 = _AVX_FMA(q6, h1, x6);
454 455

#else
Andreas Marek's avatar
Andreas Marek committed
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        x5 = _AVX_ADD(x5, _AVX_MUL(q5,h1));
        q6 = _AVX_LOAD(&q[(nb*ldq)+5*offset]);
        x6 = _AVX_ADD(x6, _AVX_MUL(q6,h1));

#endif

        /////////////////////////////////////////////////////
        // Rank-2 update of Q [24 x nb+1]
        /////////////////////////////////////////////////////

        __AVX_DATATYPE tau1 = _AVX_BROADCAST(hh);
        __AVX_DATATYPE tau2 = _AVX_BROADCAST(&hh[ldh]);
        __AVX_DATATYPE vs = _AVX_BROADCAST(&s);

        h1 = _AVX_XOR(tau1, sign);
        x1 = _AVX_MUL(x1, h1);
        x2 = _AVX_MUL(x2, h1);
        x3 = _AVX_MUL(x3, h1);
        x4 = _AVX_MUL(x4, h1);
        x5 = _AVX_MUL(x5, h1);
        x6 = _AVX_MUL(x6, h1);

        h1 = _AVX_XOR(tau2, sign);
        h2 = _AVX_MUL(h1, vs);
489
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
490 491 492 493 494 495
        y1 = _AVX_FMA(y1, h1, _AVX_MUL(x1,h2));
        y2 = _AVX_FMA(y2, h1, _AVX_MUL(x2,h2));
        y3 = _AVX_FMA(y3, h1, _AVX_MUL(x3,h2));
        y4 = _AVX_FMA(y4, h1, _AVX_MUL(x4,h2));
        y5 = _AVX_FMA(y5, h1, _AVX_MUL(x5,h2));
        y6 = _AVX_FMA(y6, h1, _AVX_MUL(x6,h2));
496 497

#else
Andreas Marek's avatar
Andreas Marek committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
        y1 = _AVX_ADD(_AVX_MUL(y1,h1), _AVX_MUL(x1,h2));
        y2 = _AVX_ADD(_AVX_MUL(y2,h1), _AVX_MUL(x2,h2));
        y3 = _AVX_ADD(_AVX_MUL(y3,h1), _AVX_MUL(x3,h2));
        y4 = _AVX_ADD(_AVX_MUL(y4,h1), _AVX_MUL(x4,h2));
        y5 = _AVX_ADD(_AVX_MUL(y5,h1), _AVX_MUL(x5,h2));
        y6 = _AVX_ADD(_AVX_MUL(y6,h1), _AVX_MUL(x6,h2));

#endif

        q1 = _AVX_LOAD(q);
        q1 = _AVX_ADD(q1, y1);
        _AVX_STORE(q,q1);
        q2 = _AVX_LOAD(&q[offset]);
        q2 = _AVX_ADD(q2, y2);
        _AVX_STORE(&q[offset],q2);
        q3 = _AVX_LOAD(&q[2*offset]);
        q3 = _AVX_ADD(q3, y3);
        _AVX_STORE(&q[2*offset],q3);
        q4 = _AVX_LOAD(&q[3*offset]);
        q4 = _AVX_ADD(q4, y4);
        _AVX_STORE(&q[3*offset],q4);
        q5 = _AVX_LOAD(&q[4*offset]);
        q5 = _AVX_ADD(q5, y5);
        _AVX_STORE(&q[4*offset],q5);
        q6 = _AVX_LOAD(&q[5*offset]);
        q6 = _AVX_ADD(q6, y6);
        _AVX_STORE(&q[5*offset],q6);

        h2 = _AVX_BROADCAST(&hh[ldh+1]);
527
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_FMA(y1, h2, x1));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_FMA(y2, h2, x2));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_FMA(y3, h2, x3));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_FMA(y4, h2, x4));
        _AVX_STORE(&q[ldq+3*offset],q4);
        q5 = _AVX_LOAD(&q[ldq+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_FMA(y5, h2, x5));
        _AVX_STORE(&q[ldq+4*offset],q5);
        q6 = _AVX_LOAD(&q[ldq+5*offset]);
        q6 = _AVX_ADD(q6, _AVX_FMA(y6, h2, x6));
        _AVX_STORE(&q[ldq+5*offset],q6);
546 547

#else
Andreas Marek's avatar
Andreas Marek committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_ADD(x1, _AVX_MUL(y1, h2)));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_ADD(x2, _AVX_MUL(y2, h2)));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_ADD(x3, _AVX_MUL(y3, h2)));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_ADD(x4, _AVX_MUL(y4, h2)));
        _AVX_STORE(&q[ldq+3*offset],q4);
        q5 = _AVX_LOAD(&q[ldq+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_ADD(x5, _AVX_MUL(y5, h2)));
        _AVX_STORE(&q[ldq+4*offset],q5);
        q6 = _AVX_LOAD(&q[ldq+5*offset]);
        q6 = _AVX_ADD(q6, _AVX_ADD(x6, _AVX_MUL(y6, h2)));
        _AVX_STORE(&q[ldq+5*offset],q6);

#endif

        for (i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
573
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_FMA(x1, h1, q1);
                q1 = _AVX_FMA(y1, h2, q1);
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_FMA(x2, h1, q2);
                q2 = _AVX_FMA(y2, h2, q2);
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_FMA(x3, h1, q3);
                q3 = _AVX_FMA(y3, h2, q3);
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_FMA(x4, h1, q4);
                q4 = _AVX_FMA(y4, h2, q4);
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                q5 = _AVX_FMA(x5, h1, q5);
                q5 = _AVX_FMA(y5, h2, q5);
                _AVX_STORE(&q[(i*ldq)+4*offset],q5);
                q6 = _AVX_LOAD(&q[(i*ldq)+5*offset]);
                q6 = _AVX_FMA(x6, h1, q6);
                q6 = _AVX_FMA(y6, h2, q6);
                _AVX_STORE(&q[(i*ldq)+5*offset],q6);
598 599

#else
Andreas Marek's avatar
Andreas Marek committed
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_ADD(q1, _AVX_ADD(_AVX_MUL(x1,h1), _AVX_MUL(y1, h2)));
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_ADD(q2, _AVX_ADD(_AVX_MUL(x2,h1), _AVX_MUL(y2, h2)));
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_ADD(q3, _AVX_ADD(_AVX_MUL(x3,h1), _AVX_MUL(y3, h2)));
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_ADD(q4, _AVX_ADD(_AVX_MUL(x4,h1), _AVX_MUL(y4, h2)));
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                q5 = _AVX_ADD(q5, _AVX_ADD(_AVX_MUL(x5,h1), _AVX_MUL(y5, h2)));
                _AVX_STORE(&q[(i*ldq)+4*offset],q5);
                q6 = _AVX_LOAD(&q[(i*ldq)+5*offset]);
                q6 = _AVX_ADD(q6, _AVX_ADD(_AVX_MUL(x6,h1), _AVX_MUL(y6, h2)));
                _AVX_STORE(&q[(i*ldq)+5*offset],q6);

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
623
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_FMA(x1, h1, q1);
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_FMA(x2, h1, q2);
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_FMA(x3, h1, q3);
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_FMA(x4, h1, q4);
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        q5 = _AVX_FMA(x5, h1, q5);
        _AVX_STORE(&q[(nb*ldq)+4*offset],q5);
        q6 = _AVX_LOAD(&q[(nb*ldq)+5*offset]);
        q6 = _AVX_FMA(x6, h1, q6);
        _AVX_STORE(&q[(nb*ldq)+5*offset],q6);
642 643

#else
Andreas Marek's avatar
Andreas Marek committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_MUL(x5, h1));
        _AVX_STORE(&q[(nb*ldq)+4*offset],q5);
        q6 = _AVX_LOAD(&q[(nb*ldq)+5*offset]);
        q6 = _AVX_ADD(q6, _AVX_MUL(x6, h1));
        _AVX_STORE(&q[(nb*ldq)+5*offset],q6);
662 663 664 665

#endif
}

666

667 668
/**
 * Unrolled kernel that computes
669 670 671 672 673 674
#ifdef DOUBLE_PRECISION_REAL
 * 20 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 40 rows of Q simultaneously, a
#endif
675 676 677 678
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
679
 __forceinline void hh_trafo_kernel_20_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
680 681
#endif
#ifdef SINGLE_PRECISION_REAL
682
 __forceinline void hh_trafo_kernel_40_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
683 684
#endif
{
Andreas Marek's avatar
Andreas Marek committed
685 686 687 688 689 690
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [24 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
        // Needed bit mask for floating point sign flip
691
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
692
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi64x(0x8000000000000000);
693 694
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
695
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi32(0x80000000);
696 697
#endif

Andreas Marek's avatar
Andreas Marek committed
698 699 700 701 702
        __AVX_DATATYPE x1 = _AVX_LOAD(&q[ldq]);
        __AVX_DATATYPE x2 = _AVX_LOAD(&q[ldq+offset]);
        __AVX_DATATYPE x3 = _AVX_LOAD(&q[ldq+2*offset]);
        __AVX_DATATYPE x4 = _AVX_LOAD(&q[ldq+3*offset]);
        __AVX_DATATYPE x5 = _AVX_LOAD(&q[ldq+4*offset]);
703

Andreas Marek's avatar
Andreas Marek committed
704 705
        __AVX_DATATYPE h1 = _AVX_BROADCAST(&hh[ldh+1]);
        __AVX_DATATYPE h2;
706 707

#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
708 709 710 711 712 713 714 715 716 717
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_FMA(x1, h1, q1);
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_FMA(x2, h1, q2);
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_FMA(x3, h1, q3);
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_FMA(x4, h1, q4);
        __AVX_DATATYPE q5 = _AVX_LOAD(&q[4*offset]);
        __AVX_DATATYPE y5 = _AVX_FMA(x5, h1, q5);
718 719

#else
Andreas Marek's avatar
Andreas Marek committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
        __AVX_DATATYPE q5 = _AVX_LOAD(&q[4*offset]);
        __AVX_DATATYPE y5 = _AVX_ADD(q5, _AVX_MUL(x5, h1));

#endif

        for(i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
737
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_FMA(q1, h1, x1);
                y1 = _AVX_FMA(q1, h2, y1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_FMA(q2, h1, x2);
                y2 = _AVX_FMA(q2, h2, y2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_FMA(q3, h1, x3);
                y3 = _AVX_FMA(q3, h2, y3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_FMA(q4, h1, x4);
                y4 = _AVX_FMA(q4, h2, y4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                x5 = _AVX_FMA(q5, h1, x5);
                y5 = _AVX_FMA(q5, h2, y5);
753 754

#else
Andreas Marek's avatar
Andreas Marek committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
                y1 = _AVX_ADD(y1, _AVX_MUL(q1,h2));
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
                y2 = _AVX_ADD(y2, _AVX_MUL(q2,h2));
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
                y3 = _AVX_ADD(y3, _AVX_MUL(q3,h2));
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));
                y4 = _AVX_ADD(y4, _AVX_MUL(q4,h2));
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                x5 = _AVX_ADD(x5, _AVX_MUL(q5,h1));
                y5 = _AVX_ADD(y5, _AVX_MUL(q5,h2));

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
775
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
776 777 778 779 780 781 782 783 784 785
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_FMA(q1, h1, x1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_FMA(q2, h1, x2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_FMA(q3, h1, x3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_FMA(q4, h1, x4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        x5 = _AVX_FMA(q5, h1, x5);
786 787

#else
Andreas Marek's avatar
Andreas Marek committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        x5 = _AVX_ADD(x5, _AVX_MUL(q5,h1));

#endif

        /////////////////////////////////////////////////////
        // Rank-2 update of Q [24 x nb+1]
        /////////////////////////////////////////////////////

        __AVX_DATATYPE tau1 = _AVX_BROADCAST(hh);
        __AVX_DATATYPE tau2 = _AVX_BROADCAST(&hh[ldh]);
        __AVX_DATATYPE vs = _AVX_BROADCAST(&s);

        h1 = _AVX_XOR(tau1, sign);
        x1 = _AVX_MUL(x1, h1);
        x2 = _AVX_MUL(x2, h1);
        x3 = _AVX_MUL(x3, h1);
        x4 = _AVX_MUL(x4, h1);
        x5 = _AVX_MUL(x5, h1);

        h1 = _AVX_XOR(tau2, sign);
        h2 = _AVX_MUL(h1, vs);
818
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
819 820 821 822 823
        y1 = _AVX_FMA(y1, h1, _AVX_MUL(x1,h2));
        y2 = _AVX_FMA(y2, h1, _AVX_MUL(x2,h2));
        y3 = _AVX_FMA(y3, h1, _AVX_MUL(x3,h2));
        y4 = _AVX_FMA(y4, h1, _AVX_MUL(x4,h2));
        y5 = _AVX_FMA(y5, h1, _AVX_MUL(x5,h2));
824 825

#else
Andreas Marek's avatar
Andreas Marek committed
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
        y1 = _AVX_ADD(_AVX_MUL(y1,h1), _AVX_MUL(x1,h2));
        y2 = _AVX_ADD(_AVX_MUL(y2,h1), _AVX_MUL(x2,h2));
        y3 = _AVX_ADD(_AVX_MUL(y3,h1), _AVX_MUL(x3,h2));
        y4 = _AVX_ADD(_AVX_MUL(y4,h1), _AVX_MUL(x4,h2));
        y5 = _AVX_ADD(_AVX_MUL(y5,h1), _AVX_MUL(x5,h2));

#endif

        q1 = _AVX_LOAD(q);
        q1 = _AVX_ADD(q1, y1);
        _AVX_STORE(q,q1);
        q2 = _AVX_LOAD(&q[offset]);
        q2 = _AVX_ADD(q2, y2);
        _AVX_STORE(&q[offset],q2);
        q3 = _AVX_LOAD(&q[2*offset]);
        q3 = _AVX_ADD(q3, y3);
        _AVX_STORE(&q[2*offset],q3);
        q4 = _AVX_LOAD(&q[3*offset]);
        q4 = _AVX_ADD(q4, y4);
        _AVX_STORE(&q[3*offset],q4);
        q5 = _AVX_LOAD(&q[4*offset]);
        q5 = _AVX_ADD(q5, y5);
        _AVX_STORE(&q[4*offset],q5);

        h2 = _AVX_BROADCAST(&hh[ldh+1]);
851
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_FMA(y1, h2, x1));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_FMA(y2, h2, x2));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_FMA(y3, h2, x3));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_FMA(y4, h2, x4));
        _AVX_STORE(&q[ldq+3*offset],q4);
        q5 = _AVX_LOAD(&q[ldq+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_FMA(y5, h2, x5));
        _AVX_STORE(&q[ldq+4*offset],q5);
867 868

#else
Andreas Marek's avatar
Andreas Marek committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_ADD(x1, _AVX_MUL(y1, h2)));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_ADD(x2, _AVX_MUL(y2, h2)));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_ADD(x3, _AVX_MUL(y3, h2)));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_ADD(x4, _AVX_MUL(y4, h2)));
        _AVX_STORE(&q[ldq+3*offset],q4);
        q5 = _AVX_LOAD(&q[ldq+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_ADD(x5, _AVX_MUL(y5, h2)));
        _AVX_STORE(&q[ldq+4*offset],q5);

#endif

        for (i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
891
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_FMA(x1, h1, q1);
                q1 = _AVX_FMA(y1, h2, q1);
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_FMA(x2, h1, q2);
                q2 = _AVX_FMA(y2, h2, q2);
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_FMA(x3, h1, q3);
                q3 = _AVX_FMA(y3, h2, q3);
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_FMA(x4, h1, q4);
                q4 = _AVX_FMA(y4, h2, q4);
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                q5 = _AVX_FMA(x5, h1, q5);
                q5 = _AVX_FMA(y5, h2, q5);
                _AVX_STORE(&q[(i*ldq)+4*offset],q5);
912 913

#else
Andreas Marek's avatar
Andreas Marek committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_ADD(q1, _AVX_ADD(_AVX_MUL(x1,h1), _AVX_MUL(y1, h2)));
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_ADD(q2, _AVX_ADD(_AVX_MUL(x2,h1), _AVX_MUL(y2, h2)));
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_ADD(q3, _AVX_ADD(_AVX_MUL(x3,h1), _AVX_MUL(y3, h2)));
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_ADD(q4, _AVX_ADD(_AVX_MUL(x4,h1), _AVX_MUL(y4, h2)));
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);
                q5 = _AVX_LOAD(&q[(i*ldq)+4*offset]);
                q5 = _AVX_ADD(q5, _AVX_ADD(_AVX_MUL(x5,h1), _AVX_MUL(y5, h2)));
                _AVX_STORE(&q[(i*ldq)+4*offset],q5);

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
934
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_FMA(x1, h1, q1);
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_FMA(x2, h1, q2);
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_FMA(x3, h1, q3);
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_FMA(x4, h1, q4);
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        q5 = _AVX_FMA(x5, h1, q5);
        _AVX_STORE(&q[(nb*ldq)+4*offset],q5);
950 951

#else
Andreas Marek's avatar
Andreas Marek committed
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
        q5 = _AVX_LOAD(&q[(nb*ldq)+4*offset]);
        q5 = _AVX_ADD(q5, _AVX_MUL(x5, h1));
        _AVX_STORE(&q[(nb*ldq)+4*offset],q5);
967 968 969 970 971 972

#endif
}

/**
 * Unrolled kernel that computes
973 974 975 976 977 978
#ifdef DOUBLE_PRECISION_REAL
 * 16 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 32 rows of Q simultaneously, a
#endif
979 980 981 982
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
983
 __forceinline void hh_trafo_kernel_16_AVX_2hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s)
984 985
#endif
#ifdef SINGLE_PRECISION_REAL
986
 __forceinline void hh_trafo_kernel_32_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
987 988
#endif
{
Andreas Marek's avatar
Andreas Marek committed
989 990 991 992 993 994
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [16 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
        // Needed bit mask for floating point sign flip
995
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
996
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi64x(0x8000000000000000);
997 998
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
999
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi32(0x80000000);
1000 1001
#endif

Andreas Marek's avatar
Andreas Marek committed
1002 1003 1004 1005
        __AVX_DATATYPE x1 = _AVX_LOAD(&q[ldq]);
        __AVX_DATATYPE x2 = _AVX_LOAD(&q[ldq+offset]);
        __AVX_DATATYPE x3 = _AVX_LOAD(&q[ldq+2*offset]);
        __AVX_DATATYPE x4 = _AVX_LOAD(&q[ldq+3*offset]);
1006

Andreas Marek's avatar
Andreas Marek committed
1007 1008
        __AVX_DATATYPE h1 = _AVX_BROADCAST(&hh[ldh+1]);
        __AVX_DATATYPE h2;
1009 1010

#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1011 1012 1013 1014 1015 1016 1017 1018
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_FMA(x1, h1, q1);
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_FMA(x2, h1, q2);
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_FMA(x3, h1, q3);
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_FMA(x4, h1, q4);
1019 1020

#else
Andreas Marek's avatar
Andreas Marek committed
1021 1022 1023 1024 1025 1026 1027 1028
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        __AVX_DATATYPE q4 = _AVX_LOAD(&q[3*offset]);
        __AVX_DATATYPE y4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
1029 1030 1031

#endif

Andreas Marek's avatar
Andreas Marek committed
1032 1033 1034 1035
        for(i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
1036
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_FMA(q1, h1, x1);
                y1 = _AVX_FMA(q1, h2, y1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_FMA(q2, h1, x2);
                y2 = _AVX_FMA(q2, h2, y2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_FMA(q3, h1, x3);
                y3 = _AVX_FMA(q3, h2, y3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_FMA(q4, h1, x4);
                y4 = _AVX_FMA(q4, h2, y4);
1049 1050

#else
Andreas Marek's avatar
Andreas Marek committed
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
                y1 = _AVX_ADD(y1, _AVX_MUL(q1,h2));
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
                y2 = _AVX_ADD(y2, _AVX_MUL(q2,h2));
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
                y3 = _AVX_ADD(y3, _AVX_MUL(q3,h2));
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));
                y4 = _AVX_ADD(y4, _AVX_MUL(q4,h2));

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
1068
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1069 1070 1071 1072 1073 1074 1075 1076
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_FMA(q1, h1, x1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_FMA(q2, h1, x2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_FMA(q3, h1, x3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_FMA(q4, h1, x4);
1077 1078

#else
Andreas Marek's avatar
Andreas Marek committed
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        x4 = _AVX_ADD(x4, _AVX_MUL(q4,h1));

#endif

        /////////////////////////////////////////////////////
        // Rank-2 update of Q [16 x nb+1]
        /////////////////////////////////////////////////////

        __AVX_DATATYPE tau1 = _AVX_BROADCAST(hh);
        __AVX_DATATYPE tau2 = _AVX_BROADCAST(&hh[ldh]);
        __AVX_DATATYPE vs = _AVX_BROADCAST(&s);

        h1 = _AVX_XOR(tau1, sign);
        x1 = _AVX_MUL(x1, h1);
        x2 = _AVX_MUL(x2, h1);
        x3 = _AVX_MUL(x3, h1);
        x4 = _AVX_MUL(x4, h1);
        h1 = _AVX_XOR(tau2, sign);
        h2 = _AVX_MUL(h1, vs);
1105
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1106 1107 1108 1109
        y1 = _AVX_FMA(y1, h1, _AVX_MUL(x1,h2));
        y2 = _AVX_FMA(y2, h1, _AVX_MUL(x2,h2));
        y3 = _AVX_FMA(y3, h1, _AVX_MUL(x3,h2));
        y4 = _AVX_FMA(y4, h1, _AVX_MUL(x4,h2));
1110 1111

#else
Andreas Marek's avatar
Andreas Marek committed
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
        y1 = _AVX_ADD(_AVX_MUL(y1,h1), _AVX_MUL(x1,h2));
        y2 = _AVX_ADD(_AVX_MUL(y2,h1), _AVX_MUL(x2,h2));
        y3 = _AVX_ADD(_AVX_MUL(y3,h1), _AVX_MUL(x3,h2));
        y4 = _AVX_ADD(_AVX_MUL(y4,h1), _AVX_MUL(x4,h2));

#endif

        q1 = _AVX_LOAD(q);
        q1 = _AVX_ADD(q1, y1);
        _AVX_STORE(q,q1);
        q2 = _AVX_LOAD(&q[offset]);
        q2 = _AVX_ADD(q2, y2);
        _AVX_STORE(&q[offset],q2);
        q3 = _AVX_LOAD(&q[2*offset]);
        q3 = _AVX_ADD(q3, y3);
        _AVX_STORE(&q[2*offset],q3);
        q4 = _AVX_LOAD(&q[3*offset]);
        q4 = _AVX_ADD(q4, y4);
        _AVX_STORE(&q[3*offset],q4);

        h2 = _AVX_BROADCAST(&hh[ldh+1]);
1133
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_FMA(y1, h2, x1));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_FMA(y2, h2, x2));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_FMA(y3, h2, x3));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_FMA(y4, h2, x4));
        _AVX_STORE(&q[ldq+3*offset],q4);
1146 1147

#else
Andreas Marek's avatar
Andreas Marek committed
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
        q1 = _AVX_LOAD(&q[ldq]);
        q1 = _AVX_ADD(q1, _AVX_ADD(x1, _AVX_MUL(y1, h2)));
        _AVX_STORE(&q[ldq],q1);
        q2 = _AVX_LOAD(&q[ldq+offset]);
        q2 = _AVX_ADD(q2, _AVX_ADD(x2, _AVX_MUL(y2, h2)));
        _AVX_STORE(&q[ldq+offset],q2);
        q3 = _AVX_LOAD(&q[ldq+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_ADD(x3, _AVX_MUL(y3, h2)));
        _AVX_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX_LOAD(&q[ldq+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_ADD(x4, _AVX_MUL(y4, h2)));
        _AVX_STORE(&q[ldq+3*offset],q4);

#endif

        for (i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
1167
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_FMA(x1, h1, q1);
                q1 = _AVX_FMA(y1, h2, q1);
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_FMA(x2, h1, q2);
                q2 = _AVX_FMA(y2, h2, q2);
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_FMA(x3, h1, q3);
                q3 = _AVX_FMA(y3, h2, q3);
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_FMA(x4, h1, q4);
                q4 = _AVX_FMA(y4, h2, q4);
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);
1184 1185

#else
Andreas Marek's avatar
Andreas Marek committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
                q1 = _AVX_LOAD(&q[i*ldq]);
                q1 = _AVX_ADD(q1, _AVX_ADD(_AVX_MUL(x1,h1), _AVX_MUL(y1, h2)));
                _AVX_STORE(&q[i*ldq],q1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                q2 = _AVX_ADD(q2, _AVX_ADD(_AVX_MUL(x2,h1), _AVX_MUL(y2, h2)));
                _AVX_STORE(&q[(i*ldq)+offset],q2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                q3 = _AVX_ADD(q3, _AVX_ADD(_AVX_MUL(x3,h1), _AVX_MUL(y3, h2)));
                _AVX_STORE(&q[(i*ldq)+2*offset],q3);
                q4 = _AVX_LOAD(&q[(i*ldq)+3*offset]);
                q4 = _AVX_ADD(q4, _AVX_ADD(_AVX_MUL(x4,h1), _AVX_MUL(y4, h2)));
                _AVX_STORE(&q[(i*ldq)+3*offset],q4);

#endif
        }

        h1 = _AVX_BROADCAST(&hh[nb-1]);
1203
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_FMA(x1, h1, q1);
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_FMA(x2, h1, q2);
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_FMA(x3, h1, q3);
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_FMA(x4, h1, q4);
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
1216 1217

#else
Andreas Marek's avatar
Andreas Marek committed
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
        q1 = _AVX_LOAD(&q[nb*ldq]);
        q1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        _AVX_STORE(&q[nb*ldq],q1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        q2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        _AVX_STORE(&q[(nb*ldq)+offset],q2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        q3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
        _AVX_STORE(&q[(nb*ldq)+2*offset],q3);
        q4 = _AVX_LOAD(&q[(nb*ldq)+3*offset]);
        q4 = _AVX_ADD(q4, _AVX_MUL(x4, h1));
        _AVX_STORE(&q[(nb*ldq)+3*offset],q4);
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252

#endif
}


/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 12 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 24 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 2 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
 __forceinline void hh_trafo_kernel_12_AVX_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_AVX_2hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s)
#endif
{
Andreas Marek's avatar
Andreas Marek committed
1253 1254 1255 1256 1257 1258
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [16 x nb+1] * hh
        // hh contains two householder vectors, with offset 1
        /////////////////////////////////////////////////////
        int i;
        // Needed bit mask for floating point sign flip
1259
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
1260
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi64x(0x8000000000000000);
1261 1262
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
1263
        __AVX_DATATYPE sign = (__AVX_DATATYPE)_mm256_set1_epi32(0x80000000);
1264 1265
#endif

Andreas Marek's avatar
Andreas Marek committed
1266 1267 1268
        __AVX_DATATYPE x1 = _AVX_LOAD(&q[ldq]);
        __AVX_DATATYPE x2 = _AVX_LOAD(&q[ldq+offset]);
        __AVX_DATATYPE x3 = _AVX_LOAD(&q[ldq+2*offset]);
1269

Andreas Marek's avatar
Andreas Marek committed
1270 1271
        __AVX_DATATYPE h1 = _AVX_BROADCAST(&hh[ldh+1]);
        __AVX_DATATYPE h2;
1272 1273

#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1274 1275 1276 1277 1278 1279
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_FMA(x1, h1, q1);
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_FMA(x2, h1, q2);
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_FMA(x3, h1, q3);
1280 1281

#else
Andreas Marek's avatar
Andreas Marek committed
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
        __AVX_DATATYPE q1 = _AVX_LOAD(q);
        __AVX_DATATYPE y1 = _AVX_ADD(q1, _AVX_MUL(x1, h1));
        __AVX_DATATYPE q2 = _AVX_LOAD(&q[offset]);
        __AVX_DATATYPE y2 = _AVX_ADD(q2, _AVX_MUL(x2, h1));
        __AVX_DATATYPE q3 = _AVX_LOAD(&q[2*offset]);
        __AVX_DATATYPE y3 = _AVX_ADD(q3, _AVX_MUL(x3, h1));
#endif

        for(i = 2; i < nb; i++)
        {
                h1 = _AVX_BROADCAST(&hh[i-1]);
                h2 = _AVX_BROADCAST(&hh[ldh+i]);
1294
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1295 1296 1297 1298 1299 1300 1301 1302 1303
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_FMA(q1, h1, x1);
                y1 = _AVX_FMA(q1, h2, y1);
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_FMA(q2, h1, x2);
                y2 = _AVX_FMA(q2, h2, y2);
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_FMA(q3, h1, x3);
                y3 = _AVX_FMA(q3, h2, y3);
1304 1305

#else
Andreas Marek's avatar
Andreas Marek committed
1306 1307 1308 1309 1310 1311 1312 1313 1314
                q1 = _AVX_LOAD(&q[i*ldq]);
                x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
                y1 = _AVX_ADD(y1, _AVX_MUL(q1,h2));
                q2 = _AVX_LOAD(&q[(i*ldq)+offset]);
                x2 = _AVX_ADD(x2, _AVX_MUL(q2,h1));
                y2 = _AVX_ADD(y2, _AVX_MUL(q2,h2));
                q3 = _AVX_LOAD(&q[(i*ldq)+2*offset]);
                x3 = _AVX_ADD(x3, _AVX_MUL(q3,h1));
                y3 = _AVX_ADD(y3, _AVX_MUL(q3,h2));
1315 1316

#endif
Andreas Marek's avatar
Andreas Marek committed
1317
        }
1318

Andreas Marek's avatar
Andreas Marek committed
1319
        h1 = _AVX_BROADCAST(&hh[nb-1]);
1320
#ifdef __ELPA_USE_FMA__
Andreas Marek's avatar
Andreas Marek committed
1321 1322 1323 1324 1325 1326
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_FMA(q1, h1, x1);
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_FMA(q2, h1, x2);
        q3 = _AVX_LOAD(&q[(nb*ldq)+2*offset]);
        x3 = _AVX_FMA(q3, h1, x3);
1327 1328

#else
Andreas Marek's avatar
Andreas Marek committed
1329 1330 1331 1332 1333 1334
        q1 = _AVX_LOAD(&q[nb*ldq]);
        x1 = _AVX_ADD(x1, _AVX_MUL(q1,h1));
        q2 = _AVX_LOAD(&q[(nb*ldq)+offset]);
        x2 = _AVX_ADD(x2