real_avx512_4hv_template.c 63.2 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
//    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.
//
// Author: Andreas Marek (andreas.marek@mpcdf.mpg.de)
// --------------------------------------------------------------------------------------------------
#include "config-f90.h"
#include <x86intrin.h>
Andreas Marek's avatar
Andreas Marek committed
49 50
#include <stdio.h>
#include <stdlib.h>
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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

#define __forceinline __attribute__((always_inline)) static

#ifdef DOUBLE_PRECISION_REAL
#define offset 8
#define __AVX512_DATATYPE __m512d
#define _AVX512_LOAD _mm512_load_pd
#define _AVX512_STORE _mm512_store_pd
#define _AVX512_SET1 _mm512_set1_pd
#define _AVX512_MUL _mm512_mul_pd
#define _AVX512_SUB _mm512_sub_pd

#ifdef HAVE_AVX512
#define __ELPA_USE_FMA__
#define _mm512_FMA_pd(a,b,c) _mm512_fmadd_pd(a,b,c)
#define _mm512_NFMA_pd(a,b,c) _mm512_fnmadd_pd(a,b,c)
#define _mm512_FMSUB_pd(a,b,c) _mm512_fmsub_pd(a,b,c)
#endif

#define _AVX512_FMA _mm512_FMA_pd
#define _AVX512_NFMA _mm512_NFMA_pd
#define _AVX512_FMSUB _mm512_FMSUB_pd
#endif /* DOUBLE_PRECISION_REAL */

#ifdef SINGLE_PRECISION_REAL
#define offset 16
#define __AVX512_DATATYPE __m512
#define _AVX512_LOAD _mm512_load_ps
#define _AVX512_STORE _mm512_store_ps
#define _AVX512_SET1 _mm512_set1_ps
#define _AVX512_MUL _mm512_mul_ps
#define _AVX512_SUB _mm512_sub_ps

#ifdef HAVE_AVX512
#define __ELPA_USE_FMA__
#define _mm512_FMA_ps(a,b,c) _mm512_fmadd_ps(a,b,c)
#define _mm512_NFMA_ps(a,b,c) _mm512_fnmadd_ps(a,b,c)
#define _mm512_FMSUB_ps(a,b,c) _mm512_fmsub_ps(a,b,c)
#endif

#define _AVX512_FMA _mm512_FMA_ps
#define _AVX512_NFMA _mm512_NFMA_ps
#define _AVX512_FMSUB _mm512_FMSUB_ps
#endif /* SINGLE_PRECISION_REAL */

#ifdef DOUBLE_PRECISION_REAL
//Forward declaration
__forceinline void hh_trafo_kernel_8_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_16_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_24_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);
__forceinline void hh_trafo_kernel_32_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4);


void quad_hh_trafo_real_avx512_4hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif
#ifdef SINGLE_PRECISION_REAL
//Forward declaration
Andreas Marek's avatar
Andreas Marek committed
108 109 110 111
__forceinline void hh_trafo_kernel_16_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_32_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_48_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
__forceinline void hh_trafo_kernel_64_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

void quad_hh_trafo_real_avx_avx2_4hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh);
#endif


#ifdef DOUBLE_PRECISION_REAL
/*
!f>#if defined(HAVE_AVX512)
!f> interface
!f>   subroutine quad_hh_trafo_real_avx512_4hv_double(q, hh, pnb, pnq, pldq, pldh) &
!f>                             bind(C, name="quad_hh_trafo_real_avx512_4hv_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
/*
!f>#if defined(HAVE_AVX512)
!f> interface
!f>   subroutine quad_hh_trafo_real_avx512_4hv_single(q, hh, pnb, pnq, pldq, pldh) &
!f>                             bind(C, name="quad_hh_trafo_real_avx512_4hv_single")
!f>     use, intrinsic :: iso_c_binding
!f>     integer(kind=c_int)     :: pnb, pnq, pldq, pldh
!f>     type(c_ptr), value      :: q
!f>     real(kind=c_float)      :: hh(pnb,6)
!f>   end subroutine
!f> end interface
!f>#endif
*/
#ifdef SINGLE_PRECISION_REAL

#endif

