xref: /aosp_15_r20/external/XNNPACK/src/f32-prelu/gen/wasmsimd-minmax-1x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-prelu/wasmsimd-minmax.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/math.h>
15 #include <xnnpack/prelu.h>
16 
17 
xnn_f32_prelu_ukernel__wasmsimd_minmax_1x8(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)18 void xnn_f32_prelu_ukernel__wasmsimd_minmax_1x8(
19     size_t rows,
20     size_t channels,
21     const float*restrict input,
22     size_t input_stride,
23     const float*restrict weights,
24     float*restrict output,
25     size_t output_stride) XNN_OOB_READS
26 {
27   assert(rows != 0);
28   assert(channels != 0);
29   assert(channels % sizeof(float) == 0);
30 
31   const float* i0 = input;
32   float* o0 = output;
33 
34   const size_t input_increment = input_stride * 1 - channels;
35   const size_t output_increment = output_stride * 1 - channels;
36 
37   const v128_t vzero = wasm_i32x4_const_splat(0);
38   do {
39 
40     const float* w = weights;
41     size_t c = channels;
42     for (; c >= 8 * sizeof(float); c -= 8 * sizeof(float)) {
43       const v128_t vw0123 = wasm_v128_load(w);
44       const v128_t vw4567 = wasm_v128_load(w + 4);
45       w += 8;
46 
47       v128_t vi0x0123 = wasm_v128_load(i0);
48       v128_t vi0x4567 = wasm_v128_load(i0 + 4);
49       i0 += 8;
50 
51       v128_t vacc0x0123 = wasm_i32x4_max(vi0x0123, vzero);
52       vi0x0123 = wasm_i32x4_min(vi0x0123, vzero);
53       v128_t vacc0x4567 = wasm_i32x4_max(vi0x4567, vzero);
54       vi0x4567 = wasm_i32x4_min(vi0x4567, vzero);
55 
56       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(vi0x0123, vw0123));
57       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(vi0x4567, vw4567));
58 
59       wasm_v128_store(o0, vacc0x0123);
60       wasm_v128_store(o0 + 4, vacc0x4567);
61       o0 += 8;
62     }
63     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
64       const v128_t vw0123 = wasm_v128_load(w);
65       w += 4;
66 
67       v128_t vi0x0123 = wasm_v128_load(i0);
68       i0 += 4;
69 
70       v128_t vacc0x0123 = wasm_i32x4_max(vi0x0123, vzero);
71       vi0x0123 = wasm_i32x4_min(vi0x0123, vzero);
72 
73       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(vi0x0123, vw0123));
74 
75       wasm_v128_store(o0, vacc0x0123);
76       o0 += 4;
77     }
78     if XNN_UNLIKELY(c != 0) {
79       const v128_t vw0123 = wasm_v128_load(w);
80       w = (const float*) ((uintptr_t) w + c);
81 
82       v128_t vi0x0123 = wasm_v128_load(i0);
83       i0 = (const float*) ((uintptr_t) i0 + c);
84 
85       v128_t vacc0x0123 = wasm_i32x4_max(vi0x0123, vzero);
86       vi0x0123 = wasm_i32x4_min(vi0x0123, vzero);
87 
88       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(vi0x0123, vw0123));
89 
90       if (c & (2 * sizeof(float))) {
91         *((double*) o0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
92 
93         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
94 
95         o0 += 2;
96       }
97       if (c & (1 * sizeof(float))) {
98         *o0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
99 
100         o0 += 1;
101       }
102     }
103     i0 = (const float*) ((uintptr_t) i0 + input_increment);
104     o0 = (float*) ((uintptr_t) o0 + output_increment);
105     rows = doz(rows, 1);
106   } while (rows != 0);
107 }
108