• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/3x3p1-sse.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <xmmintrin.h>
13 
14 #include <xnnpack/dwconv.h>
15 #include <xnnpack/math.h>
16 
17 
xnn_f32_dwconv2d_chw_ukernel_3x3p1__sse_1x4_acc3(size_t input_height,size_t input_width,const float * input,const float * weights,const float * zero,float * output,uint32_t padding_top,const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_dwconv2d_chw_ukernel_3x3p1__sse_1x4_acc3(
19     size_t input_height,
20     size_t input_width,
21     const float* input,
22     const float* weights,
23     const float* zero,
24     float* output,
25     uint32_t padding_top,
26     const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28   assert(input_height != 0);
29   assert(input_width != 0);
30   assert(input_width % sizeof(float) == 0);
31   assert(padding_top == 1);
32 
33   const __m128 vmask = _mm_load_ps((const float*) params->sse.mask);
34   const __m128 vmax = _mm_load_ps(params->sse.max);
35   const __m128 vmin = _mm_load_ps(params->sse.min);
36 
37   const __m128 vbias = _mm_load1_ps(weights);
38   const __m128 vk00 = _mm_load1_ps(weights + 1);
39   const __m128 vk01 = _mm_load1_ps(weights + 2);
40   const __m128 vk02 = _mm_load1_ps(weights + 3);
41   const __m128 vk10 = _mm_load1_ps(weights + 4);
42   const __m128 vk11 = _mm_load1_ps(weights + 5);
43   const __m128 vk12 = _mm_load1_ps(weights + 6);
44   const __m128 vk20 = _mm_load1_ps(weights + 7);
45   const __m128 vk21 = _mm_load1_ps(weights + 8);
46   const __m128 vk22 = _mm_load1_ps(weights + 9);
47 
48   const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
49 
50   const float* i0 = zero;
51   const float* i1 = input;
52   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
53 
54   float* o0 = output;
55 
56   size_t output_height = input_height;
57   do {
58     if XNN_UNPREDICTABLE(output_height < 2) {
59       i2 = zero;
60     }
61 
62     // vi0x3012 = ( vi02, vi01, vi{M}0, vi{M}3 )
63     __m128 vi0x3012 = _mm_setzero_ps();
64     // vi1x3012 = ( vi12, vi11, vi{M}0, vi{M}3 )
65     __m128 vi1x3012 = _mm_setzero_ps();
66     // vi2x3012 = ( vi22, vi21, vi{M}0, vi{M}3 )
67     __m128 vi2x3012 = _mm_setzero_ps();
68 
69     __m128 vi0x4567 = _mm_loadu_ps(i0);
70     i0 += 4;
71     __m128 vi1x4567 = _mm_loadu_ps(i1);
72     i1 += 4;
73     __m128 vi2x4567 = _mm_loadu_ps(i2);
74     i2 += 4;
75 
76     size_t w = input_width;
77     for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
78       // vi0x89AB = ( vi0B, vi0A, vi09, vi08 )
79       const __m128 vi0x89AB = _mm_loadu_ps(i0);
80       i0 += 4;
81       // vi1x89AB = ( vi1B, vi1A, vi19, vi18 )
82       const __m128 vi1x89AB = _mm_loadu_ps(i1);
83       i1 += 4;
84       // vi2x89AB = ( vi2B, vi2A, vi29, vi28 )
85       const __m128 vi2x89AB = _mm_loadu_ps(i2);
86       i2 += 4;
87 
88       // vi0x7456 = ( vi06, vi05, vi04, vi07 )
89       const __m128 vi0x7456 = _mm_shuffle_ps(vi0x4567, vi0x4567, _MM_SHUFFLE(2, 1, 0, 3));
90       // vi1x7456 = ( vi16, vi15, vi14, vi17 )
91       const __m128 vi1x7456 = _mm_shuffle_ps(vi1x4567, vi1x4567, _MM_SHUFFLE(2, 1, 0, 3));
92       // vi2x7456 = ( vi26, vi25, vi24, vi27 )
93       const __m128 vi2x7456 = _mm_shuffle_ps(vi2x4567, vi2x4567, _MM_SHUFFLE(2, 1, 0, 3));
94 
95       __m128 vo0p0 = _mm_add_ps(vbias, _mm_mul_ps(vi0x4567, vk01));
96       __m128 vo0p1 = _mm_mul_ps(vi1x4567, vk11);
97       __m128 vo0p2 = _mm_mul_ps(vi2x4567, vk21);
98 
99       // vi0x3456 = ( vi06, vi05, vi04, vi03 )
100       const __m128 vi0x3456 = _mm_move_ss(vi0x7456, vi0x3012);
101       // vi1x3456 = ( vi16, vi15, vi14, vi13 )
102       const __m128 vi1x3456 = _mm_move_ss(vi1x7456, vi1x3012);
103       // vi2x3456 = ( vi26, vi25, vi24, vi23 )
104       const __m128 vi2x3456 = _mm_move_ss(vi2x7456, vi2x3012);
105 
106       vo0p0 = _mm_add_ps(vo0p0, _mm_mul_ps(vi0x3456, vk00));
107       vo0p1 = _mm_add_ps(vo0p1, _mm_mul_ps(vi1x3456, vk10));
108       vo0p2 = _mm_add_ps(vo0p2, _mm_mul_ps(vi2x3456, vk20));
109 
110       vi0x3012 = vi0x7456;
111       vi1x3012 = vi1x7456;
112       vi2x3012 = vi2x7456;
113 
114       // vi0x8567 = ( vi07, vi06, vi05, vi08 )
115       const __m128 vi0x8567 = _mm_move_ss(vi0x4567, vi0x89AB);
116       // vi1x8567 = ( vi17, vi16, vi15, vi18 )
117       const __m128 vi1x8567 = _mm_move_ss(vi1x4567, vi1x89AB);
118       // vi2x8567 = ( vi27, vi26, vi25, vi28 )
119       const __m128 vi2x8567 = _mm_move_ss(vi2x4567, vi2x89AB);
120 
121       // vi0x5678 = ( vi08, vi07, vi06, vi05 )
122       const __m128 vi0x5678 = _mm_shuffle_ps(vi0x8567, vi0x8567, _MM_SHUFFLE(0, 3, 2, 1));
123       // vi1x5678 = ( vi18, vi17, vi16, vi15 )
124       const __m128 vi1x5678 = _mm_shuffle_ps(vi1x8567, vi1x8567, _MM_SHUFFLE(0, 3, 2, 1));
125       // vi2x5678 = ( vi28, vi27, vi26, vi25 )
126       const __m128 vi2x5678 = _mm_shuffle_ps(vi2x8567, vi2x8567, _MM_SHUFFLE(0, 3, 2, 1));
127 
128       vo0p0 = _mm_add_ps(vo0p0, _mm_mul_ps(vi0x5678, vk02));
129       vo0p1 = _mm_add_ps(vo0p1, _mm_mul_ps(vi1x5678, vk12));
130       vo0p2 = _mm_add_ps(vo0p2, _mm_mul_ps(vi2x5678, vk22));
131 
132       vi0x4567 = vi0x89AB;
133       vi1x4567 = vi1x89AB;
134       vi2x4567 = vi2x89AB;
135 
136       vo0p0 = _mm_add_ps(vo0p0, vo0p1);
137       vo0p0 = _mm_add_ps(vo0p0, vo0p2);
138 
139       __m128 vo0 = _mm_max_ps(vo0p0, vmin);
140 
141       vo0 = _mm_min_ps(vo0, vmax);
142 
143       _mm_storeu_ps(o0, vo0);
144       o0 += 4;
145     }
146     // Always process the last block of 1..4 pixels.
147     assert(w >= 1 * sizeof(float));
148     assert(w <= 4 * sizeof(float));
149     {
150       vi0x4567 = _mm_and_ps(vmask, vi0x4567);
151       vi1x4567 = _mm_and_ps(vmask, vi1x4567);
152       vi2x4567 = _mm_and_ps(vmask, vi2x4567);
153 
154       // vi0x7456 = ( vi06, vi05, vi04, vi07 )
155       const __m128 vi0x7456 = _mm_shuffle_ps(vi0x4567, vi0x4567, _MM_SHUFFLE(2, 1, 0, 3));
156       // vi1x7456 = ( vi16, vi15, vi14, vi17 )
157       const __m128 vi1x7456 = _mm_shuffle_ps(vi1x4567, vi1x4567, _MM_SHUFFLE(2, 1, 0, 3));
158       // vi2x7456 = ( vi26, vi25, vi24, vi27 )
159       const __m128 vi2x7456 = _mm_shuffle_ps(vi2x4567, vi2x4567, _MM_SHUFFLE(2, 1, 0, 3));
160 
161       __m128 vo0p0 = _mm_add_ps(vbias, _mm_mul_ps(vi0x4567, vk01));
162       __m128 vo0p1 = _mm_mul_ps(vi1x4567, vk11);
163       __m128 vo0p2 = _mm_mul_ps(vi2x4567, vk21);
164 
165       // vi0x3456 = ( vi06, vi05, vi04, vi03 )
166       const __m128 vi0x3456 = _mm_move_ss(vi0x7456, vi0x3012);
167       // vi1x3456 = ( vi16, vi15, vi14, vi13 )
168       const __m128 vi1x3456 = _mm_move_ss(vi1x7456, vi1x3012);
169       // vi2x3456 = ( vi26, vi25, vi24, vi23 )
170       const __m128 vi2x3456 = _mm_move_ss(vi2x7456, vi2x3012);
171 
172       vo0p0 = _mm_add_ps(vo0p0, _mm_mul_ps(vi0x3456, vk00));
173       vo0p1 = _mm_add_ps(vo0p1, _mm_mul_ps(vi1x3456, vk10));
174       vo0p2 = _mm_add_ps(vo0p2, _mm_mul_ps(vi2x3456, vk20));
175 
176       const __m128 vzero = _mm_setzero_ps();
177       // vi0x8567 = ( vi07, vi06, vi05, 0.0 )
178       const __m128 vi0x8567 = _mm_move_ss(vi0x4567, vzero);
179       // vi1x8567 = ( vi17, vi16, vi15, 0.0 )
180       const __m128 vi1x8567 = _mm_move_ss(vi1x4567, vzero);
181       // vi2x8567 = ( vi27, vi26, vi25, 0.0 )
182       const __m128 vi2x8567 = _mm_move_ss(vi2x4567, vzero);
183 
184       // vi0x5678 = ( vi08, vi07, vi06, vi05 )
185       const __m128 vi0x5678 = _mm_shuffle_ps(vi0x8567, vi0x8567, _MM_SHUFFLE(0, 3, 2, 1));
186       // vi1x5678 = ( vi18, vi17, vi16, vi15 )
187       const __m128 vi1x5678 = _mm_shuffle_ps(vi1x8567, vi1x8567, _MM_SHUFFLE(0, 3, 2, 1));
188       // vi2x5678 = ( vi28, vi27, vi26, vi25 )
189       const __m128 vi2x5678 = _mm_shuffle_ps(vi2x8567, vi2x8567, _MM_SHUFFLE(0, 3, 2, 1));
190 
191       vo0p0 = _mm_add_ps(vo0p0, _mm_mul_ps(vi0x5678, vk02));
192       vo0p1 = _mm_add_ps(vo0p1, _mm_mul_ps(vi1x5678, vk12));
193       vo0p2 = _mm_add_ps(vo0p2, _mm_mul_ps(vi2x5678, vk22));
194 
195       vo0p0 = _mm_add_ps(vo0p0, vo0p1);
196       vo0p0 = _mm_add_ps(vo0p0, vo0p2);
197 
198       __m128 vo0 = _mm_max_ps(vo0p0, vmin);
199 
200       vo0 = _mm_min_ps(vo0, vmax);
201 
202       if XNN_LIKELY(w == 4 * sizeof(float)) {
203         _mm_storeu_ps(o0, vo0);
204         o0 += 4;
205       } else {
206         if (w & (2 * sizeof(float))) {
207           _mm_storel_pi((__m64*) o0, vo0);
208           o0 += 2;
209 
210           vo0 = _mm_movehl_ps(vo0, vo0);
211         }
212         if (w & (1 * sizeof(float))) {
213           _mm_store_ss(o0, vo0);
214           o0 += 1;
215         }
216       }
217     }
218 
219     i0 = (const float*) ((uintptr_t) i1 - input_decrement);
220     i1 = (const float*) ((uintptr_t) i2 - input_decrement);
221     i2 = (const float*) ((uintptr_t) i1 + input_width);
222 
223 
224   } while (--output_height != 0);
225 }
226