• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/avx-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 
16 
xnn_f32_igemm_minmax_ukernel_1x16__fma3_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)])17 void xnn_f32_igemm_minmax_ukernel_1x16__fma3_broadcast(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     size_t ks,
22     const float**restrict a,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     size_t a_offset,
28     const float* zero,
29     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(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(ks != 0);
37   assert(ks % (1 * sizeof(void*)) == 0);
38   assert(a_offset % sizeof(float) == 0);
39   assert(a != NULL);
40   assert(w != NULL);
41   assert(c != NULL);
42 
43   float* c0 = c;
44 
45   do {
46     __m256 vacc0x01234567 = _mm256_load_ps(w);
47     __m256 vacc0x89ABCDEF = _mm256_load_ps(w + 8);
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 __m256 vb01234567 = _mm256_load_ps(w);
62         const __m256 vb89ABCDEF = _mm256_load_ps(w + 8);
63         w += 16;
64 
65         const __m256 va0 = _mm256_broadcast_ss(a0);
66         a0 += 1;
67 
68         vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567, vacc0x01234567);
69         vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEF, vacc0x89ABCDEF);
70         k -= sizeof(float);
71       } while (k != 0);
72       p -= 1 * sizeof(void*);
73     } while (p != 0);
74 
75     const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
76     vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
77     vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
78 
79     const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
80     vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
81     vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
82 
83     if XNN_LIKELY(nc >= 16) {
84       _mm256_storeu_ps(c0, vacc0x01234567);
85       _mm256_storeu_ps(c0 + 8, vacc0x89ABCDEF);
86       c0 = (float*) ((uintptr_t) c0 + cn_stride);
87 
88       a = (const float**restrict) ((uintptr_t) a - ks);
89       nc -= 16;
90     } else {
91       if (nc & 8) {
92         _mm256_storeu_ps(c0, vacc0x01234567);
93 
94         vacc0x01234567 = vacc0x89ABCDEF;
95 
96         c0 += 8;
97       }
98       __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
99       if (nc & 4) {
100         _mm_storeu_ps(c0, vacc0x0123);
101 
102         vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
103 
104         c0 += 4;
105       }
106       if (nc & 2) {
107         _mm_storel_pi((__m64*) c0, vacc0x0123);
108 
109         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
110 
111         c0 += 2;
112       }
113       if (nc & 1) {
114         _mm_store_ss(c0, vacc0x0123);
115       }
116 
117       nc = 0;
118     }
119   } while (nc != 0);
120 }
121