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_up4x3__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_up4x3__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 input = (const float**) ((uintptr_t) input + input_stride);
51
52 size_t c = channels;
53 const float* w = weights;
54 for (; c >= 4; c -= 4) {
55 v128_t vacc0123p0 = wasm_v128_load(w);
56
57
58 const v128_t vi0x0123 = wasm_v128_load(i0);
59 i0 += 4;
60
61 const v128_t vk0x0123 = wasm_v128_load(w + 4);
62 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
63
64 const v128_t vi1x0123 = wasm_v128_load(i1);
65 i1 += 4;
66
67 const v128_t vk1x0123 = wasm_v128_load(w + 8);
68 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
69
70 const v128_t vi2x0123 = wasm_v128_load(i2);
71 i2 += 4;
72
73 const v128_t vk2x0123 = wasm_v128_load(w + 12);
74 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
75
76 w += 16;
77
78
79 v128_t vacc0123 = wasm_f32x4_pmax(vmin, vacc0123p0);
80
81 vacc0123 = wasm_f32x4_pmin(vmax, vacc0123);
82
83 wasm_v128_store(output, vacc0123);
84 output += 4;
85 }
86 if XNN_UNLIKELY(c != 0) {
87 v128_t vacc0123p0 = wasm_v128_load(w);
88
89 const v128_t vi0x0123 = wasm_v128_load(i0);
90 const v128_t vk0x0123 = wasm_v128_load(w + 4);
91 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
92
93 const v128_t vi1x0123 = wasm_v128_load(i1);
94 const v128_t vk1x0123 = wasm_v128_load(w + 8);
95 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
96
97 const v128_t vi2x0123 = wasm_v128_load(i2);
98 const v128_t vk2x0123 = wasm_v128_load(w + 12);
99 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
100
101
102 v128_t vacc0123 = wasm_f32x4_pmax(vmin, vacc0123p0);
103 vacc0123 = wasm_f32x4_pmin(vmax, vacc0123);
104
105 if (c & 2) {
106 *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
107 vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
108 output += 2;
109 }
110 if (c & 1) {
111 *output = wasm_f32x4_extract_lane(vacc0123, 0);
112 output += 1;
113 }
114 }
115
116 output = (float*) ((uintptr_t) output + output_increment);
117 } while (--output_width != 0);
118 }
119