Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c4-minmax-avxvnni-u2-acc2.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx8c4-avxvnni.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 #include <assert.h>
11 #include <stdint.h>
12
13 #include <immintrin.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/gemm.h"
17 #include "xnnpack/intrinsics-polyfill.h"
18 #include "xnnpack/math.h"
19 #include "xnnpack/unaligned.h"
20 #include "xnnpack/prefetch.h"
21
22
23 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c4__avxvnni_u2_acc2(
24 size_t mr,
25 size_t nc,
26 size_t kc,
27 const int8_t* restrict a,
28 size_t a_stride,
29 const void* restrict w,
30 float* restrict c,
31 size_t cm_stride,
32 size_t cn_stride,
33 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
34 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
35 {
36 assert(mr != 0);
37 assert(mr <= 1);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(kc % sizeof(int8_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 kc = round_up_po2(kc, 4 * sizeof(int8_t));
46 const int8_t* a0 = a;
47 float* c0 = c;
48
49 const __m256i vsign_mask =_mm256_set1_epi8(0x80);
50 XNN_FORCE_REALIZATION(vsign_mask);
51 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point + 128);
52 const __m256 voutput_min = _mm256_set1_ps(params->scalar.min);
53 const __m256 voutput_max = _mm256_set1_ps(params->scalar.max);
54 // XNN_FORCE_REALIZATION(voutput_min);
55 // XNN_FORCE_REALIZATION(voutput_max);
56 do {
57 const __m256i vksum01234567 = _mm256_load_si256(w);
58 __m256i vacc0x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0);
59 __m256i vacc0x1x01234567 = _mm256_setzero_si256();
60 w = (const int32_t*) w + 8;
61
62 size_t k = kc;
63 while (k >= 8 * sizeof(int8_t)) {
64 __m256i va0x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 0));
65 __m256i va0x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 4));
66 a0 += 8;
67
68 va0x0x0123 = _mm256_xor_si256(va0x0x0123, vsign_mask);
69 va0x1x0123 = _mm256_xor_si256(va0x1x0123, vsign_mask);
70
71 const __m256i vb0x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 0));
72 const __m256i vb1x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
73 w = (const int8_t*) w + 64;
74
75 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0x0123, vb0x01234567);
76 vacc0x1x01234567 = _mm256_dpbusd_avx_epi32(vacc0x1x01234567, va0x1x0123, vb1x01234567);
77
78 k -= 8 * sizeof(int8_t);
79 }
80 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x1x01234567);
81 while (k != 0) {
82 __m256i va0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0));
83 a0 += 4;
84
85 va0x0123 = _mm256_xor_si256(va0x0123, vsign_mask);
86
87 const __m256i vb01234567 = _mm256_load_si256(w);
88
89 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0123, vb01234567);
90
91 w = (const int8_t*) w + 32;
92 k -= 4 * sizeof(int8_t);
93 }
94
95 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x0x01234567);
96
97 vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale));
98
99 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
100 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
101 w = (const float*) w + 16;
102
103 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
104
105 vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min);
106
107 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max);
108
109 if XNN_LIKELY(nc >= 8) {
110 _mm256_storeu_ps(c0, vout0x01234567);
111 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
112 c0 = (float*) ((uintptr_t) c0 + cn_stride);
113 nc -= 8;
114 } else {
115 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
116 if (nc & 4) {
117 _mm_storeu_ps(c0, vout0x0123);
118 c0 += 4;
119 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
120 }
121 if (nc & 2) {
122 _mm_storel_pi((__m64*) c0, vout0x0123);
123 c0 += 2;
124 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
125 }
126 if (nc & 1) {
127 _mm_store_ss(c0, vout0x0123);
128 }
129 nc = 0;
130 }
131 } while (nc != 0);
132 }