// Auto-generated file. Do not edit! // Template: src/qs8-gemm/MRx8c8-avxvnni.c.in // Generator: tools/xngen // // Copyright 2024 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 "xnnpack/gemm.h" #include "xnnpack/intrinsics-polyfill.h" #include "xnnpack/math.h" #include "xnnpack/unaligned.h" #include "xnnpack/prefetch.h" void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c8__avxvnni_prfm( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, float* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * sizeof(int8_t)); const int8_t* a0 = a; float* c0 = c; const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point); const __m256 voutput_min = _mm256_set1_ps(params->scalar.min); const __m256 voutput_max = _mm256_set1_ps(params->scalar.max); // XNN_FORCE_REALIZATION(voutput_min); // XNN_FORCE_REALIZATION(voutput_max); do { const __m256i vksum01234567 = _mm256_load_si256(w); __m256i vsum0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0); __m256i vacc0x0123 = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(vsum0x01234567, 0)); __m256i vacc0x4567 = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(vsum0x01234567, 1)); __m256i vacc1x0x0123 = _mm256_setzero_si256(); __m256i vacc1x0x4567 = _mm256_setzero_si256(); w = (const int32_t*) w + 8; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const __m256i va0x01234567 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0)); const __m256i va0x89ABCDEF = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0 + 8)); a0 += 16; const __m256i vb01234567x0123 = _mm256_load_si256(w); const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32)); const __m256i vb01234567x4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 64)); const __m256i vb89ABCDEFx4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 96)); xnn_prefetch_to_l1((const int8_t*) w + 896); vacc0x0123 = _mm256_dpbusd_avx_epi32(vacc0x0123, va0x01234567, vb01234567x0123); vacc0x4567 = _mm256_dpbusd_avx_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123); xnn_prefetch_to_l1((const int8_t*) w + 960); vacc1x0x0123 = _mm256_dpbusd_avx_epi32(vacc1x0x0123, va0x89ABCDEF, vb01234567x4567); vacc1x0x4567 = _mm256_dpbusd_avx_epi32(vacc1x0x4567, va0x89ABCDEF, vb89ABCDEFx4567); w = (const int8_t*) w + 128; k -= 16 * sizeof(int8_t); } if (k != 0) { const __m256i va0x01234567 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0)); a0 += 8; const __m256i vb01234567x0123 = _mm256_load_si256(w); const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32)); vacc0x0123 = _mm256_dpbusd_avx_epi32(vacc0x0123, va0x01234567, vb01234567x0123); vacc0x4567 = _mm256_dpbusd_avx_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123); xnn_prefetch_to_l1((const int8_t*) w + 960); w = (const int8_t*) w + 64; k -= 8 * sizeof(int8_t); } vacc0x0123 = _mm256_add_epi32(vacc0x0123, vacc1x0x0123); vacc0x4567 = _mm256_add_epi32(vacc0x4567, vacc1x0x4567); // Add adjacent pairs const __m256i vsum0x02134657 = _mm256_hadd_epi32(vacc0x0123, vacc0x4567); __m256i vacc0x01234567 = _mm256_permute4x64_epi64(vsum0x02134657, _MM_SHUFFLE(3, 1, 2, 0)); __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567); vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale)); const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w); const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8); w = (const float*) w + 16; vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567); vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min); vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max); if XNN_LIKELY(nc >= 8) { _mm256_storeu_ps(c0, vout0x01234567); a0 = (const int8_t*) ((uintptr_t) a0 - kc); c0 = (float*) ((uintptr_t) c0 + cn_stride); nc -= 8; } else { __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567); if (nc & 4) { _mm_storeu_ps(c0, vout0x0123); c0 += 4; vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1); } if (nc & 2) { _mm_storel_pi((__m64*) c0, vout0x0123); c0 += 2; vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123); } if (nc & 1) { _mm_store_ss(c0, vout0x0123); } nc = 0; } } while (nc != 0); }