// Auto-generated file. Do not edit! // Template: src/x8-packw/scalar.c.in // Generator: tools/xngen // // Copyright 2023 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include #include #include #include "xnnpack/math.h" #include "xnnpack/packw.h" #include "xnnpack/unaligned.h" void xnn_x8_packw_gemm_goi_ukernel_x2__scalar_u4( size_t g, size_t nc, size_t kc, size_t nr, size_t kr, size_t sr, const int8_t* weights, const uint32_t* bias, const void* scale, int8_t* packed_weights, size_t extra_bytes, const void* params) { assert(g != 0); assert(nc != 0); assert(kc != 0); assert(nr == 2); // This kernel is for NR=2 assert(kr == 1); assert(sr == 1); assert(weights != NULL); assert(packed_weights != NULL); int8_t* out = (int8_t*) packed_weights; const uint32_t* b = (const uint32_t*) bias; do { // NC main loop multiple of 2 const int8_t* w0 = (const int8_t*) weights; size_t n = nc; for (;n >= 2; n -= 2) { if XNN_LIKELY(b != NULL) { unaligned_store_s32(out + 0 * sizeof(int32_t), b[0]); unaligned_store_s32(out + 1 * sizeof(int32_t), b[1]); b += 2; } else { unaligned_store_s32(out + 0 * sizeof(int32_t), 0); unaligned_store_s32(out + 1 * sizeof(int32_t), 0); } out += 2 * sizeof(uint32_t); const int8_t* w1 = w0 + kc; // KC main loop multiple of 2x4 size_t k = kc; for (; k >= 4; k -= 4) { const int8_t v00 = w0[0]; const int8_t v01 = w0[1]; const int8_t v02 = w0[2]; const int8_t v03 = w0[3]; w0 += 4; const int8_t v10 = w1[0]; const int8_t v11 = w1[1]; const int8_t v12 = w1[2]; const int8_t v13 = w1[3]; w1 += 4; out[0] = v00; out[1] = v10; out[2] = v01; out[3] = v11; out[4] = v02; out[5] = v12; out[6] = v03; out[7] = v13; out += 8; } // KC remainder for (; k != 0; --k) { const int8_t v0 = *w0++; out[0] = v0; const int8_t v1 = *w1++; out[1] = v1; out += 2; } out = (int8_t*) ((uintptr_t) out + extra_bytes); w0 = w1; } // NC remainder (1..1) if XNN_UNLIKELY(n != 0) { if XNN_LIKELY(b != NULL) { size_t nb = n; do { unaligned_store_s32(out, *b++); out += sizeof(uint32_t); } while (--nb != 0); } else { size_t nb = n; do { unaligned_store_s32(out, 0); out += sizeof(uint32_t); } while (--nb != 0); } out += (2 - n) * sizeof(uint32_t); // KC main loop multiple of 2x4 size_t k = kc; for (; k >= 4; k -= 4) { const int8_t v00 = w0[0]; const int8_t v01 = w0[1]; const int8_t v02 = w0[2]; const int8_t v03 = w0[3]; w0 += 4; out[0] = v00; out[2] = v01; out[4] = v02; out[6] = v03; out += 8; } // KC remainder of 1..3 for (; k != 0; --k) { const int8_t v0 = *w0++; out[0] = v0; out += 2; } out = (int8_t*) ((uintptr_t) out + extra_bytes); } weights += nc * kc; } while (--g != 0); }