|
| 1 | +/*************************************************************************** |
| 2 | +Copyright (c) 2014, The OpenBLAS Project |
| 3 | +All rights reserved. |
| 4 | +Redistribution and use in source and binary forms, with or without |
| 5 | +modification, are permitted provided that the following conditions are |
| 6 | +met: |
| 7 | +1. Redistributions of source code must retain the above copyright |
| 8 | +notice, this list of conditions and the following disclaimer. |
| 9 | +2. Redistributions in binary form must reproduce the above copyright |
| 10 | +notice, this list of conditions and the following disclaimer in |
| 11 | +the documentation and/or other materials provided with the |
| 12 | +distribution. |
| 13 | +3. Neither the name of the OpenBLAS project nor the names of |
| 14 | +its contributors may be used to endorse or promote products |
| 15 | +derived from this software without specific prior written permission. |
| 16 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | +ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE |
| 20 | +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 25 | +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +*****************************************************************************/ |
| 27 | + |
| 28 | +/* need a new enough GCC for avx512 support */ |
| 29 | +#if (( defined(__GNUC__) && __GNUC__ > 6 && defined(__AVX2__)) || (defined(__clang__) && __clang_major__ >= 6)) |
| 30 | + |
| 31 | +#define HAVE_KERNEL_4x4 1 |
| 32 | + |
| 33 | +#include <immintrin.h> |
| 34 | + |
| 35 | +static void dgemv_kernel_4x4( BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y, FLOAT *alpha) |
| 36 | +{ |
| 37 | + |
| 38 | + int i = 0; |
| 39 | + |
| 40 | + __m256d x0, x1, x2, x3; |
| 41 | + __m256d __alpha; |
| 42 | + |
| 43 | + x0 = _mm256_broadcastsd_pd(_mm_load_sd(&x[0])); |
| 44 | + x1 = _mm256_broadcastsd_pd(_mm_load_sd(&x[1])); |
| 45 | + x2 = _mm256_broadcastsd_pd(_mm_load_sd(&x[2])); |
| 46 | + x3 = _mm256_broadcastsd_pd(_mm_load_sd(&x[3])); |
| 47 | + |
| 48 | + __alpha = _mm256_broadcastsd_pd(_mm_load_sd(alpha)); |
| 49 | + |
| 50 | +#ifdef __AVX512CD__ |
| 51 | + int n5; |
| 52 | + __m512d x05, x15, x25, x35; |
| 53 | + __m512d __alpha5; |
| 54 | + n5 = n & ~7; |
| 55 | + |
| 56 | + x05 = _mm512_broadcastsd_pd(_mm_load_sd(&x[0])); |
| 57 | + x15 = _mm512_broadcastsd_pd(_mm_load_sd(&x[1])); |
| 58 | + x25 = _mm512_broadcastsd_pd(_mm_load_sd(&x[2])); |
| 59 | + x35 = _mm512_broadcastsd_pd(_mm_load_sd(&x[3])); |
| 60 | + |
| 61 | + __alpha5 = _mm512_broadcastsd_pd(_mm_load_sd(alpha)); |
| 62 | + |
| 63 | + for (; i < n5; i+= 8) { |
| 64 | + __m512d tempY; |
| 65 | + __m512d sum; |
| 66 | + |
| 67 | + sum = _mm512_loadu_pd(&ap[0][i]) * x05 + |
| 68 | + _mm512_loadu_pd(&ap[1][i]) * x15 + |
| 69 | + _mm512_loadu_pd(&ap[2][i]) * x25 + |
| 70 | + _mm512_loadu_pd(&ap[3][i]) * x35; |
| 71 | + |
| 72 | + tempY = _mm512_loadu_pd(&y[i]); |
| 73 | + tempY += sum * __alpha5; |
| 74 | + _mm512_storeu_pd(&y[i], tempY); |
| 75 | + } |
| 76 | +#endif |
| 77 | + |
| 78 | + for (; i < n; i+= 4) { |
| 79 | + __m256d tempY; |
| 80 | + __m256d sum; |
| 81 | + |
| 82 | + sum = _mm256_loadu_pd(&ap[0][i]) * x0 + |
| 83 | + _mm256_loadu_pd(&ap[1][i]) * x1 + |
| 84 | + _mm256_loadu_pd(&ap[2][i]) * x2 + |
| 85 | + _mm256_loadu_pd(&ap[3][i]) * x3; |
| 86 | + |
| 87 | + tempY = _mm256_loadu_pd(&y[i]); |
| 88 | + tempY += sum * __alpha; |
| 89 | + _mm256_storeu_pd(&y[i], tempY); |
| 90 | + } |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | + |
| 95 | +#define HAVE_KERNEL_4x2 |
| 96 | + |
| 97 | +static void dgemv_kernel_4x2( BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y, FLOAT *alpha) |
| 98 | +{ |
| 99 | + |
| 100 | + int i = 0; |
| 101 | + |
| 102 | + __m256d x0, x1; |
| 103 | + __m256d __alpha; |
| 104 | + |
| 105 | + x0 = _mm256_broadcastsd_pd(_mm_load_sd(&x[0])); |
| 106 | + x1 = _mm256_broadcastsd_pd(_mm_load_sd(&x[1])); |
| 107 | + |
| 108 | + __alpha = _mm256_broadcastsd_pd(_mm_load_sd(alpha)); |
| 109 | + |
| 110 | + |
| 111 | + for (i = 0; i < n; i+= 4) { |
| 112 | + __m256d tempY; |
| 113 | + __m256d sum; |
| 114 | + |
| 115 | + sum = _mm256_loadu_pd(&ap[0][i]) * x0 + _mm256_loadu_pd(&ap[1][i]) * x1; |
| 116 | + |
| 117 | + tempY = _mm256_loadu_pd(&y[i]); |
| 118 | + tempY += sum * __alpha; |
| 119 | + _mm256_storeu_pd(&y[i], tempY); |
| 120 | + } |
| 121 | + |
| 122 | +} |
| 123 | + |
| 124 | +#else |
| 125 | +#include "dgemv_n_microk_haswell-4.c" |
| 126 | +#endif |
0 commit comments