Debian Codegraph @

src/f32-igemm/gen/f32-igemm-5x16-minmax-avx512f-broadcast.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-igemm/avx512-broadcast.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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_f32_igemm_minmax_ukernel_5x16__avx512f_broadcast(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const float** restrict a,
24 const float* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const float* zero,
30 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mr != 0);
33 assert(mr <= 5);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(float) == 0);
37 assert(ks != 0);
38 assert(ks % (5 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(float) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 float* c0 = c;
45 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
46 if XNN_UNPREDICTABLE(mr < 2) {
47 c1 = c0;
48 }
49 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 c2 = c1;
52 }
53 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
54 if XNN_UNPREDICTABLE(mr < 4) {
55 c3 = c2;
56 }
57 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
58 if XNN_UNPREDICTABLE(mr <= 4) {
59 c4 = c3;
60 }
61
62 do {
63 __m512 vacc0x0 = _mm512_load_ps(w);
64 __m512 vacc1x0 = vacc0x0;
65 __m512 vacc2x0 = vacc0x0;
66 __m512 vacc3x0 = vacc0x0;
67 __m512 vacc4x0 = vacc0x0;
68 w += 16;
69
70 size_t p = ks;
71 do {
72 const float* restrict a0 = a[0];
73 assert(a0 != NULL);
74 if XNN_UNPREDICTABLE(a0 != zero) {
75 a0 = (const float*) ((uintptr_t) a0 + a_offset);
76 }
77 const float* restrict a1 = a[1];
78 assert(a1 != NULL);
79 if XNN_UNPREDICTABLE(a1 != zero) {
80 a1 = (const float*) ((uintptr_t) a1 + a_offset);
81 }
82 const float* restrict a2 = a[2];
83 assert(a2 != NULL);
84 if XNN_UNPREDICTABLE(a2 != zero) {
85 a2 = (const float*) ((uintptr_t) a2 + a_offset);
86 }
87 const float* restrict a3 = a[3];
88 assert(a3 != NULL);
89 if XNN_UNPREDICTABLE(a3 != zero) {
90 a3 = (const float*) ((uintptr_t) a3 + a_offset);
91 }
92 const float* restrict a4 = a[4];
93 assert(a4 != NULL);
94 if XNN_UNPREDICTABLE(a4 != zero) {
95 a4 = (const float*) ((uintptr_t) a4 + a_offset);
96 }
97 a += 5;
98
99 size_t k = kc;
100 do {
101 const __m512 vb0 = _mm512_load_ps(w);
102 w += 16;
103
104 const __m512 va0 = _mm512_set1_ps(*a0);
105 vacc0x0 = _mm512_fmadd_ps(va0, vb0, vacc0x0);
106 const __m512 va1 = _mm512_set1_ps(*a1);
107 vacc1x0 = _mm512_fmadd_ps(va1, vb0, vacc1x0);
108 const __m512 va2 = _mm512_set1_ps(*a2);
109 vacc2x0 = _mm512_fmadd_ps(va2, vb0, vacc2x0);
110 const __m512 va3 = _mm512_set1_ps(*a3);
111 vacc3x0 = _mm512_fmadd_ps(va3, vb0, vacc3x0);
112 const __m512 va4 = _mm512_set1_ps(*a4);
113 vacc4x0 = _mm512_fmadd_ps(va4, vb0, vacc4x0);
114
115 a0 += 1;
116 a1 += 1;
117 a2 += 1;
118 a3 += 1;
119 a4 += 1;
120
121 k -= sizeof(float);
122 } while (k != 0);
123 p -= 5 * sizeof(void*);
124 } while (p != 0);
125
126 const __m512 vmin = _mm512_set1_ps(params->scalar.min);
127 vacc0x0 = _mm512_max_ps(vmin, vacc0x0);
128 vacc1x0 = _mm512_max_ps(vmin, vacc1x0);
129 vacc2x0 = _mm512_max_ps(vmin, vacc2x0);
130 vacc3x0 = _mm512_max_ps(vmin, vacc3x0);
131 vacc4x0 = _mm512_max_ps(vmin, vacc4x0);
132
133 const __m512 vmax = _mm512_set1_ps(params->scalar.max);
134 vacc0x0 = _mm512_min_ps(vmax, vacc0x0);
135 vacc1x0 = _mm512_min_ps(vmax, vacc1x0);
136 vacc2x0 = _mm512_min_ps(vmax, vacc2x0);
137 vacc3x0 = _mm512_min_ps(vmax, vacc3x0);
138 vacc4x0 = _mm512_min_ps(vmax, vacc4x0);
139
140 if XNN_LIKELY(nc >= 16) {
141 _mm512_storeu_ps(c4, vacc4x0);
142 c4 = (float*) ((uintptr_t) c4 + cn_stride);
143 _mm512_storeu_ps(c3, vacc3x0);
144 c3 = (float*) ((uintptr_t) c3 + cn_stride);
145 _mm512_storeu_ps(c2, vacc2x0);
146 c2 = (float*) ((uintptr_t) c2 + cn_stride);
147 _mm512_storeu_ps(c1, vacc1x0);
148 c1 = (float*) ((uintptr_t) c1 + cn_stride);
149 _mm512_storeu_ps(c0, vacc0x0);
150 c0 = (float*) ((uintptr_t) c0 + cn_stride);
151
152 a = (const float**restrict) ((uintptr_t) a - ks);
153 nc -= 16;
154 } else {
155 // NC remainder (1..15)
156 assert(nc >= 1);
157 assert(nc <= 15);
158 // Prepare mask for valid 32-bit elements (depends on nc).
159 const __mmask16 vmask0 = _cvtu32_mask16((uint32_t) (((UINT64_C(1) << nc) - 1) >> 0));
160
161 _mm512_mask_storeu_ps(c4 + 0, vmask0, vacc4x0);
162 _mm512_mask_storeu_ps(c3 + 0, vmask0, vacc3x0);
163 _mm512_mask_storeu_ps(c2 + 0, vmask0, vacc2x0);
164 _mm512_mask_storeu_ps(c1 + 0, vmask0, vacc1x0);
165 _mm512_mask_storeu_ps(c0 + 0, vmask0, vacc0x0);
166 nc = 0;
167 }
168 } while (nc != 0);
169 }