• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-avx.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/dwconv.h>
15 
16 
17 static const int32_t mask_table[14] = {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0};
18 
xnn_f32_dwconv_ukernel_up8x9__fma3(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,const union xnn_f32_output_params params[restrict static1])19 void xnn_f32_dwconv_ukernel_up8x9__fma3(
20     size_t channels,
21     size_t output_width,
22     const float** input,
23     const float* weights,
24     float* output,
25     size_t input_stride,
26     size_t output_increment,
27     const union xnn_f32_output_params params[restrict static 1])
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
33   const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
34   do {
35     const float* i0 = input[0];
36     assert(i0 != NULL);
37     const float* i1 = input[1];
38     assert(i1 != NULL);
39     const float* i2 = input[2];
40     assert(i2 != NULL);
41     const float* i3 = input[3];
42     assert(i3 != NULL);
43     const float* i4 = input[4];
44     assert(i4 != NULL);
45     const float* i5 = input[5];
46     assert(i5 != NULL);
47     const float* i6 = input[6];
48     assert(i6 != NULL);
49     const float* i7 = input[7];
50     assert(i7 != NULL);
51     const float* i8 = input[8];
52     assert(i8 != NULL);
53     input = (const float**) ((uintptr_t) input + input_stride);
54 
55     size_t c = channels;
56     const float* w = weights;
57     for (; c >= 8; c -= 8) {
58       __m256 vacc01234567p0 = _mm256_load_ps(w);
59 
60 
61       const __m256 vi0x01234567 = _mm256_loadu_ps(i0);
62       i0 += 8;
63 
64       const __m256 vk0x01234567 = _mm256_load_ps(w + 8);
65       vacc01234567p0 = _mm256_fmadd_ps(vi0x01234567, vk0x01234567, vacc01234567p0);
66 
67       const __m256 vi1x01234567 = _mm256_loadu_ps(i1);
68       i1 += 8;
69 
70       const __m256 vk1x01234567 = _mm256_load_ps(w + 16);
71       vacc01234567p0 = _mm256_fmadd_ps(vi1x01234567, vk1x01234567, vacc01234567p0);
72 
73       const __m256 vi2x01234567 = _mm256_loadu_ps(i2);
74       i2 += 8;
75 
76       const __m256 vk2x01234567 = _mm256_load_ps(w + 24);
77       vacc01234567p0 = _mm256_fmadd_ps(vi2x01234567, vk2x01234567, vacc01234567p0);
78 
79       const __m256 vi3x01234567 = _mm256_loadu_ps(i3);
80       i3 += 8;
81 
82       const __m256 vk3x01234567 = _mm256_load_ps(w + 32);
83       vacc01234567p0 = _mm256_fmadd_ps(vi3x01234567, vk3x01234567, vacc01234567p0);
84 
85       const __m256 vi4x01234567 = _mm256_loadu_ps(i4);
86       i4 += 8;
87 
88       const __m256 vk4x01234567 = _mm256_load_ps(w + 40);
89       vacc01234567p0 = _mm256_fmadd_ps(vi4x01234567, vk4x01234567, vacc01234567p0);
90 
91       const __m256 vi5x01234567 = _mm256_loadu_ps(i5);
92       i5 += 8;
93 
94       const __m256 vk5x01234567 = _mm256_load_ps(w + 48);
95       vacc01234567p0 = _mm256_fmadd_ps(vi5x01234567, vk5x01234567, vacc01234567p0);
96 
97       const __m256 vi6x01234567 = _mm256_loadu_ps(i6);
98       i6 += 8;
99 
100       const __m256 vk6x01234567 = _mm256_load_ps(w + 56);
101       vacc01234567p0 = _mm256_fmadd_ps(vi6x01234567, vk6x01234567, vacc01234567p0);
102 
103       const __m256 vi7x01234567 = _mm256_loadu_ps(i7);
104       i7 += 8;
105 
106       const __m256 vk7x01234567 = _mm256_load_ps(w + 64);
107       vacc01234567p0 = _mm256_fmadd_ps(vi7x01234567, vk7x01234567, vacc01234567p0);
108 
109       const __m256 vi8x01234567 = _mm256_loadu_ps(i8);
110       i8 += 8;
111 
112       const __m256 vk8x01234567 = _mm256_load_ps(w + 72);
113       vacc01234567p0 = _mm256_fmadd_ps(vi8x01234567, vk8x01234567, vacc01234567p0);
114 
115       w += 80;
116 
117 
118       __m256 vacc01234567 = _mm256_max_ps(vacc01234567p0, vmin);
119       vacc01234567 = _mm256_min_ps(vacc01234567, vmax);
120 
121       _mm256_storeu_ps(output, vacc01234567);
122       output += 8;
123     }
124     if XNN_UNLIKELY(c != 0) {
125       assert(c >= 1);
126       assert(c <= 7);
127       __m256i vmask = _mm256_loadu_si256((const __m256i*) &mask_table[7 - c]);
128 
129       __m256 vacc01234567p0 = _mm256_load_ps(w);
130 
131       const __m256 vi0x01234567 = _mm256_maskload_ps(i0, vmask);
132       const __m256 vk0x01234567 = _mm256_load_ps(w + 8);
133       vacc01234567p0 = _mm256_fmadd_ps(vi0x01234567, vk0x01234567, vacc01234567p0);
134 
135       const __m256 vi1x01234567 = _mm256_maskload_ps(i1, vmask);
136       const __m256 vk1x01234567 = _mm256_load_ps(w + 16);
137       vacc01234567p0 = _mm256_fmadd_ps(vi1x01234567, vk1x01234567, vacc01234567p0);
138 
139       const __m256 vi2x01234567 = _mm256_maskload_ps(i2, vmask);
140       const __m256 vk2x01234567 = _mm256_load_ps(w + 24);
141       vacc01234567p0 = _mm256_fmadd_ps(vi2x01234567, vk2x01234567, vacc01234567p0);
142 
143       const __m256 vi3x01234567 = _mm256_maskload_ps(i3, vmask);
144       const __m256 vk3x01234567 = _mm256_load_ps(w + 32);
145       vacc01234567p0 = _mm256_fmadd_ps(vi3x01234567, vk3x01234567, vacc01234567p0);
146 
147       const __m256 vi4x01234567 = _mm256_maskload_ps(i4, vmask);
148       const __m256 vk4x01234567 = _mm256_load_ps(w + 40);
149       vacc01234567p0 = _mm256_fmadd_ps(vi4x01234567, vk4x01234567, vacc01234567p0);
150 
151       const __m256 vi5x01234567 = _mm256_maskload_ps(i5, vmask);
152       const __m256 vk5x01234567 = _mm256_load_ps(w + 48);
153       vacc01234567p0 = _mm256_fmadd_ps(vi5x01234567, vk5x01234567, vacc01234567p0);
154 
155       const __m256 vi6x01234567 = _mm256_maskload_ps(i6, vmask);
156       const __m256 vk6x01234567 = _mm256_load_ps(w + 56);
157       vacc01234567p0 = _mm256_fmadd_ps(vi6x01234567, vk6x01234567, vacc01234567p0);
158 
159       const __m256 vi7x01234567 = _mm256_maskload_ps(i7, vmask);
160       const __m256 vk7x01234567 = _mm256_load_ps(w + 64);
161       vacc01234567p0 = _mm256_fmadd_ps(vi7x01234567, vk7x01234567, vacc01234567p0);
162 
163       const __m256 vi8x01234567 = _mm256_maskload_ps(i8, vmask);
164       const __m256 vk8x01234567 = _mm256_load_ps(w + 72);
165       vacc01234567p0 = _mm256_fmadd_ps(vi8x01234567, vk8x01234567, vacc01234567p0);
166 
167 
168       __m256 vacc01234567 = _mm256_max_ps(vacc01234567p0, vmin);
169       vacc01234567 = _mm256_min_ps(vacc01234567, vmax);
170 
171       // _mm256_maskstore_ps(output, vmask, vacc01234567); output += c; could be used here, but triggers msan failures (probably an msan bug).
172       __m128 vacc0123 = _mm256_castps256_ps128(vacc01234567);
173       if (c & 4) {
174         _mm_storeu_ps(output, vacc0123);
175         vacc0123 = _mm256_extractf128_ps(vacc01234567, 1);
176         output += 4;
177       }
178       if (c & 2) {
179         _mm_storel_pi((__m64*) output, vacc0123);
180         vacc0123 = _mm_movehl_ps(vacc0123, vacc0123);
181         output += 2;
182       }
183       if (c & 1) {
184         _mm_store_ss(output, vacc0123);
185         output += 1;
186       }
187     }
188 
189     output = (float*) ((uintptr_t) output + output_increment);
190   } while (--output_width != 0);
191 }
192