• 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_ukernel_1x16__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_output_params params[restrict static1])18 void xnn_f32_igemm_ukernel_1x16__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_output_params params[restrict static 1])
31 {
32   assert(mr != 0);
33   assert(mr <= 1);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(kc % sizeof(float) == 0);
37   assert(ks != 0);
38   assert(ks % (1 * 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 
46   do {
47     __m512 vacc0x0123456789ABCDEF = _mm512_load_ps(w);
48     w += 16;
49 
50     size_t p = ks;
51     do {
52       const float* restrict a0 = a[0];
53       assert(a0 != NULL);
54       if XNN_UNPREDICTABLE(a0 != zero) {
55         a0 = (const float*) ((uintptr_t) a0 + a_offset);
56       }
57       a += 1;
58 
59       size_t k = kc;
60       do {
61         const __m512 vb0123456789ABCDEF = _mm512_load_ps(w);
62         w += 16;
63 
64         vacc0x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a0), vb0123456789ABCDEF, vacc0x0123456789ABCDEF);
65 
66         a0 += 1;
67 
68         k -= sizeof(float);
69       } while (k != 0);
70       p -= 1 * sizeof(void*);
71     } while (p != 0);
72 
73     const __m512 vmax = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
74     vacc0x0123456789ABCDEF = _mm512_min_ps(vacc0x0123456789ABCDEF, vmax);
75 
76     const __m512 vmin = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
77     vacc0x0123456789ABCDEF = _mm512_max_ps(vacc0x0123456789ABCDEF, vmin);
78 
79     if XNN_LIKELY(nc >= 16) {
80       _mm512_storeu_ps(c0, vacc0x0123456789ABCDEF);
81       c0 = (float*) ((uintptr_t) c0 + cn_stride);
82 
83       a = (const float**restrict) ((uintptr_t) a - ks);
84       nc -= 16;
85     } else {
86       if (nc & 15) {
87         // Prepare mask for valid 32-bit elements (depends on nc).
88         const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << nc) - UINT32_C(1)));
89 
90         _mm512_mask_storeu_ps(c0, vmask, vacc0x0123456789ABCDEF);
91       }
92 
93       nc = 0;
94     }
95   } while (nc != 0);
96 }
97