Debian Codegraph @

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