Debian Codegraph @

src/f16-f32acc-igemm/gen/f16-f32acc-igemm-7x8-minmax-avx2-broadcast.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-igemm/avx2-broadcast.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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/igemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16
17
18 void xnn_f16_f32acc_igemm_minmax_ukernel_7x8__avx2_broadcast(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const xnn_float16** restrict a,
24 const xnn_float16* restrict w,
25 xnn_float16* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const xnn_float16* zero,
30 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mr != 0);
33 assert(mr <= 7);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(uint16_t) == 0);
37 assert(ks != 0);
38 assert(ks % (7 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(uint16_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 const __m256 vmin = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.min));
45 const __m256 vmax = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.max));
46 XNN_FORCE_REALIZATION(vmin);
47 XNN_FORCE_REALIZATION(vmax);
48
49 uint16_t* c0 = (uint16_t*) c;
50 uint16_t* c1 = (uint16_t*) ((uintptr_t) c0 + cm_stride);
51 if XNN_UNPREDICTABLE(mr < 2) {
52 c1 = c0;
53 }
54 uint16_t* c2 = (uint16_t*) ((uintptr_t) c1 + cm_stride);
55 if XNN_UNPREDICTABLE(mr <= 2) {
56 c2 = c1;
57 }
58 uint16_t* c3 = (uint16_t*) ((uintptr_t) c2 + cm_stride);
59 if XNN_UNPREDICTABLE(mr < 4) {
60 c3 = c2;
61 }
62 uint16_t* c4 = (uint16_t*) ((uintptr_t) c3 + cm_stride);
63 if XNN_UNPREDICTABLE(mr <= 4) {
64 c4 = c3;
65 }
66 uint16_t* c5 = (uint16_t*) ((uintptr_t) c4 + cm_stride);
67 if XNN_UNPREDICTABLE(mr < 6) {
68 c5 = c4;
69 }
70 uint16_t* c6 = (uint16_t*) ((uintptr_t) c5 + cm_stride);
71 if XNN_UNPREDICTABLE(mr <= 6) {
72 c6 = c5;
73 }
74
75 do {
76 __m256 vacc0x0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
77 __m256 vacc1x0 = vacc0x0;
78 __m256 vacc2x0 = vacc0x0;
79 __m256 vacc3x0 = vacc0x0;
80 __m256 vacc4x0 = vacc0x0;
81 __m256 vacc5x0 = vacc0x0;
82 __m256 vacc6x0 = vacc0x0;
83 w = (const xnn_float16*) w + 8;
84
85 size_t p = ks;
86 do {
87 const uint16_t* restrict a0 = (const uint16_t*) a[0];
88 assert(a0 != NULL);
89 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
90 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
91 }
92 const uint16_t* restrict a1 = (const uint16_t*) a[1];
93 assert(a1 != NULL);
94 if XNN_UNPREDICTABLE(a1 != (const uint16_t*) zero) {
95 a1 = (const uint16_t*) ((uintptr_t) a1 + a_offset);
96 }
97 const uint16_t* restrict a2 = (const uint16_t*) a[2];
98 assert(a2 != NULL);
99 if XNN_UNPREDICTABLE(a2 != (const uint16_t*) zero) {
100 a2 = (const uint16_t*) ((uintptr_t) a2 + a_offset);
101 }
102 const uint16_t* restrict a3 = (const uint16_t*) a[3];
103 assert(a3 != NULL);
104 if XNN_UNPREDICTABLE(a3 != (const uint16_t*) zero) {
105 a3 = (const uint16_t*) ((uintptr_t) a3 + a_offset);
106 }
107 const uint16_t* restrict a4 = (const uint16_t*) a[4];
108 assert(a4 != NULL);
109 if XNN_UNPREDICTABLE(a4 != (const uint16_t*) zero) {
110 a4 = (const uint16_t*) ((uintptr_t) a4 + a_offset);
111 }
112 const uint16_t* restrict a5 = (const uint16_t*) a[5];
113 assert(a5 != NULL);
114 if XNN_UNPREDICTABLE(a5 != (const uint16_t*) zero) {
115 a5 = (const uint16_t*) ((uintptr_t) a5 + a_offset);
116 }
117 const uint16_t* restrict a6 = (const uint16_t*) a[6];
118 assert(a6 != NULL);
119 if XNN_UNPREDICTABLE(a6 != (const uint16_t*) zero) {
120 a6 = (const uint16_t*) ((uintptr_t) a6 + a_offset);
121 }
122 a += 7;
123
124 size_t k = kc;
125 do {
126 const __m256 vb0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
127 w = (const xnn_float16*) w + 8;
128
129 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
130 a0 += 1;
131 const __m256 va1 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a1));
132 a1 += 1;
133 const __m256 va2 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a2));
134 a2 += 1;
135 const __m256 va3 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a3));
136 a3 += 1;
137 const __m256 va4 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a4));
138 a4 += 1;
139 const __m256 va5 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a5));
140 a5 += 1;
141 const __m256 va6 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a6));
142 a6 += 1;
143
144 vacc0x0 = _mm256_fmadd_ps(va0, vb0, vacc0x0);
145 vacc1x0 = _mm256_fmadd_ps(va1, vb0, vacc1x0);
146 vacc2x0 = _mm256_fmadd_ps(va2, vb0, vacc2x0);
147 vacc3x0 = _mm256_fmadd_ps(va3, vb0, vacc3x0);
148 vacc4x0 = _mm256_fmadd_ps(va4, vb0, vacc4x0);
149 vacc5x0 = _mm256_fmadd_ps(va5, vb0, vacc5x0);
150 vacc6x0 = _mm256_fmadd_ps(va6, vb0, vacc6x0);
151
152 k -= sizeof(uint16_t);
153 } while (k != 0);
154 p -= 7 * sizeof(void*);
155 } while (p != 0);
156
157 vacc0x0 = _mm256_max_ps(vacc0x0, vmin);
158 vacc1x0 = _mm256_max_ps(vacc1x0, vmin);
159 vacc2x0 = _mm256_max_ps(vacc2x0, vmin);
160 vacc3x0 = _mm256_max_ps(vacc3x0, vmin);
161 vacc4x0 = _mm256_max_ps(vacc4x0, vmin);
162 vacc5x0 = _mm256_max_ps(vacc5x0, vmin);
163 vacc6x0 = _mm256_max_ps(vacc6x0, vmin);
164
165 vacc0x0 = _mm256_min_ps(vacc0x0, vmax);
166 vacc1x0 = _mm256_min_ps(vacc1x0, vmax);
167 vacc2x0 = _mm256_min_ps(vacc2x0, vmax);
168 vacc3x0 = _mm256_min_ps(vacc3x0, vmax);
169 vacc4x0 = _mm256_min_ps(vacc4x0, vmax);
170 vacc5x0 = _mm256_min_ps(vacc5x0, vmax);
171 vacc6x0 = _mm256_min_ps(vacc6x0, vmax);
172
173 if XNN_LIKELY(nc >= 8) {
174 _mm_storeu_si128((__m128i*) c6, _mm256_cvtps_ph(vacc6x0, _MM_FROUND_TO_NEAREST_INT));
175 c6 = (uint16_t*) ((uintptr_t) c6 + cn_stride);
176 _mm_storeu_si128((__m128i*) c5, _mm256_cvtps_ph(vacc5x0, _MM_FROUND_TO_NEAREST_INT));
177 c5 = (uint16_t*) ((uintptr_t) c5 + cn_stride);
178 _mm_storeu_si128((__m128i*) c4, _mm256_cvtps_ph(vacc4x0, _MM_FROUND_TO_NEAREST_INT));
179 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
180 _mm_storeu_si128((__m128i*) c3, _mm256_cvtps_ph(vacc3x0, _MM_FROUND_TO_NEAREST_INT));
181 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
182 _mm_storeu_si128((__m128i*) c2, _mm256_cvtps_ph(vacc2x0, _MM_FROUND_TO_NEAREST_INT));
183 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
184 _mm_storeu_si128((__m128i*) c1, _mm256_cvtps_ph(vacc1x0, _MM_FROUND_TO_NEAREST_INT));
185 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
186 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT));
187 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
188
189 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
190 nc -= 8;
191 } else {
192 __m128i vh6x0 = _mm256_cvtps_ph(vacc6x0, _MM_FROUND_TO_NEAREST_INT);
193 __m128i vh5x0 = _mm256_cvtps_ph(vacc5x0, _MM_FROUND_TO_NEAREST_INT);
194 __m128i vh4x0 = _mm256_cvtps_ph(vacc4x0, _MM_FROUND_TO_NEAREST_INT);
195 __m128i vh3x0 = _mm256_cvtps_ph(vacc3x0, _MM_FROUND_TO_NEAREST_INT);
196 __m128i vh2x0 = _mm256_cvtps_ph(vacc2x0, _MM_FROUND_TO_NEAREST_INT);
197 __m128i vh1x0 = _mm256_cvtps_ph(vacc1x0, _MM_FROUND_TO_NEAREST_INT);
198 __m128i vh0x0 = _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT);
199 if (nc & 4) {
200 _mm_storel_epi64((__m128i*) c6, vh6x0);
201 _mm_storel_epi64((__m128i*) c5, vh5x0);
202 _mm_storel_epi64((__m128i*) c4, vh4x0);
203 _mm_storel_epi64((__m128i*) c3, vh3x0);
204 _mm_storel_epi64((__m128i*) c2, vh2x0);
205 _mm_storel_epi64((__m128i*) c1, vh1x0);
206 _mm_storel_epi64((__m128i*) c0, vh0x0);
207
208 vh6x0 = _mm_unpackhi_epi64(vh6x0, vh6x0);
209 vh5x0 = _mm_unpackhi_epi64(vh5x0, vh5x0);
210 vh4x0 = _mm_unpackhi_epi64(vh4x0, vh4x0);
211 vh3x0 = _mm_unpackhi_epi64(vh3x0, vh3x0);
212 vh2x0 = _mm_unpackhi_epi64(vh2x0, vh2x0);
213 vh1x0 = _mm_unpackhi_epi64(vh1x0, vh1x0);
214 vh0x0 = _mm_unpackhi_epi64(vh0x0, vh0x0);
215
216 c6 += 4;
217 c5 += 4;
218 c4 += 4;
219 c3 += 4;
220 c2 += 4;
221 c1 += 4;
222 c0 += 4;
223 }
224 if (nc & 2) {
225 _mm_storeu_si32(c6, vh6x0);
226 _mm_storeu_si32(c5, vh5x0);
227 _mm_storeu_si32(c4, vh4x0);
228 _mm_storeu_si32(c3, vh3x0);
229 _mm_storeu_si32(c2, vh2x0);
230 _mm_storeu_si32(c1, vh1x0);
231 _mm_storeu_si32(c0, vh0x0);
232
233 vh6x0 = _mm_srli_epi64(vh6x0, 32);
234 vh5x0 = _mm_srli_epi64(vh5x0, 32);
235 vh4x0 = _mm_srli_epi64(vh4x0, 32);
236 vh3x0 = _mm_srli_epi64(vh3x0, 32);
237 vh2x0 = _mm_srli_epi64(vh2x0, 32);
238 vh1x0 = _mm_srli_epi64(vh1x0, 32);
239 vh0x0 = _mm_srli_epi64(vh0x0, 32);
240
241 c6 += 2;
242 c5 += 2;
243 c4 += 2;
244 c3 += 2;
245 c2 += 2;
246 c1 += 2;
247 c0 += 2;
248 }
249 if (nc & 1) {
250 *c6 = _mm_extract_epi16(vh6x0, 0);
251 *c5 = _mm_extract_epi16(vh5x0, 0);
252 *c4 = _mm_extract_epi16(vh4x0, 0);
253 *c3 = _mm_extract_epi16(vh3x0, 0);
254 *c2 = _mm_extract_epi16(vh2x0, 0);
255 *c1 = _mm_extract_epi16(vh1x0, 0);
256 *c0 = _mm_extract_epi16(vh0x0, 0);
257 }
258
259 nc = 0;
260 }
261 } while (nc != 0);
262 }