|
| 1 | +/*************************************************************************** |
| 2 | +Copyright (c) 2025, The OpenBLAS Project |
| 3 | +All rights reserved. |
| 4 | +
|
| 5 | +Redistribution and use in source and binary forms, with or without |
| 6 | +modification, are permitted provided that the following conditions are |
| 7 | +met: |
| 8 | +
|
| 9 | + 1. Redistributions of source code must retain the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer. |
| 11 | +
|
| 12 | + 2. Redistributions in binary form must reproduce the above copyright |
| 13 | + notice, this list of conditions and the following disclaimer in |
| 14 | + the documentation and/or other materials provided with the |
| 15 | + distribution. |
| 16 | + 3. Neither the name of the OpenBLAS project nor the names of |
| 17 | + its contributors may be used to endorse or promote products |
| 18 | + derived from this software without specific prior written |
| 19 | + permission. |
| 20 | +
|
| 21 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 22 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 25 | +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 28 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 29 | +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 30 | +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +*****************************************************************************/ |
| 32 | + |
| 33 | +#include <arm_sve.h> |
| 34 | + |
| 35 | +#include "common.h" |
| 36 | + |
| 37 | +#ifdef DOUBLE |
| 38 | +#define SV_TYPE svfloat64_t |
| 39 | +#define SV_COUNT svcntd |
| 40 | +#define SV_DUP svdup_f64 |
| 41 | +#define SV_WHILE svwhilelt_b64_s64 |
| 42 | +#define SV_TRUE svptrue_b64 |
| 43 | +#else |
| 44 | +#define SV_TYPE svfloat32_t |
| 45 | +#define SV_COUNT svcntw |
| 46 | +#define SV_DUP svdup_f32 |
| 47 | +#define SV_WHILE svwhilelt_b32_s64 |
| 48 | +#define SV_TRUE svptrue_b32 |
| 49 | +#endif |
| 50 | + |
| 51 | +int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2) { |
| 52 | + BLASLONG i = 0; |
| 53 | + BLASLONG ix = 0, iy = 0; |
| 54 | + BLASLONG sve_size = SV_COUNT(); |
| 55 | + |
| 56 | + if (n < 0) return (0); |
| 57 | + if (da == 0.0) return (0); |
| 58 | + |
| 59 | + if (inc_x == 1 && inc_y == 1) { |
| 60 | + SV_TYPE da_vec = SV_DUP(da); |
| 61 | + for (i = 0; i + sve_size - 1 < n; i += sve_size) { |
| 62 | + SV_TYPE x_vec = svld1(SV_TRUE(), &x[i]); |
| 63 | + SV_TYPE y_vec = svld1(SV_TRUE(), &y[i]); |
| 64 | + y_vec = svmla_x(SV_TRUE(), y_vec, da_vec, x_vec); |
| 65 | + svst1(SV_TRUE(), &y[i], y_vec); |
| 66 | + } |
| 67 | + |
| 68 | + if (i < n) { |
| 69 | + svbool_t pg = SV_WHILE(i, n); |
| 70 | + SV_TYPE x_vec = svld1(pg, &x[i]); |
| 71 | + SV_TYPE y_vec = svld1(pg, &y[i]); |
| 72 | + y_vec = svmla_x(pg, y_vec, da_vec, x_vec); |
| 73 | + svst1(pg, &y[i], y_vec); |
| 74 | + } |
| 75 | + return (0); |
| 76 | + } |
| 77 | + |
| 78 | + while (i < n) { |
| 79 | + y[iy] += da * x[ix]; |
| 80 | + ix += inc_x; |
| 81 | + iy += inc_y; |
| 82 | + i++; |
| 83 | + } |
| 84 | + |
| 85 | + return (0); |
| 86 | +} |
0 commit comments