• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_up4x4__wasmsimd_arm(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_up4x4__wasmsimd_arm(
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_DISABLE_TSAN
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
33   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.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     const float* i3 = input[3];
51     assert(i3 != NULL);
52     if XNN_UNPREDICTABLE(i3 != zero) {
53       i3 = (const float*) ((uintptr_t) i3 + input_offset);
54     }
55     input = (const float**) ((uintptr_t) input + input_stride);
56 
57     size_t c = channels;
58     const float* w = weights;
59     for (; c >= 4; c -= 4) {
60       v128_t vacc0123p0 = wasm_v128_load(w);
61 
62 
63       const v128_t vi0x0123 = wasm_v128_load(i0);
64       i0 += 4;
65 
66       const v128_t vk0x0123 = wasm_v128_load(w + 4);
67       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
68 
69       const v128_t vi1x0123 = wasm_v128_load(i1);
70       i1 += 4;
71 
72       const v128_t vk1x0123 = wasm_v128_load(w + 8);
73       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
74 
75       const v128_t vi2x0123 = wasm_v128_load(i2);
76       i2 += 4;
77 
78       const v128_t vk2x0123 = wasm_v128_load(w + 12);
79       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
80 
81       const v128_t vi3x0123 = wasm_v128_load(i3);
82       i3 += 4;
83 
84       const v128_t vk3x0123 = wasm_v128_load(w + 16);
85       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
86 
87       w += 20;
88 
89 
90       v128_t vacc0123 = wasm_f32x4_max(vacc0123p0, vmin);
91 
92       vacc0123 = wasm_f32x4_min(vacc0123, vmax);
93 
94       wasm_v128_store(output, vacc0123);
95       output += 4;
96     }
97     if XNN_UNLIKELY(c != 0) {
98       v128_t vacc0123p0 = wasm_v128_load(w);
99 
100       const v128_t vi0x0123 = wasm_v128_load(i0);
101       const v128_t vk0x0123 = wasm_v128_load(w + 4);
102       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
103 
104       const v128_t vi1x0123 = wasm_v128_load(i1);
105       const v128_t vk1x0123 = wasm_v128_load(w + 8);
106       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
107 
108       const v128_t vi2x0123 = wasm_v128_load(i2);
109       const v128_t vk2x0123 = wasm_v128_load(w + 12);
110       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
111 
112       const v128_t vi3x0123 = wasm_v128_load(i3);
113       const v128_t vk3x0123 = wasm_v128_load(w + 16);
114       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
115 
116 
117       v128_t vacc0123 = wasm_f32x4_max(vacc0123p0, vmin);
118       vacc0123 = wasm_f32x4_min(vacc0123, vmax);
119 
120       if (c & 2) {
121         *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
122         vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
123         output += 2;
124       }
125       if (c & 1) {
126         *output = wasm_f32x4_extract_lane(vacc0123, 0);
127         output += 1;
128       }
129     }
130 
131     output = (float*) ((uintptr_t) output + output_increment);
132   } while (--output_width != 0);
133 }
134