Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c8-minmax-avx2.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx8c8-avx2.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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 <immintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/intrinsics-polyfill.h"
17 #include "xnnpack/math.h"
18 #include "xnnpack/unaligned.h"
19
20
21 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c8__avx2(
22 size_t mr,
23 size_t nc,
24 size_t kc,
25 const int8_t* restrict a,
26 size_t a_stride,
27 const void* restrict w,
28 float* restrict c,
29 size_t cm_stride,
30 size_t cn_stride,
31 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33 {
34 assert(mr != 0);
35 assert(mr <= 1);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(kc % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 kc = round_up_po2(kc, 8 * sizeof(int8_t));
44 const int8_t* a0 = a;
45 float* c0 = c;
46
47 const __m256 vmin = _mm256_set1_ps(params->scalar.min);
48 const __m256 vmax = _mm256_set1_ps(params->scalar.max);
49 XNN_FORCE_REALIZATION(vmin);
50 XNN_FORCE_REALIZATION(vmax);
51
52 do {
53 const __m128i vinit0 = _mm_cvtsi32_si128(((const int*) w)[0]);
54 const __m128i vinit1 = _mm_cvtsi32_si128(((const int*) w)[1]);
55 const __m256i vinit01 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit0), vinit1, 1);
56 const __m128i vinit2 = _mm_cvtsi32_si128(((const int*) w)[2]);
57 const __m128i vinit3 = _mm_cvtsi32_si128(((const int*) w)[3]);
58 const __m256i vinit23 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit2), vinit3, 1);
59 const __m128i vinit4 = _mm_cvtsi32_si128(((const int*) w)[4]);
60 const __m128i vinit5 = _mm_cvtsi32_si128(((const int*) w)[5]);
61 const __m256i vinit45 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit4), vinit5, 1);
62 const __m128i vinit6 = _mm_cvtsi32_si128(((const int*) w)[6]);
63 const __m128i vinit7 = _mm_cvtsi32_si128(((const int*) w)[7]);
64 const __m256i vinit67 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit6), vinit7, 1);
65 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point);
66 __m256i vacc0x01 = _mm256_mullo_epi32(vinit01, vinput_zero_point0);
67 __m256i vacc0x23 = _mm256_mullo_epi32(vinit23, vinput_zero_point0);
68 __m256i vacc0x45 = _mm256_mullo_epi32(vinit45, vinput_zero_point0);
69 __m256i vacc0x67 = _mm256_mullo_epi32(vinit67, vinput_zero_point0);
70 w = (const int32_t*) w + 8;
71
72 size_t k = kc;
73
74 while (k >= 8 * sizeof(int8_t)) {
75 const __m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0));
76 const __m256i vxa0 = _mm256_cvtepi8_epi16(va0);
77 a0 += 8;
78
79 const __m256i vxb01 = _mm256_cvtepi8_epi16(_mm_load_si128((const __m128i*) w));
80
81 vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01));
82 const __m256i vxb23 = _mm256_cvtepi8_epi16(_mm_load_si128((const __m128i*) ((const int8_t*) w + 16)));
83
84 vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23));
85 const __m256i vxb45 = _mm256_cvtepi8_epi16(_mm_load_si128((const __m128i*) ((const int8_t*) w + 32)));
86
87 vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45));
88 const __m256i vxb67 = _mm256_cvtepi8_epi16(_mm_load_si128((const __m128i*) ((const int8_t*) w + 48)));
89
90 vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67));
91
92 w = (const int8_t*) w + 64;
93 k -= 8 * sizeof(int8_t);
94 }
95
96 const __m256i vacc0x0213 = _mm256_hadd_epi32(vacc0x01, vacc0x23);
97 const __m256i vacc0x4657 = _mm256_hadd_epi32(vacc0x45, vacc0x67);
98
99 const __m256i vacc0x02461357 = _mm256_hadd_epi32(vacc0x0213, vacc0x4657);
100
101 const __m256i vpermute_mask = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0);
102 __m256i vacc0x01234567 = _mm256_permutevar8x32_epi32(vacc0x02461357, vpermute_mask);
103
104 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567);
105 const __m256 vinput_scale0 = _mm256_broadcast_ss(&quantization_params[0].inv_scale);
106
107 vout0x01234567 = _mm256_mul_ps(vout0x01234567, vinput_scale0);
108
109 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
110 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
111 w = (const float*) w + 16;
112 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
113
114 vout0x01234567 = _mm256_max_ps(vout0x01234567, vmin);
115
116 vout0x01234567 = _mm256_min_ps(vout0x01234567, vmax);
117
118 if XNN_LIKELY(nc >= 8) {
119 _mm256_storeu_ps(c0, vout0x01234567);
120 c0 = (float*) ((uintptr_t) c0 + cn_stride);
121
122 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
123
124 nc -= 8;
125 } else {
126 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
127 if (nc & 4) {
128 _mm_storeu_ps(c0, vout0x0123);
129
130 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
131
132 c0 += 4;
133 }
134 if (nc & 2) {
135 _mm_storel_pi((__m64*) c0, vout0x0123);
136
137 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
138
139 c0 += 2;
140 }
141 if (nc & 1) {
142 _mm_store_ss(c0, vout0x0123);
143 }
144 nc = 0;
145 }
146 } while (nc != 0);
147 }