Debian Codegraph @

src/f16-f32acc-igemm/gen/f16-f32acc-igemm-6x8-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_6x8__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 <= 6);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(uint16_t) == 0);
37 assert(ks != 0);
38 assert(ks % (6 * 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
71 do {
72 __m256 vacc0x0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
73 __m256 vacc1x0 = vacc0x0;
74 __m256 vacc2x0 = vacc0x0;
75 __m256 vacc3x0 = vacc0x0;
76 __m256 vacc4x0 = vacc0x0;
77 __m256 vacc5x0 = vacc0x0;
78 w = (const xnn_float16*) w + 8;
79
80 size_t p = ks;
81 do {
82 const uint16_t* restrict a0 = (const uint16_t*) a[0];
83 assert(a0 != NULL);
84 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
85 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
86 }
87 const uint16_t* restrict a1 = (const uint16_t*) a[1];
88 assert(a1 != NULL);
89 if XNN_UNPREDICTABLE(a1 != (const uint16_t*) zero) {
90 a1 = (const uint16_t*) ((uintptr_t) a1 + a_offset);
91 }
92 const uint16_t* restrict a2 = (const uint16_t*) a[2];
93 assert(a2 != NULL);
94 if XNN_UNPREDICTABLE(a2 != (const uint16_t*) zero) {
95 a2 = (const uint16_t*) ((uintptr_t) a2 + a_offset);
96 }
97 const uint16_t* restrict a3 = (const uint16_t*) a[3];
98 assert(a3 != NULL);
99 if XNN_UNPREDICTABLE(a3 != (const uint16_t*) zero) {
100 a3 = (const uint16_t*) ((uintptr_t) a3 + a_offset);
101 }
102 const uint16_t* restrict a4 = (const uint16_t*) a[4];
103 assert(a4 != NULL);
104 if XNN_UNPREDICTABLE(a4 != (const uint16_t*) zero) {
105 a4 = (const uint16_t*) ((uintptr_t) a4 + a_offset);
106 }
107 const uint16_t* restrict a5 = (const uint16_t*) a[5];
108 assert(a5 != NULL);
109 if XNN_UNPREDICTABLE(a5 != (const uint16_t*) zero) {
110 a5 = (const uint16_t*) ((uintptr_t) a5 + a_offset);
111 }
112 a += 6;
113
114 size_t k = kc;
115 do {
116 const __m256 vb0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
117 w = (const xnn_float16*) w + 8;
118
119 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
120 a0 += 1;
121 const __m256 va1 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a1));
122 a1 += 1;
123 const __m256 va2 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a2));
124 a2 += 1;
125 const __m256 va3 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a3));
126 a3 += 1;
127 const __m256 va4 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a4));
128 a4 += 1;
129 const __m256 va5 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a5));
130 a5 += 1;
131
132 vacc0x0 = _mm256_fmadd_ps(va0, vb0, vacc0x0);
133 vacc1x0 = _mm256_fmadd_ps(va1, vb0, vacc1x0);
134 vacc2x0 = _mm256_fmadd_ps(va2, vb0, vacc2x0);
135 vacc3x0 = _mm256_fmadd_ps(va3, vb0, vacc3x0);
136 vacc4x0 = _mm256_fmadd_ps(va4, vb0, vacc4x0);
137 vacc5x0 = _mm256_fmadd_ps(va5, vb0, vacc5x0);
138
139 k -= sizeof(uint16_t);
140 } while (k != 0);
141 p -= 6 * sizeof(void*);
142 } while (p != 0);
143
144 vacc0x0 = _mm256_max_ps(vacc0x0, vmin);
145 vacc1x0 = _mm256_max_ps(vacc1x0, vmin);
146 vacc2x0 = _mm256_max_ps(vacc2x0, vmin);
147 vacc3x0 = _mm256_max_ps(vacc3x0, vmin);
148 vacc4x0 = _mm256_max_ps(vacc4x0, vmin);
149 vacc5x0 = _mm256_max_ps(vacc5x0, vmin);
150
151 vacc0x0 = _mm256_min_ps(vacc0x0, vmax);
152 vacc1x0 = _mm256_min_ps(vacc1x0, vmax);
153 vacc2x0 = _mm256_min_ps(vacc2x0, vmax);
154 vacc3x0 = _mm256_min_ps(vacc3x0, vmax);
155 vacc4x0 = _mm256_min_ps(vacc4x0, vmax);
156 vacc5x0 = _mm256_min_ps(vacc5x0, vmax);
157
158 if XNN_LIKELY(nc >= 8) {
159 _mm_storeu_si128((__m128i*) c5, _mm256_cvtps_ph(vacc5x0, _MM_FROUND_TO_NEAREST_INT));
160 c5 = (uint16_t*) ((uintptr_t) c5 + cn_stride);
161 _mm_storeu_si128((__m128i*) c4, _mm256_cvtps_ph(vacc4x0, _MM_FROUND_TO_NEAREST_INT));
162 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
163 _mm_storeu_si128((__m128i*) c3, _mm256_cvtps_ph(vacc3x0, _MM_FROUND_TO_NEAREST_INT));
164 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
165 _mm_storeu_si128((__m128i*) c2, _mm256_cvtps_ph(vacc2x0, _MM_FROUND_TO_NEAREST_INT));
166 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
167 _mm_storeu_si128((__m128i*) c1, _mm256_cvtps_ph(vacc1x0, _MM_FROUND_TO_NEAREST_INT));
168 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
169 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT));
170 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
171
172 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
173 nc -= 8;
174 } else {
175 __m128i vh5x0 = _mm256_cvtps_ph(vacc5x0, _MM_FROUND_TO_NEAREST_INT);
176 __m128i vh4x0 = _mm256_cvtps_ph(vacc4x0, _MM_FROUND_TO_NEAREST_INT);
177 __m128i vh3x0 = _mm256_cvtps_ph(vacc3x0, _MM_FROUND_TO_NEAREST_INT);
178 __m128i vh2x0 = _mm256_cvtps_ph(vacc2x0, _MM_FROUND_TO_NEAREST_INT);
179 __m128i vh1x0 = _mm256_cvtps_ph(vacc1x0, _MM_FROUND_TO_NEAREST_INT);
180 __m128i vh0x0 = _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT);
181 if (nc & 4) {
182 _mm_storel_epi64((__m128i*) c5, vh5x0);
183 _mm_storel_epi64((__m128i*) c4, vh4x0);
184 _mm_storel_epi64((__m128i*) c3, vh3x0);
185 _mm_storel_epi64((__m128i*) c2, vh2x0);
186 _mm_storel_epi64((__m128i*) c1, vh1x0);
187 _mm_storel_epi64((__m128i*) c0, vh0x0);
188
189 vh5x0 = _mm_unpackhi_epi64(vh5x0, vh5x0);
190 vh4x0 = _mm_unpackhi_epi64(vh4x0, vh4x0);
191 vh3x0 = _mm_unpackhi_epi64(vh3x0, vh3x0);
192 vh2x0 = _mm_unpackhi_epi64(vh2x0, vh2x0);
193 vh1x0 = _mm_unpackhi_epi64(vh1x0, vh1x0);
194 vh0x0 = _mm_unpackhi_epi64(vh0x0, vh0x0);
195
196 c5 += 4;
197 c4 += 4;
198 c3 += 4;
199 c2 += 4;
200 c1 += 4;
201 c0 += 4;
202 }
203 if (nc & 2) {
204 _mm_storeu_si32(c5, vh5x0);
205 _mm_storeu_si32(c4, vh4x0);
206 _mm_storeu_si32(c3, vh3x0);
207 _mm_storeu_si32(c2, vh2x0);
208 _mm_storeu_si32(c1, vh1x0);
209 _mm_storeu_si32(c0, vh0x0);
210
211 vh5x0 = _mm_srli_epi64(vh5x0, 32);
212 vh4x0 = _mm_srli_epi64(vh4x0, 32);
213 vh3x0 = _mm_srli_epi64(vh3x0, 32);
214 vh2x0 = _mm_srli_epi64(vh2x0, 32);
215 vh1x0 = _mm_srli_epi64(vh1x0, 32);
216 vh0x0 = _mm_srli_epi64(vh0x0, 32);
217
218 c5 += 2;
219 c4 += 2;
220 c3 += 2;
221 c2 += 2;
222 c1 += 2;
223 c0 += 2;
224 }
225 if (nc & 1) {
226 *c5 = _mm_extract_epi16(vh5x0, 0);
227 *c4 = _mm_extract_epi16(vh4x0, 0);
228 *c3 = _mm_extract_epi16(vh3x0, 0);
229 *c2 = _mm_extract_epi16(vh2x0, 0);
230 *c1 = _mm_extract_epi16(vh1x0, 0);
231 *c0 = _mm_extract_epi16(vh0x0, 0);
232 }
233
234 nc = 0;
235 }
236 } while (nc != 0);
237 }