• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-wasmsimd.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 <wasm_simd128.h>
13 
14 #include <xnnpack/dwconv.h>
15 
16 
xnn_f32_dwconv_minmax_ukernel_up8x4__wasmsimd_x86(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_up8x4__wasmsimd_x86(
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_OOB_READS
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const v128_t vmin = wasm_v128_load64_splat(params->wasmsimd.min);
33   const v128_t vmax = wasm_v128_load64_splat(params->wasmsimd.max);
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 >= 8; c -= 8) {
60       v128_t vacc0123p0 = wasm_v128_load(w);
61       v128_t vacc4567p0 = wasm_v128_load(w + 4);
62 
63 
64       const v128_t vi0x0123 = wasm_v128_load(i0);
65       const v128_t vi0x4567 = wasm_v128_load(i0 + 4);
66       i0 += 8;
67 
68       const v128_t vk0x0123 = wasm_v128_load(w + 8);
69       const v128_t vk0x4567 = wasm_v128_load(w + 12);
70       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
71       vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi0x4567, vk0x4567));
72 
73       const v128_t vi1x0123 = wasm_v128_load(i1);
74       const v128_t vi1x4567 = wasm_v128_load(i1 + 4);
75       i1 += 8;
76 
77       const v128_t vk1x0123 = wasm_v128_load(w + 16);
78       const v128_t vk1x4567 = wasm_v128_load(w + 20);
79       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
80       vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi1x4567, vk1x4567));
81 
82       const v128_t vi2x0123 = wasm_v128_load(i2);
83       const v128_t vi2x4567 = wasm_v128_load(i2 + 4);
84       i2 += 8;
85 
86       const v128_t vk2x0123 = wasm_v128_load(w + 24);
87       const v128_t vk2x4567 = wasm_v128_load(w + 28);
88       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
89       vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi2x4567, vk2x4567));
90 
91       const v128_t vi3x0123 = wasm_v128_load(i3);
92       const v128_t vi3x4567 = wasm_v128_load(i3 + 4);
93       i3 += 8;
94 
95       const v128_t vk3x0123 = wasm_v128_load(w + 32);
96       const v128_t vk3x4567 = wasm_v128_load(w + 36);
97       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
98       vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi3x4567, vk3x4567));
99 
100       w += 40;
101 
102 
103       v128_t vacc0123 = wasm_f32x4_pmax(vmin, vacc0123p0);
104       v128_t vacc4567 = wasm_f32x4_pmax(vmin, vacc4567p0);
105 
106       vacc0123 = wasm_f32x4_pmin(vmax, vacc0123);
107       vacc4567 = wasm_f32x4_pmin(vmax, vacc4567);
108 
109       wasm_v128_store(output, vacc0123);
110       wasm_v128_store(output + 4, vacc4567);
111       output += 8;
112     }
113     for (; c >= 4; c -= 4) {
114       v128_t vacc0123p0 = wasm_v128_load(w);
115 
116       const v128_t vi0x0123 = wasm_v128_load(i0);
117       i0 += 4;
118 
119       const v128_t vk0x0123 = wasm_v128_load(w + 8);
120       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
121 
122       const v128_t vi1x0123 = wasm_v128_load(i1);
123       i1 += 4;
124 
125       const v128_t vk1x0123 = wasm_v128_load(w + 16);
126       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
127 
128       const v128_t vi2x0123 = wasm_v128_load(i2);
129       i2 += 4;
130 
131       const v128_t vk2x0123 = wasm_v128_load(w + 24);
132       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
133 
134       const v128_t vi3x0123 = wasm_v128_load(i3);
135       i3 += 4;
136 
137       const v128_t vk3x0123 = wasm_v128_load(w + 32);
138       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
139 
140       w += 4;
141 
142 
143       v128_t vacc0123 = wasm_f32x4_pmax(vmin, vacc0123p0);
144       vacc0123 = wasm_f32x4_pmin(vmax, vacc0123);
145 
146       wasm_v128_store(output, vacc0123);
147       output += 4;
148     }
149     if XNN_UNLIKELY(c != 0) {
150       v128_t vacc0123p0 = wasm_v128_load(w);
151 
152       const v128_t vi0x0123 = wasm_v128_load(i0);
153       const v128_t vk0x0123 = wasm_v128_load(w + 8);
154       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
155 
156       const v128_t vi1x0123 = wasm_v128_load(i1);
157       const v128_t vk1x0123 = wasm_v128_load(w + 16);
158       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
159 
160       const v128_t vi2x0123 = wasm_v128_load(i2);
161       const v128_t vk2x0123 = wasm_v128_load(w + 24);
162       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
163 
164       const v128_t vi3x0123 = wasm_v128_load(i3);
165       const v128_t vk3x0123 = wasm_v128_load(w + 32);
166       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
167 
168 
169       v128_t vacc0123 = wasm_f32x4_pmax(vmin, vacc0123p0);
170       vacc0123 = wasm_f32x4_pmin(vmax, vacc0123);
171 
172       if (c & 2) {
173         *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
174         vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
175         output += 2;
176       }
177       if (c & 1) {
178         *output = wasm_f32x4_extract_lane(vacc0123, 0);
179         output += 1;
180       }
181     }
182 
183     output = (float*) ((uintptr_t) output + output_increment);
184   } while (--output_width != 0);
185 }
186