Debian Codegraph @

src/f16-f32acc-gemm/gen/f16-f32acc-gemm-1x16-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_1x16__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 <= 1);
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
48 do {
49 __m256 vacc0x0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
50 __m256 vacc0x1 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
51 w = (const xnn_float16*) w + 16;
52
53 size_t k = kc;
54 do {
55 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
56 a0 += 1;
57
58 const __m256 vb0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
59 const __m256 vb1 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
60 w = (const xnn_float16*) w + 16;
61
62 vacc0x0 = _mm256_fmadd_ps(va0, vb0, vacc0x0);
63 vacc0x1 = _mm256_fmadd_ps(va0, vb1, vacc0x1);
64
65 k -= sizeof(uint16_t);
66 } while (k != 0);
67
68 vacc0x0 = _mm256_max_ps(vacc0x0, vmin);
69 vacc0x1 = _mm256_max_ps(vacc0x1, vmin);
70
71 vacc0x0 = _mm256_min_ps(vacc0x0, vmax);
72 vacc0x1 = _mm256_min_ps(vacc0x1, vmax);
73
74 if XNN_LIKELY(nc >= 16) {
75 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT));
76 _mm_storeu_si128((__m128i*) (c0 + 8), _mm256_cvtps_ph(vacc0x1, _MM_FROUND_TO_NEAREST_INT));
77 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
78
79 a0 = (const uint16_t*) ((uintptr_t) a0 - kc);
80
81 nc -= 16;
82 } else {
83 __m128i vh0x0 = _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT);
84 if (nc & 8) {
85 _mm_storeu_si128((__m128i*) c0, vh0x0);
86
87 vh0x0 = _mm256_cvtps_ph(vacc0x1, _MM_FROUND_TO_NEAREST_INT);
88
89 c0 += 8;
90 }
91 if (nc & 4) {
92 _mm_storel_epi64((__m128i*) c0, vh0x0);
93
94 vh0x0 = _mm_unpackhi_epi64(vh0x0, vh0x0);
95
96 c0 += 4;
97 }
98 if (nc & 2) {
99 _mm_storeu_si32(c0, vh0x0);
100
101 vh0x0 = _mm_srli_epi64(vh0x0, 32);
102
103 c0 += 2;
104 }
105 if (nc & 1) {
106 *c0 = (uint16_t) _mm_extract_epi16(vh0x0, 0);
107 }
108
109 nc = 0;
110 }
111 } while (nc != 0);
112 }