|
| 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 | +#include <stdlib.h> |
| 29 | +#include <stdio.h> |
| 30 | +#include "common.h" |
| 31 | + |
| 32 | +#if defined(HASWELL) |
| 33 | +#include "cgemv_n_microk_haswell-2.c" |
| 34 | +#endif |
| 35 | + |
| 36 | + |
| 37 | +#define NBMAX 2048 |
| 38 | + |
| 39 | +#ifndef HAVE_KERNEL_16x4 |
| 40 | + |
| 41 | +static void cgemv_kernel_16x4(BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y) |
| 42 | +{ |
| 43 | + BLASLONG i; |
| 44 | + FLOAT *a0,*a1,*a2,*a3; |
| 45 | + a0 = ap[0]; |
| 46 | + a1 = ap[1]; |
| 47 | + a2 = ap[2]; |
| 48 | + a3 = ap[3]; |
| 49 | + |
| 50 | + for ( i=0; i< 2*n; i+=2 ) |
| 51 | + { |
| 52 | +#if ( !defined(CONJ) && !defined(XCONJ) ) || ( defined(CONJ) && defined(XCONJ) ) |
| 53 | + y[i] += a0[i]*x[0] - a0[i+1] * x[1]; |
| 54 | + y[i+1] += a0[i]*x[1] + a0[i+1] * x[0]; |
| 55 | + y[i] += a1[i]*x[2] - a1[i+1] * x[3]; |
| 56 | + y[i+1] += a1[i]*x[3] + a1[i+1] * x[2]; |
| 57 | + y[i] += a2[i]*x[4] - a2[i+1] * x[5]; |
| 58 | + y[i+1] += a2[i]*x[5] + a2[i+1] * x[4]; |
| 59 | + y[i] += a3[i]*x[6] - a3[i+1] * x[7]; |
| 60 | + y[i+1] += a3[i]*x[7] + a3[i+1] * x[6]; |
| 61 | +#else |
| 62 | + y[i] += a0[i]*x[0] + a0[i+1] * x[1]; |
| 63 | + y[i+1] += a0[i]*x[1] - a0[i+1] * x[0]; |
| 64 | + y[i] += a1[i]*x[2] + a1[i+1] * x[3]; |
| 65 | + y[i+1] += a1[i]*x[3] - a1[i+1] * x[2]; |
| 66 | + y[i] += a2[i]*x[4] + a2[i+1] * x[5]; |
| 67 | + y[i+1] += a2[i]*x[5] - a2[i+1] * x[4]; |
| 68 | + y[i] += a3[i]*x[6] + a3[i+1] * x[7]; |
| 69 | + y[i+1] += a3[i]*x[7] - a3[i+1] * x[6]; |
| 70 | +#endif |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +#endif |
| 75 | + |
| 76 | +static void cgemv_kernel_16x1(BLASLONG n, FLOAT *ap, FLOAT *x, FLOAT *y) |
| 77 | +{ |
| 78 | + BLASLONG i; |
| 79 | + FLOAT *a0; |
| 80 | + a0 = ap; |
| 81 | + |
| 82 | + for ( i=0; i< 2*n; i+=2 ) |
| 83 | + { |
| 84 | +#if ( !defined(CONJ) && !defined(XCONJ) ) || ( defined(CONJ) && defined(XCONJ) ) |
| 85 | + y[i] += a0[i]*x[0] - a0[i+1] * x[1]; |
| 86 | + y[i+1] += a0[i]*x[1] + a0[i+1] * x[0]; |
| 87 | +#else |
| 88 | + y[i] += a0[i]*x[0] + a0[i+1] * x[1]; |
| 89 | + y[i+1] += a0[i]*x[1] - a0[i+1] * x[0]; |
| 90 | +#endif |
| 91 | + |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +static void zero_y(BLASLONG n, FLOAT *dest) |
| 97 | +{ |
| 98 | + BLASLONG i; |
| 99 | + for ( i=0; i<2*n; i++ ) |
| 100 | + { |
| 101 | + *dest = 0.0; |
| 102 | + dest++; |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +static void add_y(BLASLONG n, FLOAT *src, FLOAT *dest, BLASLONG inc_dest,FLOAT alpha_r, FLOAT alpha_i) |
| 109 | +{ |
| 110 | + BLASLONG i; |
| 111 | + FLOAT temp_r; |
| 112 | + FLOAT temp_i; |
| 113 | + for ( i=0; i<n; i++ ) |
| 114 | + { |
| 115 | +#if !defined(XCONJ) |
| 116 | + temp_r = alpha_r * src[0] - alpha_i * src[1]; |
| 117 | + temp_i = alpha_r * src[1] + alpha_i * src[0]; |
| 118 | +#else |
| 119 | + temp_r = alpha_r * src[0] + alpha_i * src[1]; |
| 120 | + temp_i = -alpha_r * src[1] + alpha_i * src[0]; |
| 121 | +#endif |
| 122 | + |
| 123 | + *dest += temp_r; |
| 124 | + *(dest+1) += temp_i; |
| 125 | + |
| 126 | + src+=2; |
| 127 | + dest += inc_dest; |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha_r,FLOAT alpha_i, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer) |
| 132 | +{ |
| 133 | + BLASLONG i; |
| 134 | + BLASLONG j; |
| 135 | + FLOAT *a_ptr; |
| 136 | + FLOAT *x_ptr; |
| 137 | + FLOAT *y_ptr; |
| 138 | + FLOAT *ap[4]; |
| 139 | + BLASLONG n1; |
| 140 | + BLASLONG m1; |
| 141 | + BLASLONG m2; |
| 142 | + BLASLONG n2; |
| 143 | + FLOAT xbuffer[8],*ybuffer; |
| 144 | + |
| 145 | + |
| 146 | +#if 0 |
| 147 | +printf("%s %d %d %.16f %.16f %d %d %d\n","zgemv_n",m,n,alpha_r,alpha_i,lda,inc_x,inc_y); |
| 148 | +#endif |
| 149 | + |
| 150 | + if ( m < 1 ) return(0); |
| 151 | + if ( n < 1 ) return(0); |
| 152 | + |
| 153 | + ybuffer = buffer; |
| 154 | + |
| 155 | + inc_x *= 2; |
| 156 | + inc_y *= 2; |
| 157 | + lda *= 2; |
| 158 | + |
| 159 | + n1 = n / 4 ; |
| 160 | + n2 = n % 4 ; |
| 161 | + |
| 162 | + m1 = m - ( m % 16 ); |
| 163 | + m2 = (m % NBMAX) - (m % 16) ; |
| 164 | + |
| 165 | + y_ptr = y; |
| 166 | + |
| 167 | + BLASLONG NB = NBMAX; |
| 168 | + |
| 169 | + while ( NB == NBMAX ) |
| 170 | + { |
| 171 | + |
| 172 | + m1 -= NB; |
| 173 | + if ( m1 < 0) |
| 174 | + { |
| 175 | + if ( m2 == 0 ) break; |
| 176 | + NB = m2; |
| 177 | + } |
| 178 | + |
| 179 | + a_ptr = a; |
| 180 | + x_ptr = x; |
| 181 | + zero_y(NB,ybuffer); |
| 182 | + for( i = 0; i < n1 ; i++) |
| 183 | + { |
| 184 | + |
| 185 | + xbuffer[0] = x_ptr[0]; |
| 186 | + xbuffer[1] = x_ptr[1]; |
| 187 | + x_ptr += inc_x; |
| 188 | + xbuffer[2] = x_ptr[0]; |
| 189 | + xbuffer[3] = x_ptr[1]; |
| 190 | + x_ptr += inc_x; |
| 191 | + xbuffer[4] = x_ptr[0]; |
| 192 | + xbuffer[5] = x_ptr[1]; |
| 193 | + x_ptr += inc_x; |
| 194 | + xbuffer[6] = x_ptr[0]; |
| 195 | + xbuffer[7] = x_ptr[1]; |
| 196 | + x_ptr += inc_x; |
| 197 | + |
| 198 | + ap[0] = a_ptr; |
| 199 | + ap[1] = a_ptr + lda; |
| 200 | + ap[2] = ap[1] + lda; |
| 201 | + ap[3] = ap[2] + lda; |
| 202 | + cgemv_kernel_16x4(NB,ap,xbuffer,ybuffer); |
| 203 | + a_ptr += 4 * lda; |
| 204 | + } |
| 205 | + |
| 206 | + for( i = 0; i < n2 ; i++) |
| 207 | + { |
| 208 | + xbuffer[0] = x_ptr[0]; |
| 209 | + xbuffer[1] = x_ptr[1]; |
| 210 | + x_ptr += inc_x; |
| 211 | + cgemv_kernel_16x1(NB,a_ptr,xbuffer,ybuffer); |
| 212 | + a_ptr += 1 * lda; |
| 213 | + |
| 214 | + } |
| 215 | + add_y(NB,ybuffer,y_ptr,inc_y,alpha_r,alpha_i); |
| 216 | + a += 2 * NB; |
| 217 | + y_ptr += NB * inc_y; |
| 218 | + } |
| 219 | + |
| 220 | + j=0; |
| 221 | + while ( j < (m % 16)) |
| 222 | + { |
| 223 | + a_ptr = a; |
| 224 | + x_ptr = x; |
| 225 | + FLOAT temp_r = 0.0; |
| 226 | + FLOAT temp_i = 0.0; |
| 227 | + for( i = 0; i < n; i++ ) |
| 228 | + { |
| 229 | +#if ( !defined(CONJ) && !defined(XCONJ) ) || ( defined(CONJ) && defined(XCONJ) ) |
| 230 | + temp_r += a_ptr[0] * x_ptr[0] - a_ptr[1] * x_ptr[1]; |
| 231 | + temp_i += a_ptr[0] * x_ptr[1] + a_ptr[1] * x_ptr[0]; |
| 232 | +#else |
| 233 | + temp_r += a_ptr[0] * x_ptr[0] + a_ptr[1] * x_ptr[1]; |
| 234 | + temp_i += a_ptr[0] * x_ptr[1] - a_ptr[1] * x_ptr[0]; |
| 235 | +#endif |
| 236 | + |
| 237 | + a_ptr += lda; |
| 238 | + x_ptr += inc_x; |
| 239 | + } |
| 240 | + |
| 241 | +#if !defined(XCONJ) |
| 242 | + y_ptr[0] += alpha_r * temp_r - alpha_i * temp_i; |
| 243 | + y_ptr[1] += alpha_r * temp_i + alpha_i * temp_r; |
| 244 | +#else |
| 245 | + y_ptr[0] += alpha_r * temp_r + alpha_i * temp_i; |
| 246 | + y_ptr[1] -= alpha_r * temp_i - alpha_i * temp_r; |
| 247 | +#endif |
| 248 | + y_ptr += inc_y; |
| 249 | + a+=2; |
| 250 | + j++; |
| 251 | + } |
| 252 | + return(0); |
| 253 | +} |
| 254 | + |
| 255 | + |
0 commit comments