| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/x8-packw/scalar.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2023 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 |
|
| 11 |
#include <assert.h> |
| 12 |
#include <stddef.h> |
| 13 |
#include <stdint.h> |
| 14 |
|
| 15 |
#include "xnnpack/math.h" |
| 16 |
#include "xnnpack/packw.h" |
| 17 |
#include "xnnpack/unaligned.h" |
| 18 |
|
| 19 |
void xnn_x8_packw_gemm_goi_ukernel_x16__scalar_u2( |
| 20 |
size_t g, |
| 21 |
size_t nc, |
| 22 |
size_t kc, |
| 23 |
size_t nr, |
| 24 |
size_t kr, |
| 25 |
size_t sr, |
| 26 |
const int8_t* weights, |
| 27 |
const uint32_t* bias, |
| 28 |
const void* scale, |
| 29 |
int8_t* packed_weights, |
| 30 |
size_t extra_bytes, |
| 31 |
const void* params) |
| 32 |
{ |
| 33 |
assert(g != 0); |
| 34 |
assert(nc != 0); |
| 35 |
assert(kc != 0); |
| 36 |
assert(nr == 16); // This kernel is for NR=16 |
| 37 |
assert(kr == 1); |
| 38 |
assert(sr == 1); |
| 39 |
assert(weights != NULL); |
| 40 |
assert(packed_weights != NULL); |
| 41 |
|
| 42 |
int8_t* out = (int8_t*) packed_weights; |
| 43 |
const uint32_t* b = (const uint32_t*) bias; |
| 44 |
|
| 45 |
do { |
| 46 |
// NC main loop multiple of 16 |
| 47 |
const int8_t* w0 = (const int8_t*) weights; |
| 48 |
size_t n = nc; |
| 49 |
for (;n >= 16; n -= 16) { |
| 50 |
if XNN_LIKELY(b != NULL) { |
| 51 |
unaligned_store_s32(out + 0 * sizeof(int32_t), b[0]); |
| 52 |
unaligned_store_s32(out + 1 * sizeof(int32_t), b[1]); |
| 53 |
unaligned_store_s32(out + 2 * sizeof(int32_t), b[2]); |
| 54 |
unaligned_store_s32(out + 3 * sizeof(int32_t), b[3]); |
| 55 |
unaligned_store_s32(out + 4 * sizeof(int32_t), b[4]); |
| 56 |
unaligned_store_s32(out + 5 * sizeof(int32_t), b[5]); |
| 57 |
unaligned_store_s32(out + 6 * sizeof(int32_t), b[6]); |
| 58 |
unaligned_store_s32(out + 7 * sizeof(int32_t), b[7]); |
| 59 |
unaligned_store_s32(out + 8 * sizeof(int32_t), b[8]); |
| 60 |
unaligned_store_s32(out + 9 * sizeof(int32_t), b[9]); |
| 61 |
unaligned_store_s32(out + 10 * sizeof(int32_t), b[10]); |
| 62 |
unaligned_store_s32(out + 11 * sizeof(int32_t), b[11]); |
| 63 |
unaligned_store_s32(out + 12 * sizeof(int32_t), b[12]); |
| 64 |
unaligned_store_s32(out + 13 * sizeof(int32_t), b[13]); |
| 65 |
unaligned_store_s32(out + 14 * sizeof(int32_t), b[14]); |
| 66 |
unaligned_store_s32(out + 15 * sizeof(int32_t), b[15]); |
| 67 |
b += 16; |
| 68 |
} else { |
| 69 |
unaligned_store_s32(out + 0 * sizeof(int32_t), 0); |
| 70 |
unaligned_store_s32(out + 1 * sizeof(int32_t), 0); |
| 71 |
unaligned_store_s32(out + 2 * sizeof(int32_t), 0); |
| 72 |
unaligned_store_s32(out + 3 * sizeof(int32_t), 0); |
| 73 |
unaligned_store_s32(out + 4 * sizeof(int32_t), 0); |
| 74 |
unaligned_store_s32(out + 5 * sizeof(int32_t), 0); |
| 75 |
unaligned_store_s32(out + 6 * sizeof(int32_t), 0); |
| 76 |
unaligned_store_s32(out + 7 * sizeof(int32_t), 0); |
| 77 |
unaligned_store_s32(out + 8 * sizeof(int32_t), 0); |
| 78 |
unaligned_store_s32(out + 9 * sizeof(int32_t), 0); |
| 79 |
unaligned_store_s32(out + 10 * sizeof(int32_t), 0); |
| 80 |
unaligned_store_s32(out + 11 * sizeof(int32_t), 0); |
| 81 |
unaligned_store_s32(out + 12 * sizeof(int32_t), 0); |
| 82 |
unaligned_store_s32(out + 13 * sizeof(int32_t), 0); |
| 83 |
unaligned_store_s32(out + 14 * sizeof(int32_t), 0); |
| 84 |
unaligned_store_s32(out + 15 * sizeof(int32_t), 0); |
| 85 |
} |
| 86 |
out += 16 * sizeof(uint32_t); |
| 87 |
|
| 88 |
const int8_t* w1 = w0 + kc; |
| 89 |
const int8_t* w2 = w1 + kc; |
| 90 |
const int8_t* w3 = w2 + kc; |
| 91 |
const int8_t* w4 = w3 + kc; |
| 92 |
const int8_t* w5 = w4 + kc; |
| 93 |
const int8_t* w6 = w5 + kc; |
| 94 |
const int8_t* w7 = w6 + kc; |
| 95 |
const int8_t* w8 = w7 + kc; |
| 96 |
const int8_t* w9 = w8 + kc; |
| 97 |
const int8_t* w10 = w9 + kc; |
| 98 |
const int8_t* w11 = w10 + kc; |
| 99 |
const int8_t* w12 = w11 + kc; |
| 100 |
const int8_t* w13 = w12 + kc; |
| 101 |
const int8_t* w14 = w13 + kc; |
| 102 |
const int8_t* w15 = w14 + kc; |
| 103 |
|
| 104 |
// KC main loop multiple of 16x2 |
| 105 |
size_t k = kc; |
| 106 |
for (; k >= 2; k -= 2) { |
| 107 |
const int8_t v00 = w0[0]; |
| 108 |
const int8_t v01 = w0[1]; |
| 109 |
w0 += 2; |
| 110 |
const int8_t v10 = w1[0]; |
| 111 |
const int8_t v11 = w1[1]; |
| 112 |
w1 += 2; |
| 113 |
const int8_t v20 = w2[0]; |
| 114 |
const int8_t v21 = w2[1]; |
| 115 |
w2 += 2; |
| 116 |
const int8_t v30 = w3[0]; |
| 117 |
const int8_t v31 = w3[1]; |
| 118 |
w3 += 2; |
| 119 |
const int8_t v40 = w4[0]; |
| 120 |
const int8_t v41 = w4[1]; |
| 121 |
w4 += 2; |
| 122 |
const int8_t v50 = w5[0]; |
| 123 |
const int8_t v51 = w5[1]; |
| 124 |
w5 += 2; |
| 125 |
const int8_t v60 = w6[0]; |
| 126 |
const int8_t v61 = w6[1]; |
| 127 |
w6 += 2; |
| 128 |
const int8_t v70 = w7[0]; |
| 129 |
const int8_t v71 = w7[1]; |
| 130 |
w7 += 2; |
| 131 |
const int8_t v80 = w8[0]; |
| 132 |
const int8_t v81 = w8[1]; |
| 133 |
w8 += 2; |
| 134 |
const int8_t v90 = w9[0]; |
| 135 |
const int8_t v91 = w9[1]; |
| 136 |
w9 += 2; |
| 137 |
const int8_t v100 = w10[0]; |
| 138 |
const int8_t v101 = w10[1]; |
| 139 |
w10 += 2; |
| 140 |
const int8_t v110 = w11[0]; |
| 141 |
const int8_t v111 = w11[1]; |
| 142 |
w11 += 2; |
| 143 |
const int8_t v120 = w12[0]; |
| 144 |
const int8_t v121 = w12[1]; |
| 145 |
w12 += 2; |
| 146 |
const int8_t v130 = w13[0]; |
| 147 |
const int8_t v131 = w13[1]; |
| 148 |
w13 += 2; |
| 149 |
const int8_t v140 = w14[0]; |
| 150 |
const int8_t v141 = w14[1]; |
| 151 |
w14 += 2; |
| 152 |
const int8_t v150 = w15[0]; |
| 153 |
const int8_t v151 = w15[1]; |
| 154 |
w15 += 2; |
| 155 |
out[0] = v00; |
| 156 |
out[1] = v10; |
| 157 |
out[2] = v20; |
| 158 |
out[3] = v30; |
| 159 |
out[4] = v40; |
| 160 |
out[5] = v50; |
| 161 |
out[6] = v60; |
| 162 |
out[7] = v70; |
| 163 |
out[8] = v80; |
| 164 |
out[9] = v90; |
| 165 |
out[10] = v100; |
| 166 |
out[11] = v110; |
| 167 |
out[12] = v120; |
| 168 |
out[13] = v130; |
| 169 |
out[14] = v140; |
| 170 |
out[15] = v150; |
| 171 |
out[16] = v01; |
| 172 |
out[17] = v11; |
| 173 |
out[18] = v21; |
| 174 |
out[19] = v31; |
| 175 |
out[20] = v41; |
| 176 |
out[21] = v51; |
| 177 |
out[22] = v61; |
| 178 |
out[23] = v71; |
| 179 |
out[24] = v81; |
| 180 |
out[25] = v91; |
| 181 |
out[26] = v101; |
| 182 |
out[27] = v111; |
| 183 |
out[28] = v121; |
| 184 |
out[29] = v131; |
| 185 |
out[30] = v141; |
| 186 |
out[31] = v151; |
| 187 |
out += 32; |
| 188 |
} |
| 189 |
|
| 190 |
// KC remainder |
| 191 |
for (; k != 0; --k) { |
| 192 |
const int8_t v0 = *w0++; |
| 193 |
out[0] = v0; |
| 194 |
const int8_t v1 = *w1++; |
| 195 |
out[1] = v1; |
| 196 |
const int8_t v2 = *w2++; |
| 197 |
out[2] = v2; |
| 198 |
const int8_t v3 = *w3++; |
| 199 |
out[3] = v3; |
| 200 |
const int8_t v4 = *w4++; |
| 201 |
out[4] = v4; |
| 202 |
const int8_t v5 = *w5++; |
| 203 |
out[5] = v5; |
| 204 |
const int8_t v6 = *w6++; |
| 205 |
out[6] = v6; |
| 206 |
const int8_t v7 = *w7++; |
| 207 |
out[7] = v7; |
| 208 |
const int8_t v8 = *w8++; |
| 209 |
out[8] = v8; |
| 210 |
const int8_t v9 = *w9++; |
| 211 |
out[9] = v9; |
| 212 |
const int8_t v10 = *w10++; |
| 213 |
out[10] = v10; |
| 214 |
const int8_t v11 = *w11++; |
| 215 |
out[11] = v11; |
| 216 |
const int8_t v12 = *w12++; |
| 217 |
out[12] = v12; |
| 218 |
const int8_t v13 = *w13++; |
| 219 |
out[13] = v13; |
| 220 |
const int8_t v14 = *w14++; |
| 221 |
out[14] = v14; |
| 222 |
const int8_t v15 = *w15++; |
| 223 |
out[15] = v15; |
| 224 |
out += 16; |
| 225 |
} |
| 226 |
out = (int8_t*) ((uintptr_t) out + extra_bytes); |
| 227 |
w0 = w15; |
| 228 |
} |
| 229 |
|
| 230 |
// NC remainder (1..15) |
| 231 |
if XNN_UNLIKELY(n != 0) { |
| 232 |
if XNN_LIKELY(b != NULL) { |
| 233 |
size_t nb = n; |
| 234 |
do { |
| 235 |
unaligned_store_s32(out, *b++); |
| 236 |
out += sizeof(uint32_t); |
| 237 |
} while (--nb != 0); |
| 238 |
} else { |
| 239 |
size_t nb = n; |
| 240 |
do { |
| 241 |
unaligned_store_s32(out, 0); |
| 242 |
out += sizeof(uint32_t); |
| 243 |
} while (--nb != 0); |
| 244 |
} |
| 245 |
out += (16 - n) * sizeof(uint32_t); |
| 246 |
|
| 247 |
// NR remainder has less than 16 rows so last row is not loaded |
| 248 |
const int8_t* w1 = w0 + kc; |
| 249 |
if XNN_UNPREDICTABLE(n < 2) { |
| 250 |
w1 = w0; |
| 251 |
} |
| 252 |
const int8_t* w2 = w1 + kc; |
| 253 |
if XNN_UNPREDICTABLE(n <= 2) { |
| 254 |
w2 = w1; |
| 255 |
} |
| 256 |
const int8_t* w3 = w2 + kc; |
| 257 |
if XNN_UNPREDICTABLE(n < 4) { |
| 258 |
w3 = w2; |
| 259 |
} |
| 260 |
const int8_t* w4 = w3 + kc; |
| 261 |
if XNN_UNPREDICTABLE(n <= 4) { |
| 262 |
w4 = w3; |
| 263 |
} |
| 264 |
const int8_t* w5 = w4 + kc; |
| 265 |
if XNN_UNPREDICTABLE(n < 6) { |
| 266 |
w5 = w4; |
| 267 |
} |
| 268 |
const int8_t* w6 = w5 + kc; |
| 269 |
if XNN_UNPREDICTABLE(n <= 6) { |
| 270 |
w6 = w5; |
| 271 |
} |
| 272 |
const int8_t* w7 = w6 + kc; |
| 273 |
if XNN_UNPREDICTABLE(n < 8) { |
| 274 |
w7 = w6; |
| 275 |
} |
| 276 |
const int8_t* w8 = w7 + kc; |
| 277 |
if XNN_UNPREDICTABLE(n <= 8) { |
| 278 |
w8 = w7; |
| 279 |
} |
| 280 |
const int8_t* w9 = w8 + kc; |
| 281 |
if XNN_UNPREDICTABLE(n < 10) { |
| 282 |
w9 = w8; |
| 283 |
} |
| 284 |
const int8_t* w10 = w9 + kc; |
| 285 |
if XNN_UNPREDICTABLE(n <= 10) { |
| 286 |
w10 = w9; |
| 287 |
} |
| 288 |
const int8_t* w11 = w10 + kc; |
| 289 |
if XNN_UNPREDICTABLE(n < 12) { |
| 290 |
w11 = w10; |
| 291 |
} |
| 292 |
const int8_t* w12 = w11 + kc; |
| 293 |
if XNN_UNPREDICTABLE(n <= 12) { |
| 294 |
w12 = w11; |
| 295 |
} |
| 296 |
const int8_t* w13 = w12 + kc; |
| 297 |
if XNN_UNPREDICTABLE(n < 14) { |
| 298 |
w13 = w12; |
| 299 |
} |
| 300 |
const int8_t* w14 = w13 + kc; |
| 301 |
if XNN_UNPREDICTABLE(n <= 14) { |
| 302 |
w14 = w13; |
| 303 |
} |
| 304 |
|
| 305 |
// KC main loop multiple of 16x2 |
| 306 |
size_t k = kc; |
| 307 |
for (; k >= 2; k -= 2) { |
| 308 |
const int8_t v00 = w0[0]; |
| 309 |
const int8_t v01 = w0[1]; |
| 310 |
w0 += 2; |
| 311 |
const int8_t v10 = w1[0]; |
| 312 |
const int8_t v11 = w1[1]; |
| 313 |
w1 += 2; |
| 314 |
const int8_t v20 = w2[0]; |
| 315 |
const int8_t v21 = w2[1]; |
| 316 |
w2 += 2; |
| 317 |
const int8_t v30 = w3[0]; |
| 318 |
const int8_t v31 = w3[1]; |
| 319 |
w3 += 2; |
| 320 |
const int8_t v40 = w4[0]; |
| 321 |
const int8_t v41 = w4[1]; |
| 322 |
w4 += 2; |
| 323 |
const int8_t v50 = w5[0]; |
| 324 |
const int8_t v51 = w5[1]; |
| 325 |
w5 += 2; |
| 326 |
const int8_t v60 = w6[0]; |
| 327 |
const int8_t v61 = w6[1]; |
| 328 |
w6 += 2; |
| 329 |
const int8_t v70 = w7[0]; |
| 330 |
const int8_t v71 = w7[1]; |
| 331 |
w7 += 2; |
| 332 |
const int8_t v80 = w8[0]; |
| 333 |
const int8_t v81 = w8[1]; |
| 334 |
w8 += 2; |
| 335 |
const int8_t v90 = w9[0]; |
| 336 |
const int8_t v91 = w9[1]; |
| 337 |
w9 += 2; |
| 338 |
const int8_t v100 = w10[0]; |
| 339 |
const int8_t v101 = w10[1]; |
| 340 |
w10 += 2; |
| 341 |
const int8_t v110 = w11[0]; |
| 342 |
const int8_t v111 = w11[1]; |
| 343 |
w11 += 2; |
| 344 |
const int8_t v120 = w12[0]; |
| 345 |
const int8_t v121 = w12[1]; |
| 346 |
w12 += 2; |
| 347 |
const int8_t v130 = w13[0]; |
| 348 |
const int8_t v131 = w13[1]; |
| 349 |
w13 += 2; |
| 350 |
const int8_t v140 = w14[0]; |
| 351 |
const int8_t v141 = w14[1]; |
| 352 |
w14 += 2; |
| 353 |
out[0] = v00; |
| 354 |
out[1] = v10; |
| 355 |
out[2] = v20; |
| 356 |
out[3] = v30; |
| 357 |
out[4] = v40; |
| 358 |
out[5] = v50; |
| 359 |
out[6] = v60; |
| 360 |
out[7] = v70; |
| 361 |
out[8] = v80; |
| 362 |
out[9] = v90; |
| 363 |
out[10] = v100; |
| 364 |
out[11] = v110; |
| 365 |
out[12] = v120; |
| 366 |
out[13] = v130; |
| 367 |
out[14] = v140; |
| 368 |
out[16] = v01; |
| 369 |
out[17] = v11; |
| 370 |
out[18] = v21; |
| 371 |
out[19] = v31; |
| 372 |
out[20] = v41; |
| 373 |
out[21] = v51; |
| 374 |
out[22] = v61; |
| 375 |
out[23] = v71; |
| 376 |
out[24] = v81; |
| 377 |
out[25] = v91; |
| 378 |
out[26] = v101; |
| 379 |
out[27] = v111; |
| 380 |
out[28] = v121; |
| 381 |
out[29] = v131; |
| 382 |
out[30] = v141; |
| 383 |
out += 32; |
| 384 |
} |
| 385 |
|
| 386 |
// KC remainder of 1..1 |
| 387 |
for (; k != 0; --k) { |
| 388 |
const int8_t v0 = *w0++; |
| 389 |
out[0] = v0; |
| 390 |
const int8_t v1 = *w1++; |
| 391 |
out[1] = v1; |
| 392 |
const int8_t v2 = *w2++; |
| 393 |
out[2] = v2; |
| 394 |
const int8_t v3 = *w3++; |
| 395 |
out[3] = v3; |
| 396 |
const int8_t v4 = *w4++; |
| 397 |
out[4] = v4; |
| 398 |
const int8_t v5 = *w5++; |
| 399 |
out[5] = v5; |
| 400 |
const int8_t v6 = *w6++; |
| 401 |
out[6] = v6; |
| 402 |
const int8_t v7 = *w7++; |
| 403 |
out[7] = v7; |
| 404 |
const int8_t v8 = *w8++; |
| 405 |
out[8] = v8; |
| 406 |
const int8_t v9 = *w9++; |
| 407 |
out[9] = v9; |
| 408 |
const int8_t v10 = *w10++; |
| 409 |
out[10] = v10; |
| 410 |
const int8_t v11 = *w11++; |
| 411 |
out[11] = v11; |
| 412 |
const int8_t v12 = *w12++; |
| 413 |
out[12] = v12; |
| 414 |
const int8_t v13 = *w13++; |
| 415 |
out[13] = v13; |
| 416 |
const int8_t v14 = *w14++; |
| 417 |
out[14] = v14; |
| 418 |
out += 16; |
| 419 |
} |
| 420 |
out = (int8_t*) ((uintptr_t) out + extra_bytes); |
| 421 |
} |
| 422 |
weights += nc * kc; |
| 423 |
} while (--g != 0); |
| 424 |
} |