• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/3x3p1-wasmsimd-loadsplat.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 
15 #include <xnnpack/dwconv.h>
16 #include <xnnpack/math.h>
17 
18 
19 
xnn_f32_dwconv2d_chw_ukernel_3x3p1__wasmsimd_arm_loadsplat_1x4(size_t input_height,size_t input_width,const float * input,const float * weights,const float * zero,float * output,uint32_t padding_top,const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f32_dwconv2d_chw_ukernel_3x3p1__wasmsimd_arm_loadsplat_1x4(
21     size_t input_height,
22     size_t input_width,
23     const float* input,
24     const float* weights,
25     const float* zero,
26     float* output,
27     uint32_t padding_top,
28     const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(input_height != 0);
31   assert(input_width != 0);
32   assert(input_width % sizeof(float) == 0);
33   assert(padding_top == 1);
34 
35   const v128_t vmask = wasm_v128_load(params->scalar.mask);
36   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
37   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
38 
39   const v128_t vw0123 = wasm_v128_load(weights);
40   const v128_t vw4567 = wasm_v128_load(weights + 4);
41   const v128_t vw89 = wasm_v64x2_load_splat(weights + 8);
42   const v128_t vbias = wasm_v32x4_shuffle(vw0123, vw0123, 0, 0, 0, 0);
43   const v128_t vk00 = wasm_v32x4_shuffle(vw0123, vw0123, 1, 1, 1, 1);
44   const v128_t vk01 = wasm_v32x4_shuffle(vw0123, vw0123, 2, 2, 2, 2);
45   const v128_t vk02 = wasm_v32x4_shuffle(vw0123, vw0123, 3, 3, 3, 3);
46   const v128_t vk10 = wasm_v32x4_shuffle(vw4567, vw4567, 0, 0, 0, 0);
47   const v128_t vk11 = wasm_v32x4_shuffle(vw4567, vw4567, 1, 1, 1, 1);
48   const v128_t vk12 = wasm_v32x4_shuffle(vw4567, vw4567, 2, 2, 2, 2);
49   const v128_t vk20 = wasm_v32x4_shuffle(vw4567, vw4567, 3, 3, 3, 3);
50   const v128_t vk21 = wasm_v32x4_shuffle(vw89, vw89, 0, 0, 0, 0);
51   const v128_t vk22 = wasm_v32x4_shuffle(vw89, vw89, 1, 1, 1, 1);
52 
53   const v128_t vzero = wasm_f32x4_splat(0.0f);
54 
55   const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
56 
57   const float* i0 = zero;
58   const float* i1 = input;
59   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
60 
61   float* o0 = output;
62 
63   size_t output_height = input_height;
64   do {
65     if XNN_UNPREDICTABLE(output_height < 2) {
66       i2 = zero;
67     }
68 
69     v128_t vi0x0123 = vzero;
70     v128_t vi1x0123 = vzero;
71     v128_t vi2x0123 = vzero;
72 
73     v128_t vi0x4567 = wasm_v128_load(i0);
74     i0 += 4;
75     v128_t vi1x4567 = wasm_v128_load(i1);
76     i1 += 4;
77     v128_t vi2x4567 = wasm_v128_load(i2);
78     i2 += 4;
79 
80     size_t w = input_width;
81     for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
82       const v128_t vi0x89AB = wasm_v128_load(i0);
83       i0 += 4;
84       const v128_t vi1x89AB = wasm_v128_load(i1);
85       i1 += 4;
86       const v128_t vi2x89AB = wasm_v128_load(i2);
87       i2 += 4;
88 
89       v128_t vo0p0 = wasm_f32x4_add(vbias, wasm_f32x4_mul(vi0x4567, vk01));
90       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x4567, vk11));
91       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x4567, vk21));
92 
93       const v128_t vi0x3456 = wasm_v32x4_shuffle(vi0x0123, vi0x4567, 3, 4, 5, 6);
94       const v128_t vi1x3456 = wasm_v32x4_shuffle(vi1x0123, vi1x4567, 3, 4, 5, 6);
95       const v128_t vi2x3456 = wasm_v32x4_shuffle(vi2x0123, vi2x4567, 3, 4, 5, 6);
96 
97       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x3456, vk00));
98       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x3456, vk10));
99       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x3456, vk20));
100 
101       vi0x0123 = vi0x4567;
102       vi1x0123 = vi1x4567;
103       vi2x0123 = vi2x4567;
104 
105       const v128_t vi0x5678 = wasm_v32x4_shuffle(vi0x4567, vi0x89AB, 1, 2, 3, 4);
106       const v128_t vi1x5678 = wasm_v32x4_shuffle(vi1x4567, vi1x89AB, 1, 2, 3, 4);
107       const v128_t vi2x5678 = wasm_v32x4_shuffle(vi2x4567, vi2x89AB, 1, 2, 3, 4);
108 
109       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x5678, vk02));
110       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x5678, vk12));
111       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x5678, vk22));
112 
113       vi0x4567 = vi0x89AB;
114       vi1x4567 = vi1x89AB;
115       vi2x4567 = vi2x89AB;
116 
117 
118       v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
119       vo0 = wasm_f32x4_min(vo0, vmax);
120 
121       wasm_v128_store(o0, vo0);
122       o0 += 4;
123     }
124     // Always process the last block of 1..4 pixels.
125     assert(w >= 1 * sizeof(float));
126     assert(w <= 4 * sizeof(float));
127     {
128       vi0x4567 = wasm_v128_and(vmask, vi0x4567);
129       vi1x4567 = wasm_v128_and(vmask, vi1x4567);
130       vi2x4567 = wasm_v128_and(vmask, vi2x4567);
131 
132       v128_t vo0p0 = wasm_f32x4_add(vbias, wasm_f32x4_mul(vi0x4567, vk01));
133       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x4567, vk11));
134       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x4567, vk21));
135 
136       const v128_t vi0x3456 = wasm_v32x4_shuffle(vi0x0123, vi0x4567, 3, 4, 5, 6);
137       const v128_t vi1x3456 = wasm_v32x4_shuffle(vi1x0123, vi1x4567, 3, 4, 5, 6);
138       const v128_t vi2x3456 = wasm_v32x4_shuffle(vi2x0123, vi2x4567, 3, 4, 5, 6);
139 
140       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x3456, vk00));
141       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x3456, vk10));
142       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x3456, vk20));
143 
144       const v128_t vi0x5678 = wasm_v32x4_shuffle(vi0x4567, vzero, 1, 2, 3, 4);
145       const v128_t vi1x5678 = wasm_v32x4_shuffle(vi1x4567, vzero, 1, 2, 3, 4);
146       const v128_t vi2x5678 = wasm_v32x4_shuffle(vi2x4567, vzero, 1, 2, 3, 4);
147 
148       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x5678, vk02));
149       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x5678, vk12));
150       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x5678, vk22));
151 
152 
153       v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
154       vo0 = wasm_f32x4_min(vo0, vmax);
155 
156       if XNN_LIKELY(w == 4 * sizeof(float)) {
157         wasm_v128_store(o0, vo0);
158         o0 += 4;
159       } else {
160         if (w & (2 * sizeof(float))) {
161           *((double*) o0) = wasm_f64x2_extract_lane(vo0, 0);
162           o0 += 2;
163 
164           vo0 = wasm_v32x4_shuffle(vo0, vo0, 2, 3, 0, 1);
165         }
166         if (w & (1 * sizeof(float))) {
167           *o0 = wasm_f32x4_extract_lane(vo0, 0);
168           o0 += 1;
169         }
170       }
171     }
172 
173     i0 = (const float*) ((uintptr_t) i1 - input_decrement);
174     i1 = (const float*) ((uintptr_t) i2 - input_decrement);
175     i2 = (const float*) ((uintptr_t) i1 + input_width);
176 
177 
178   } while (--output_height != 0);
179 }
180