1 // Auto-generated file. Do not edit!
2 // Template: src/f32-dwconv/up-sse.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 <xmmintrin.h>
13
14 #include <xnnpack/dwconv.h>
15
16
xnn_f32_dwconv_minmax_ukernel_up4x4__sse(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,size_t input_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_dwconv_minmax_ukernel_up4x4__sse(
18 size_t channels,
19 size_t output_width,
20 const float** input,
21 const float* weights,
22 float* output,
23 size_t input_stride,
24 size_t output_increment,
25 size_t input_offset,
26 const float* zero,
27 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
28 {
29 assert(channels != 0);
30 assert(output_width != 0);
31
32 const __m128 vmax = _mm_load_ps(params->sse.max);
33 const __m128 vmin = _mm_load_ps(params->sse.min);
34 do {
35 const float* i0 = input[0];
36 assert(i0 != NULL);
37 if XNN_UNPREDICTABLE(i0 != zero) {
38 i0 = (const float*) ((uintptr_t) i0 + input_offset);
39 }
40 const float* i1 = input[1];
41 assert(i1 != NULL);
42 if XNN_UNPREDICTABLE(i1 != zero) {
43 i1 = (const float*) ((uintptr_t) i1 + input_offset);
44 }
45 const float* i2 = input[2];
46 assert(i2 != NULL);
47 if XNN_UNPREDICTABLE(i2 != zero) {
48 i2 = (const float*) ((uintptr_t) i2 + input_offset);
49 }
50 const float* i3 = input[3];
51 assert(i3 != NULL);
52 if XNN_UNPREDICTABLE(i3 != zero) {
53 i3 = (const float*) ((uintptr_t) i3 + input_offset);
54 }
55 input = (const float**) ((uintptr_t) input + input_stride);
56
57 size_t c = channels;
58 const float* w = weights;
59 for (; c >= 4; c -= 4) {
60 __m128 vacc0123p0 = _mm_load_ps(w);
61
62
63 const __m128 vi0x0123 = _mm_loadu_ps(i0);
64 i0 += 4;
65
66 const __m128 vk0x0123 = _mm_load_ps(w + 4);
67 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi0x0123, vk0x0123));
68
69 const __m128 vi1x0123 = _mm_loadu_ps(i1);
70 i1 += 4;
71
72 const __m128 vk1x0123 = _mm_load_ps(w + 8);
73 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi1x0123, vk1x0123));
74
75 const __m128 vi2x0123 = _mm_loadu_ps(i2);
76 i2 += 4;
77
78 const __m128 vk2x0123 = _mm_load_ps(w + 12);
79 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi2x0123, vk2x0123));
80
81 const __m128 vi3x0123 = _mm_loadu_ps(i3);
82 i3 += 4;
83
84 const __m128 vk3x0123 = _mm_load_ps(w + 16);
85 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi3x0123, vk3x0123));
86
87 w += 20;
88
89
90 __m128 vacc0123 = _mm_max_ps(vacc0123p0, vmin);
91 vacc0123 = _mm_min_ps(vacc0123, vmax);
92
93 _mm_storeu_ps(output, vacc0123);
94 output += 4;
95 }
96 if XNN_UNLIKELY(c != 0) {
97 __m128 vacc0123p0 = _mm_load_ps(w);
98
99 const __m128 vi0x0123 = _mm_loadu_ps(i0);
100 const __m128 vk0x0123 = _mm_load_ps(w + 4);
101 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi0x0123, vk0x0123));
102
103 const __m128 vi1x0123 = _mm_loadu_ps(i1);
104 const __m128 vk1x0123 = _mm_load_ps(w + 8);
105 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi1x0123, vk1x0123));
106
107 const __m128 vi2x0123 = _mm_loadu_ps(i2);
108 const __m128 vk2x0123 = _mm_load_ps(w + 12);
109 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi2x0123, vk2x0123));
110
111 const __m128 vi3x0123 = _mm_loadu_ps(i3);
112 const __m128 vk3x0123 = _mm_load_ps(w + 16);
113 vacc0123p0 = _mm_add_ps(vacc0123p0, _mm_mul_ps(vi3x0123, vk3x0123));
114
115
116 __m128 vacc0123 = _mm_max_ps(vacc0123p0, vmin);
117 vacc0123 = _mm_min_ps(vacc0123, vmax);
118
119 if (c & 2) {
120 _mm_storel_pi((__m64*) output, vacc0123);
121 vacc0123 = _mm_movehl_ps(vacc0123, vacc0123);
122 output += 2;
123 }
124 if (c & 1) {
125 _mm_store_ss(output, vacc0123);
126 output += 1;
127 }
128 }
129
130 output = (float*) ((uintptr_t) output + output_increment);
131 } while (--output_width != 0);
132 }
133