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