Debian Codegraph @

src/f16-f32acc-gemm/gen/f16-f32acc-gemm-6x8-minmax-avx2-broadcast.c

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