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_ukernel_up4x4__wasmsimd(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_default_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_dwconv_ukernel_up4x4__wasmsimd(
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_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29 assert(channels != 0);
30 assert(output_width != 0);
31
32 do {
33 const float* i0 = input[0];
34 assert(i0 != NULL);
35 if XNN_UNPREDICTABLE(i0 != zero) {
36 i0 = (const float*) ((uintptr_t) i0 + input_offset);
37 }
38 const float* i1 = input[1];
39 assert(i1 != NULL);
40 if XNN_UNPREDICTABLE(i1 != zero) {
41 i1 = (const float*) ((uintptr_t) i1 + input_offset);
42 }
43 const float* i2 = input[2];
44 assert(i2 != NULL);
45 if XNN_UNPREDICTABLE(i2 != zero) {
46 i2 = (const float*) ((uintptr_t) i2 + input_offset);
47 }
48 const float* i3 = input[3];
49 assert(i3 != NULL);
50 if XNN_UNPREDICTABLE(i3 != zero) {
51 i3 = (const float*) ((uintptr_t) i3 + input_offset);
52 }
53 input = (const float**) ((uintptr_t) input + input_stride);
54
55 size_t c = channels;
56 const float* w = weights;
57 for (; c >= 4; c -= 4) {
58 v128_t vacc0123p0 = wasm_v128_load(w);
59
60
61 const v128_t vi0x0123 = wasm_v128_load(i0);
62 i0 += 4;
63
64 const v128_t vk0x0123 = wasm_v128_load(w + 4);
65 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
66
67 const v128_t vi1x0123 = wasm_v128_load(i1);
68 i1 += 4;
69
70 const v128_t vk1x0123 = wasm_v128_load(w + 8);
71 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
72
73 const v128_t vi2x0123 = wasm_v128_load(i2);
74 i2 += 4;
75
76 const v128_t vk2x0123 = wasm_v128_load(w + 12);
77 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
78
79 const v128_t vi3x0123 = wasm_v128_load(i3);
80 i3 += 4;
81
82 const v128_t vk3x0123 = wasm_v128_load(w + 16);
83 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
84
85 w += 20;
86
87
88 const v128_t vacc0123 = vacc0123p0;
89
90 wasm_v128_store(output, vacc0123);
91 output += 4;
92 }
93 if XNN_UNLIKELY(c != 0) {
94 v128_t vacc0123p0 = wasm_v128_load(w);
95
96 const v128_t vi0x0123 = wasm_v128_load(i0);
97 const v128_t vk0x0123 = wasm_v128_load(w + 4);
98 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
99
100 const v128_t vi1x0123 = wasm_v128_load(i1);
101 const v128_t vk1x0123 = wasm_v128_load(w + 8);
102 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
103
104 const v128_t vi2x0123 = wasm_v128_load(i2);
105 const v128_t vk2x0123 = wasm_v128_load(w + 12);
106 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
107
108 const v128_t vi3x0123 = wasm_v128_load(i3);
109 const v128_t vk3x0123 = wasm_v128_load(w + 16);
110 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
111
112
113 v128_t vacc0123 = vacc0123p0;
114
115 if (c & 2) {
116 *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
117 vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
118 output += 2;
119 }
120 if (c & 1) {
121 *output = wasm_f32x4_extract_lane(vacc0123, 0);
122 output += 1;
123 }
124 }
125
126 output = (float*) ((uintptr_t) output + output_increment);
127 } while (--output_width != 0);
128 }
129