• 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_acc3(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_acc3(
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       v128_t vo0p1 = wasm_f32x4_mul(vi1x4567, vk11);
91       v128_t vo0p2 = 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       vo0p1 = wasm_f32x4_add(vo0p1, wasm_f32x4_mul(vi1x3456, vk10));
99       vo0p2 = wasm_f32x4_add(vo0p2, 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       vo0p1 = wasm_f32x4_add(vo0p1, wasm_f32x4_mul(vi1x5678, vk12));
111       vo0p2 = wasm_f32x4_add(vo0p2, wasm_f32x4_mul(vi2x5678, vk22));
112 
113       vi0x4567 = vi0x89AB;
114       vi1x4567 = vi1x89AB;
115       vi2x4567 = vi2x89AB;
116 
117       vo0p0 = wasm_f32x4_add(vo0p0, vo0p1);
118       vo0p0 = wasm_f32x4_add(vo0p0, vo0p2);
119 
120       v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
121       vo0 = wasm_f32x4_min(vo0, vmax);
122 
123       wasm_v128_store(o0, vo0);
124       o0 += 4;
125     }
126     // Always process the last block of 1..4 pixels.
127     assert(w >= 1 * sizeof(float));
128     assert(w <= 4 * sizeof(float));
129     {
130       vi0x4567 = wasm_v128_and(vmask, vi0x4567);
131       vi1x4567 = wasm_v128_and(vmask, vi1x4567);
132       vi2x4567 = wasm_v128_and(vmask, vi2x4567);
133 
134       v128_t vo0p0 = wasm_f32x4_add(vbias, wasm_f32x4_mul(vi0x4567, vk01));
135       v128_t vo0p1 = wasm_f32x4_mul(vi1x4567, vk11);
136       v128_t vo0p2 = wasm_f32x4_mul(vi2x4567, vk21);
137 
138       const v128_t vi0x3456 = wasm_v32x4_shuffle(vi0x0123, vi0x4567, 3, 4, 5, 6);
139       const v128_t vi1x3456 = wasm_v32x4_shuffle(vi1x0123, vi1x4567, 3, 4, 5, 6);
140       const v128_t vi2x3456 = wasm_v32x4_shuffle(vi2x0123, vi2x4567, 3, 4, 5, 6);
141 
142       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x3456, vk00));
143       vo0p1 = wasm_f32x4_add(vo0p1, wasm_f32x4_mul(vi1x3456, vk10));
144       vo0p2 = wasm_f32x4_add(vo0p2, wasm_f32x4_mul(vi2x3456, vk20));
145 
146       const v128_t vi0x5678 = wasm_v32x4_shuffle(vi0x4567, vzero, 1, 2, 3, 4);
147       const v128_t vi1x5678 = wasm_v32x4_shuffle(vi1x4567, vzero, 1, 2, 3, 4);
148       const v128_t vi2x5678 = wasm_v32x4_shuffle(vi2x4567, vzero, 1, 2, 3, 4);
149 
150       vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x5678, vk02));
151       vo0p1 = wasm_f32x4_add(vo0p1, wasm_f32x4_mul(vi1x5678, vk12));
152       vo0p2 = wasm_f32x4_add(vo0p2, wasm_f32x4_mul(vi2x5678, vk22));
153 
154       vo0p0 = wasm_f32x4_add(vo0p0, vo0p1);
155       vo0p0 = wasm_f32x4_add(vo0p0, vo0p2);
156 
157       v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
158       vo0 = wasm_f32x4_min(vo0, vmax);
159 
160       if XNN_LIKELY(w == 4 * sizeof(float)) {
161         wasm_v128_store(o0, vo0);
162         o0 += 4;
163       } else {
164         if (w & (2 * sizeof(float))) {
165           *((double*) o0) = wasm_f64x2_extract_lane(vo0, 0);
166           o0 += 2;
167 
168           vo0 = wasm_v32x4_shuffle(vo0, vo0, 2, 3, 0, 1);
169         }
170         if (w & (1 * sizeof(float))) {
171           *o0 = wasm_f32x4_extract_lane(vo0, 0);
172           o0 += 1;
173         }
174       }
175     }
176 
177     i0 = (const float*) ((uintptr_t) i1 - input_decrement);
178     i1 = (const float*) ((uintptr_t) i2 - input_decrement);
179     i2 = (const float*) ((uintptr_t) i1 + input_width);
180 
181 
182   } while (--output_height != 0);
183 }
184