• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
xnn_f32_igemm_minmax_ukernel_4x16__avx512f_broadcast(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_igemm_minmax_ukernel_4x16__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 <= 4);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(kc % sizeof(float) == 0);
37   assert(ks != 0);
38   assert(ks % (4 * 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 
58   do {
59     __m512 vacc0x0123456789ABCDEF = _mm512_load_ps(w);
60     __m512 vacc1x0123456789ABCDEF = vacc0x0123456789ABCDEF;
61     __m512 vacc2x0123456789ABCDEF = vacc0x0123456789ABCDEF;
62     __m512 vacc3x0123456789ABCDEF = vacc0x0123456789ABCDEF;
63     w += 16;
64 
65     size_t p = ks;
66     do {
67       const float* restrict a0 = a[0];
68       assert(a0 != NULL);
69       if XNN_UNPREDICTABLE(a0 != zero) {
70         a0 = (const float*) ((uintptr_t) a0 + a_offset);
71       }
72       const float* restrict a1 = a[1];
73       assert(a1 != NULL);
74       if XNN_UNPREDICTABLE(a1 != zero) {
75         a1 = (const float*) ((uintptr_t) a1 + a_offset);
76       }
77       const float* restrict a2 = a[2];
78       assert(a2 != NULL);
79       if XNN_UNPREDICTABLE(a2 != zero) {
80         a2 = (const float*) ((uintptr_t) a2 + a_offset);
81       }
82       const float* restrict a3 = a[3];
83       assert(a3 != NULL);
84       if XNN_UNPREDICTABLE(a3 != zero) {
85         a3 = (const float*) ((uintptr_t) a3 + a_offset);
86       }
87       a += 4;
88 
89       size_t k = kc;
90       do {
91         const __m512 vb0123456789ABCDEF = _mm512_load_ps(w);
92         w += 16;
93 
94         vacc0x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a0), vb0123456789ABCDEF, vacc0x0123456789ABCDEF);
95         vacc1x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a1), vb0123456789ABCDEF, vacc1x0123456789ABCDEF);
96         vacc2x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a2), vb0123456789ABCDEF, vacc2x0123456789ABCDEF);
97         vacc3x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a3), vb0123456789ABCDEF, vacc3x0123456789ABCDEF);
98 
99         a0 += 1;
100         a1 += 1;
101         a2 += 1;
102         a3 += 1;
103 
104         k -= sizeof(float);
105       } while (k != 0);
106       p -= 4 * sizeof(void*);
107     } while (p != 0);
108 
109     const __m512 vmax = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
110     vacc0x0123456789ABCDEF = _mm512_min_ps(vacc0x0123456789ABCDEF, vmax);
111     vacc1x0123456789ABCDEF = _mm512_min_ps(vacc1x0123456789ABCDEF, vmax);
112     vacc2x0123456789ABCDEF = _mm512_min_ps(vacc2x0123456789ABCDEF, vmax);
113     vacc3x0123456789ABCDEF = _mm512_min_ps(vacc3x0123456789ABCDEF, vmax);
114 
115     const __m512 vmin = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
116     vacc0x0123456789ABCDEF = _mm512_max_ps(vacc0x0123456789ABCDEF, vmin);
117     vacc1x0123456789ABCDEF = _mm512_max_ps(vacc1x0123456789ABCDEF, vmin);
118     vacc2x0123456789ABCDEF = _mm512_max_ps(vacc2x0123456789ABCDEF, vmin);
119     vacc3x0123456789ABCDEF = _mm512_max_ps(vacc3x0123456789ABCDEF, vmin);
120 
121     if XNN_LIKELY(nc >= 16) {
122       _mm512_storeu_ps(c3, vacc3x0123456789ABCDEF);
123       c3 = (float*) ((uintptr_t) c3 + cn_stride);
124       _mm512_storeu_ps(c2, vacc2x0123456789ABCDEF);
125       c2 = (float*) ((uintptr_t) c2 + cn_stride);
126       _mm512_storeu_ps(c1, vacc1x0123456789ABCDEF);
127       c1 = (float*) ((uintptr_t) c1 + cn_stride);
128       _mm512_storeu_ps(c0, vacc0x0123456789ABCDEF);
129       c0 = (float*) ((uintptr_t) c0 + cn_stride);
130 
131       a = (const float**restrict) ((uintptr_t) a - ks);
132       nc -= 16;
133     } else {
134       if (nc & 15) {
135         // Prepare mask for valid 32-bit elements (depends on nc).
136         const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << nc) - UINT32_C(1)));
137 
138         _mm512_mask_storeu_ps(c3, vmask, vacc3x0123456789ABCDEF);
139         _mm512_mask_storeu_ps(c2, vmask, vacc2x0123456789ABCDEF);
140         _mm512_mask_storeu_ps(c1, vmask, vacc1x0123456789ABCDEF);
141         _mm512_mask_storeu_ps(c0, vmask, vacc0x0123456789ABCDEF);
142       }
143 
144       nc = 0;
145     }
146   } while (nc != 0);
147 }
148