• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-psimd.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 <psimd.h>
13 
14 #include <xnnpack/dwconv.h>
15 
16 
xnn_f32_dwconv_ukernel_up8x4__psimd_acc2(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])17 void xnn_f32_dwconv_ukernel_up8x4__psimd_acc2(
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     const union xnn_f32_output_params params[restrict static 1])
26 {
27   assert(channels != 0);
28   assert(output_width != 0);
29 
30   const psimd_f32 vmax = psimd_load_splat_f32(&params->scalar.max);
31   const psimd_f32 vmin = psimd_load_splat_f32(&params->scalar.min);
32   do {
33     const float* i0 = input[0];
34     assert(i0 != NULL);
35     const float* i1 = input[1];
36     assert(i1 != NULL);
37     const float* i2 = input[2];
38     assert(i2 != NULL);
39     const float* i3 = input[3];
40     assert(i3 != NULL);
41     input = (const float**) ((uintptr_t) input + input_stride);
42 
43     size_t c = channels;
44     const float* w = weights;
45     for (; c >= 8; c -= 8) {
46       psimd_f32 vacc0123p0 = psimd_load_f32(w);
47       psimd_f32 vacc4567p0 = psimd_load_f32(w + 4);
48 
49 
50       const psimd_f32 vi0x0123 = psimd_load_f32(i0);
51       const psimd_f32 vi0x4567 = psimd_load_f32(i0 + 4);
52       i0 += 8;
53 
54       const psimd_f32 vk0x0123 = psimd_load_f32(w + 8);
55       const psimd_f32 vk0x4567 = psimd_load_f32(w + 12);
56       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi0x0123, vk0x0123);
57       vacc4567p0 = psimd_qfma_f32(vacc4567p0, vi0x4567, vk0x4567);
58 
59       const psimd_f32 vi1x0123 = psimd_load_f32(i1);
60       const psimd_f32 vi1x4567 = psimd_load_f32(i1 + 4);
61       i1 += 8;
62 
63       const psimd_f32 vk1x0123 = psimd_load_f32(w + 16);
64       const psimd_f32 vk1x4567 = psimd_load_f32(w + 20);
65       psimd_f32 vacc0123p1 = psimd_mul_f32(vi1x0123, vk1x0123);
66       psimd_f32 vacc4567p1 = psimd_mul_f32(vi1x4567, vk1x4567);
67 
68       const psimd_f32 vi2x0123 = psimd_load_f32(i2);
69       const psimd_f32 vi2x4567 = psimd_load_f32(i2 + 4);
70       i2 += 8;
71 
72       const psimd_f32 vk2x0123 = psimd_load_f32(w + 24);
73       const psimd_f32 vk2x4567 = psimd_load_f32(w + 28);
74       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi2x0123, vk2x0123);
75       vacc4567p0 = psimd_qfma_f32(vacc4567p0, vi2x4567, vk2x4567);
76 
77       const psimd_f32 vi3x0123 = psimd_load_f32(i3);
78       const psimd_f32 vi3x4567 = psimd_load_f32(i3 + 4);
79       i3 += 8;
80 
81       const psimd_f32 vk3x0123 = psimd_load_f32(w + 32);
82       const psimd_f32 vk3x4567 = psimd_load_f32(w + 36);
83       vacc0123p1 = psimd_qfma_f32(vacc0123p1, vi3x0123, vk3x0123);
84       vacc4567p1 = psimd_qfma_f32(vacc4567p1, vi3x4567, vk3x4567);
85 
86       w += 40;
87 
88       // Add up all accumulators to vacc01234567p0
89       vacc0123p0 = psimd_add_f32(vacc0123p0, vacc0123p1);
90       vacc4567p0 = psimd_add_f32(vacc4567p0, vacc4567p1);
91 
92       psimd_f32 vacc0123 = psimd_max_f32(vacc0123p0, vmin);
93       psimd_f32 vacc4567 = psimd_max_f32(vacc4567p0, vmin);
94       vacc0123 = psimd_min_f32(vacc0123, vmax);
95       vacc4567 = psimd_min_f32(vacc4567, vmax);
96 
97       psimd_store_f32(output, vacc0123);
98       psimd_store_f32(output + 4, vacc4567);
99       output += 8;
100     }
101     for (; c >= 4; c -= 4) {
102       psimd_f32 vacc0123p0 = psimd_load_f32(w);
103 
104       const psimd_f32 vi0x0123 = psimd_load_f32(i0);
105       i0 += 4;
106 
107       const psimd_f32 vk0x0123 = psimd_load_f32(w + 8);
108       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi0x0123, vk0x0123);
109 
110       const psimd_f32 vi1x0123 = psimd_load_f32(i1);
111       i1 += 4;
112 
113       const psimd_f32 vk1x0123 = psimd_load_f32(w + 16);
114       psimd_f32 vacc0123p1 = psimd_mul_f32(vi1x0123, vk1x0123);
115 
116       const psimd_f32 vi2x0123 = psimd_load_f32(i2);
117       i2 += 4;
118 
119       const psimd_f32 vk2x0123 = psimd_load_f32(w + 24);
120       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi2x0123, vk2x0123);
121 
122       const psimd_f32 vi3x0123 = psimd_load_f32(i3);
123       i3 += 4;
124 
125       const psimd_f32 vk3x0123 = psimd_load_f32(w + 32);
126       vacc0123p1 = psimd_qfma_f32(vacc0123p1, vi3x0123, vk3x0123);
127 
128       w += 4;
129 
130       // Add up all accumulators to vacc01234567p0
131       vacc0123p0 = psimd_add_f32(vacc0123p0, vacc0123p1);
132 
133       psimd_f32 vacc0123 = psimd_max_f32(vacc0123p0, vmin);
134       vacc0123 = psimd_min_f32(vacc0123, vmax);
135 
136       psimd_store_f32(output, vacc0123);
137       output += 4;
138     }
139     if XNN_UNLIKELY(c != 0) {
140       psimd_f32 vacc0123p0 = psimd_load_f32(w);
141 
142       const psimd_f32 vi0x0123 = psimd_load_f32(i0);
143       const psimd_f32 vk0x0123 = psimd_load_f32(w + 8);
144       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi0x0123, vk0x0123);
145 
146       const psimd_f32 vi1x0123 = psimd_load_f32(i1);
147       const psimd_f32 vk1x0123 = psimd_load_f32(w + 16);
148       psimd_f32 vacc0123p1 = psimd_mul_f32(vi1x0123, vk1x0123);
149 
150       const psimd_f32 vi2x0123 = psimd_load_f32(i2);
151       const psimd_f32 vk2x0123 = psimd_load_f32(w + 24);
152       vacc0123p0 = psimd_qfma_f32(vacc0123p0, vi2x0123, vk2x0123);
153 
154       const psimd_f32 vi3x0123 = psimd_load_f32(i3);
155       const psimd_f32 vk3x0123 = psimd_load_f32(w + 32);
156       vacc0123p1 = psimd_qfma_f32(vacc0123p1, vi3x0123, vk3x0123);
157 
158       // Add up all accumulators to vacc01234567p0
159       vacc0123p0 = psimd_add_f32(vacc0123p0, vacc0123p1);
160 
161       psimd_f32 vacc0123 = psimd_max_f32(vacc0123p0, vmin);
162       vacc0123 = psimd_min_f32(vacc0123, vmax);
163 
164       if (c & 2) {
165         psimd_store2_f32(output, vacc0123);
166         vacc0123 = psimd_concat_hi_f32(vacc0123, vacc0123);
167         output += 2;
168       }
169       if (c & 1) {
170         psimd_store1_f32(output, vacc0123);
171         output += 1;
172       }
173     }
174 
175     output = (float*) ((uintptr_t) output + output_increment);
176   } while (--output_width != 0);
177 }
178