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
xnn_f16_gemm_minmax_ukernel_1x8__avx2_broadcast(size_t mr,size_t nc,size_t kc,const void * restrict a,size_t a_stride,const void * restrict w,void * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_gemm_minmax_ukernel_1x8__avx2_broadcast(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const void*restrict a,
23 size_t a_stride,
24 const void*restrict w,
25 void*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 = a;
40 uint16_t* c0 = c;
41
42 do {
43 __m256 vacc0x01234567 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
44 w = (const uint16_t*) w + 8;
45
46 size_t k = kc;
47 do {
48 const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0));
49 a0 += 1;
50
51 const __m256 vb01234567 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w));
52 w = (const uint16_t*) w + 8;
53
54 vacc0x01234567 = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_fmadd_ps(va0, vb01234567, vacc0x01234567), _MM_FROUND_NO_EXC));
55
56 k -= sizeof(uint16_t);
57 } while (k != 0);
58
59 const __m256 vmin = _mm256_load_ps(params->avx.min);
60 vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
61
62 const __m256 vmax = _mm256_load_ps(params->avx.max);
63 vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
64
65 if XNN_LIKELY(nc >= 8) {
66 _mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x01234567, _MM_FROUND_NO_EXC));
67 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
68
69 a0 = (const uint16_t*) ((uintptr_t) a0 - kc);
70
71 nc -= 8;
72 } else {
73 __m128i vh0x01234567 = _mm256_cvtps_ph(vacc0x01234567, _MM_FROUND_NO_EXC);
74 if (nc & 4) {
75 _mm_storel_epi64((__m128i*) c0, vh0x01234567);
76
77 vh0x01234567 = _mm_unpackhi_epi64(vh0x01234567, vh0x01234567);
78
79 c0 += 4;
80 }
81 if (nc & 2) {
82 _mm_storeu_si32(c0, vh0x01234567);
83
84 vh0x01234567 = _mm_srli_epi64(vh0x01234567, 32);
85
86 c0 += 2;
87 }
88 if (nc & 1) {
89 *c0 = (uint16_t) _mm_extract_epi16(vh0x01234567, 0);
90 }
91
92 nc = 0;
93 }
94 } while (nc != 0);
95 }
96