|
| 1 | +/*************************************************************************** |
| 2 | +Copyright (c) 2023, 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 "common.h" |
| 29 | + |
| 30 | +double CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y) |
| 31 | +{ |
| 32 | + BLASLONG i=0, j=0; |
| 33 | + double dot = 0.0 ; |
| 34 | + |
| 35 | + if ( n < 1 ) return(dot); |
| 36 | + vfloat64m4_t vr; |
| 37 | + vfloat32m2_t vx, vy; |
| 38 | + unsigned int gvl = 0; |
| 39 | + vfloat64m1_t v_res, v_z0; |
| 40 | + gvl = vsetvlmax_e64m1(); |
| 41 | + v_res = vfmv_v_f_f64m1(0, gvl); |
| 42 | + v_z0 = vfmv_v_f_f64m1(0, gvl); |
| 43 | + |
| 44 | + if(inc_x == 1 && inc_y == 1){ |
| 45 | + gvl = vsetvl_e64m4(n); |
| 46 | + vr = vfmv_v_f_f64m4(0, gvl); |
| 47 | + for(i=0,j=0; i<n/gvl; i++){ |
| 48 | + vx = vle32_v_f32m2(&x[j], gvl); |
| 49 | + vy = vle32_v_f32m2(&y[j], gvl); |
| 50 | + vr = vfwmacc_vv_f64m4(vr, vx, vy, gvl); |
| 51 | + j += gvl; |
| 52 | + } |
| 53 | + if(j > 0){ |
| 54 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 55 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 56 | + } |
| 57 | + //tail |
| 58 | + if(j < n){ |
| 59 | + gvl = vsetvl_e64m4(n-j); |
| 60 | + vx = vle32_v_f32m2(&x[j], gvl); |
| 61 | + vy = vle32_v_f32m2(&y[j], gvl); |
| 62 | + vfloat64m4_t vz = vfmv_v_f_f64m4(0, gvl); |
| 63 | + //vr = vfdot_vv_f32m2(vx, vy, gvl); |
| 64 | + vr = vfwmacc_vv_f64m4(vz, vx, vy, gvl); |
| 65 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 66 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 67 | + } |
| 68 | + }else if(inc_y == 1){ |
| 69 | + gvl = vsetvl_e64m4(n); |
| 70 | + vr = vfmv_v_f_f64m4(0, gvl); |
| 71 | + int stride_x = inc_x * sizeof(FLOAT); |
| 72 | + for(i=0,j=0; i<n/gvl; i++){ |
| 73 | + vx = vlse32_v_f32m2(&x[j*inc_x], stride_x, gvl); |
| 74 | + vy = vle32_v_f32m2(&y[j], gvl); |
| 75 | + vr = vfwmacc_vv_f64m4(vr, vx, vy, gvl); |
| 76 | + j += gvl; |
| 77 | + } |
| 78 | + if(j > 0){ |
| 79 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 80 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 81 | + |
| 82 | + } |
| 83 | + //tail |
| 84 | + if(j < n){ |
| 85 | + gvl = vsetvl_e64m4(n-j); |
| 86 | + vx = vlse32_v_f32m2(&x[j*inc_x], stride_x, gvl); |
| 87 | + vy = vle32_v_f32m2(&y[j], gvl); |
| 88 | + vfloat64m4_t vz = vfmv_v_f_f64m4(0, gvl); |
| 89 | + //vr = vfdot_vv_f32m2(vx, vy, gvl); |
| 90 | + vr = vfwmacc_vv_f64m4(vz, vx, vy, gvl); |
| 91 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 92 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 93 | + |
| 94 | + } |
| 95 | + }else if(inc_x == 1){ |
| 96 | + gvl = vsetvl_e64m4(n); |
| 97 | + vr = vfmv_v_f_f64m4(0, gvl); |
| 98 | + int stride_y = inc_y * sizeof(FLOAT); |
| 99 | + for(i=0,j=0; i<n/gvl; i++){ |
| 100 | + vx = vle32_v_f32m2(&x[j], gvl); |
| 101 | + vy = vlse32_v_f32m2(&y[j*inc_y], stride_y, gvl); |
| 102 | + vr = vfwmacc_vv_f64m4(vr, vx, vy, gvl); |
| 103 | + j += gvl; |
| 104 | + } |
| 105 | + if(j > 0){ |
| 106 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 107 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 108 | + |
| 109 | + } |
| 110 | + //tail |
| 111 | + if(j < n){ |
| 112 | + gvl = vsetvl_e64m4(n-j); |
| 113 | + vx = vle32_v_f32m2(&x[j], gvl); |
| 114 | + vy = vlse32_v_f32m2(&y[j*inc_y], stride_y, gvl); |
| 115 | + vfloat64m4_t vz = vfmv_v_f_f64m4(0, gvl); |
| 116 | + //vr = vfdot_vv_f32m2(vx, vy, gvl); |
| 117 | + vr = vfwmacc_vv_f64m4(vz, vx, vy, gvl); |
| 118 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 119 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 120 | + |
| 121 | + } |
| 122 | + }else{ |
| 123 | + gvl = vsetvl_e64m4(n); |
| 124 | + vr = vfmv_v_f_f64m4(0, gvl); |
| 125 | + int stride_x = inc_x * sizeof(FLOAT); |
| 126 | + int stride_y = inc_y * sizeof(FLOAT); |
| 127 | + for(i=0,j=0; i<n/gvl; i++){ |
| 128 | + vx = vlse32_v_f32m2(&x[j*inc_x], stride_x, gvl); |
| 129 | + vy = vlse32_v_f32m2(&y[j*inc_y], stride_y, gvl); |
| 130 | + vr = vfwmacc_vv_f64m4(vr, vx, vy, gvl); |
| 131 | + j += gvl; |
| 132 | + } |
| 133 | + if(j > 0){ |
| 134 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 135 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 136 | + |
| 137 | + } |
| 138 | + //tail |
| 139 | + if(j < n){ |
| 140 | + gvl = vsetvl_e64m4(n-j); |
| 141 | + vx = vlse32_v_f32m2(&x[j*inc_x], stride_x, gvl); |
| 142 | + vy = vlse32_v_f32m2(&y[j*inc_y], stride_y, gvl); |
| 143 | + vfloat64m4_t vz = vfmv_v_f_f64m4(0, gvl); |
| 144 | + //vr = vfdot_vv_f32m2(vx, vy, gvl); |
| 145 | + vr = vfwmacc_vv_f64m4(vz, vx, vy, gvl); |
| 146 | + v_res = vfredusum_vs_f64m4_f64m1(v_res, vr, v_z0, gvl); |
| 147 | + dot += (double)vfmv_f_s_f64m1_f64(v_res); |
| 148 | + |
| 149 | + } |
| 150 | + } |
| 151 | + return(dot); |
| 152 | +} |
0 commit comments