#ifdef DOUBLE_PRECISION_REAL
void quad_hh_trafo_real_avx512_4hv_double(double* q, double* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
#ifdef SINGLE_PRECISION_REAL
void quad_hh_trafo_real_avx512_4hv_single(float* q, float* hh, int* pnb, int* pnq, int* pldq, int* pldh)
#endif
{
Andreas Marek's avatar
Andreas Marek committed
156 157 158 159 160 161
        int i;
        int nb = *pnb;
        int nq = *pldq;
        int ldq = *pldq;
        int ldh = *pldh;
        int worked_on;
Andreas Marek's avatar
Andreas Marek committed
162

Andreas Marek's avatar
Andreas Marek committed
163
        worked_on = 0;
164

Andreas Marek's avatar
Andreas Marek committed
165 166
        // calculating scalar products to compute
        // 4 householder vectors simultaneously
167
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
168 169 170 171 172 173
        double s_1_2 = hh[(ldh)+1];
        double s_1_3 = hh[(ldh*2)+2];
        double s_2_3 = hh[(ldh*2)+1];
        double s_1_4 = hh[(ldh*3)+3];
        double s_2_4 = hh[(ldh*3)+2];
        double s_3_4 = hh[(ldh*3)+1];
174 175
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
176 177 178 179 180 181
        float s_1_2 = hh[(ldh)+1];
        float s_1_3 = hh[(ldh*2)+2];
        float s_2_3 = hh[(ldh*2)+1];
        float s_1_4 = hh[(ldh*3)+3];
        float s_2_4 = hh[(ldh*3)+2];
        float s_3_4 = hh[(ldh*3)+1];
182 183 184
#endif


Andreas Marek's avatar
Andreas Marek committed
185 186 187 188 189
        // calculate scalar product of first and fourth householder Vector
        // loop counter = 2
        s_1_2 += hh[2-1] * hh[(2+ldh)];
        s_2_3 += hh[(ldh)+2-1] * hh[2+(ldh*2)];
        s_3_4 += hh[(ldh*2)+2-1] * hh[2+(ldh*3)];
190

Andreas Marek's avatar
Andreas Marek committed
191 192 193 194
        // loop counter = 3
        s_1_2 += hh[3-1] * hh[(3+ldh)];
        s_2_3 += hh[(ldh)+3-1] * hh[3+(ldh*2)];
        s_3_4 += hh[(ldh*2)+3-1] * hh[3+(ldh*3)];
195

Andreas Marek's avatar
Andreas Marek committed
196 197
        s_1_3 += hh[3-2] * hh[3+(ldh*2)];
        s_2_4 += hh[(ldh*1)+3-2] * hh[3+(ldh*3)];
198

Andreas Marek's avatar
Andreas Marek committed
199 200 201 202 203 204
        #pragma ivdep
        for (i = 4; i < nb; i++)
        {
                s_1_2 += hh[i-1] * hh[(i+ldh)];
                s_2_3 += hh[(ldh)+i-1] * hh[i+(ldh*2)];
                s_3_4 += hh[(ldh*2)+i-1] * hh[i+(ldh*3)];
205

Andreas Marek's avatar
Andreas Marek committed
206 207
                s_1_3 += hh[i-2] * hh[i+(ldh*2)];
                s_2_4 += hh[(ldh*1)+i-2] * hh[i+(ldh*3)];
208

Andreas Marek's avatar
Andreas Marek committed
209 210
                s_1_4 += hh[i-3] * hh[i+(ldh*3)];
        }
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-24; i+=32)
        {
                hh_trafo_kernel_32_AVX512_4hv_double(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 32;
        }
219 220
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
221 222 223 224 225
        for (i = 0; i < nq-48; i+=64)
        {
                hh_trafo_kernel_64_AVX512_4hv_single(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 64;
        }
226
#endif
Andreas Marek's avatar
Andreas Marek committed
227 228 229 230
        if (nq == i)
        {
                return;
        }
231
#ifdef DOUBLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
232 233 234 235 236
        if (nq-i == 24)
        {
                hh_trafo_kernel_24_AVX512_4hv_double(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 24;
        }
Andreas Marek's avatar
Andreas Marek committed
237 238 239
#endif

#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
240 241 242 243 244
        if (nq-i == 48)
        {
                hh_trafo_kernel_48_AVX512_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 48;
        }
Andreas Marek's avatar
Andreas Marek committed
245
#endif
246

Andreas Marek's avatar
Andreas Marek committed
247 248
#ifdef DOUBLE_PRECISION_REAL
        if (nq-i == 16)
Andreas Marek's avatar
Andreas Marek committed
249 250 251 252
        {
                hh_trafo_kernel_16_AVX512_4hv_double(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 16;
        }
253
#endif
254

255
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
256
        if (nq-i == 32)
Andreas Marek's avatar
Andreas Marek committed
257 258 259
        {
                hh_trafo_kernel_32_AVX512_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 32;
Andreas Marek's avatar
Andreas Marek committed
260 261 262 263 264
        }
#endif

#ifdef DOUBLE_PRECISION_REAL
        if (nq-i == 8)
Andreas Marek's avatar
Andreas Marek committed
265 266 267 268
        {
                hh_trafo_kernel_8_AVX512_4hv_double(&q[i], hh, nb, ldq, ldh, s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 8;
        }
269
#endif
Andreas Marek's avatar
Andreas Marek committed
270 271 272

#ifdef SINGLE_PRECISION_REAL
        if (nq-i == 16)
Andreas Marek's avatar
Andreas Marek committed
273 274 275
        {
                hh_trafo_kernel_16_AVX512_4hv_single(&q[i], hh, nb, ldq, ldh,  s_1_2, s_1_3, s_2_3, s_1_4, s_2_4, s_3_4);
                worked_on += 16;
Andreas Marek's avatar
Andreas Marek committed
276 277 278
        }
#endif

279
#ifdef WITH_DEBUG
Andreas Marek's avatar
Andreas Marek committed
280
        if (worked_on != nq)
Andreas Marek's avatar
Andreas Marek committed
281 282 283 284
        {
                 printf("Error in AVX512 real BLOCK 2 kernel \n");
                 abort();
        }
285
#endif
286 287 288 289
}

/**
 * Unrolled kernel that computes
Andreas Marek's avatar
Andreas Marek committed
290 291

#ifdef DOUBLE_PRECISION_REAL
292
 * 32 rows of Q simultaneously, a
Andreas Marek's avatar
Andreas Marek committed
293 294 295 296
#endif
#ifdef SINGLE_PRECISION_REAL
 * 64 rows of Q simultaneously, a
#endif
297 298 299
 * matrix Vector product with two householder
 * vectors + a rank 1 update is performed
 */
Andreas Marek's avatar
Andreas Marek committed
300 301

#ifdef DOUBLE_PRECISION_REAL
302
__forceinline void hh_trafo_kernel_32_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
Andreas Marek's avatar
Andreas Marek committed
303 304 305 306 307
#endif
#ifdef SINGLE_PRECISION_REAL
__forceinline void hh_trafo_kernel_64_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
#endif

308
{
Andreas Marek's avatar
Andreas Marek committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [4 x nb+3] * hh
        // hh contains four householder vectors
        /////////////////////////////////////////////////////
        int i;

        __AVX512_DATATYPE a1_1 = _AVX512_LOAD(&q[ldq*3]);
        __AVX512_DATATYPE a2_1 = _AVX512_LOAD(&q[ldq*2]);
        __AVX512_DATATYPE a3_1 = _AVX512_LOAD(&q[ldq]);
        __AVX512_DATATYPE a4_1 = _AVX512_LOAD(&q[0]);

        __AVX512_DATATYPE a1_2 = _AVX512_LOAD(&q[(ldq*3)+offset]);
        __AVX512_DATATYPE a2_2 = _AVX512_LOAD(&q[(ldq*2)+offset]);
        __AVX512_DATATYPE a3_2 = _AVX512_LOAD(&q[ldq+offset]);
        __AVX512_DATATYPE a4_2 = _AVX512_LOAD(&q[0+offset]);

        __AVX512_DATATYPE a1_3 = _AVX512_LOAD(&q[(ldq*3)+2*offset]);
        __AVX512_DATATYPE a2_3 = _AVX512_LOAD(&q[(ldq*2)+2*offset]);
        __AVX512_DATATYPE a3_3 = _AVX512_LOAD(&q[ldq+2*offset]);
        __AVX512_DATATYPE a4_3 = _AVX512_LOAD(&q[0+2*offset]);

        __AVX512_DATATYPE a1_4 = _AVX512_LOAD(&q[(ldq*3)+3*offset]);
        __AVX512_DATATYPE a2_4 = _AVX512_LOAD(&q[(ldq*2)+3*offset]);
        __AVX512_DATATYPE a3_4 = _AVX512_LOAD(&q[ldq+3*offset]);
        __AVX512_DATATYPE a4_4 = _AVX512_LOAD(&q[0+3*offset]);


        __AVX512_DATATYPE h_2_1 = _AVX512_SET1(hh[ldh+1]);
        __AVX512_DATATYPE h_3_2 = _AVX512_SET1(hh[(ldh*2)+1]);
        __AVX512_DATATYPE h_3_1 = _AVX512_SET1(hh[(ldh*2)+2]);
        __AVX512_DATATYPE h_4_3 = _AVX512_SET1(hh[(ldh*3)+1]);
        __AVX512_DATATYPE h_4_2 = _AVX512_SET1(hh[(ldh*3)+2]);
        __AVX512_DATATYPE h_4_1 = _AVX512_SET1(hh[(ldh*3)+3]);

        __AVX512_DATATYPE w1 = _AVX512_FMA(a3_1, h_4_3, a4_1);
        w1 = _AVX512_FMA(a2_1, h_4_2, w1);
        w1 = _AVX512_FMA(a1_1, h_4_1, w1);
        __AVX512_DATATYPE z1 = _AVX512_FMA(a2_1, h_3_2, a3_1);
        z1 = _AVX512_FMA(a1_1, h_3_1, z1);
        __AVX512_DATATYPE y1 = _AVX512_FMA(a1_1, h_2_1, a2_1);
        __AVX512_DATATYPE x1 = a1_1;

        __AVX512_DATATYPE w2 = _AVX512_FMA(a3_2, h_4_3, a4_2);
        w2 = _AVX512_FMA(a2_2, h_4_2, w2);
        w2 = _AVX512_FMA(a1_2, h_4_1, w2);
        __AVX512_DATATYPE z2 = _AVX512_FMA(a2_2, h_3_2, a3_2);
        z2 = _AVX512_FMA(a1_2, h_3_1, z2);
        __AVX512_DATATYPE y2 = _AVX512_FMA(a1_2, h_2_1, a2_2);
        __AVX512_DATATYPE x2 = a1_2;

        __AVX512_DATATYPE w3 = _AVX512_FMA(a3_3, h_4_3, a4_3);
        w3 = _AVX512_FMA(a2_3, h_4_2, w3);
        w3 = _AVX512_FMA(a1_3, h_4_1, w3);
        __AVX512_DATATYPE z3 = _AVX512_FMA(a2_3, h_3_2, a3_3);
        z3 = _AVX512_FMA(a1_3, h_3_1, z3);
        __AVX512_DATATYPE y3 = _AVX512_FMA(a1_3, h_2_1, a2_3);
        __AVX512_DATATYPE x3 = a1_3;

        __AVX512_DATATYPE w4 = _AVX512_FMA(a3_4, h_4_3, a4_4);
        w4 = _AVX512_FMA(a2_4, h_4_2, w4);
        w4 = _AVX512_FMA(a1_4, h_4_1, w4);
        __AVX512_DATATYPE z4 = _AVX512_FMA(a2_4, h_3_2, a3_4);
        z4 = _AVX512_FMA(a1_4, h_3_1, z4);
        __AVX512_DATATYPE y4 = _AVX512_FMA(a1_4, h_2_1, a2_4);
        __AVX512_DATATYPE x4 = a1_4;


        __AVX512_DATATYPE q1;
        __AVX512_DATATYPE q2;
        __AVX512_DATATYPE q3;
        __AVX512_DATATYPE q4;

        __AVX512_DATATYPE h1;
        __AVX512_DATATYPE h2;
        __AVX512_DATATYPE h3;
        __AVX512_DATATYPE h4;

        for(i = 4; i < nb; i++)
        {
                h1 = _AVX512_SET1(hh[i-3]);
                h2 = _AVX512_SET1(hh[ldh+i-2]);
                h3 = _AVX512_SET1(hh[(ldh*2)+i-1]);
                h4 = _AVX512_SET1(hh[(ldh*3)+i]);

                q1 = _AVX512_LOAD(&q[i*ldq]);
                q2 = _AVX512_LOAD(&q[(i*ldq)+offset]);
                q3 = _AVX512_LOAD(&q[(i*ldq)+2*offset]);
                q4 = _AVX512_LOAD(&q[(i*ldq)+3*offset]);

                x1 = _AVX512_FMA(q1, h1, x1);
                y1 = _AVX512_FMA(q1, h2, y1);
                z1 = _AVX512_FMA(q1, h3, z1);
                w1 = _AVX512_FMA(q1, h4, w1);

                x2 = _AVX512_FMA(q2, h1, x2);
                y2 = _AVX512_FMA(q2, h2, y2);
                z2 = _AVX512_FMA(q2, h3, z2);
                w2 = _AVX512_FMA(q2, h4, w2);

                x3 = _AVX512_FMA(q3, h1, x3);
                y3 = _AVX512_FMA(q3, h2, y3);
                z3 = _AVX512_FMA(q3, h3, z3);
                w3 = _AVX512_FMA(q3, h4, w3);

                x4 = _AVX512_FMA(q4, h1, x4);
                y4 = _AVX512_FMA(q4, h2, y4);
                z4 = _AVX512_FMA(q4, h3, z4);
                w4 = _AVX512_FMA(q4, h4, w4);

        }

        h1 = _AVX512_SET1(hh[nb-3]);
        h2 = _AVX512_SET1(hh[ldh+nb-2]);
        h3 = _AVX512_SET1(hh[(ldh*2)+nb-1]);

        q1 = _AVX512_LOAD(&q[nb*ldq]);
        q2 = _AVX512_LOAD(&q[(nb*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[(nb*ldq)+2*offset]);
        q4 = _AVX512_LOAD(&q[(nb*ldq)+3*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        y1 = _AVX512_FMA(q1, h2, y1);
        z1 = _AVX512_FMA(q1, h3, z1);

        x2 = _AVX512_FMA(q2, h1, x2);
        y2 = _AVX512_FMA(q2, h2, y2);
        z2 = _AVX512_FMA(q2, h3, z2);

        x3 = _AVX512_FMA(q3, h1, x3);
        y3 = _AVX512_FMA(q3, h2, y3);
        z3 = _AVX512_FMA(q3, h3, z3);

        x4 = _AVX512_FMA(q4, h1, x4);
        y4 = _AVX512_FMA(q4, h2, y4);
        z4 = _AVX512_FMA(q4, h3, z4);


        h1 = _AVX512_SET1(hh[nb-2]);
        h2 = _AVX512_SET1(hh[(ldh*1)+nb-1]);

        q1 = _AVX512_LOAD(&q[(nb+1)*ldq]);
        q2 = _AVX512_LOAD(&q[((nb+1)*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[((nb+1)*ldq)+2*offset]);
        q4 = _AVX512_LOAD(&q[((nb+1)*ldq)+3*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        y1 = _AVX512_FMA(q1, h2, y1);
        x2 = _AVX512_FMA(q2, h1, x2);
        y2 = _AVX512_FMA(q2, h2, y2);
        x3 = _AVX512_FMA(q3, h1, x3);
        y3 = _AVX512_FMA(q3, h2, y3);
        x4 = _AVX512_FMA(q4, h1, x4);
        y4 = _AVX512_FMA(q4, h2, y4);

        h1 = _AVX512_SET1(hh[nb-1]);

        q1 = _AVX512_LOAD(&q[(nb+2)*ldq]);
        q2 = _AVX512_LOAD(&q[((nb+2)*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[((nb+2)*ldq)+2*offset]);
        q4 = _AVX512_LOAD(&q[((nb+2)*ldq)+3*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        x2 = _AVX512_FMA(q2, h1, x2);
        x3 = _AVX512_FMA(q3, h1, x3);
        x4 = _AVX512_FMA(q4, h1, x4);

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

        __AVX512_DATATYPE tau1 = _AVX512_SET1(hh[0]);
        __AVX512_DATATYPE tau2 = _AVX512_SET1(hh[ldh]);
        __AVX512_DATATYPE tau3 = _AVX512_SET1(hh[ldh*2]);
        __AVX512_DATATYPE tau4 = _AVX512_SET1(hh[ldh*3]);

        __AVX512_DATATYPE vs_1_2 = _AVX512_SET1(s_1_2);
        __AVX512_DATATYPE vs_1_3 = _AVX512_SET1(s_1_3);
        __AVX512_DATATYPE vs_2_3 = _AVX512_SET1(s_2_3);
        __AVX512_DATATYPE vs_1_4 = _AVX512_SET1(s_1_4);
        __AVX512_DATATYPE vs_2_4 = _AVX512_SET1(s_2_4);
        __AVX512_DATATYPE vs_3_4 = _AVX512_SET1(s_3_4);

        h1 = tau1;
        x1 = _AVX512_MUL(x1, h1);
        x2 = _AVX512_MUL(x2, h1);
        x3 = _AVX512_MUL(x3, h1);
        x4 = _AVX512_MUL(x4, h1);

        h1 = tau2;
        h2 = _AVX512_MUL(h1, vs_1_2);

        y1 = _AVX512_FMSUB(y1, h1, _AVX512_MUL(x1,h2));
        y2 = _AVX512_FMSUB(y2, h1, _AVX512_MUL(x2,h2));
        y3 = _AVX512_FMSUB(y3, h1, _AVX512_MUL(x3,h2));
        y4 = _AVX512_FMSUB(y4, h1, _AVX512_MUL(x4,h2));

        h1 = tau3;
        h2 = _AVX512_MUL(h1, vs_1_3);
        h3 = _AVX512_MUL(h1, vs_2_3);

        z1 = _AVX512_FMSUB(z1, h1, _AVX512_FMA(y1, h3, _AVX512_MUL(x1,h2)));
        z2 = _AVX512_FMSUB(z2, h1, _AVX512_FMA(y2, h3, _AVX512_MUL(x2,h2)));
        z3 = _AVX512_FMSUB(z3, h1, _AVX512_FMA(y3, h3, _AVX512_MUL(x3,h2)));
        z4 = _AVX512_FMSUB(z4, h1, _AVX512_FMA(y4, h3, _AVX512_MUL(x4,h2)));

        h1 = tau4;
        h2 = _AVX512_MUL(h1, vs_1_4);
        h3 = _AVX512_MUL(h1, vs_2_4);
        h4 = _AVX512_MUL(h1, vs_3_4);

        w1 = _AVX512_FMSUB(w1, h1, _AVX512_FMA(z1, h4, _AVX512_FMA(y1, h3, _AVX512_MUL(x1,h2))));
        w2 = _AVX512_FMSUB(w2, h1, _AVX512_FMA(z2, h4, _AVX512_FMA(y2, h3, _AVX512_MUL(x2,h2))));
        w3 = _AVX512_FMSUB(w3, h1, _AVX512_FMA(z3, h4, _AVX512_FMA(y3, h3, _AVX512_MUL(x3,h2))));
        w4 = _AVX512_FMSUB(w4, h1, _AVX512_FMA(z4, h4, _AVX512_FMA(y4, h3, _AVX512_MUL(x4,h2))));

        q1 = _AVX512_LOAD(&q[0]);
        q1 = _AVX512_SUB(q1, w1);
        _AVX512_STORE(&q[0],q1);

        q2 = _AVX512_LOAD(&q[0+offset]);
        q2 = _AVX512_SUB(q2, w2);
        _AVX512_STORE(&q[0+offset],q2);

        q3 = _AVX512_LOAD(&q[0+2*offset]);
        q3 = _AVX512_SUB(q3, w3);
        _AVX512_STORE(&q[0+2*offset],q3);

        q4 = _AVX512_LOAD(&q[0+3*offset]);
        q4 = _AVX512_SUB(q4, w4);
        _AVX512_STORE(&q[0+3*offset],q4);


        h4 = _AVX512_SET1(hh[(ldh*3)+1]);
        q1 = _AVX512_LOAD(&q[ldq]);
        q2 = _AVX512_LOAD(&q[ldq+offset]);
        q3 = _AVX512_LOAD(&q[ldq+2*offset]);
        q4 = _AVX512_LOAD(&q[ldq+3*offset]);

        q1 = _AVX512_SUB(q1, _AVX512_FMA(w1, h4, z1));
        _AVX512_STORE(&q[ldq],q1);
        q2 = _AVX512_SUB(q2, _AVX512_FMA(w2, h4, z2));
        _AVX512_STORE(&q[ldq+offset],q2);
        q3 = _AVX512_SUB(q3, _AVX512_FMA(w3, h4, z3));
        _AVX512_STORE(&q[ldq+2*offset],q3);
        q4 = _AVX512_SUB(q4, _AVX512_FMA(w4, h4, z4));
        _AVX512_STORE(&q[ldq+3*offset],q4);


        h3 = _AVX512_SET1(hh[(ldh*2)+1]);
        h4 = _AVX512_SET1(hh[(ldh*3)+2]);
        q1 = _AVX512_LOAD(&q[ldq*2]);
        q2 = _AVX512_LOAD(&q[(ldq*2)+offset]);
        q3 = _AVX512_LOAD(&q[(ldq*2)+2*offset]);
        q4 = _AVX512_LOAD(&q[(ldq*2)+3*offset]);
563 564 565 566

        q1 = _AVX512_SUB(q1, y1);
        q1 = _AVX512_NFMA(z1, h3, q1);
        q1 = _AVX512_NFMA(w1, h4, q1);
Andreas Marek's avatar
Andreas Marek committed
567
        _AVX512_STORE(&q[ldq*2],q1);
568 569 570 571

        q2 = _AVX512_SUB(q2, y2);
        q2 = _AVX512_NFMA(z2, h3, q2);
        q2 = _AVX512_NFMA(w2, h4, q2);
Andreas Marek's avatar
Andreas Marek committed
572
        _AVX512_STORE(&q[(ldq*2)+offset],q2);
573 574 575 576

        q3 = _AVX512_SUB(q3, y3);
        q3 = _AVX512_NFMA(z3, h3, q3);
        q3 = _AVX512_NFMA(w3, h4, q3);
Andreas Marek's avatar
Andreas Marek committed
577
        _AVX512_STORE(&q[(ldq*2)+2*offset],q3);
578 579 580 581

        q4 = _AVX512_SUB(q4, y4);
        q4 = _AVX512_NFMA(z4, h3, q4);
        q4 = _AVX512_NFMA(w4, h4, q4);
Andreas Marek's avatar
Andreas Marek committed
582
        _AVX512_STORE(&q[(ldq*2)+3*offset],q4);
583 584


Andreas Marek's avatar
Andreas Marek committed
585 586 587
        h2 = _AVX512_SET1(hh[ldh+1]);
        h3 = _AVX512_SET1(hh[(ldh*2)+2]);
        h4 = _AVX512_SET1(hh[(ldh*3)+3]);
588

Andreas Marek's avatar
Andreas Marek committed
589
        q1 = _AVX512_LOAD(&q[ldq*3]);
590

Andreas Marek's avatar
Andreas Marek committed
591
        q1 = _AVX512_SUB(q1, x1);
592 593 594
        q1 = _AVX512_NFMA(y1, h2, q1);
        q1 = _AVX512_NFMA(z1, h3, q1);
        q1 = _AVX512_NFMA(w1, h4, q1);
Andreas Marek's avatar
Andreas Marek committed
595
        _AVX512_STORE(&q[ldq*3], q1);
596

Andreas Marek's avatar
Andreas Marek committed
597
        q2 = _AVX512_LOAD(&q[(ldq*3)+offset]);
598

Andreas Marek's avatar
Andreas Marek committed
599
        q2 = _AVX512_SUB(q2, x2);
600 601 602
        q2 = _AVX512_NFMA(y2, h2, q2);
        q2 = _AVX512_NFMA(z2, h3, q2);
        q2 = _AVX512_NFMA(w2, h4, q2);
Andreas Marek's avatar
Andreas Marek committed
603
        _AVX512_STORE(&q[(ldq*3)+offset], q2);
604

Andreas Marek's avatar
Andreas Marek committed
605
        q3 = _AVX512_LOAD(&q[(ldq*3)+2*offset]);
606

Andreas Marek's avatar
Andreas Marek committed
607
        q3 = _AVX512_SUB(q3, x3);
608 609 610
        q3 = _AVX512_NFMA(y3, h2, q3);
        q3 = _AVX512_NFMA(z3, h3, q3);
        q3 = _AVX512_NFMA(w3, h4, q3);
Andreas Marek's avatar
Andreas Marek committed
611
        _AVX512_STORE(&q[(ldq*3)+2*offset], q3);
612

Andreas Marek's avatar
Andreas Marek committed
613
        q4 = _AVX512_LOAD(&q[(ldq*3)+3*offset]);
614

Andreas Marek's avatar
Andreas Marek committed
615
        q4 = _AVX512_SUB(q4, x4);
616 617 618
        q4 = _AVX512_NFMA(y4, h2, q4);
        q4 = _AVX512_NFMA(z4, h3, q4);
        q4 = _AVX512_NFMA(w4, h4, q4);
Andreas Marek's avatar
Andreas Marek committed
619
        _AVX512_STORE(&q[(ldq*3)+3*offset], q4);
620

Andreas Marek's avatar
Andreas Marek committed
621 622 623 624 625 626
        for (i = 4; i < nb; i++)
        {
                h1 = _AVX512_SET1(hh[i-3]);
                h2 = _AVX512_SET1(hh[ldh+i-2]);
                h3 = _AVX512_SET1(hh[(ldh*2)+i-1]);
                h4 = _AVX512_SET1(hh[(ldh*3)+i]);
627

Andreas Marek's avatar
Andreas Marek committed
628
                q1 = _AVX512_LOAD(&q[i*ldq]);
629 630 631 632
                q1 = _AVX512_NFMA(x1, h1, q1);
                q1 = _AVX512_NFMA(y1, h2, q1);
                q1 = _AVX512_NFMA(z1, h3, q1);
                q1 = _AVX512_NFMA(w1, h4, q1);
Andreas Marek's avatar
Andreas Marek committed
633
                _AVX512_STORE(&q[i*ldq],q1);
634

Andreas Marek's avatar
Andreas Marek committed
635
                q2 = _AVX512_LOAD(&q[(i*ldq)+offset]);
636 637 638 639
                q2 = _AVX512_NFMA(x2, h1, q2);
                q2 = _AVX512_NFMA(y2, h2, q2);
                q2 = _AVX512_NFMA(z2, h3, q2);
                q2 = _AVX512_NFMA(w2, h4, q2);
Andreas Marek's avatar
Andreas Marek committed
640
                _AVX512_STORE(&q[(i*ldq)+offset],q2);
641

Andreas Marek's avatar
Andreas Marek committed
642
                q3 = _AVX512_LOAD(&q[(i*ldq)+2*offset]);
643 644 645 646
                q3 = _AVX512_NFMA(x3, h1, q3);
                q3 = _AVX512_NFMA(y3, h2, q3);
                q3 = _AVX512_NFMA(z3, h3, q3);
                q3 = _AVX512_NFMA(w3, h4, q3);
Andreas Marek's avatar
Andreas Marek committed
647
                _AVX512_STORE(&q[(i*ldq)+2*offset],q3);
648

Andreas Marek's avatar
Andreas Marek committed
649
                q4 = _AVX512_LOAD(&q[(i*ldq)+3*offset]);
650 651 652 653
                q4 = _AVX512_NFMA(x4, h1, q4);
                q4 = _AVX512_NFMA(y4, h2, q4);
                q4 = _AVX512_NFMA(z4, h3, q4);
                q4 = _AVX512_NFMA(w4, h4, q4);
Andreas Marek's avatar
Andreas Marek committed
654
                _AVX512_STORE(&q[(i*ldq)+3*offset],q4);
655

Andreas Marek's avatar
Andreas Marek committed
656
        }
657

Andreas Marek's avatar
Andreas Marek committed
658 659 660 661
        h1 = _AVX512_SET1(hh[nb-3]);
        h2 = _AVX512_SET1(hh[ldh+nb-2]);
        h3 = _AVX512_SET1(hh[(ldh*2)+nb-1]);
        q1 = _AVX512_LOAD(&q[nb*ldq]);
662

Andreas Marek's avatar
Andreas Marek committed
663
        q1 = _AVX512_NFMA(x1, h1, q1);
664 665
        q1 = _AVX512_NFMA(y1, h2, q1);
        q1 = _AVX512_NFMA(z1, h3, q1);
Andreas Marek's avatar
Andreas Marek committed
666
        _AVX512_STORE(&q[nb*ldq],q1);
667

Andreas Marek's avatar
Andreas Marek committed
668
        q2 = _AVX512_LOAD(&q[(nb*ldq)+offset]);
669

Andreas Marek's avatar
Andreas Marek committed
670
        q2 = _AVX512_NFMA(x2, h1, q2);
671 672
        q2 = _AVX512_NFMA(y2, h2, q2);
        q2 = _AVX512_NFMA(z2, h3, q2);
Andreas Marek's avatar
Andreas Marek committed
673
        _AVX512_STORE(&q[(nb*ldq)+offset],q2);
674

Andreas Marek's avatar
Andreas Marek committed
675
        q3 = _AVX512_LOAD(&q[(nb*ldq)+2*offset]);
676

Andreas Marek's avatar
Andreas Marek committed
677
        q3 = _AVX512_NFMA(x3, h1, q3);
678 679
        q3 = _AVX512_NFMA(y3, h2, q3);
        q3 = _AVX512_NFMA(z3, h3, q3);
Andreas Marek's avatar
Andreas Marek committed
680
        _AVX512_STORE(&q[(nb*ldq)+2*offset],q3);
681

Andreas Marek's avatar
Andreas Marek committed
682
        q4 = _AVX512_LOAD(&q[(nb*ldq)+3*offset]);
683

Andreas Marek's avatar
Andreas Marek committed
684
        q4 = _AVX512_NFMA(x4, h1, q4);
685 686
        q4 = _AVX512_NFMA(y4, h2, q4);
        q4 = _AVX512_NFMA(z4, h3, q4);
Andreas Marek's avatar
Andreas Marek committed
687
        _AVX512_STORE(&q[(nb*ldq)+3*offset],q4);
688

Andreas Marek's avatar
Andreas Marek committed
689 690 691
        h1 = _AVX512_SET1(hh[nb-2]);
        h2 = _AVX512_SET1(hh[ldh+nb-1]);
        q1 = _AVX512_LOAD(&q[(nb+1)*ldq]);
692

Andreas Marek's avatar
Andreas Marek committed
693 694 695
        q1 = _AVX512_NFMA(x1, h1, q1);
        q1 = _AVX512_NFMA(y1, h2, q1);
        _AVX512_STORE(&q[(nb+1)*ldq],q1);
696

Andreas Marek's avatar
Andreas Marek committed
697
        q2 = _AVX512_LOAD(&q[((nb+1)*ldq)+offset]);
698

Andreas Marek's avatar
Andreas Marek committed
699 700 701
        q2 = _AVX512_NFMA(x2, h1, q2);
        q2 = _AVX512_NFMA(y2, h2, q2);
        _AVX512_STORE(&q[((nb+1)*ldq)+offset],q2);
702

Andreas Marek's avatar
Andreas Marek committed
703
        q3 = _AVX512_LOAD(&q[((nb+1)*ldq)+2*offset]);
704

Andreas Marek's avatar
Andreas Marek committed
705 706 707
        q3 = _AVX512_NFMA(x3, h1, q3);
        q3 = _AVX512_NFMA(y3, h2, q3);
        _AVX512_STORE(&q[((nb+1)*ldq)+2*offset],q3);
708

Andreas Marek's avatar
Andreas Marek committed
709
        q4 = _AVX512_LOAD(&q[((nb+1)*ldq)+3*offset]);
710

Andreas Marek's avatar
Andreas Marek committed
711 712 713
        q4 = _AVX512_NFMA(x4, h1, q4);
        q4 = _AVX512_NFMA(y4, h2, q4);
        _AVX512_STORE(&q[((nb+1)*ldq)+3*offset],q4);
714 715


Andreas Marek's avatar
Andreas Marek committed
716 717
        h1 = _AVX512_SET1(hh[nb-1]);
        q1 = _AVX512_LOAD(&q[(nb+2)*ldq]);
718

Andreas Marek's avatar
Andreas Marek committed
719 720
        q1 = _AVX512_NFMA(x1, h1, q1);
        _AVX512_STORE(&q[(nb+2)*ldq],q1);
721

Andreas Marek's avatar
Andreas Marek committed
722
        q2 = _AVX512_LOAD(&q[((nb+2)*ldq)+offset]);
723

Andreas Marek's avatar
Andreas Marek committed
724 725
        q2 = _AVX512_NFMA(x2, h1, q2);
        _AVX512_STORE(&q[((nb+2)*ldq)+offset],q2);
726

Andreas Marek's avatar
Andreas Marek committed
727
        q3 = _AVX512_LOAD(&q[((nb+2)*ldq)+2*offset]);
728

Andreas Marek's avatar
Andreas Marek committed
729 730
        q3 = _AVX512_NFMA(x3, h1, q3);
        _AVX512_STORE(&q[((nb+2)*ldq)+2*offset],q3);
731

Andreas Marek's avatar
Andreas Marek committed
732
        q4 = _AVX512_LOAD(&q[((nb+2)*ldq)+3*offset]);
733

Andreas Marek's avatar
Andreas Marek committed
734 735
        q4 = _AVX512_NFMA(x4, h1, q4);
        _AVX512_STORE(&q[((nb+2)*ldq)+3*offset],q4);
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753

}

/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 24 rows of Q simultaneously, a
#endif
#ifdef DOUBLE_PRECISION_REAL
 * 48 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 1 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
__forceinline void hh_trafo_kernel_24_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
754
__forceinline void hh_trafo_kernel_48_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
755 756
#endif
{
Andreas Marek's avatar
Andreas Marek committed
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 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 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
        /////////////////////////////////////////////////////
        // Matrix Vector Multiplication, Q [4 x nb+3] * hh
        // hh contains four householder vectors
        /////////////////////////////////////////////////////
        int i;

        __AVX512_DATATYPE a1_1 = _AVX512_LOAD(&q[ldq*3]);
        __AVX512_DATATYPE a2_1 = _AVX512_LOAD(&q[ldq*2]);
        __AVX512_DATATYPE a3_1 = _AVX512_LOAD(&q[ldq]);
        __AVX512_DATATYPE a4_1 = _AVX512_LOAD(&q[0]);


        __AVX512_DATATYPE a1_2 = _AVX512_LOAD(&q[(ldq*3)+offset]);
        __AVX512_DATATYPE a2_2 = _AVX512_LOAD(&q[(ldq*2)+offset]);
        __AVX512_DATATYPE a3_2 = _AVX512_LOAD(&q[ldq+offset]);
        __AVX512_DATATYPE a4_2 = _AVX512_LOAD(&q[0+offset]);

        __AVX512_DATATYPE a1_3 = _AVX512_LOAD(&q[(ldq*3)+2*offset]);
        __AVX512_DATATYPE a2_3 = _AVX512_LOAD(&q[(ldq*2)+2*offset]);
        __AVX512_DATATYPE a3_3 = _AVX512_LOAD(&q[ldq+2*offset]);
        __AVX512_DATATYPE a4_3 = _AVX512_LOAD(&q[0+2*offset]);

        __AVX512_DATATYPE h_2_1 = _AVX512_SET1(hh[ldh+1]);
        __AVX512_DATATYPE h_3_2 = _AVX512_SET1(hh[(ldh*2)+1]);
        __AVX512_DATATYPE h_3_1 = _AVX512_SET1(hh[(ldh*2)+2]);
        __AVX512_DATATYPE h_4_3 = _AVX512_SET1(hh[(ldh*3)+1]);
        __AVX512_DATATYPE h_4_2 = _AVX512_SET1(hh[(ldh*3)+2]);
        __AVX512_DATATYPE h_4_1 = _AVX512_SET1(hh[(ldh*3)+3]);

        __AVX512_DATATYPE w1 = _AVX512_FMA(a3_1, h_4_3, a4_1);
        w1 = _AVX512_FMA(a2_1, h_4_2, w1);
        w1 = _AVX512_FMA(a1_1, h_4_1, w1);
        __AVX512_DATATYPE z1 = _AVX512_FMA(a2_1, h_3_2, a3_1);
        z1 = _AVX512_FMA(a1_1, h_3_1, z1);
        __AVX512_DATATYPE y1 = _AVX512_FMA(a1_1, h_2_1, a2_1);
        __AVX512_DATATYPE x1 = a1_1;

        __AVX512_DATATYPE w2 = _AVX512_FMA(a3_2, h_4_3, a4_2);
        w2 = _AVX512_FMA(a2_2, h_4_2, w2);
        w2 = _AVX512_FMA(a1_2, h_4_1, w2);
        __AVX512_DATATYPE z2 = _AVX512_FMA(a2_2, h_3_2, a3_2);
        z2 = _AVX512_FMA(a1_2, h_3_1, z2);
        __AVX512_DATATYPE y2 = _AVX512_FMA(a1_2, h_2_1, a2_2);
        __AVX512_DATATYPE x2 = a1_2;

        __AVX512_DATATYPE w3 = _AVX512_FMA(a3_3, h_4_3, a4_3);
        w3 = _AVX512_FMA(a2_3, h_4_2, w3);
        w3 = _AVX512_FMA(a1_3, h_4_1, w3);
        __AVX512_DATATYPE z3 = _AVX512_FMA(a2_3, h_3_2, a3_3);
        z3 = _AVX512_FMA(a1_3, h_3_1, z3);
        __AVX512_DATATYPE y3 = _AVX512_FMA(a1_3, h_2_1, a2_3);
        __AVX512_DATATYPE x3 = a1_3;

        __AVX512_DATATYPE q1;
        __AVX512_DATATYPE q2;
        __AVX512_DATATYPE q3;

        __AVX512_DATATYPE h1;
        __AVX512_DATATYPE h2;
        __AVX512_DATATYPE h3;
        __AVX512_DATATYPE h4;

        for(i = 4; i < nb; i++)
        {
                h1 = _AVX512_SET1(hh[i-3]);
                h2 = _AVX512_SET1(hh[ldh+i-2]);
                h3 = _AVX512_SET1(hh[(ldh*2)+i-1]);
                h4 = _AVX512_SET1(hh[(ldh*3)+i]);

                q1 = _AVX512_LOAD(&q[i*ldq]);
                q2 = _AVX512_LOAD(&q[(i*ldq)+offset]);
                q3 = _AVX512_LOAD(&q[(i*ldq)+2*offset]);

                x1 = _AVX512_FMA(q1, h1, x1);
                y1 = _AVX512_FMA(q1, h2, y1);
                z1 = _AVX512_FMA(q1, h3, z1);
                w1 = _AVX512_FMA(q1, h4, w1);

                x2 = _AVX512_FMA(q2, h1, x2);
                y2 = _AVX512_FMA(q2, h2, y2);
                z2 = _AVX512_FMA(q2, h3, z2);
                w2 = _AVX512_FMA(q2, h4, w2);

                x3 = _AVX512_FMA(q3, h1, x3);
                y3 = _AVX512_FMA(q3, h2, y3);
                z3 = _AVX512_FMA(q3, h3, z3);
                w3 = _AVX512_FMA(q3, h4, w3);

        }

        h1 = _AVX512_SET1(hh[nb-3]);
        h2 = _AVX512_SET1(hh[ldh+nb-2]);
        h3 = _AVX512_SET1(hh[(ldh*2)+nb-1]);

        q1 = _AVX512_LOAD(&q[nb*ldq]);
        q2 = _AVX512_LOAD(&q[(nb*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[(nb*ldq)+2*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        y1 = _AVX512_FMA(q1, h2, y1);
        z1 = _AVX512_FMA(q1, h3, z1);

        x2 = _AVX512_FMA(q2, h1, x2);
        y2 = _AVX512_FMA(q2, h2, y2);
        z2 = _AVX512_FMA(q2, h3, z2);

        x3 = _AVX512_FMA(q3, h1, x3);
        y3 = _AVX512_FMA(q3, h2, y3);
        z3 = _AVX512_FMA(q3, h3, z3);

        h1 = _AVX512_SET1(hh[nb-2]);
        h2 = _AVX512_SET1(hh[(ldh*1)+nb-1]);

        q1 = _AVX512_LOAD(&q[(nb+1)*ldq]);
        q2 = _AVX512_LOAD(&q[((nb+1)*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[((nb+1)*ldq)+2*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        y1 = _AVX512_FMA(q1, h2, y1);
        x2 = _AVX512_FMA(q2, h1, x2);
        y2 = _AVX512_FMA(q2, h2, y2);
        x3 = _AVX512_FMA(q3, h1, x3);
        y3 = _AVX512_FMA(q3, h2, y3);

        h1 = _AVX512_SET1(hh[nb-1]);

        q1 = _AVX512_LOAD(&q[(nb+2)*ldq]);
        q2 = _AVX512_LOAD(&q[((nb+2)*ldq)+offset]);
        q3 = _AVX512_LOAD(&q[((nb+2)*ldq)+2*offset]);

        x1 = _AVX512_FMA(q1, h1, x1);
        x2 = _AVX512_FMA(q2, h1, x2);
        x3 = _AVX512_FMA(q3, h1, x3);

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

        __AVX512_DATATYPE tau1 = _AVX512_SET1(hh[0]);
        __AVX512_DATATYPE tau2 = _AVX512_SET1(hh[ldh]);
        __AVX512_DATATYPE tau3 = _AVX512_SET1(hh[ldh*2]);
        __AVX512_DATATYPE tau4 = _AVX512_SET1(hh[ldh*3]);

        __AVX512_DATATYPE vs_1_2 = _AVX512_SET1(s_1_2);
        __AVX512_DATATYPE vs_1_3 = _AVX512_SET1(s_1_3);
        __AVX512_DATATYPE vs_2_3 = _AVX512_SET1(s_2_3);
        __AVX512_DATATYPE vs_1_4 = _AVX512_SET1(s_1_4);
        __AVX512_DATATYPE vs_2_4 = _AVX512_SET1(s_2_4);
        __AVX512_DATATYPE vs_3_4 = _AVX512_SET1(s_3_4);

        h1 = tau1;
        x1 = _AVX512_MUL(x1, h1);
        x2 = _AVX512_MUL(x2, h1);
        x3 = _AVX512_MUL(x3, h1);

        h1 = tau2;
        h2 = _AVX512_MUL(h1, vs_1_2);

        y1 = _AVX512_FMSUB(y1, h1, _AVX512_MUL(x1,h2));
        y2 = _AVX512_FMSUB(y2, h1, _AVX512_MUL(x2,h2));
        y3 = _AVX512_FMSUB(y3, h1, _AVX512_MUL(x3,h2));

        h1 = tau3;
        h2 = _AVX512_MUL(h1, vs_1_3);
        h3 = _AVX512_MUL(h1, vs_2_3);

        z1 = _AVX512_FMSUB(z1, h1, _AVX512_FMA(y1, h3, _AVX512_MUL(x1,h2)));
        z2 = _AVX512_FMSUB(z2, h1, _AVX512_FMA(y2, h3, _AVX512_MUL(x2,h2)));
        z3 = _AVX512_FMSUB(z3, h1, _AVX512_FMA(y3, h3, _AVX512_MUL(x3,h2)));

        h1 = tau4;
        h2 = _AVX512_MUL(h1, vs_1_4);
        h3 = _AVX512_MUL(h1, vs_2_4);
        h4 = _AVX512_MUL(h1, vs_3_4);

        w1 = _AVX512_FMSUB(w1, h1, _AVX512_FMA(z1, h4, _AVX512_FMA(y1, h3, _AVX512_MUL(x1,h2))));
        w2 = _AVX512_FMSUB(w2, h1, _AVX512_FMA(z2, h4, _AVX512_FMA(y2, h3, _AVX512_MUL(x2,h2))));
        w3 = _AVX512_FMSUB(w3, h1, _AVX512_FMA(z3, h4, _AVX512_FMA(y3, h3, _AVX512_MUL(x3,h2))));

        q1 = _AVX512_LOAD(&q[0]);
        q1 = _AVX512_SUB(q1, w1);
        _AVX512_STORE(&q[0],q1);
939

Andreas Marek's avatar
Andreas Marek committed
940 941 942
        q2 = _AVX512_LOAD(&q[0+offset]);
        q2 = _AVX512_SUB(q2, w2);
        _AVX512_STORE(&q[0+offset],q2);
943

Andreas Marek's avatar
Andreas Marek committed
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
        q3 = _AVX512_LOAD(&q[0+2*offset]);
        q3 = _AVX512_SUB(q3, w3);
        _AVX512_STORE(&q[0+2*offset],q3);


        h4 = _AVX512_SET1(hh[(ldh*3)+1]);
        q1 = _AVX512_LOAD(&q[ldq]);
        q2 = _AVX512_LOAD(&q[ldq+offset]);
        q3 = _AVX512_LOAD(&q[ldq+2*offset]);

        q1 = _AVX512_SUB(q1, _AVX512_FMA(w1, h4, z1));
        _AVX512_STORE(&q[ldq],q1);
        q2 = _AVX512_SUB(q2, _AVX512_FMA(w2, h4, z2));
        _AVX512_STORE(&q[ldq+offset],q2);
        q3 = _AVX512_SUB(q3, _AVX512_FMA(w3, h4, z3));
        _AVX512_STORE(&q[ldq+2*offset],q3);
960 961


Andreas Marek's avatar
Andreas Marek committed
962 963 964 965 966
        h3 = _AVX512_SET1(hh[(ldh*2)+1]);
        h4 = _AVX512_SET1(hh[(ldh*3)+2]);
        q1 = _AVX512_LOAD(&q[ldq*2]);
        q2 = _AVX512_LOAD(&q[(ldq*2)+offset]);
        q3 = _AVX512_LOAD(&q[(ldq*2)+2*offset]);
967 968 969 970 971

        q1 = _AVX512_SUB(q1, y1);
        q1 = _AVX512_NFMA(z1, h3, q1);
        q1 = _AVX512_NFMA(w1, h4, q1);

Andreas Marek's avatar
Andreas Marek committed
972
        _AVX512_STORE(&q[ldq*2],q1);
973 974 975 976 977

        q2 = _AVX512_SUB(q2, y2);
        q2 = _AVX512_NFMA(z2, h3, q2);
        q2 = _AVX512_NFMA(w2, h4, q2);

Andreas Marek's avatar
Andreas Marek committed
978
        _AVX512_STORE(&q[(ldq*2)+offset],q2);
979 980 981 982 983

        q3 = _AVX512_SUB(q3, y3);
        q3 = _AVX512_NFMA(z3, h3, q3);
        q3 = _AVX512_NFMA(w3, h4, q3);

Andreas Marek's avatar
Andreas Marek committed
984
        _AVX512_STORE(&q[(ldq*2)+2*offset],q3);
985

Andreas Marek's avatar
Andreas Marek committed
986 987 988
        h2 = _AVX512_SET1(hh[ldh+1]);
        h3 = _AVX512_SET1(hh[(ldh*2)+2]);
        h4 = _AVX512_SET1(hh[(ldh*3)+3]);
989

Andreas Marek's avatar
Andreas Marek committed
990
        q1 = _AVX512_LOAD(&q[ldq*3]);
991

Andreas Marek's avatar
Andreas Marek committed
992
        q1 = _AVX512_SUB(q1, x1);
993 994 995 996
        q1 = _AVX512_NFMA(y1, h2, q1);
        q1 = _AVX512_NFMA(z1, h3, q1);
        q1 = _AVX512_NFMA(w1, h4, q1);

Andreas Marek's avatar
Andreas Marek committed
997
        _AVX512_STORE(&q[ldq*3], q1);
998

Andreas Marek's avatar
Andreas Marek committed
999
        q2 = _AVX512_LOAD(&q[(ldq*3)+offset]);
1000

Andreas Marek's avatar
Andreas Marek committed
1001
        q2 = _AVX512_SUB(q2, x2);
1002 1003 1004 1005
        q2 = _AVX512_NFMA(y2, h2, q2);
        q2 = _AVX512_NFMA(z2, h3, q2);
        q2 = _AVX512_NFMA(w2, h4, q2);

Andreas Marek's avatar
Andreas Marek committed
1006
        _AVX512_STORE(&q[(ldq*3)+offset], q2);
1007

Andreas Marek's avatar
Andreas Marek committed
1008
        q3 = _AVX512_LOAD(&q[(ldq*3)+2*offset]);
1009

Andreas Marek's avatar
Andreas Marek committed
1010
        q3 = _AVX512_SUB(q3, x3);
1011 1012 1013 1014
        q3 = _AVX512_NFMA(y3, h2, q3);
        q3 = _AVX512_NFMA(z3, h3, q3);
        q3 = _AVX512_NFMA(w3, h4, q3);

Andreas Marek's avatar
Andreas Marek committed
1015
        _AVX512_STORE(&q[(ldq*3)+2*offset], q3);
1016

Andreas Marek's avatar
Andreas Marek committed
1017 1018 1019 1020 1021 1022
        for (i = 4; i < nb; i++)
        {
                h1 = _AVX512_SET1(hh[i-3]);
                h2 = _AVX512_SET1(hh[ldh+i-2]);
                h3 = _AVX512_SET1(hh[(ldh*2)+i-1]);
                h4 = _AVX512_SET1(hh[(ldh*3)+i]);
1023

Andreas Marek's avatar
Andreas Marek committed
1024
                q1 = _AVX512_LOAD(&q[i*ldq]);
1025 1026 1027 1028
                q1 = _AVX512_NFMA(x1, h1, q1);
                q1 = _AVX512_NFMA(y1, h2, q1);
                q1 = _AVX512_NFMA(z1, h3, q1);
                q1 = _AVX512_NFMA(w1, h4, q1);
Andreas Marek's avatar
Andreas Marek committed
1029
                _AVX512_STORE(&q[i*ldq],q1);
1030

Andreas Marek's avatar
Andreas Marek committed
1031
                q2 = _AVX512_LOAD(&q[(i*ldq)+offset]);
1032 1033 1034 1035
                q2 = _AVX512_NFMA(x2, h1, q2);
                q2 = _AVX512_NFMA(y2, h2, q2);
                q2 = _AVX512_NFMA(z2, h3, q2);
                q2 = _AVX512_NFMA(w2, h4, q2);
Andreas Marek's avatar
Andreas Marek committed
1036
                _AVX512_STORE(&q[(i*ldq)+offset],q2);
1037

Andreas Marek's avatar
Andreas Marek committed
1038
                q3 = _AVX512_LOAD(&q[(i*ldq)+2*offset]);
1039 1040 1041 1042
                q3 = _AVX512_NFMA(x3, h1, q3);
                q3 = _AVX512_NFMA(y3, h2, q3);
                q3 = _AVX512_NFMA(z3, h3, q3);
                q3 = _AVX512_NFMA(w3, h4, q3);
Andreas Marek's avatar
Andreas Marek committed
1043
                _AVX512_STORE(&q[(i*ldq)+2*offset],q3);
1044

Andreas Marek's avatar
Andreas Marek committed
1045
        }
1046

Andreas Marek's avatar
Andreas Marek committed
1047 1048 1049 1050
        h1 = _AVX512_SET1(hh[nb-3]);
        h2 = _AVX512_SET1(hh[ldh+nb-2]);
        h3 = _AVX512_SET1(hh[(ldh*2)+nb-1]);
        q1 = _AVX512_LOAD(&q[nb*ldq]);
1051

Andreas Marek's avatar
Andreas Marek committed
1052
        q1 = _AVX512_NFMA(x1, h1, q1);
1053 1054 1055
        q1 = _AVX512_NFMA(y1, h2, q1);
        q1 = _AVX512_NFMA(z1, h3, q1);

Andreas Marek's avatar
Andreas Marek committed
1056
        _AVX512_STORE(&q[nb*ldq],q1);
1057

Andreas Marek's avatar
Andreas Marek committed
1058
        q2 = _AVX512_LOAD(&q[(nb*ldq)+offset]);
1059

Andreas Marek's avatar
Andreas Marek committed
1060
        q2 = _AVX512_NFMA(x2, h1, q2);
1061 1062 1063
        q2 = _AVX512_NFMA(y2, h2, q2);
        q2 = _AVX512_NFMA(z2, h3, q2);

Andreas Marek's avatar
Andreas Marek committed
1064
        _AVX512_STORE(&q[(nb*ldq)+offset],q2);
1065

Andreas Marek's avatar
Andreas Marek committed
1066
        q3 = _AVX512_LOAD(&q[(nb*ldq)+2*offset]);
1067

Andreas Marek's avatar
Andreas Marek committed
1068
        q3 = _AVX512_NFMA(x3, h1, q3);
1069 1070 1071
        q3 = _AVX512_NFMA(y3, h2, q3);
        q3 = _AVX512_NFMA(z3, h3, q3);

Andreas Marek's avatar
Andreas Marek committed
1072
        _AVX512_STORE(&q[(nb*ldq)+2*offset],q3);
1073 1074


Andreas Marek's avatar
Andreas Marek committed
1075 1076 1077
        h1 = _AVX512_SET1(hh[nb-2]);
        h2 = _AVX512_SET1(hh[ldh+nb-1]);
        q1 = _AVX512_LOAD(&q[(nb+1)*ldq]);
1078

Andreas Marek's avatar
Andreas Marek committed
1079 1080
        q1 = _AVX512_NFMA(x1, h1, q1);
        q1 = _AVX512_NFMA(y1, h2, q1);
1081

Andreas Marek's avatar
Andreas Marek committed
1082
        _AVX512_STORE(&q[(nb+1)*ldq],q1);
1083

Andreas Marek's avatar
Andreas Marek committed
1084
        q2 = _AVX512_LOAD(&q[((nb+1)*ldq)+offset]);
1085

Andreas Marek's avatar
Andreas Marek committed
1086 1087
        q2 = _AVX512_NFMA(x2, h1, q2);
        q2 = _AVX512_NFMA(y2, h2, q2);
1088

Andreas Marek's avatar
Andreas Marek committed
1089
        _AVX512_STORE(&q[((nb+1)*ldq)+offset],q2);
1090

Andreas Marek's avatar
Andreas Marek committed
1091
        q3 = _AVX512_LOAD(&q[((nb+1)*ldq)+2*offset]);
1092

Andreas Marek's avatar
Andreas Marek committed
1093 1094
        q3 = _AVX512_NFMA(x3, h1, q3);
        q3 = _AVX512_NFMA(y3, h2, q3);
1095

Andreas Marek's avatar
Andreas Marek committed
1096
        _AVX512_STORE(&q[((nb+1)*ldq)+2*offset],q3);
1097 1098


Andreas Marek's avatar
Andreas Marek committed
1099 1100
        h1 = _AVX512_SET1(hh[nb-1]);
        q1 = _AVX512_LOAD(&q[(nb+2)*ldq]);
1101

Andreas Marek's avatar
Andreas Marek committed
1102
        q1 = _AVX512_NFMA(x1, h1, q1);
1103

Andreas Marek's avatar
Andreas Marek committed
1104
        _AVX512_STORE(&q[(nb+2)*ldq],q1);
1105

Andreas Marek's avatar
Andreas Marek committed
1106
        q2 = _AVX512_LOAD(&q[((nb+2)*ldq)+offset]);
1107

Andreas Marek's avatar
Andreas Marek committed
1108
        q2 = _AVX512_NFMA(x2, h1, q2);
1109

Andreas Marek's avatar
Andreas Marek committed
1110
        _AVX512_STORE(&q[((nb+2)*ldq)+offset],q2);
1111

Andreas Marek's avatar
Andreas Marek committed
1112
        q3 = _AVX512_LOAD(&q[((nb+2)*ldq)+2*offset]);
1113

Andreas Marek's avatar
Andreas Marek committed
1114
        q3 = _AVX512_NFMA(x3, h1, q3);
1115

Andreas Marek's avatar
Andreas Marek committed
1116
        _AVX512_STORE(&q[((nb+2)*ldq)+2*offset],q3);
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134

}

/**
 * Unrolled kernel that computes
#ifdef DOUBLE_PRECISION_REAL
 * 16 rows of Q simultaneously, a
#endif
#ifdef SINGLE_PRECISION_REAL
 * 32 rows of Q simultaneously, a
#endif
 * matrix Vector product with two householder
 * vectors + a rank 1 update is performed
 */
#ifdef DOUBLE_PRECISION_REAL
__forceinline void hh_trafo_kernel_16_AVX512_4hv_double(double* q, double* hh, int nb, int ldq, int ldh, double s_1_2, double s_1_3, double s_2_3, double s_1_4, double s_2_4, double s_3_4)
#endif
#ifdef SINGLE_PRECISION_REAL
Andreas Marek's avatar
Andreas Marek committed
1135
__forceinline void hh_trafo_kernel_32_AVX512_4hv_single(float* q, float* hh, int nb, int ldq, int ldh, float s_1_2, float s_1_3, float s_2_3, float s_1_4, float s_2_4, float s_3_4)
1136 1137
#endif
{
Andreas Marek's avatar
Andreas Marek committed
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258