Debian Codegraph @

src/f16-f32acc-igemm/gen/f16-f32acc-igemm-1x16-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_1x16__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 <= 1);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(uint16_t) == 0);
37 assert(ks != 0);
38 assert(ks % (1 * 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
51 do {
52 __m256 vacc0x0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
53 __m256 vacc0x1 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
54 w = (const xnn_float16*) w + 16;
55
56 size_t p = ks;
57 do {
58 const uint16_t* restrict a0 = (const uint16_t*) a[0];
59 assert(a0 != NULL);
60 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
61 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
62 }
63 a += 1;
64
65 size_t k = kc;
66 do {
67 const __m256 vb0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
68 const __m256 vb1 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
69 w = (const xnn_float16*) w + 16;
70
71 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
72 a0 += 1;
73
74 vacc0x0 = _mm256_fmadd_ps(va0, vb0, vacc0x0);
75 vacc0x1 = _mm256_fmadd_ps(va0, vb1, vacc0x1);
76
77 k -= sizeof(uint16_t);
78 } while (k != 0);
79 p -= 1 * sizeof(void*);
80 } while (p != 0);
81
82 vacc0x0 = _mm256_max_ps(vacc0x0, vmin);
83 vacc0x1 = _mm256_max_ps(vacc0x1, vmin);
84
85 vacc0x0 = _mm256_min_ps(vacc0x0, vmax);
86 vacc0x1 = _mm256_min_ps(vacc0x1, vmax);
87
88 if XNN_LIKELY(nc >= 16) {
89 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT));
90 _mm_storeu_si128((__m128i*) (c0 + 8), _mm256_cvtps_ph(vacc0x1, _MM_FROUND_TO_NEAREST_INT));
91 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
92
93 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
94 nc -= 16;
95 } else {
96 __m128i vh0x0 = _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT);
97 if (nc & 8) {
98 _mm_storeu_si128((__m128i*) c0, vh0x0);
99
100 vh0x0 = _mm256_cvtps_ph(vacc0x1, _MM_FROUND_TO_NEAREST_INT);
101
102 c0 += 8;
103 }
104 if (nc & 4) {
105 _mm_storel_epi64((__m128i*) c0, vh0x0);
106
107 vh0x0 = _mm_unpackhi_epi64(vh0x0, vh0x0);
108
109 c0 += 4;
110 }
111 if (nc & 2) {
112 _mm_storeu_si32(c0, vh0x0);
113
114 vh0x0 = _mm_srli_epi64(vh0x0, 32);
115
116 c0 += 2;
117 }
118 if (nc & 1) {
119 *c0 = _mm_extract_epi16(vh0x0, 0);
120 }
121
122 nc = 0;
123 }
124 } while (nc != 0);
125 }