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
xnn_f16_igemm_minmax_ukernel_1x16__avx2_broadcast(size_t mr,size_t nc,size_t kc,size_t ks,const void ** restrict a,const void * restrict w,void * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const void * zero,const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_igemm_minmax_ukernel_1x16__avx2_broadcast(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const void**restrict a,
24 const void*restrict w,
25 void*restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const void* 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 uint16_t* c0 = c;
45
46 do {
47 __m256 vacc0x01234567 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
48 __m256 vacc0x89ABCDEF = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
49 w = (const uint16_t*) w + 16;
50
51 size_t p = ks;
52 do {
53 const uint16_t* restrict a0 = (const uint16_t*) a[0];
54 assert(a0 != NULL);
55 if XNN_UNPREDICTABLE(a0 != zero) {
56 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
57 }
58 a += 1;
59
60 size_t k = kc;
61 do {
62 const __m256 vb01234567 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
63 const __m256 vb89ABCDEF = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) ((const uint16_t*) w + 8)));
64 w = (const uint16_t*) w + 16;
65
66 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
67 a0 += 1;
68
69 vacc0x01234567 = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_fmadd_ps(va0, vb01234567, vacc0x01234567), _MM_FROUND_NO_EXC));
70 vacc0x89ABCDEF = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_fmadd_ps(va0, vb89ABCDEF, vacc0x89ABCDEF), _MM_FROUND_NO_EXC));
71
72 k -= sizeof(uint16_t);
73 } while (k != 0);
74 p -= 1 * sizeof(void*);
75 } while (p != 0);
76
77 const __m256 vmin = _mm256_load_ps(params->avx.min);
78 vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
79 vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
80
81 const __m256 vmax = _mm256_load_ps(params->avx.max);
82 vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
83 vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
84
85 if XNN_LIKELY(nc >= 16) {
86 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x01234567, _MM_FROUND_NO_EXC));
87 _mm_storeu_si128((__m128i*) (c0 + 8), _mm256_cvtps_ph(vacc0x89ABCDEF, _MM_FROUND_NO_EXC));
88 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
89
90 a = (const void**restrict) ((uintptr_t) a - ks);
91 nc -= 16;
92 } else {
93 __m128i vh0x01234567 = _mm256_cvtps_ph(vacc0x01234567, _MM_FROUND_NO_EXC);
94 if (nc & 8) {
95 _mm_storeu_si128((__m128i*) c0, vh0x01234567);
96
97 vh0x01234567 = _mm256_cvtps_ph(vacc0x89ABCDEF, _MM_FROUND_NO_EXC);
98
99 c0 += 8;
100 }
101 if (nc & 4) {
102 _mm_storel_epi64((__m128i*) c0, vh0x01234567);
103
104 vh0x01234567 = _mm_unpackhi_epi64(vh0x01234567, vh0x01234567);
105
106 c0 += 4;
107 }
108 if (nc & 2) {
109 _mm_storeu_si32(c0, vh0x01234567);
110
111 vh0x01234567 = _mm_srli_epi64(vh0x01234567, 32);
112
113 c0 += 2;
114 }
115 if (nc & 1) {
116 *c0 = _mm_extract_epi16(vh0x01234567, 0);
117 }
118
119 nc = 0;
120 }
121 } while (nc != 0);
122 }
123