• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/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/gemm.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 
17 
xnn_f32_gemminc_ukernel_1x16__avx512f_broadcast(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const float * restrict acc,const union xnn_f32_output_params params[restrict static1])18 void xnn_f32_gemminc_ukernel_1x16__avx512f_broadcast(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const float*restrict a,
23     size_t a_stride,
24     const float*restrict w,
25     float*restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const float*restrict acc,
29     const union xnn_f32_output_params params[restrict static 1])
30 {
31   assert(mr != 0);
32   assert(mr <= 1);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(a != NULL);
37   assert(w != NULL);
38   assert(c != NULL);
39   assert(acc != NULL);
40 
41   const float* a0 = a;
42   float* c0 = c;
43 
44   do {
45     __m512 vacc0x0123456789ABCDEF = _mm512_load_ps(acc + 0);
46     acc += 16;
47 
48     size_t k = kc;
49     do {
50       const __m512 vb0123456789ABCDEF = _mm512_load_ps(w);
51       w += 16;
52 
53       vacc0x0123456789ABCDEF = _mm512_fmadd_ps(_mm512_set1_ps(*a0), vb0123456789ABCDEF, vacc0x0123456789ABCDEF);
54 
55       a0 += 1;
56 
57       k -= sizeof(float);
58     } while (k != 0);
59 
60     const __m512 vmax = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
61     vacc0x0123456789ABCDEF = _mm512_min_ps(vacc0x0123456789ABCDEF, vmax);
62 
63     const __m512 vmin = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
64     vacc0x0123456789ABCDEF = _mm512_max_ps(vacc0x0123456789ABCDEF, vmin);
65 
66     if XNN_LIKELY(nc >= 16) {
67       _mm512_storeu_ps(c0, vacc0x0123456789ABCDEF);
68       c0 = (float*) ((uintptr_t) c0 + cn_stride);
69 
70       a0 = (const float*) ((uintptr_t) a0 - kc);
71 
72       nc -= 16;
73     } else {
74       if (nc & 15) {
75         // Prepare mask for valid 32-bit elements (depends on nc).
76         const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << nc) - UINT32_C(1)));
77 
78         _mm512_mask_storeu_ps(c0, vmask, vacc0x0123456789ABCDEF);
79       }
80 
81       nc = 0;
82     }
83   } while (nc != 0);
84 }
85