• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/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/gemm.h>
15 
16 
xnn_f32_gemminc_ukernel_6x8__avx_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])17 void xnn_f32_gemminc_ukernel_6x8__avx_broadcast(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     const float*restrict a,
22     size_t a_stride,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     const float*restrict acc,
28     const union xnn_f32_output_params params[restrict static 1])
29 {
30   assert(mr != 0);
31   assert(mr <= 6);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38   assert(acc != NULL);
39 
40   const float* a0 = a;
41   float* c0 = c;
42   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr < 2) {
45     a1 = a0;
46     c1 = c0;
47   }
48   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     a2 = a1;
52     c2 = c1;
53   }
54   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
55   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56   if XNN_UNPREDICTABLE(mr < 4) {
57     a3 = a2;
58     c3 = c2;
59   }
60   const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
61   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
62   if XNN_UNPREDICTABLE(mr <= 4) {
63     a4 = a3;
64     c4 = c3;
65   }
66   const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
67   float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
68   if XNN_UNPREDICTABLE(mr != 6) {
69     a5 = a4;
70     c5 = c4;
71   }
72 
73   do {
74     __m256 vacc0x01234567 = _mm256_load_ps(acc + 0);
75     __m256 vacc1x01234567 = _mm256_load_ps(acc + 8);
76     __m256 vacc2x01234567 = _mm256_load_ps(acc + 16);
77     __m256 vacc3x01234567 = _mm256_load_ps(acc + 24);
78     __m256 vacc4x01234567 = _mm256_load_ps(acc + 32);
79     __m256 vacc5x01234567 = _mm256_load_ps(acc + 40);
80     acc += 48;
81 
82     size_t k = kc;
83     do {
84       const __m256 va0 = _mm256_broadcast_ss(a0);
85       a0 += 1;
86       const __m256 va1 = _mm256_broadcast_ss(a1);
87       a1 += 1;
88       const __m256 va2 = _mm256_broadcast_ss(a2);
89       a2 += 1;
90       const __m256 va3 = _mm256_broadcast_ss(a3);
91       a3 += 1;
92       const __m256 va4 = _mm256_broadcast_ss(a4);
93       a4 += 1;
94       const __m256 va5 = _mm256_broadcast_ss(a5);
95       a5 += 1;
96 
97       const __m256 vb01234567 = _mm256_load_ps(w);
98       w += 8;
99 
100       vacc0x01234567 = _mm256_add_ps(vacc0x01234567, _mm256_mul_ps(va0, vb01234567));
101       vacc1x01234567 = _mm256_add_ps(vacc1x01234567, _mm256_mul_ps(va1, vb01234567));
102       vacc2x01234567 = _mm256_add_ps(vacc2x01234567, _mm256_mul_ps(va2, vb01234567));
103       vacc3x01234567 = _mm256_add_ps(vacc3x01234567, _mm256_mul_ps(va3, vb01234567));
104       vacc4x01234567 = _mm256_add_ps(vacc4x01234567, _mm256_mul_ps(va4, vb01234567));
105       vacc5x01234567 = _mm256_add_ps(vacc5x01234567, _mm256_mul_ps(va5, vb01234567));
106 
107       k -= sizeof(float);
108     } while (k != 0);
109 
110     const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
111     vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
112     vacc1x01234567 = _mm256_min_ps(vacc1x01234567, vmax);
113     vacc2x01234567 = _mm256_min_ps(vacc2x01234567, vmax);
114     vacc3x01234567 = _mm256_min_ps(vacc3x01234567, vmax);
115     vacc4x01234567 = _mm256_min_ps(vacc4x01234567, vmax);
116     vacc5x01234567 = _mm256_min_ps(vacc5x01234567, vmax);
117 
118     const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
119     vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
120     vacc1x01234567 = _mm256_max_ps(vacc1x01234567, vmin);
121     vacc2x01234567 = _mm256_max_ps(vacc2x01234567, vmin);
122     vacc3x01234567 = _mm256_max_ps(vacc3x01234567, vmin);
123     vacc4x01234567 = _mm256_max_ps(vacc4x01234567, vmin);
124     vacc5x01234567 = _mm256_max_ps(vacc5x01234567, vmin);
125 
126     if XNN_LIKELY(nc >= 8) {
127       _mm256_storeu_ps(c5, vacc5x01234567);
128       c5 = (float*) ((uintptr_t) c5 + cn_stride);
129       _mm256_storeu_ps(c4, vacc4x01234567);
130       c4 = (float*) ((uintptr_t) c4 + cn_stride);
131       _mm256_storeu_ps(c3, vacc3x01234567);
132       c3 = (float*) ((uintptr_t) c3 + cn_stride);
133       _mm256_storeu_ps(c2, vacc2x01234567);
134       c2 = (float*) ((uintptr_t) c2 + cn_stride);
135       _mm256_storeu_ps(c1, vacc1x01234567);
136       c1 = (float*) ((uintptr_t) c1 + cn_stride);
137       _mm256_storeu_ps(c0, vacc0x01234567);
138       c0 = (float*) ((uintptr_t) c0 + cn_stride);
139 
140       a5 = (const float*) ((uintptr_t) a5 - kc);
141       a4 = (const float*) ((uintptr_t) a4 - kc);
142       a3 = (const float*) ((uintptr_t) a3 - kc);
143       a2 = (const float*) ((uintptr_t) a2 - kc);
144       a1 = (const float*) ((uintptr_t) a1 - kc);
145       a0 = (const float*) ((uintptr_t) a0 - kc);
146 
147       nc -= 8;
148     } else {
149       __m128 vacc5x0123 = _mm256_castps256_ps128(vacc5x01234567);
150       __m128 vacc4x0123 = _mm256_castps256_ps128(vacc4x01234567);
151       __m128 vacc3x0123 = _mm256_castps256_ps128(vacc3x01234567);
152       __m128 vacc2x0123 = _mm256_castps256_ps128(vacc2x01234567);
153       __m128 vacc1x0123 = _mm256_castps256_ps128(vacc1x01234567);
154       __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
155       if (nc & 4) {
156         _mm_storeu_ps(c5, vacc5x0123);
157         _mm_storeu_ps(c4, vacc4x0123);
158         _mm_storeu_ps(c3, vacc3x0123);
159         _mm_storeu_ps(c2, vacc2x0123);
160         _mm_storeu_ps(c1, vacc1x0123);
161         _mm_storeu_ps(c0, vacc0x0123);
162 
163         vacc5x0123 = _mm256_extractf128_ps(vacc5x01234567, 1);
164         vacc4x0123 = _mm256_extractf128_ps(vacc4x01234567, 1);
165         vacc3x0123 = _mm256_extractf128_ps(vacc3x01234567, 1);
166         vacc2x0123 = _mm256_extractf128_ps(vacc2x01234567, 1);
167         vacc1x0123 = _mm256_extractf128_ps(vacc1x01234567, 1);
168         vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
169 
170         c5 += 4;
171         c4 += 4;
172         c3 += 4;
173         c2 += 4;
174         c1 += 4;
175         c0 += 4;
176       }
177       if (nc & 2) {
178         _mm_storel_pi((__m64*) c5, vacc5x0123);
179         _mm_storel_pi((__m64*) c4, vacc4x0123);
180         _mm_storel_pi((__m64*) c3, vacc3x0123);
181         _mm_storel_pi((__m64*) c2, vacc2x0123);
182         _mm_storel_pi((__m64*) c1, vacc1x0123);
183         _mm_storel_pi((__m64*) c0, vacc0x0123);
184 
185         vacc5x0123 = _mm_movehl_ps(vacc5x0123, vacc5x0123);
186         vacc4x0123 = _mm_movehl_ps(vacc4x0123, vacc4x0123);
187         vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
188         vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
189         vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
190         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
191 
192         c5 += 2;
193         c4 += 2;
194         c3 += 2;
195         c2 += 2;
196         c1 += 2;
197         c0 += 2;
198       }
199       if (nc & 1) {
200         _mm_store_ss(c5, vacc5x0123);
201         _mm_store_ss(c4, vacc4x0123);
202         _mm_store_ss(c3, vacc3x0123);
203         _mm_store_ss(c2, vacc2x0123);
204         _mm_store_ss(c1, vacc1x0123);
205         _mm_store_ss(c0, vacc0x0123);
206       }
207 
208       nc = 0;
209     }
210   } while (nc != 0);
211 }
212