| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-spmm/neon.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2019 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/prefetch.h" |
| 15 |
#include "xnnpack/spmm.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f32_spmm_minmax_ukernel_32x1__neon_x2( |
| 19 |
size_t mc, |
| 20 |
size_t nc, |
| 21 |
const float* input, |
| 22 |
const float* weights, |
| 23 |
const int32_t* widx_dmap, |
| 24 |
const uint32_t* nidx_nnzmap, |
| 25 |
float* output, |
| 26 |
size_t output_stride, |
| 27 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 28 |
{ |
| 29 |
assert(mc != 0); |
| 30 |
assert(mc % sizeof(float) == 0); |
| 31 |
assert(nc != 0); |
| 32 |
|
| 33 |
#if XNN_ARCH_ARM64 |
| 34 |
const float32x4x2_t vminmax = vld2q_dup_f32(¶ms->scalar.min); |
| 35 |
const float32x4_t vmin = vminmax.val[0]; |
| 36 |
const float32x4_t vmax = vminmax.val[1]; |
| 37 |
#else |
| 38 |
const float32x2x2_t vminmax = vld2_dup_f32(¶ms->scalar.min); |
| 39 |
const float32x4_t vmin = vcombine_f32(vminmax.val[0], vminmax.val[0]); |
| 40 |
const float32x4_t vmax = vcombine_f32(vminmax.val[1], vminmax.val[1]); |
| 41 |
#endif |
| 42 |
|
| 43 |
size_t output_decrement = output_stride * nc - 32 * sizeof(float); |
| 44 |
while XNN_LIKELY(mc >= 32 * sizeof(float)) { |
| 45 |
const float* w = weights; |
| 46 |
const int32_t* dmap = widx_dmap; |
| 47 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 48 |
size_t n = nc; |
| 49 |
do { |
| 50 |
uint32_t nnz = *nnzmap++; |
| 51 |
float32x4_t vacc0123x0 = vld1q_dup_f32(w); w += 1; |
| 52 |
float32x4_t vacc0123x1 = vmovq_n_f32(0.0f); |
| 53 |
float32x4_t vacc4567x0 = vacc0123x0; |
| 54 |
float32x4_t vacc4567x1 = vmovq_n_f32(0.0f); |
| 55 |
float32x4_t vacc89ABx0 = vacc0123x0; |
| 56 |
float32x4_t vacc89ABx1 = vmovq_n_f32(0.0f); |
| 57 |
float32x4_t vaccCDEFx0 = vacc0123x0; |
| 58 |
float32x4_t vaccCDEFx1 = vmovq_n_f32(0.0f); |
| 59 |
float32x4_t vaccGHIJx0 = vacc0123x0; |
| 60 |
float32x4_t vaccGHIJx1 = vmovq_n_f32(0.0f); |
| 61 |
float32x4_t vaccKLMNx0 = vacc0123x0; |
| 62 |
float32x4_t vaccKLMNx1 = vmovq_n_f32(0.0f); |
| 63 |
float32x4_t vaccOPQRx0 = vacc0123x0; |
| 64 |
float32x4_t vaccOPQRx1 = vmovq_n_f32(0.0f); |
| 65 |
float32x4_t vaccSTUVx0 = vacc0123x0; |
| 66 |
float32x4_t vaccSTUVx1 = vmovq_n_f32(0.0f); |
| 67 |
for (; nnz >= 2; nnz -= 2) { |
| 68 |
const intptr_t diff0 = dmap[0]; |
| 69 |
const intptr_t diff1 = dmap[1]; |
| 70 |
dmap += 2; |
| 71 |
const float32x4_t vi0123x0 = vld1q_f32(input); |
| 72 |
const float32x4_t vi4567x0 = vld1q_f32(input + 4); |
| 73 |
const float32x4_t vi89ABx0 = vld1q_f32(input + 8); |
| 74 |
const float32x4_t viCDEFx0 = vld1q_f32(input + 12); |
| 75 |
const float32x4_t viGHIJx0 = vld1q_f32(input + 16); |
| 76 |
const float32x4_t viKLMNx0 = vld1q_f32(input + 20); |
| 77 |
const float32x4_t viOPQRx0 = vld1q_f32(input + 24); |
| 78 |
const float32x4_t viSTUVx0 = vld1q_f32(input + 28); |
| 79 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff0); |
| 80 |
xnn_prefetch_to_l1(input + 16); |
| 81 |
xnn_prefetch_to_l1(input + 32); |
| 82 |
const float32x4_t vw0 = vld1q_dup_f32(w); w += 1; |
| 83 |
xnn_prefetch_to_l1(w + 32); |
| 84 |
vacc0123x0 = vmlaq_f32(vacc0123x0, vi0123x0, vw0); |
| 85 |
vacc4567x0 = vmlaq_f32(vacc4567x0, vi4567x0, vw0); |
| 86 |
vacc89ABx0 = vmlaq_f32(vacc89ABx0, vi89ABx0, vw0); |
| 87 |
vaccCDEFx0 = vmlaq_f32(vaccCDEFx0, viCDEFx0, vw0); |
| 88 |
vaccGHIJx0 = vmlaq_f32(vaccGHIJx0, viGHIJx0, vw0); |
| 89 |
vaccKLMNx0 = vmlaq_f32(vaccKLMNx0, viKLMNx0, vw0); |
| 90 |
vaccOPQRx0 = vmlaq_f32(vaccOPQRx0, viOPQRx0, vw0); |
| 91 |
vaccSTUVx0 = vmlaq_f32(vaccSTUVx0, viSTUVx0, vw0); |
| 92 |
const float32x4_t vi0123x1 = vld1q_f32(input); |
| 93 |
const float32x4_t vi4567x1 = vld1q_f32(input + 4); |
| 94 |
const float32x4_t vi89ABx1 = vld1q_f32(input + 8); |
| 95 |
const float32x4_t viCDEFx1 = vld1q_f32(input + 12); |
| 96 |
const float32x4_t viGHIJx1 = vld1q_f32(input + 16); |
| 97 |
const float32x4_t viKLMNx1 = vld1q_f32(input + 20); |
| 98 |
const float32x4_t viOPQRx1 = vld1q_f32(input + 24); |
| 99 |
const float32x4_t viSTUVx1 = vld1q_f32(input + 28); |
| 100 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff1); |
| 101 |
xnn_prefetch_to_l1(input + 16); |
| 102 |
xnn_prefetch_to_l1(input + 32); |
| 103 |
const float32x4_t vw1 = vld1q_dup_f32(w); w += 1; |
| 104 |
xnn_prefetch_to_l1(w + 32); |
| 105 |
vacc0123x1 = vmlaq_f32(vacc0123x1, vi0123x1, vw1); |
| 106 |
vacc4567x1 = vmlaq_f32(vacc4567x1, vi4567x1, vw1); |
| 107 |
vacc89ABx1 = vmlaq_f32(vacc89ABx1, vi89ABx1, vw1); |
| 108 |
vaccCDEFx1 = vmlaq_f32(vaccCDEFx1, viCDEFx1, vw1); |
| 109 |
vaccGHIJx1 = vmlaq_f32(vaccGHIJx1, viGHIJx1, vw1); |
| 110 |
vaccKLMNx1 = vmlaq_f32(vaccKLMNx1, viKLMNx1, vw1); |
| 111 |
vaccOPQRx1 = vmlaq_f32(vaccOPQRx1, viOPQRx1, vw1); |
| 112 |
vaccSTUVx1 = vmlaq_f32(vaccSTUVx1, viSTUVx1, vw1); |
| 113 |
} |
| 114 |
float32x4_t vacc0123 = vacc0123x0; |
| 115 |
float32x4_t vacc4567 = vacc4567x0; |
| 116 |
float32x4_t vacc89AB = vacc89ABx0; |
| 117 |
float32x4_t vaccCDEF = vaccCDEFx0; |
| 118 |
float32x4_t vaccGHIJ = vaccGHIJx0; |
| 119 |
float32x4_t vaccKLMN = vaccKLMNx0; |
| 120 |
float32x4_t vaccOPQR = vaccOPQRx0; |
| 121 |
float32x4_t vaccSTUV = vaccSTUVx0; |
| 122 |
vacc0123 = vaddq_f32(vacc0123, vacc0123x1); |
| 123 |
vacc4567 = vaddq_f32(vacc4567, vacc4567x1); |
| 124 |
vacc89AB = vaddq_f32(vacc89AB, vacc89ABx1); |
| 125 |
vaccCDEF = vaddq_f32(vaccCDEF, vaccCDEFx1); |
| 126 |
vaccGHIJ = vaddq_f32(vaccGHIJ, vaccGHIJx1); |
| 127 |
vaccKLMN = vaddq_f32(vaccKLMN, vaccKLMNx1); |
| 128 |
vaccOPQR = vaddq_f32(vaccOPQR, vaccOPQRx1); |
| 129 |
vaccSTUV = vaddq_f32(vaccSTUV, vaccSTUVx1); |
| 130 |
if XNN_LIKELY(nnz != 0) { |
| 131 |
do { |
| 132 |
const intptr_t diff = *dmap++; |
| 133 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 134 |
const float32x4_t vi4567 = vld1q_f32(input + 4); |
| 135 |
const float32x4_t vi89AB = vld1q_f32(input + 8); |
| 136 |
const float32x4_t viCDEF = vld1q_f32(input + 12); |
| 137 |
const float32x4_t viGHIJ = vld1q_f32(input + 16); |
| 138 |
const float32x4_t viKLMN = vld1q_f32(input + 20); |
| 139 |
const float32x4_t viOPQR = vld1q_f32(input + 24); |
| 140 |
const float32x4_t viSTUV = vld1q_f32(input + 28); |
| 141 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 142 |
xnn_prefetch_to_l1(input + 16); |
| 143 |
xnn_prefetch_to_l1(input + 32); |
| 144 |
const float32x4_t vw = vld1q_dup_f32(w); w += 1; |
| 145 |
xnn_prefetch_to_l1(w + 32); |
| 146 |
vacc0123 = vmlaq_f32(vacc0123, vi0123, vw); |
| 147 |
vacc4567 = vmlaq_f32(vacc4567, vi4567, vw); |
| 148 |
vacc89AB = vmlaq_f32(vacc89AB, vi89AB, vw); |
| 149 |
vaccCDEF = vmlaq_f32(vaccCDEF, viCDEF, vw); |
| 150 |
vaccGHIJ = vmlaq_f32(vaccGHIJ, viGHIJ, vw); |
| 151 |
vaccKLMN = vmlaq_f32(vaccKLMN, viKLMN, vw); |
| 152 |
vaccOPQR = vmlaq_f32(vaccOPQR, viOPQR, vw); |
| 153 |
vaccSTUV = vmlaq_f32(vaccSTUV, viSTUV, vw); |
| 154 |
} while (--nnz != 0); |
| 155 |
} |
| 156 |
float32x4_t vout0123 = vminq_f32(vacc0123, vmax); |
| 157 |
float32x4_t vout4567 = vminq_f32(vacc4567, vmax); |
| 158 |
float32x4_t vout89AB = vminq_f32(vacc89AB, vmax); |
| 159 |
float32x4_t voutCDEF = vminq_f32(vaccCDEF, vmax); |
| 160 |
float32x4_t voutGHIJ = vminq_f32(vaccGHIJ, vmax); |
| 161 |
float32x4_t voutKLMN = vminq_f32(vaccKLMN, vmax); |
| 162 |
float32x4_t voutOPQR = vminq_f32(vaccOPQR, vmax); |
| 163 |
float32x4_t voutSTUV = vminq_f32(vaccSTUV, vmax); |
| 164 |
vout0123 = vmaxq_f32(vout0123, vmin); |
| 165 |
vout4567 = vmaxq_f32(vout4567, vmin); |
| 166 |
vout89AB = vmaxq_f32(vout89AB, vmin); |
| 167 |
voutCDEF = vmaxq_f32(voutCDEF, vmin); |
| 168 |
voutGHIJ = vmaxq_f32(voutGHIJ, vmin); |
| 169 |
voutKLMN = vmaxq_f32(voutKLMN, vmin); |
| 170 |
voutOPQR = vmaxq_f32(voutOPQR, vmin); |
| 171 |
voutSTUV = vmaxq_f32(voutSTUV, vmin); |
| 172 |
vst1q_f32(output, vout0123); |
| 173 |
vst1q_f32(output + 4, vout4567); |
| 174 |
vst1q_f32(output + 8, vout89AB); |
| 175 |
vst1q_f32(output + 12, voutCDEF); |
| 176 |
vst1q_f32(output + 16, voutGHIJ); |
| 177 |
vst1q_f32(output + 20, voutKLMN); |
| 178 |
vst1q_f32(output + 24, voutOPQR); |
| 179 |
vst1q_f32(output + 28, voutSTUV); |
| 180 |
output = (float*) ((uintptr_t) output + output_stride); |
| 181 |
} while (--n != 0); |
| 182 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 183 |
input += 32; |
| 184 |
mc -= 32 * sizeof(float); |
| 185 |
} |
| 186 |
if XNN_UNLIKELY(mc != 0) { |
| 187 |
output_decrement += 16 * sizeof(float); |
| 188 |
if (mc & (16 * sizeof(float))) { |
| 189 |
const float* w = weights; |
| 190 |
const int32_t* dmap = widx_dmap; |
| 191 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 192 |
size_t n = nc; |
| 193 |
do { |
| 194 |
uint32_t nnz = *nnzmap++; |
| 195 |
float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; |
| 196 |
float32x4_t vacc4567 = vacc0123; |
| 197 |
float32x4_t vacc89AB = vacc0123; |
| 198 |
float32x4_t vaccCDEF = vacc0123; |
| 199 |
if XNN_LIKELY(nnz != 0) { |
| 200 |
do { |
| 201 |
const intptr_t diff = *dmap++; |
| 202 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 203 |
const float32x4_t vi4567 = vld1q_f32(input + 4); |
| 204 |
const float32x4_t vi89AB = vld1q_f32(input + 8); |
| 205 |
const float32x4_t viCDEF = vld1q_f32(input + 12); |
| 206 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 207 |
const float32x4_t vw = vld1q_dup_f32(w); w += 1; |
| 208 |
vacc0123 = vmlaq_f32(vacc0123, vi0123, vw); |
| 209 |
vacc4567 = vmlaq_f32(vacc4567, vi4567, vw); |
| 210 |
vacc89AB = vmlaq_f32(vacc89AB, vi89AB, vw); |
| 211 |
vaccCDEF = vmlaq_f32(vaccCDEF, viCDEF, vw); |
| 212 |
} while (--nnz != 0); |
| 213 |
} |
| 214 |
float32x4_t vout0123 = vminq_f32(vacc0123, vmax); |
| 215 |
float32x4_t vout4567 = vminq_f32(vacc4567, vmax); |
| 216 |
float32x4_t vout89AB = vminq_f32(vacc89AB, vmax); |
| 217 |
float32x4_t voutCDEF = vminq_f32(vaccCDEF, vmax); |
| 218 |
vout0123 = vmaxq_f32(vout0123, vmin); |
| 219 |
vout4567 = vmaxq_f32(vout4567, vmin); |
| 220 |
vout89AB = vmaxq_f32(vout89AB, vmin); |
| 221 |
voutCDEF = vmaxq_f32(voutCDEF, vmin); |
| 222 |
vst1q_f32(output, vout0123); |
| 223 |
vst1q_f32(output + 4, vout4567); |
| 224 |
vst1q_f32(output + 8, vout89AB); |
| 225 |
vst1q_f32(output + 12, voutCDEF); |
| 226 |
output = (float*) ((uintptr_t) output + output_stride); |
| 227 |
} while (--n != 0); |
| 228 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 229 |
input += 16; |
| 230 |
} |
| 231 |
output_decrement += 8 * sizeof(float); |
| 232 |
if (mc & (8 * sizeof(float))) { |
| 233 |
const float* w = weights; |
| 234 |
const int32_t* dmap = widx_dmap; |
| 235 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 236 |
size_t n = nc; |
| 237 |
do { |
| 238 |
uint32_t nnz = *nnzmap++; |
| 239 |
float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; |
| 240 |
float32x4_t vacc4567 = vacc0123; |
| 241 |
if XNN_LIKELY(nnz != 0) { |
| 242 |
do { |
| 243 |
const intptr_t diff = *dmap++; |
| 244 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 245 |
const float32x4_t vi4567 = vld1q_f32(input + 4); |
| 246 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 247 |
const float32x4_t vw = vld1q_dup_f32(w); w += 1; |
| 248 |
vacc0123 = vmlaq_f32(vacc0123, vi0123, vw); |
| 249 |
vacc4567 = vmlaq_f32(vacc4567, vi4567, vw); |
| 250 |
} while (--nnz != 0); |
| 251 |
} |
| 252 |
float32x4_t vout0123 = vminq_f32(vacc0123, vmax); |
| 253 |
float32x4_t vout4567 = vminq_f32(vacc4567, vmax); |
| 254 |
vout0123 = vmaxq_f32(vout0123, vmin); |
| 255 |
vout4567 = vmaxq_f32(vout4567, vmin); |
| 256 |
vst1q_f32(output, vout0123); |
| 257 |
vst1q_f32(output + 4, vout4567); |
| 258 |
output = (float*) ((uintptr_t) output + output_stride); |
| 259 |
} while (--n != 0); |
| 260 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 261 |
input += 8; |
| 262 |
} |
| 263 |
output_decrement += 4 * sizeof(float); |
| 264 |
if (mc & (4 * sizeof(float))) { |
| 265 |
const float* w = weights; |
| 266 |
const int32_t* dmap = widx_dmap; |
| 267 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 268 |
size_t n = nc; |
| 269 |
do { |
| 270 |
uint32_t nnz = *nnzmap++; |
| 271 |
float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; |
| 272 |
if XNN_LIKELY(nnz != 0) { |
| 273 |
do { |
| 274 |
const intptr_t diff = *dmap++; |
| 275 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 276 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 277 |
const float32x4_t vw = vld1q_dup_f32(w); w += 1; |
| 278 |
vacc0123 = vmlaq_f32(vacc0123, vi0123, vw); |
| 279 |
} while (--nnz != 0); |
| 280 |
} |
| 281 |
float32x4_t vout0123 = vminq_f32(vacc0123, vmax); |
| 282 |
vout0123 = vmaxq_f32(vout0123, vmin); |
| 283 |
vst1q_f32(output, vout0123); |
| 284 |
output = (float*) ((uintptr_t) output + output_stride); |
| 285 |
} while (--n != 0); |
| 286 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 287 |
input += 4; |
| 288 |
} |
| 289 |
output_decrement += 2 * sizeof(float); |
| 290 |
if (mc & (2 * sizeof(float))) { |
| 291 |
const float* w = weights; |
| 292 |
const int32_t* dmap = widx_dmap; |
| 293 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 294 |
size_t n = nc; |
| 295 |
do { |
| 296 |
uint32_t nnz = *nnzmap++; |
| 297 |
float32x2_t vacc01 = vld1_dup_f32(w); w += 1; |
| 298 |
if XNN_LIKELY(nnz != 0) { |
| 299 |
do { |
| 300 |
const intptr_t diff = *dmap++; |
| 301 |
const float32x2_t vi01 = vld1_f32(input); |
| 302 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 303 |
const float32x2_t vw = vld1_dup_f32(w); w += 1; |
| 304 |
vacc01 = vmla_f32(vacc01, vi01, vw); |
| 305 |
} while (--nnz != 0); |
| 306 |
} |
| 307 |
float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax)); |
| 308 |
vout01 = vmax_f32(vout01, vget_low_f32(vmin)); |
| 309 |
vst1_f32(output, vout01); |
| 310 |
output = (float*) ((uintptr_t) output + output_stride); |
| 311 |
} while (--n != 0); |
| 312 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 313 |
input += 2; |
| 314 |
} |
| 315 |
output_decrement += 1 * sizeof(float); |
| 316 |
if (mc & (1 * sizeof(float))) { |
| 317 |
const float* w = weights; |
| 318 |
const int32_t* dmap = widx_dmap; |
| 319 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 320 |
size_t n = nc; |
| 321 |
do { |
| 322 |
uint32_t nnz = *nnzmap++; |
| 323 |
float32x2_t vacc0 = vld1_dup_f32(w); w += 1; |
| 324 |
if XNN_LIKELY(nnz != 0) { |
| 325 |
do { |
| 326 |
const intptr_t diff = *dmap++; |
| 327 |
const float32x2_t vi0 = vld1_dup_f32(input); |
| 328 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 329 |
const float32x2_t vw = vld1_dup_f32(w); w += 1; |
| 330 |
vacc0 = vmla_f32(vacc0, vi0, vw); |
| 331 |
} while (--nnz != 0); |
| 332 |
} |
| 333 |
float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax)); |
| 334 |
vout0 = vmax_f32(vout0, vget_low_f32(vmin)); |
| 335 |
vst1_lane_f32(output, vout0, 0); |
| 336 |
output = (float*) ((uintptr_t) output + output_stride); |
| 337 |
} while (--n != 0); |
| 338 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 339 |
input += 1; |
| 340 |
} |
| 341 |
} |
| 342 |
} |